Repository navigation
fix(worktrees): stop leaving branches after recovery expires - #195484
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. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR deletes eligible managed branches when recovery expires and adds owner-routed orphan cleanup with a preview mode. Example: The 30-day recovery period for openclaw/retired-task expires.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 4 items remain Keep this PR open: it addresses a source-confirmed recovery-expiry leak that remains on main, and its maintainer-authored direction is approved. No concrete introduced code defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe managed-worktree service receives CLI, administrator RPC, and maintenance requests, reconciles Git refs against registry and pending-allocation ownership, and returns cleanup outcomes. flowchart TD
A[CLI or administrator RPC] --> B[Managed worktree service]
C[Recovery expiry] --> B
B --> D[Existing lifecycle leases]
D --> E[Registry and Git ownership checks]
E --> F[Native Git branch deletion]
F --> G[Cleanup result or retained retry row]
Technical reviewBest possible solution: Keep cleanup in the existing worktree lifecycle owner, preserving native Git protections, recovery custody, and visible retry outcomes. Do we have a high-confidence way to reproduce the issue? Current-main expiry source shows the branch leak, and the PR supplies native Git regressions for snapshot-loss and detached recovery expiry; no target code was executed during this read-only review. Is this the best way to solve the issue? The fix uses existing leases, registry ownership, and native Git deletion rather than adding another state owner; the separate cleanup mode also repairs branches already orphaned by older versions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f9206425face. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: Source inspection found live-owner and administrator guards, with final-effect authority validation still outstanding. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +309, Tests +263, Docs +41, Other +246. Total +859 across 19 files. Added test files: 1. 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:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed November 8, 2026, 7:43 PM ET / November 9, 2026, 00:43 UTC. |
928235d to
6bc19d1
Compare
Delete eligible managed branches when recovery expires, retain failed cleanup for retry, and preserve checkout files awaiting recovery. Add owner-routed orphan branch cleanup with dry-run and native Git safety checks. Require independent retained source for early snapshot retirement.
Remove the direct orphan-cleanup RPC and CLI mode. Discover managed branch orphans through GC's recorded repositories, preserving its no-op lease and worktree-inventory costs and retaining lifecycle authority at native deletion. Keep interrupted expiry recovery assertions and require the branch to retire only after settlement. Prove actual GC authorization, expired allocation custody, and restoration/expiry of a v2026.11.2-shaped persisted recovery row. Allocate exactly 422 net test lines for the complete lifecycle, orphan safety, authority, stable-record, work-count, and churn regressions in this PR.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 68fe503c9d
ℹ️ 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".
| const refs = await requireGit( | ||
| repoRoot, | ||
| [ | ||
| "for-each-ref", | ||
| "--format=%(refname)%09%(symref)", |
There was a problem hiding this comment.
Verify repository identity before sweeping branch refs
If a registered nested repository loses its .git directory while its path and registry row remain, Git discovers the enclosing repository instead. Both the new preflight and this inventory accept that repository, but ownership protection still filters records by the stale nested repoRoot. Consequently, ordinary GC can delete unattached openclaw/* branches from the enclosing repository rather than the recorded source, potentially losing unmerged work (git branch -h describes -D as “delete branch (even if not merged)”). This discovery/deletion behavior is reproducible with a nested Git fixture; clearing inherited Git variables does not prevent it. Verify the discovered canonical repository/common directory against the recorded repository identity before admitting branch cleanup.
Useful? React with 👍 / 👎.
68fe503 to
c2cb16c
Compare
|
Landing note: ClawSweeper's findings on 928235da are addressed at 69823b6. The new destructive RPC/CLI surface is removed (existing GC owns orphan cleanup; retirement deletes branches when recovery obligations end). Real (non-mocked) authority tests cover refusal for write-scoped/revoked/replaced owners before any Git effect. The final-effect lease is revalidated immediately before each branch deletion. A latest-stable record upgrade test passes, and the race shard that failed (service.exact-state-races) is green. Exact-head CI is green. |
…w#195484) * fix(worktrees): retire orphaned branches with recovery Delete eligible managed branches when recovery expires, retain failed cleanup for retry, and preserve checkout files awaiting recovery. Add owner-routed orphan branch cleanup with dry-run and native Git safety checks. Require independent retained source for early snapshot retirement. * fix(worktrees): route orphan branch cleanup through existing GC Remove the direct orphan-cleanup RPC and CLI mode. Discover managed branch orphans through GC's recorded repositories, preserving its no-op lease and worktree-inventory costs and retaining lifecycle authority at native deletion. Keep interrupted expiry recovery assertions and require the branch to retire only after settlement. Prove actual GC authorization, expired allocation custody, and restoration/expiry of a v2026.11.2-shaped persisted recovery row. Allocate exactly 422 net test lines for the complete lifecycle, orphan safety, authority, stable-record, work-count, and churn regressions in this PR. * test(worktrees): account for GC branch inventory work * test(gateway): report project refresh boundary failures * test(gateway): follow the shared refresh transport boundary * test(gateway): fence refresh at the transport handoff
What Problem This Solves
Managed branches retained for snapshot-loss or detached-worktree recovery survived after expiry removed their recovery refs and registry rows. Repeated retirement accumulated orphaned local branches.
User Impact
Recovery expiry now deletes eligible managed branches and retains retryable ownership when deletion fails. Ordinary
openclaw worktrees gcalso cleans existing orphanedopenclaw/*branches in repositories recorded by the registry or pending allocations. It reports failures through the existing GC receipt and logs successful deletion counts.The extra orphan-cleanup RPC request and CLI mode from the first revision have been removed. There are no protocol, generated-validator, UI, config, schema, or retention-period changes. GC selects repositories from its existing owner inventory; callers cannot supply arbitrary cleanup targets. Repositories with no remaining registry or pending records are not discovered by this sweep.
Safety and Recovery
Only direct managed heads without an attached Git worktree, live/retained registry reference, or pending allocation are eligible. Unknown recovery refs preserve every candidate in the repository. Native Git retains its checked-out-branch protection. Existing leases and the clean Git environment own deletion; the same closure-bound guard is revalidated synchronously after ref-queue admission and immediately before each native deletion command.
Normal removal keeps its ancestry-safe branch deletion (#148765). Missing Git metadata with surviving checkout files preserves recovery ownership. Explicit snapshot retirement requires an independent ordinary branch or remote-tracking source; a managed branch cannot provide durable custody after its row is forgotten.
Evidence
Exact head
69823b6f1ec8f2db21d71c25843e327674064dbapassed CI run 42550750226, including the original failingchecks-node-changed-compact-small-2shard.CI run 42540143974 failed two interrupted-expiry cases because their last assertions still required orphan branches after complete retirement. The repaired tests keep every interruption/custody assertion, additionally prove the branch survives the interrupted pass, and require it to disappear after settlement. The new authority test uses real GC, state-owner capture, and guards; it covers write-only, revoked, replaced-owner, and authorized requests. A delayed native-effect test checks actual allocation-lease expiry, and a persisted v2026.11.2-shaped row verifies restore and expiry without any new cleanup field.
Focused proof: 43 exact-state race cases, 25 GC cases, 21 removal-safety cases, 20 snapshot-retirement cases, five orphan/upgrade/churn cases, and four real GC authority cases. The existing zero-allocation and single-linked-worktree-inventory no-op guarantees remain asserted; GC inventory performance cases are separated into their own file to preserve the line cap, and assert the exact new repository metadata work; the GC test also discovers a branch added between passes. The two updated branch-deletion assertions fail against the pinned pre-fix lifecycle owners because the branch survives settlement; all 43 cases pass on the final fixed sources (185.94 s).
pnpm check:changedcompleted. Three unnecessary default type arguments in the new tests were corrected and focused core lint passed. Every other code/type/format/schema/export gate passed. The remaining failure is the same 20 changelog-attribution violations reproduced by the actual guard on exact main parent61db4b336f89957d7916580871b288d0d8c9ba82. #194364 /266a7aa0fe69e2b5fe6445c4ceb1e15b5360c957introduced that signature without correcting historical release artifacts; its parent already had a different failing signature. This is an unresolved main regression for follow-up, not a passing check.Codex P0–P2 autoreview is scoped-clean. The exact test-line allocation is +479 lines (6,589,675 total / 6,589,707 ceiling; 32 slack). Handwritten production growth is +237 lines, with zero generated changes, reduced from +295 handwritten / +14 generated. The remaining growth implements safe ownership classification, native batch deletion/reconciliation, and existing GC/retirement integration. No production system was accessed or modified.
Follow-up CI exposed two stale GC inventory expectations, now reproduced and corrected with exact metadata-command assertions and the existing checkout/lease constraints intact. The extracted inventory and maintenance files pass together (20 passed, one platform-specific skip). CI also merged in newer main containing #195488 (
3908a3e4619905ab8589d220147292779f1df2f1): its shared transport renamed the temporary directory, leaving the existing clone-identity test watching a removed prefix. The test now invokes the real shared transport helper and revokes identity at its handoff after awaited staging setup, preserving every revocation and authorized-effect assertion. It no longer depends on the temporary-directory name, so it also remains compatible with peer #195505. The three refresh cases fail with the same boundary assertion on an unmodified checkout of exact main parent61db4b336f89957d7916580871b288d0d8c9ba82; all six clone/refresh cases pass after repairing the boundary hook. This is a proven main test regression with a named introducer, fixed here. The final rebase preserves all reviewed worktree owner changes byte-for-byte.Synthetic scale proof uses 13,531 refs, 3,145 local heads, 1,843 managed heads, 1,598 real linked worktrees and 1,228 registry records. Every one of five cleanup samples removes exactly 615 orphan heads, preserves the entire remaining ref set, and finds zero candidates on the next pass: 12,916 total refs / 1,228 managed heads. On macOS/APFS with Node 26.12.1, collector median wall time is 812 ms populated preview, 2,757 ms cleanup, 992 ms clean next pass. Median Node CPU is 652/674/646 ms; native Git CPU 330/2,170/500 ms; main V8 allocation 5.681/8.405/6.819 MiB. Five A/A previews have 814 ms median and 1,037 ms p95 (31.67% range/median); shared-host variance prevents a speedup claim. This measures the collector under real custody, excluding fixture setup, GC preflight and other GC stages. It does not measure publication fetch latency or unrelated agent databases/workspace files.
This PR remains open and must not be merged automatically.