Repository navigation
fix(agents): clear empty uncharged recovery residue - #166294
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 9:21 PM ET / October 7, 2026, 01:21 UTC (Revision 4). ClawSweeper reviewWhat this changesClear empty, uncharged restart-recovery records during reservation cancellation, reconciliation, and foreground admission so completed subagent results can start a requester turn. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main still leaves empty recovery residue. No actionable correctness or security finding remains, and the updated evidence resolves the previous review's test-cost request. Priority: P1 Review scores
Verification
How this fits togetherRestart recovery keeps interrupted agent work and pending delivery under durable ownership. Foreground admission reads that ownership before allowing a new turn, including a follow-up carrying completed subagent results. flowchart TD
A[Completed subagent result] --> B[Requester turn admission]
C[Persisted recovery record] --> D[Recovery state owner]
E[Reservation cancellation or reconciliation] --> D
D --> F{Remaining work or custody?}
F -->|Yes| G[Preserve recovery ownership]
F -->|No| H[Clear empty residue]
H --> B
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +24, Tests +304, Docs +5. Total +333 across 5 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep recovery cleanup in the existing state owner, retire only ownerless residue, and preserve every live execution or delivery obligation. Do we have a high-confidence way to reproduce the issue? Yes: a healthy persisted session with an empty, uncharged recovery aggregate reaches invalidated requester admission on current main. The captured isolated negative control confirms SESSION_WORK_START_CHANGED; this read-only review did not execute target code. Is this the best way to solve the issue? Yes: repairing cancellation at its producer and reusing the existing reconciliation and admission owner is a narrow fix, while explicit custody exclusions preserve interrupted work. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ed4974479682. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
2471700 to
71c62a4
Compare
|
Merged via squash.
|
* fix(agents): preserve interrupted empty recovery custody * fix(agents): retire empty recovery state after reservation cancellation --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Completed subagent results can fail to start their requester turn with
SESSION_WORK_START_CHANGEDwhen the requester retains an empty, uncharged restart-recovery record. The same session stays blocked on later completions.Fixes #166203
User Impact
Healthy sessions can receive completed subagent results again. Interrupted work and pending execution or delivery retain recovery custody.
Why This Change Was Made
A foreground turn can settle while an automatic recovery reservation remains. Cancelling that reservation refunds its last charge and previously left an ownerless aggregate behind. The recovery state owner now clears that residue during cancellation. Its existing reconciliation and foreground cleanup paths also retire residue already persisted by older versions. Admission continues to require a healthy, fully cleared session.
No configuration, schema, or public protocol changes. The helper stays separate because the state owner's existing file-size limit prevents inlining it. Maintainer cleanup factors duplicated admission conditions and adds producer/reconciliation coverage, including statusless requester admission.
Evidence
Validated head:
21328d2afeba369256dc1fac9b2adfbe382dbf3f. Current-main source still contains the defect; its recovery state/store owners do not clean empty healthy aggregates. Independent review found no actionable P0–P2 findings. ClawSweeper's latest review of this head likewise found no correctness or security defect; its remaining request for per-file wall time and CI seconds is supplied below.Local static checks passed: targeted oxfmt, oxlint with
config/tsconfig/oxlint.core.json, andgit diff --check. No contributor runtime code executed on the maintainer host.Crabbox Untrusted AWS lease
cbx_421cea415919(stopped after proof): trusted-main bootstrap verified the full pushed SHA and no instance-role credentials; no Tailscale or credential hydration. Core typechecking and all 132 tests across four files passed, in 139.12 s wall time:On the same lease and head, the negative control restored only production code to merge-base
4de57f22aa1dcd118ec156a08588adb1b54404bd(including removal of the newly added predicate module), keeping the new tests:The producer and reconciliation assertions failed in 29.35 s. Because the runner stops after its first failing shard, the persisted admission regression ran separately with
pnpm test src/agents/agent-command-recovery-owner.test.ts --maxWorkers=1 -t 'resumes requester settle': both statusless and completed-session cases failed in 38.26 s.Restoring the two production files to the pushed head made both complete changed files pass again. This proves persisted command admission and recovery transitions; the executor callback uses synthetic text and does not contact a provider or channel.
Test cost
Measured individually with
pnpm test <file> --maxWorkers=1on the same AWS lease. CI seconds are each file's shard begin-to-end wall time from the successful exact-head CI job.src/agents/main-session-recovery/main-session-recovery-empty-aggregate.test.tssrc/agents/agent-command-recovery-owner.test.tsThe >30 s observations are dominated by existing import transformation: 94% of the AWS empty-aggregate Vitest duration and 87% of the CI requester-owner duration. The regression uses the real transition/lifecycle owners; the persisted test requires the actual session writer and admission boundary. Mocking those owners would miss the defect. The added tests contain no sleeps, real timers, polling, process boots, or test-only production seams. Exact-head CI completed successfully.
Diff size and credit
Production +25 / -1 (net +24); tests +304 / -0; docs +5 / -0, from
git diff --numstat origin/main...HEAD:Production LOC exception: the final delta remains positive. Deslop removes duplicated admission conditions; further reduction would require a separate refactor of inspection ordering or removing custody checks. The existing owner file-size gate also requires retaining the small predicate module. No guard was weakened or unrelated file changed to meet a line-count target.
Original fix by @sunlit-deng; maintainer cleanup adds producer-side cancellation repair, recovery reconciliation, statusless admission coverage, documentation, and isolated positive/negative proof. Contributor commits and attribution are preserved.