diff --git a/src/gateway/server-methods/chat.directive-tags.test.ts b/src/gateway/server-methods/chat.directive-tags.test.ts index 5d4412318c7..b6af0120a4d 100644 --- a/src/gateway/server-methods/chat.directive-tags.test.ts +++ b/src/gateway/server-methods/chat.directive-tags.test.ts @@ -307,6 +307,7 @@ function createChatContext(): Pick< | "chatDeltaSentAt" | "chatDeltaLastBroadcastLen" | "chatAbortedRuns" + | "addChatRun" | "removeChatRun" | "dedupe" | "loadGatewayModelCatalog" @@ -322,6 +323,7 @@ function createChatContext(): Pick< chatDeltaSentAt: new Map(), chatDeltaLastBroadcastLen: new Map(), chatAbortedRuns: new Map(), + addChatRun: vi.fn(), removeChatRun: vi.fn(), dedupe: new Map(), loadGatewayModelCatalog: async () => diff --git a/src/gateway/server-methods/chat.ts b/src/gateway/server-methods/chat.ts index cea6b4707f4..5a8c7c608ee 100644 --- a/src/gateway/server-methods/chat.ts +++ b/src/gateway/server-methods/chat.ts @@ -2248,6 +2248,10 @@ export const chatHandlers: GatewayRequestHandlers = { ownerConnId: normalizeOptionalText(client?.connId), ownerDeviceId: normalizeOptionalText(client?.connect?.device?.id), }); + context.addChatRun(clientRunId, { + sessionKey, + clientRunId, + }); const ackPayload = { runId: clientRunId, status: "started" as const, @@ -2740,8 +2744,11 @@ export const chatHandlers: GatewayRequestHandlers = { }) .finally(() => { context.chatAbortControllers.delete(clientRunId); + context.removeChatRun(clientRunId, clientRunId, sessionKey); }); } catch (err) { + context.chatAbortControllers.delete(clientRunId); + context.removeChatRun(clientRunId, clientRunId, sessionKey); const error = errorShape(ErrorCodes.UNAVAILABLE, String(err)); const payload = { runId: clientRunId,