Skip to content

Commit af9a230

Browse files
authored
fix(agents): bind failed wait recovery to tool call (#128098)
1 parent 3e0ee38 commit af9a230

2 files changed

Lines changed: 51 additions & 29 deletions

File tree

‎src/agents/main-session-recovery/main-session-restart-recovery-resume-policy.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,7 @@ export function resolveMainSessionResumePolicy(
437437
return { action: "resume", forceRestartSafeTools: true };
438438
}
439439
if (isRestartAbortedWaitFailure(lastMeaningful)) {
440-
const waitCall = readCodeModeWaitCall(meaningfulMessages[1]);
441-
const checkpoint = readCodeModeCheckpoint(meaningfulMessages[2]);
442-
return waitCall && checkpoint?.replaySafe === true && checkpoint.runId === waitCall.runId
443-
? { action: "resume", forceRestartSafeTools: true, forceCodeModeTools: true }
444-
: { action: "resume", forceRestartSafeTools: true };
440+
return { action: "resume", forceRestartSafeTools: true };
445441
}
446442
const waitCall = readCodeModeWaitCall(lastMeaningful);
447443
if (waitCall) {

‎src/agents/main-session-recovery/main-session-restart-recovery.test.ts‎

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5102,31 +5102,57 @@ describe("main-session-restart-recovery", () => {
51025102
});
51035103
});
51045104

5105-
it("keeps an unmatched failed wait restricted when its checkpoint is replay-safe", async () => {
5106-
await writeMainSessionTranscript([
5107-
{ role: "user", content: "do the thing" },
5108-
codeModeCheckpointMessage(),
5109-
codeModeWaitCallMessage(),
5110-
{
5111-
role: "toolResult",
5112-
toolName: "wait",
5113-
toolCallId: "call-other",
5114-
content: [{ type: "text", text: "Error: The operation was aborted." }],
5115-
details: {
5116-
status: "failed",
5117-
error: "Error: The operation was aborted.",
5118-
code: "internal_error",
5119-
},
5120-
isError: true,
5121-
},
5122-
]);
5105+
it.each([
5106+
{
5107+
label: "matching failed-wait result identity",
5108+
toolCallIds: ["call-wait-1"],
5109+
restoresCodeModeTools: true,
5110+
},
5111+
{
5112+
label: "mismatched failed-wait result identity",
5113+
toolCallIds: ["call-other"],
5114+
restoresCodeModeTools: false,
5115+
},
5116+
{
5117+
label: "missing failed-wait result identity",
5118+
toolCallIds: [undefined],
5119+
restoresCodeModeTools: false,
5120+
},
5121+
{
5122+
label: "duplicate failed-wait result identities",
5123+
toolCallIds: ["call-wait-1", "call-wait-1"],
5124+
restoresCodeModeTools: false,
5125+
},
5126+
])(
5127+
"restores Code Mode tools only for exactly one $label",
5128+
async ({ toolCallIds, restoresCodeModeTools }) => {
5129+
await writeMainSessionTranscript([
5130+
{ role: "user", content: "do the thing" },
5131+
codeModeCheckpointMessage(),
5132+
codeModeWaitCallMessage(),
5133+
...toolCallIds.map((toolCallId) => ({
5134+
role: "toolResult",
5135+
toolName: "wait",
5136+
...(toolCallId ? { toolCallId } : {}),
5137+
content: [{ type: "text", text: "Error: The operation was aborted." }],
5138+
details: {
5139+
status: "failed",
5140+
error: "Error: The operation was aborted.",
5141+
code: "internal_error",
5142+
},
5143+
isError: true,
5144+
})),
5145+
]);
51235146

5124-
await expectRecovery({ recovered: 1, failed: 0, skipped: 0 });
5125-
expect(gatewayParams()).toMatchObject({
5126-
forceRestartSafeTools: true,
5127-
forceCodeModeTools: true,
5128-
});
5129-
});
5147+
await expectRecovery({ recovered: 1, failed: 0, skipped: 0 });
5148+
expect(gatewayParams()).toMatchObject({ forceRestartSafeTools: true });
5149+
if (restoresCodeModeTools) {
5150+
expect(gatewayParams()).toMatchObject({ forceCodeModeTools: true });
5151+
} else {
5152+
expect(gatewayParams()).not.toHaveProperty("forceCodeModeTools");
5153+
}
5154+
},
5155+
);
51305156

51315157
it.each([
51325158
{

0 commit comments

Comments
 (0)