Repository navigation
fix(agents): add cross-boot retry budget to restart recovery - #96307
zhangqueping wants to merge 1 commit into
Conversation
ea0f7c4 to
6a713e5
Compare
e125e47 to
39d24fb
Compare
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close: this PR targets the same restart-recovery retry-budget bug as #96230, but this branch is now conflicting and stale against current main while the sibling PR is open, clean, proof-positive, and covers the current lifecycle cleanup path. Canonical path: Route maintainer review to the single clean canonical candidate, #96230, and avoid landing competing retry/quarantine field variants for the same session-state contract. So I’m closing this here and keeping the remaining discussion on #96230. Review detailsBest possible solution: Route maintainer review to the single clean canonical candidate, #96230, and avoid landing competing retry/quarantine field variants for the same session-state contract. Do we have a high-confidence way to reproduce the issue? Yes. At source level, current main recovers running Is this the best way to solve the issue? No. The durable budget is the right solution shape, but this PR is stale against current main and is superseded by a cleaner proof-positive PR for the same root cause. Security review: Security review cleared: The diff changes session recovery, reply session-state cleanup, tests, and type/slot metadata only; I found no concrete security or supply-chain concern. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 56d95b18f4bc. |
39d24fb to
70a41e4
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
70a41e4 to
242d856
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
When a channel main-session turn wedges and the gateway is restarted (via SIGUSR1 or systemd), the recovery pass unconditionally re-retries every restart-aborted session on every boot. There is no per-session retry counter or quarantine, so a repeatedly-wedged session death-loops the gateway until systemd exhausts StartLimitBurst. Add abortedLastRunAttempts (persistent counter) and quarantinedAt / quarantineReason fields to SessionEntry. - Every mark site that sets abortedLastRun=true now also increments abortedLastRunAttempts (4 sites: markRestartAbortedMainSessions, markStartupOrphanedMainSessionsForRecovery, markPendingFinalDeliveryAsAborted, markRestartAbortedMainSessionsFromLocks) - The resume gate in recoverStore checks (abortedLastRunAttempts >= MAX_RECOVERY_RETRIES) and quarantines overrun entries by clearing abortedLastRun, setting quarantinedAt + quarantineReason, and emitting a WARN log line. Quarantined sessions skip auto-recovery. - clearQuarantine resets the counter when a new inbound turn clears the quarantine (prepared for future use in session-accessor paths). MAX_RECOVERY_RETRIES (3) is reused as the cross-boot ceiling — the same value that bounds in-process retries. Fixes openclaw#95750
242d856 to
5c226e3
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
ClawSweeper applied the proposed close for this PR.
|
Summary
Problem: When a main-session turn wedges, flags the entry and retries it on every boot. There's no persistent retry counter or quarantine—a wedged session death-loops the gateway across restarts until systemd exhausts StartLimitBurst. See #95750 for the full production incident report (6 cycles before operator intervention).
Solution: Add
abortedLastRunAttempts(persistent counter) with a> MAX_RECOVERY_RETRIESceiling. When exceeded, quarantine the session instead of resuming it. On successful resume, reset the counter and clear quarantine. The quarantine check runs AFTER all existing skip/routing/owner/dedupe guards to avoid suppressing owning recovery paths in configured or duplicate stores.What changed (4 files, +140/−22):
src/config/sessions/types.ts: +10 —abortedLastRunAttempts,quarantinedAt,quarantineReasonsrc/plugins/session-entry-slot-keys.ts: +3 — register new fields in compile guardsrc/agents/main-session-restart-recovery.ts: +61/−7 — increment at 4 mark sites, quarantine AFTER guards with> MAX_RECOVERY_RETRIES, reset on successsrc/agents/main-session-restart-recovery.test.ts: +88/−15 — quarantine + counter increment + successful-resume reset testsWhat did NOT change: In-process retry orchestration, subagent-orphan-recovery (already bounded with SUBAGENT_RECOVERY_MAX_AUTOMATIC_ATTEMPTS), channel dispatch, model routing, auth.
Fixes #95750. Supersedes #86239.
Behavioral contract
MAX_RECOVERY_RETRIES = 3is reused from the existing in-process budget. The gate is> MAX_RECOVERY_RETRIES, so the 3rd restart is the last valid retry (attempts=3), and the 4th triggers quarantine (attempts=4).Real behavior proof
Runtime: Node 24.13, Linux x86_64 — Branch:
fix/issue-95750-recovery-retry-budget@242d856dc7— Vitest: 4.1.8Proof A — Real sessions.json state transitions
Script exercises the exact recovery functions against a temp directory (full source at
proof-recovery-budget.tson the branch):Proof B — Full test suite (36/36 passed)
Proof C — Custom-store recovery resets counter on success
Observed result: The fourth restart quarantines instead of resuming. The counter correctly increments through all four mark sites. Successful auto-resume clears the counter and quarantine. Existing sessions without the field start at 0.
What was not tested: Live gateway restart with systemd supervision (not reproducible here). Proof covers every lifecycle boundary via real filesystem operations and 36 dedicated tests.
Risk checklist
Highest-risk area: Counter increment at mark sites and quarantine gate ordering.
Risk level: Medium — 3 new persistent SessionEntry fields. Existing entries default safely. Quarantine check runs AFTER guards. Operator intervention for quarantined sessions is better than a death-loop.
Mitigation: All 4 mark sites instrumented. Reset on success. 36 tests cover all boundaries.
session-entry-slot-keys.tscompile guard prevents drift.Merge risk:
session-state— 3 new SessionEntry fields, backward-compatible defaults (counter=0)availability— quarantine skips auto-recovery, intentional (death-loop is worse)compatibility— existing sessions without the field default to 0, upgrade-safeAll ClawSweeper P1 findings resolved
>= MAX_RECOVERY_RETRIESto> MAX_RECOVERY_RETRIES; 3rd restart is last valid retry, 4th triggers quarantineresumeMainSessionclearsabortedLastRunAttempts,quarantinedAt,quarantineReason@clawsweeper re-review