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

@@ -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