Skip to content

Commit f2a46a3

Browse files
committed
fix(gateway): preserve timeout abort stop reason
1 parent d40f1cd commit f2a46a3

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/gateway/server-methods/agent.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,6 +2720,7 @@ describe("gateway agent handler", () => {
27202720
runId: "task-registry-agent-run-abort-error",
27212721
status: "timeout",
27222722
summary: "aborted",
2723+
stopReason: "rpc",
27232724
},
27242725
);
27252726
});
@@ -2762,6 +2763,7 @@ describe("gateway agent handler", () => {
27622763
runId: "task-registry-agent-run-timeout-error",
27632764
status: "timeout",
27642765
summary: "aborted",
2766+
stopReason: "timeout",
27652767
},
27662768
);
27672769
});
@@ -2808,6 +2810,7 @@ describe("gateway agent handler", () => {
28082810
runId: "task-registry-agent-run-wrapped-timeout-error",
28092811
status: "timeout",
28102812
summary: "aborted",
2813+
stopReason: "timeout",
28112814
},
28122815
);
28132816
expect(

src/gateway/server-methods/agent.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ function isGatewayAgentAbortRejection(error: unknown, signal: AbortSignal): bool
631631
return isAbortError(error) || readErrorName(error) === "TimeoutError";
632632
}
633633

634+
function resolveGatewayAgentAbortStopReason(signal: AbortSignal): "rpc" | "timeout" {
635+
return readErrorName(signal.reason) === "TimeoutError" ? "timeout" : "rpc";
636+
}
637+
634638
function resolveAbortedAgentStopReason(entry?: ChatAbortControllerEntry): string {
635639
return entry?.abortStopReason?.trim() || "rpc";
636640
}
@@ -732,11 +736,12 @@ function dispatchAgentRunFromGateway(params: {
732736
});
733737
}
734738
const error = errorShape(ErrorCodes.UNAVAILABLE, renderedErr);
739+
const stopReason = resolveGatewayAgentAbortStopReason(params.abortController.signal);
735740
const payload = {
736741
runId: params.runId,
737742
status: aborted ? ("timeout" as const) : ("error" as const),
738743
summary: aborted ? "aborted" : renderedErr,
739-
...(aborted ? { stopReason: "rpc", timeoutPhase: "gateway_draining" as const } : {}),
744+
...(aborted ? { stopReason, timeoutPhase: "gateway_draining" as const } : {}),
740745
};
741746
setGatewayDedupeEntries({
742747
dedupe: params.context.dedupe,

0 commit comments

Comments
 (0)