fix(gateway): canonicalize main session aliases

This commit is contained in:
Peter Steinberger
2026-01-12 01:05:43 +00:00
parent d4e9f23ee9
commit 9877733748
6 changed files with 145 additions and 91 deletions

View File

@@ -11,7 +11,6 @@ import {
import { registerAgentRunContext } from "../../infra/agent-events.js";
import { resolveOutboundTarget } from "../../infra/outbound/targets.js";
import { DEFAULT_CHAT_PROVIDER } from "../../providers/registry.js";
import { normalizeMainKey } from "../../routing/session-key.js";
import { defaultRuntime } from "../../runtime.js";
import { resolveSendPolicy } from "../../sessions/send-policy.js";
import {
@@ -29,7 +28,7 @@ import {
validateAgentParams,
validateAgentWaitParams,
} from "../protocol/index.js";
import { loadSessionEntry } from "../session-utils.js";
import { loadSessionEntry, resolveSessionStoreKey } from "../session-utils.js";
import { formatForLog } from "../ws-log.js";
import { waitForAgentJob } from "./agent-job.js";
import type { GatewayRequestHandlers } from "./types.js";
@@ -190,24 +189,21 @@ export const agentHandlers: GatewayRequestHandlers = {
return;
}
resolvedSessionId = sessionId;
const agentId = resolveAgentIdFromSessionKey(requestedSessionKey);
const mainSessionKey = resolveAgentMainSessionKey({
const canonicalSessionKey = resolveSessionStoreKey({
cfg,
agentId,
sessionKey: requestedSessionKey,
});
const rawMainKey = normalizeMainKey(cfg.session?.mainKey);
// Normalize short main key alias to canonical form before store write
const storeKey =
requestedSessionKey === rawMainKey ? mainSessionKey : requestedSessionKey;
const agentId = resolveAgentIdFromSessionKey(canonicalSessionKey);
const mainSessionKey = resolveAgentMainSessionKey({ cfg, agentId });
if (store) {
store[storeKey] = nextEntry;
store[canonicalSessionKey] = nextEntry;
if (storePath) {
await saveSessionStore(storePath, store);
}
}
if (
requestedSessionKey === mainSessionKey ||
requestedSessionKey === rawMainKey
canonicalSessionKey === mainSessionKey ||
canonicalSessionKey === "global"
) {
context.addChatRun(idem, {
sessionKey: requestedSessionKey,