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

+9 -6
View File
@@ -189,12 +189,6 @@ export const agentHandlers: GatewayRequestHandlers = {
);
return;
}
if (store) {
store[requestedSessionKey] = nextEntry;
if (storePath) {
await saveSessionStore(storePath, store);
}
}
resolvedSessionId = sessionId;
const agentId = resolveAgentIdFromSessionKey(requestedSessionKey);
const mainSessionKey = resolveAgentMainSessionKey({
@@ -202,6 +196,15 @@ export const agentHandlers: GatewayRequestHandlers = {
agentId,
});
const rawMainKey = normalizeMainKey(cfg.session?.mainKey);
// Normalize short main key alias to canonical form before store write
const storeKey =
requestedSessionKey === rawMainKey ? mainSessionKey : requestedSessionKey;
if (store) {
store[storeKey] = nextEntry;
if (storePath) {
await saveSessionStore(storePath, store);
}
}
if (
requestedSessionKey === mainSessionKey ||
requestedSessionKey === rawMainKey