























@@ -91,6 +91,7 @@ import {
9191} from "../session-utils.js";
9292import { applySessionsPatchToStore } from "../sessions-patch.js";
9393import { resolveSessionKeyFromResolveParams } from "../sessions-resolve.js";
94+import { setGatewayDedupeEntry } from "./agent-wait-dedupe.js";
9495import { chatHandlers } from "./chat.js";
9596import type {
9697GatewayClient,
@@ -1314,6 +1315,19 @@ export const sessionsHandlers: GatewayRequestHandlers = {
13141315 canonicalKey,
13151316runId: requestedRunId,
13161317});
1318+// Capture run kinds before the abort because abortChatRunById deletes entries
1319+// from chatAbortControllers synchronously. We use this snapshot to choose the
1320+// correct dedupe namespace: agent-kind runs use "agent:" (their runId equals
1321+// their idempotency key), while chat-send runs use "chat:" so the abort
1322+// snapshot does not collide with the agent RPC dedupe cache.
1323+const preAbortRunKinds = new Map<string, "chat-send" | "agent" | undefined>();
1324+if (requestedRunId) {
1325+preAbortRunKinds.set(requestedRunId, context.chatAbortControllers.get(requestedRunId)?.kind);
1326+} else {
1327+for (const [rid, entry] of context.chatAbortControllers) {
1328+preAbortRunKinds.set(rid, entry.kind);
1329+}
1330+}
13171331let abortedRunId: string | null = null;
13181332await chatHandlers["chat.abort"]({
13191333 req,
@@ -1334,7 +1348,27 @@ export const sessionsHandlers: GatewayRequestHandlers = {
13341348Boolean(normalizeOptionalString(value)),
13351349)
13361350 : [];
1337-abortedRunId = runIds[0] ?? null;
1351+const firstAbortedRunId = runIds[0] ?? null;
1352+abortedRunId = firstAbortedRunId;
1353+if (firstAbortedRunId) {
1354+const endedAt = Date.now();
1355+const runKind = preAbortRunKinds.get(firstAbortedRunId);
1356+const dedupePrefix = runKind === "agent" ? "agent" : "chat";
1357+setGatewayDedupeEntry({
1358+dedupe: context.dedupe,
1359+key: `${dedupePrefix}:${firstAbortedRunId}`,
1360+entry: {
1361+ts: endedAt,
1362+ok: true,
1363+payload: {
1364+status: "timeout",
1365+runId: firstAbortedRunId,
1366+stopReason: "rpc",
1367+ endedAt,
1368+},
1369+},
1370+});
1371+}
13381372respond(
13391373true,
13401374{
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。