Skip to content

Commit 2800715

Browse files
wangmiao0668000666claude
authored andcommitted
fix(auto-reply): honor abortSignal in transient-HTTP retry backoff
The transient-HTTP retry in handleAgentExecutionError slept its full TRANSIENT_HTTP_RETRY_DELAY_MS (2500ms) on a bare setTimeout, ignoring the turn abortSignal. A cancelled turn stayed parked for the whole backoff and then returned { kind: "retry" }, issuing another provider attempt after cancellation. Mirror the sibling overload-retry branch (abort-aware since #109354): sleep via sleepWithAbort with turn.replyOperation?.abortSignal ?? turn.opts?.abortSignal and map a sleep rejection through resolveReplyOperationAbortAction, returning the abort action when set. Co-Authored-By: Claude <[email protected]>
1 parent 4a67522 commit 2800715

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎src/auto-reply/reply/agent-runner-error-handler.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,16 @@ export async function handleAgentExecutionError(params: {
407407
defaultRuntime.error(
408408
`Transient HTTP provider error before reply (${message}). Retrying once in ${TRANSIENT_HTTP_RETRY_DELAY_MS}ms.`,
409409
);
410-
await new Promise<void>((resolve) => {
411-
setTimeout(resolve, TRANSIENT_HTTP_RETRY_DELAY_MS);
412-
});
410+
const retryAbortSignal = turn.replyOperation?.abortSignal ?? turn.opts?.abortSignal;
411+
try {
412+
await sleepWithAbort(TRANSIENT_HTTP_RETRY_DELAY_MS, retryAbortSignal);
413+
} catch (sleepError) {
414+
const abortAction = resolveReplyOperationAbortAction(sleepError);
415+
if (abortAction) {
416+
return abortAction;
417+
}
418+
throw sleepError;
419+
}
413420
return { kind: "retry" };
414421
}
415422
defaultRuntime.error(`Embedded agent failed before reply: ${message}`);

‎src/auto-reply/reply/agent-runner-execution-provider-failures.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,31 @@ describe("runAgentTurnWithFallback: provider failures", () => {
496496
);
497497
});
498498

499+
it("interrupts the transient HTTP retry backoff on abort", async () => {
500+
const runAgentTurnWithFallback = await getRunAgentTurnWithFallback();
501+
vi.useFakeTimers();
502+
state.runEmbeddedAgentMock.mockRejectedValue(
503+
new FailoverError("provider request timed out", {
504+
reason: "timeout",
505+
provider: "anthropic",
506+
model: "claude-opus-4-1",
507+
}),
508+
);
509+
const abortController = new AbortController();
510+
const { replyOperation } = createMockReplyOperation({ abortSignal: abortController.signal });
511+
512+
const resultPromise = runAgentTurnWithFallback(
513+
createMinimalRunAgentTurnParams({ replyOperation }),
514+
);
515+
await vi.advanceTimersByTimeAsync(0);
516+
abortController.abort();
517+
await expect(resultPromise).resolves.toMatchObject({
518+
kind: "final",
519+
payload: { text: SILENT_REPLY_TOKEN },
520+
});
521+
expect(state.runEmbeddedAgentMock).toHaveBeenCalledTimes(1);
522+
});
523+
499524
it("cancels the overload notice immediately when a slow retrying turn is aborted", async () => {
500525
const runAgentTurnWithFallback = await getRunAgentTurnWithFallback();
501526
vi.useFakeTimers();

0 commit comments

Comments
 (0)