Skip to content

Commit 1bf7dd9

Browse files
committed
fix(gateway): reset restart-recovery budget on fresh non-recovery start
Address ClawSweeper P1: a quarantined main-session row that accepts a new user turn retained its over-budget restartRecoveryAttempts, so the next unrelated interruption was quarantined immediately. Clear the budget + quarantine metadata on a fresh non-recovery 'start' (not only on 'done'); restart-recovery starts are already excluded via isRestartRecoveryLifecycleEvent, so a start reaching here is a genuine new turn. Adds regression test. Fixes #95750.
1 parent 6849da1 commit 1bf7dd9

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎src/gateway/session-lifecycle-state.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,28 @@ describe("session lifecycle state", () => {
556556
});
557557
});
558558

559+
it("clears the restart-recovery budget + quarantine on a fresh non-recovery start (#95750)", () => {
560+
expectPersistedLifecyclePatch({
561+
entry: {
562+
restartRecoveryAttempts: 4,
563+
restartRecoveryQuarantinedAt: "2026-06-23T00:00:00.000Z",
564+
restartRecoveryQuarantineReason: "exceeded_restart_retry_budget",
565+
},
566+
data: { phase: "start", startedAt: 1_500 },
567+
expected: {
568+
updatedAt: 1_500,
569+
status: "running",
570+
startedAt: 1_500,
571+
endedAt: undefined,
572+
runtimeMs: undefined,
573+
abortedLastRun: false,
574+
restartRecoveryAttempts: undefined,
575+
restartRecoveryQuarantinedAt: undefined,
576+
restartRecoveryQuarantineReason: undefined,
577+
},
578+
});
579+
});
580+
559581
it("leaves the restart-recovery budget untouched on a non-successful run (#95750)", () => {
560582
expectPersistedLifecyclePatch({
561583
entry: {

‎src/gateway/session-lifecycle-state.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,18 @@ export function derivePersistedSessionLifecyclePatch(params: {
194194
...snapshot,
195195
updatedAt: typeof snapshot.updatedAt === "number" ? snapshot.updatedAt : undefined,
196196
};
197-
// A genuinely successful run means the session is no longer wedged: clear the
198-
// cross-boot restart-recovery budget and any quarantine so a future, unrelated
199-
// interruption gets a fresh attempt allowance. See #95750.
200-
if (snapshot.status === "done") {
197+
// Fresh progress means the session is no longer wedged: clear the cross-boot
198+
// restart-recovery budget and any quarantine so a future, unrelated
199+
// interruption gets a fresh attempt allowance. This must fire on BOTH a
200+
// genuinely successful run (`done`) AND a fresh non-recovery `start` — a
201+
// quarantined row that accepts a new user turn otherwise retains its
202+
// over-budget count, so the next unrelated interruption is quarantined
203+
// immediately. Restart-recovery start events are excluded above via
204+
// isRestartRecoveryLifecycleEvent, so a `start` reaching here is a genuine
205+
// new turn, not a recovery resume. See #95750.
206+
const clearsRecoveryBudget =
207+
snapshot.status === "done" || resolveLifecyclePhase(params.event) === "start";
208+
if (clearsRecoveryBudget) {
201209
if (normalizeRecoveryAttempts(params.entry?.restartRecoveryAttempts) > 0) {
202210
patch.restartRecoveryAttempts = undefined;
203211
}

0 commit comments

Comments
 (0)