From fd1dd6fa80ee0a1a58a78fbbb266a9c7384ba32a Mon Sep 17 00:00:00 2001 From: Bryan Marty Date: Tue, 10 Mar 2026 01:44:44 +0000 Subject: [PATCH] fix: merge accountId when preferring live delivery context for restart sentinel When liveContext (gateway-tool.ts) or paramsDeliveryContext (config.ts) is present but lacks an accountId, fall back to the accountId from the extracted session store rather than dropping it entirely. This prevents restart follow-up notices from being misrouted on multi-account channels when callers supply channel/to without an explicit accountId. Addresses CR comments on PR #34580. --- src/agents/tools/gateway-tool.ts | 8 +++++++- src/gateway/server-methods/config.ts | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/agents/tools/gateway-tool.ts b/src/agents/tools/gateway-tool.ts index b47293f0106..ca125deb6a6 100644 --- a/src/agents/tools/gateway-tool.ts +++ b/src/agents/tools/gateway-tool.ts @@ -157,7 +157,13 @@ export function createGatewayTool(opts?: { } : undefined; const extracted = extractDeliveryInfo(sessionKey); - const deliveryContext = liveContext ?? extracted.deliveryContext; + const deliveryContext = + liveContext != null + ? { + ...liveContext, + accountId: liveContext.accountId ?? extracted.deliveryContext?.accountId, + } + : extracted.deliveryContext; // Guard threadId with the same session check as deliveryContext. When // targeting another session, opts.agentThreadId belongs to the current // session's thread and must not be written into the sentinel — it would diff --git a/src/gateway/server-methods/config.ts b/src/gateway/server-methods/config.ts index 7c9e4cf95a0..e3300d02045 100644 --- a/src/gateway/server-methods/config.ts +++ b/src/gateway/server-methods/config.ts @@ -205,7 +205,13 @@ function resolveConfigRestartRequest(params: unknown): { const { deliveryContext: extractedDeliveryContext, threadId: extractedThreadId } = extractDeliveryInfo(sessionKey); const paramsDeliveryContext = parseDeliveryContextFromParams(params); - const deliveryContext = paramsDeliveryContext ?? extractedDeliveryContext; + const deliveryContext = + paramsDeliveryContext != null + ? { + ...paramsDeliveryContext, + accountId: paramsDeliveryContext.accountId ?? extractedDeliveryContext?.accountId, + } + : extractedDeliveryContext; const threadId = paramsDeliveryContext?.threadId ?? extractedThreadId; return {