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 authored and Peter Steinberger committed 2026-01-12 00:53:20 +00:00
1 parent 7d6f17d77f
commit d4e9f23ee9
4 files changed
+68 -15

No files matched your search

+11 -1
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 };
}