Repository navigation
fix: skip repeated removal of preserved worktrees - #200434
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 Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6426954aad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Addressed both hosted review findings on
Focused follow-up proof: 35 preservation tests, 91 UI browser tests, and 5 Chromium E2E tests pass. Fresh Codex autoreview is scoped-clean through P2. The test-fixture type error found by check:changed is fixed; the targeted regression and all core test typecheck shards pass. The three documented dead-export failures reproduce on the original main parent and remain inherited main regressions. Synthetic UI proof below compares the original @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR skips repeated removal of preserved worktrees, exposes typed cleanup status, and adds an explicit safe retry. Example: A checkout containing nested/valuable.txt already has a terminal nested-repository receipt with attempts set to 1.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a current removal-path defect, and the final lease-test correction preserves its safety assertions; no actionable correctness or security findings remain. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherCLI, Gateway, session cleanup, and Control UI callers use the managed-worktree service, which reads revision-bound SQLite receipts before admitting Git snapshot and removal work. flowchart LR
A[CLI and Control UI] --> B[Gateway or local owner]
B --> C[Managed worktree service]
D[SQLite cleanup receipt] --> C
C --> E[Preserved outcome]
C --> F[Safe snapshot and removal]
E --> A
F --> A
Technical reviewBest possible solution: Keep the existing removal owner authoritative, reuse its terminal receipt, and require an explicit retry while retaining snapshot and lease protections. Do we have a high-confidence way to reproduce the issue? Current-main source admits repeated direct removal despite a terminal receipt, and the extended real Git/registry regression exercises that path; no target code was executed during this read-only review. Is this the best way to solve the issue? The change fixes the decision at its existing owner, derives status from existing storage, updates affected consumers, and retains distinct lease, snapshot, and UI regressions without introducing another state owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8f0d03fe9c46. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +80, Tests +190, Docs +16, Other +11. Total +297 across 20 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 17, 2026, 1:43 AM ET / 06:43 UTC (Revision 2). |
|
@clawsweeper re-review Final head is |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
* fix: skip repeated removal of preserved worktrees * fix: settle preserved removal claims and UI retries * test: explicitly retry preserved worktree lease checks




Related: #200350
What Problem This Solves
A periodic cleanup script can repeatedly try to remove a worktree whose contents OpenClaw has already preserved because they cannot be snapshotted safely. Each call repeats snapshot work, while
worktrees list --jsonomits the typed cleanup status the script needs to skip it.User Impact
User impact: cleanup scripts can filter
cleanup.state == "preserved"; unfiltered removal exits 1 immediately withremoved: falseand typedpreservedmetadata. After repairing the cause, an operator can explicitly runworktrees remove <id> --retry-preserved. This flag reopens the existing safe removal path; it does not permit snapshot loss.--forcealone does not reopen a terminal receipt. Existinggc --retry-deferredremains an explicit retry.Why This Change Was Made
The registry decoder projects the existing revision-bound receipt as
cleanup: { state, reason, attempts, nextAttemptAt }. The removal owner checks it before acquiring the mutation lease or settling the workspace, so local CLI and Gateway callers share one decision. Session deletion continues reporting a retained worktree when removal returns that outcome. Clean-only cleanup releases its removal claim on refusal. The Worktrees UI offers an explicit safe Retry; the session organizer preserves its existing destructive confirmation and reports refused outcomes. No configuration, SQLite schema, cache, or preservation policy changes.Production code grows by 77 lines to expose the typed contract, explicit retry, and visible outcome; tests grow by 190, generated validators by 3, docs by 16, and the existing benchmark by 11. The allocation-held implementation moves unchanged from the oversized service into its existing removal module; no duplicate owner is added.
Evidence
The nested-repository regression fails on the original service at the repeated removal and passes with the fix: no new snapshot or Git command, unchanged attempt count, and unsaved nested bytes retained. Explicit retry performs another safe attempt. Real Commander parser tests cover the flag, conflict, JSON/text refusal, and exit 1. Focused preservation, removal safety, exact-state, CLI, registry, protocol, and Gateway tests pass; the final affected UI browser suites (91 tests) and Chromium E2E suite (5 tests) also pass. Hosted review caught a leaked clean-only removal claim and unhandled UI results; both have red/green regressions and are fixed. All 35 preservation tests pass again, including a repaired checkout that can be explicitly retried after clean-only refusal.
A production-shaped synthetic fixture on btrfs contains 5,000 sessions, a 35 GiB size-shaped database, and 62,000 files totaling 1.1 GB. Five interleaved baseline/candidate pairs (25 repeat calls per arm) show median owner wall time 1283.724 → 1.176 ms, process CPU 1050.661 → 1.434 ms, and main-isolate allocation 22,132,280 → 351,320 bytes. Baseline calls range 848–2049 ms; candidate calls 0.60–6.25 ms. A/A controls have medians 3310/1310 ms, so host drift is substantial: these are synthetic work-count and cost measurements, not a production latency forecast. CPU excludes Git subprocesses; initial preservation is excluded. No production data was copied.
The isolated Linux
pnpm openclawflow also passes end to end: create → failed safe snapshot → list preserved state → fast refusal with exit 1 → explicit retry increments attempts to 2; unsaved bytes remain intact. All 12 session-lifecycle tests pass. Codex autoreview is scoped-clean through P2.pnpm check:changedexposes three inherited dead-export regressions, reproduced on exact main parent346d231275b3930848b8e31239c74f689d361436:approval-shared.ts:isApprovalRecordVisibleToClient(#200360, ff2cb7e),spawn-broker/host.ts:BrokerNativeResourceLease(#200370, df78722), andoperation-types.ts:SystemAgentPluginCapabilityReview(#200392, b0d95fd). These are reported main regressions, not silently ignored checks. The follow-up check also caught a missing required reason in the new regression fixture; that is corrected, the targeted regression passes again, and every core test typecheck shard passes. All other changed-file gates passed. Exact-head PR CI will determine landing eligibility.Numbered review responses and inspected before/after screenshots.
CI follow-through: run 44029059502 exposed a lease test that still used force as an implicit preserved retry. The test now opts in with retryPreserved and releases its lease in finally, preventing assertion failures from hanging teardown. No production change. All 43 remaining #200350 GC, eviction, and lease tests pass (199.26s), completing that regression footprint; targeted typecheck/lint and a fourth Codex autoreview pass.