Skip to content

Commit 76ab9a7

Browse files
authored
fix(agents): treat observed CLI activity as replay-unsafe for whole-turn retries (#122153)
1 parent 7fb18bf commit 76ab9a7

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "../../agents/embedded-agent-helpers.js";
88
import { sanitizeUserFacingText } from "../../agents/embedded-agent-helpers/sanitize-user-facing-text.js";
99
import { renderUserFacingText } from "../../agents/embedded-agent-helpers/user-facing-text.js";
10-
import { isFailoverError } from "../../agents/failover-error.js";
10+
import { findCliTimeoutError, isFailoverError } from "../../agents/failover-error.js";
1111
import {
1212
GENERIC_EXTERNAL_RUN_FAILURE_TEXT,
1313
HEARTBEAT_EXTERNAL_RUN_FAILURE_TEXT,
@@ -263,6 +263,11 @@ export async function handleAgentExecutionError(params: {
263263
}),
264264
};
265265
}
266+
// The CLI boundary records this fact even when phase callbacks do not arrive.
267+
// Replaying an observed turn may duplicate already-started side effects.
268+
if (findCliTimeoutError(err)?.cliTimeout.observedActivity === true) {
269+
markOverloadRetryUnsafeToReplay(params.overloadRetryState);
270+
}
266271
if (
267272
isOverloaded &&
268273
!params.overloadRetryState.unsafeToReplay &&

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,9 @@ describe("executeAgentTurn: provider failures", () => {
529529
},
530530
);
531531

532-
it("currently retries a CLI timeout whose recorded activity has no execution phase mark", async () => {
532+
it("does not retry a CLI timeout whose recorded activity has no execution phase mark", async () => {
533533
vi.useFakeTimers();
534-
// BUG(refactor-02b): replay guard ignores recorded cliTimeout.observedActivity; fixed in B2
534+
// FIXED(refactor-02b): the typed CLI activity fact blocks whole-turn replay without a phase mark.
535535
const timeoutError = new FailoverError("CLI exceeded timeout (600s) and was terminated.", {
536536
reason: "timeout",
537537
provider: "claude-cli",
@@ -561,16 +561,16 @@ describe("executeAgentTurn: provider failures", () => {
561561
await vi.advanceTimersByTimeAsync(2_500);
562562
const result = await resultPromise;
563563

564-
expect(state.runCliAgentMock).toHaveBeenCalledTimes(2);
565-
expect(state.runWithModelFallbackMock).toHaveBeenCalledTimes(2);
564+
expect(state.runCliAgentMock).toHaveBeenCalledTimes(1);
565+
expect(state.runWithModelFallbackMock).toHaveBeenCalledTimes(1);
566566
expect(state.runEmbeddedAgentMock).not.toHaveBeenCalled();
567567
const wholeTurnRetries = state.runCliAgentMock.mock.calls.length - 1;
568-
expect(wholeTurnRetries).toBe(1);
568+
expect(wholeTurnRetries).toBe(0);
569569
expect(result.kind).toBe("final");
570570
if (result.kind === "final") {
571571
expect(result.payload.text).toContain("overall turn limit");
572572
expect(result.payload.text).toMatch(/effects may be partial/i);
573-
expect(result.payload.text).not.toContain("did not replay this turn automatically");
573+
expect(result.payload.text).toContain("did not replay this turn automatically");
574574
}
575575
});
576576

0 commit comments

Comments
 (0)