Repository navigation
feat(agents): record run-end worktree cleanup outcome; prove Workboard dirty retention - #120434
Conversation
|
Codex review: needs changes before merge. Reviewed August 8, 2026, 6:47 PM ET / 22:47 UTC. ClawSweeper reviewWhat this changesThis PR records managed-worktree run-end cleanup outcomes in SQLite, exposes them through Gateway and CLI worktree listings, and adds Workboard dirty-retention coverage. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep open: the exact-head ABA fence can reuse the same millisecond timestamp after restore, allowing a delayed prior-lifecycle cleanup write to overwrite the restored worktree’s newer state. Priority: P2 Review scores
Verification
How this fits togetherAgent and Workboard runs create managed worktrees that are cleaned up after the run ends. The cleanup owner records the result in the worktree registry, which Gateway and the CLI expose to operators and QA. flowchart LR
A[Agent or Workboard run] --> B[Managed worktree]
B --> C[Run-end cleanup decision]
C --> D[Worktree registry]
D --> E[Gateway worktree listing]
E --> F[CLI and QA evidence]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +194, Tests +430, Docs +2, Generated +1, Other +6. Total +633 across 57 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep outcome recording at the generic cleanup owner, but fence delayed writes with an atomically advancing lifecycle generation rather than a wall-clock timestamp and prove the equal-clock ABA sequence. Do we have a high-confidence way to reproduce the issue? Yes, from source: hold a stale cleanup writer, remove and restore the row in the same clock millisecond, then allow the stale retained/failed write to resume. Is this the best way to solve the issue? No. Recording the fact at the generic cleanup owner is the best layer, but Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cdaea2d6b67c. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (11 earlier review cycles; latest 8 shown)
|
b24b0eb to
2faf1be
Compare
52bb200 to
5fe0abc
Compare
71834a8 to
9f1ceb4
Compare
791a567 to
0eb5e85
Compare
The red-main landing rule requires this PR to repair repository-wide merge-gate debt instead of bypassing it. Apply the current lint contracts mechanically and split turn-transition coverage into a concept-named sibling with per-file-safe test state. Exact line delta: +676/-574 (net +102) across 44 test/support files.
Require the public refresh call to exist before accepting that sensitive fields were omitted, so the boundary proof cannot pass on a missing call.
Literal-widened totalTokensVersion fixtures, a WebSocket RawData overload mismatch, and the protocol schema document cast broke check-test-types after the repo-wide lint repair. Aligns the fixtures with SessionEntry, narrows Buffer handling per RawData, and keeps the JSON-shaped undefined omission under structuredClone.
The session-loop split and #120463's helper extraction landed the same createResourceLoader/createCompactionHandlers twice; the rebase kept both, orphaning main's agent-session-loop-resource-loader.test-support.ts and failing the dead-code gate. Import the upstream helpers and delete the duplicates.
Address the accepted ClawSweeper late-claim finding by rereading and rejecting missing or finalized worktree rows inside the synchronous removal-claim transaction. Preserve the authoritative cleanup invariant: finalized contenders record nothing, while retained-busy is written only while the row remains live.
Keep the live-row conditional write in the canonical registry update path so the finalized-claim repair stays below the registry max-lines ratchet without weakening the authoritative-outcome invariant.
Keep current main as the canonical owner of next-turn lifecycle coverage and correctness test support after replaying the older lint-debt split.
After abortWorktreeRemoval releases a stale remover's claim, its retained or failed write raced a finalizing remover and could overwrite the authoritative removed-lossless fact. Route every retained/failed write through the live-row condition; only the finalizing remover's own removed-lossless write stays unconditional.
A delayed removed-lossless write after remove() finalized could race a restore plus newer cleanup and overwrite the newer operator-visible fact. The run-end outcome now rides remove()'s finalization update; every other cleanup write stays live-row conditional, so no post-finalize write path remains.
The lint sweep's Boolean() coercions let truthy non-booleans satisfy the wire-typed cached-meta contract. Assert the literal boolean for unknown-typed fields and use nullish-coalesced strict equivalents for boolean chains.
3854e51 to
3b04a59
Compare
|
@clawsweeper re-review — rebased across main's overnight advance on head 3b04a59: all eight worktree-feature commits patch-identical (only an import-context conflict in service.ts, both imports retained), generated Swift/SDK outputs regenerated and unchanged, CI green on this exact head. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
A restored checkout begins a new lifecycle; leaving the removed-lossless fact on the live row showed operators a stale result until the next cleanup. Restore clears the recorded outcome and the regression asserts the cleared state before the next cleanup records fresh truth.
|
@clawsweeper re-review — the restore-staleness P2 is fixed on head 0836780: restore clears the recorded cleanup outcome (a restored checkout starts a new lifecycle), with the generation regression asserting the cleared state before the next cleanup records fresh truth. CI green on this exact head. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
A stale remover's retained/failed write raced a concurrent remove-plus- restore: the revived row is live again, so the live-row condition alone could stamp a prior-lifecycle outcome. Condition those writes on the activity stamp the remover observed; restore bumps lastActiveAt, making any prior-lifecycle write a no-op.
|
@clawsweeper re-review — the prior-lifecycle ABA P2 is fixed on head e4da939, closing the write-race class: stale retained/failed writes are now conditioned on both the live row AND the activity stamp the remover observed. Every lifecycle transition either sets removed_at (blocked by the live condition) or bumps last_active_at via restore (blocked by the stamp condition), so no stale cleanup can stamp another lifecycle's row. ABA regression included. CI green on this exact head. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Stale cleanup writes fence on the activity stamp they observed; a restore completing in the same millisecond could revive the row with an identical stamp and let the fence match. Restore now always advances past the stored value, and the ABA regression pins the clock to prove the same-millisecond case.
|
@clawsweeper re-review — the same-millisecond fence P2 is fixed on head f8a80c7: restore now always advances the activity stamp past the stored value (Math.max(now, prior+1)), so the stale writer's fence can never match a revived row even within one millisecond; the ABA regression pins the clock to prove exactly that case. The write-race class is closed: live-row condition blocks post-finalization writes, the observed-stamp fence blocks prior-lifecycle writes, and restore stamps are strictly monotonic. CI green on this exact head. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
…d dirty retention (openclaw#120434) * feat(agents): record run-end worktree cleanup outcome Persist removed, retained, and failed run-end cleanup outcomes on managed worktree records. Operators and QA can inspect the durable fact through worktrees.list and openclaw worktrees list --json. Release note: Managed worktree run-end cleanup now records why a checkout was removed or retained in worktree list JSON. * test(qa): prove dirty worktree retention outcome * chore(protocol): regenerate swift gateway models * fix(agents): harden worktree cleanup recovery Register run_end_cleanup_json as a lazy compatible column so same-version v6 index repair and read-only doctor migration can recover databases created before the column existed. Type removal contention at the registry boundary; unexpected claim failures now best-effort record a bounded failed outcome and rethrow the original error. * fix(ci): clear repo-wide lint debt blocking merge gates The red-main landing rule requires this PR to repair repository-wide merge-gate debt instead of bypassing it. Apply the current lint contracts mechanically and split turn-transition coverage into a concept-named sibling with per-file-safe test state. Exact line delta: +676/-574 (net +102) across 44 test/support files. * fix(ci): preserve cached health refresh proof Require the public refresh call to exist before accepting that sensitive fields were omitted, so the boundary proof cannot pass on a missing call. * fix(ci): correct test typing left by the lint sweep Literal-widened totalTokensVersion fixtures, a WebSocket RawData overload mismatch, and the protocol schema document cast broke check-test-types after the repo-wide lint repair. Aligns the fixtures with SessionEntry, narrows Buffer handling per RawData, and keeps the JSON-shaped undefined omission under structuredClone. * test(agents): reuse upstream resource-loader test support The session-loop split and openclaw#120463's helper extraction landed the same createResourceLoader/createCompactionHandlers twice; the rebase kept both, orphaning main's agent-session-loop-resource-loader.test-support.ts and failing the dead-code gate. Import the upstream helpers and delete the duplicates. * fix(agents): reject finalized rows at the worktree removal claim Address the accepted ClawSweeper late-claim finding by rereading and rejecting missing or finalized worktree rows inside the synchronous removal-claim transaction. Preserve the authoritative cleanup invariant: finalized contenders record nothing, while retained-busy is written only while the row remains live. * refactor(agents): reuse registry update for busy outcomes Keep the live-row conditional write in the canonical registry update path so the finalized-claim repair stays below the registry max-lines ratchet without weakening the authoritative-outcome invariant. * test(agents): drop session test duplicates after rebase Keep current main as the canonical owner of next-turn lifecycle coverage and correctness test support after replaying the older lint-debt split. * fix(agents): guard post-abort cleanup outcomes against finalization After abortWorktreeRemoval releases a stale remover's claim, its retained or failed write raced a finalizing remover and could overwrite the authoritative removed-lossless fact. Route every retained/failed write through the live-row condition; only the finalizing remover's own removed-lossless write stays unconditional. * fix(agents): persist the removal outcome atomically with finalization A delayed removed-lossless write after remove() finalized could race a restore plus newer cleanup and overwrite the newer operator-visible fact. The run-end outcome now rides remove()'s finalization update; every other cleanup write stays live-row conditional, so no post-finalize write path remains. * test(qa): restore strict cached-health contract assertions The lint sweep's Boolean() coercions let truthy non-booleans satisfy the wire-typed cached-meta contract. Assert the literal boolean for unknown-typed fields and use nullish-coalesced strict equivalents for boolean chains. * fix(agents): clear the stale cleanup outcome when restoring a worktree A restored checkout begins a new lifecycle; leaving the removed-lossless fact on the live row showed operators a stale result until the next cleanup. Restore clears the recorded outcome and the regression asserts the cleared state before the next cleanup records fresh truth. * fix(agents): scope stale cleanup outcomes to their observed lifecycle A stale remover's retained/failed write raced a concurrent remove-plus- restore: the revived row is live again, so the live-row condition alone could stamp a prior-lifecycle outcome. Condition those writes on the activity stamp the remover observed; restore bumps lastActiveAt, making any prior-lifecycle write a no-op. * fix(agents): advance the restore activity stamp within one millisecond Stale cleanup writes fence on the activity stamp they observed; a restore completing in the same millisecond could revive the row with an identical stamp and let the fence match. Restore now always advances past the stored value, and the ABA regression pins the clock to prove the same-millisecond case.
What Problem This Solves
Follow-up recorded in #120362: the Workboard dirty-retention QA case had to be dropped because run-end worktree cleanup left no observable fact.
agent.waitcan resolve before the asyncsubagent_endedcleanup hook, and nothing recorded whether cleanup ran or why it kept a checkout — so a retention assertion would have been false proof, and an operator looking at a surviving worktree had no way to know it was retained deliberately.Why This Change Was Made
Per the Product Doctrine ("record facts where they happen; every action ends in a visible outcome or a recorded non-outcome"),
removeIfLossless— the single lifecycle owner where the lossless/retain decision is made — now persists a durable outcome on the worktree registry row at every exit:removed-lossless,retained-busy(live run lease or competing remover),retained-dirty,retained-unpushed,retained-provisioned-drift, orfailedwith a bounded reason. Storage is a single additiverun_end_cleanup_jsoncolumn (declared in the canonical schema plus the idempotent lazy ensure; no schema-version bump — older readers tolerate it). The fact flows through the existingworktrees.listRPC andopenclaw worktrees list --jsonvia an additive optional field on the protocol record schema; the plugin SDK surface is untouched (removeIfLosslessstill returns boolean).The generic owner boundary means every run-end cleanup path records the fact — Workboard today, any future session run-end path for free.
User Impact
Operators can see why a worktree survived run-end cleanup instead of guessing. QA now proves dirty retention at a real product boundary: the e2e dirty-retention case waits on the recorded fact rather than racing the async cleanup hook. Taxonomy (
agent-runtime.managed-worktrees-workboard-lifecycle) and the scenario successCriteria claim exactly what is proven.Evidence
src/agents/worktrees/service.run-end-cleanup.test.ts): clean →removed-losslesson the removed row; dirty →retained-dirtywith checkout intact; unpushed →retained-unpushed; held run lease →retained-busy.removed-lossless; new dirty-retention case passes — 2/2, run twice green. Two initial test-side synchronization races (global owner capacity, observingremovedAtbefore the outcome write) were fixed in the test without changing production semantics or timeouts.maturity:checkclean; targeted lint/format clean; autoreview (Codexgpt-5.6-sol, high) clean.Red-main merge-gate repair
This branch also repairs the unrelated context-freshness test breakage introduced on
mainby #120497. The repair preserves the historical assertions and adds the versioned token provenance now required by the shipped runtime; no memory-flush runtime behavior changes.