refactor(gateway): use canonical session store keys

This commit is contained in:
Peter Steinberger
2026-01-12 01:21:44 +00:00
parent c1236e86fa
commit f504bfdde8
4 changed files with 50 additions and 32 deletions

View File

@@ -28,7 +28,7 @@ import {
validateAgentParams,
validateAgentWaitParams,
} from "../protocol/index.js";
import { loadSessionEntry, resolveSessionStoreKey } from "../session-utils.js";
import { loadSessionEntry } from "../session-utils.js";
import { formatForLog } from "../ws-log.js";
import { waitForAgentJob } from "./agent-job.js";
import type { GatewayRequestHandlers } from "./types.js";
@@ -146,7 +146,7 @@ export const agentHandlers: GatewayRequestHandlers = {
let cfgForAgent: ReturnType<typeof loadConfig> | undefined;
if (requestedSessionKey) {
const { cfg, storePath, store, entry } =
const { cfg, storePath, store, entry, canonicalKey } =
loadSessionEntry(requestedSessionKey);
cfgForAgent = cfg;
const now = Date.now();
@@ -189,10 +189,7 @@ export const agentHandlers: GatewayRequestHandlers = {
return;
}
resolvedSessionId = sessionId;
const canonicalSessionKey = resolveSessionStoreKey({
cfg,
sessionKey: requestedSessionKey,
});
const canonicalSessionKey = canonicalKey;
const agentId = resolveAgentIdFromSessionKey(canonicalSessionKey);
const mainSessionKey = resolveAgentMainSessionKey({ cfg, agentId });
if (store) {

View File

@@ -32,7 +32,6 @@ import {
loadSessionEntry,
readSessionMessages,
resolveSessionModelRef,
resolveSessionStoreKey,
} from "../session-utils.js";
import { formatForLog } from "../ws-log.js";
import type { GatewayRequestHandlers } from "./types.js";
@@ -223,7 +222,9 @@ export const chatHandlers: GatewayRequestHandlers = {
return;
}
}
const { cfg, storePath, store, entry } = loadSessionEntry(p.sessionKey);
const { cfg, storePath, store, entry, canonicalKey } = loadSessionEntry(
p.sessionKey,
);
const timeoutMs = resolveAgentTimeoutMs({
cfg,
overrideMs: p.timeoutMs,
@@ -307,12 +308,8 @@ export const chatHandlers: GatewayRequestHandlers = {
clientRunId,
});
const storeKey = resolveSessionStoreKey({
cfg,
sessionKey: p.sessionKey,
});
if (store) {
store[storeKey] = sessionEntry;
store[canonicalKey] = sessionEntry;
if (storePath) {
await saveSessionStore(storePath, store);
}