fix(gateway): normalize session key to canonical form before store writes

Ensure 'main' alias is always stored as 'agent:main:main' to prevent
duplicate entries. Also update loadSessionEntry to check both forms
when looking up entries.

Fixes duplicate main sessions in session store.
This commit is contained in:
user
2026-01-11 07:06:25 +00:00
committed by Peter Steinberger
parent 7d6f17d77f
commit d4e9f23ee9
4 changed files with 68 additions and 15 deletions

View File

@@ -15,6 +15,7 @@ import {
buildGroupDisplayName,
loadSessionStore,
resolveAgentIdFromSessionKey,
resolveAgentMainSessionKey,
resolveSessionTranscriptPath,
resolveStorePath,
type SessionEntry,
@@ -172,7 +173,16 @@ export function loadSessionEntry(sessionKey: string) {
const store = loadSessionStore(storePath);
const parsed = parseAgentSessionKey(sessionKey);
const legacyKey = parsed?.rest;
const entry = store[sessionKey] ?? (legacyKey ? store[legacyKey] : undefined);
// Also try the canonical key if sessionKey is the short mainKey alias
const rawMainKey = normalizeMainKey(sessionCfg?.mainKey);
const canonicalKey =
sessionKey === rawMainKey
? resolveAgentMainSessionKey({ cfg, agentId })
: undefined;
const entry =
store[sessionKey] ??
(legacyKey ? store[legacyKey] : undefined) ??
(canonicalKey ? store[canonicalKey] : undefined);
return { cfg, storePath, store, entry };
}