Repository navigation
fix(worktrees): stop repeated Git maintenance failures - #165204
Conversation
Use threshold-gated incremental maintenance instead of full auto-GC, preserving objects and reflogs shared by active worktrees. Suspend failed repositories until explicit retry while keeping cleanup best effort. Expose retry through the existing worktrees gc --retry-deferred flag.
|
🦞👀 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 4, 2026, 8:15 PM ET / October 5, 2026, 00:15 UTC. ClawSweeper reviewWhat this changesManaged worktree cleanup switches to incremental Git maintenance and suspends failed repositories until an explicit retry or service restart. Merge readiness✅ Ready for maintainer review This PR remains useful: current main still retries configuration-selected maintenance after failures. The introduced patch has no identified blocking defect, and the supplied real-Git verification covers its central behavior. Priority: P2 Review scores
Verification
How this fits togetherManaged worktrees give agent tasks separate Git checkouts backed by shared repositories. Gateway cleanup and CLI requests feed the cleanup service, which retires checkouts and snapshots before maintaining repositories that still have live worktrees. flowchart TD
A[Hourly Gateway cleanup] --> C[Worktree cleanup service]
B[CLI cleanup or retry] --> C
C --> D[Live repository inventory]
D --> E[Failed repository suspended]
E -->|Eligible or explicit retry| F[Incremental Git tasks]
F --> G[Preserved objects and reflogs]
F -->|Failure| H[One warning and suspension]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +41, Tests +83, Docs 0. Total +124 across 5 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep repository maintenance incremental and best effort, with one cleanup owner, preserved shared history, and an explicit recovery path for suspended repositories. Do we have a high-confidence way to reproduce the issue? Yes: current main has an unconditional per-pass maintenance attempt, and the supplied native-Git negative control reproduces repeated failures with missing reflog objects. This review inspected that path without executing it. Is this the best way to solve the issue? Yes: explicit incremental tasks and service-owned failure suspension address repeated failures without reconstructing corrupt objects, duplicating cleanup policy, or adding configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6de5ce9777a6. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Use threshold-gated incremental maintenance instead of full auto-GC, preserving objects and reflogs shared by active worktrees. Suspend failed repositories until explicit retry while keeping cleanup best effort. Expose retry through the existing worktrees gc --retry-deferred flag.
What Problem This Solves
Managed repositories with missing reflog objects can repeat the same failing full Git GC on every worktree cleanup cycle, wasting Git subprocesses and repeating warnings.
User Impact
Worktree cleanup now uses incremental maintenance that preserves unique objects and worktree reflogs. A failing repository is logged once with Git's stderr, then suspended until
openclaw worktrees gc --retry-deferredor service restart. Other repositories and worktree cleanup continue. This change does not reconstruct missing objects.Why This Change Was Made
Select threshold-gated commit-graph, loose-object packing, and incremental-repack tasks instead of configuration-selected full GC. Keep the existing canonical-repository deduplication, cancellation guards, and 30-minute process budget. The maintenance owner lives in one sibling module; the old service block, redundant path probe, and manual command-result handling are removed.
Cleanup already removes the retired checkout's Git administration before retiring snapshot refs. Inspection found no shared-object pruning in the suspected cleanup changes; the source of the reported missing objects remains unproven. The failing fixture models existing corruption rather than claiming cleanup created it.
Production LOC: +41 net, with the oversized service shrinking by 25 lines. Per-repository log-once suspension and explicit retry require the small service-lifetime failure set. The line-cap gate requires a sibling module, accounting for its typed factory boundary; the remaining growth is the explicit task list. No parallel maintenance implementation, schema change, or new configuration option.
Evidence
Real
ManagedWorktreeService.create,remove, andgccalls on an isolated Linux rig (Node 26.8.1, Git 2.53.0), with shared worktrees and seeded missing reflog objects:No latency or memory improvement is claimed for this tiny fixture. The avoided full-GC work and repeat failures are the improvement. Forced-threshold runs exercised all three selected tasks and preserved the surviving worktree's reflog-only commit, including a replay through the final extracted module. A real MIDX lock failure produced one attempt and one stderr warning across three cycles; explicit retry succeeded after removing the synthetic lock.
references pruned commits/failed to run repack/task 'gc' failed.node scripts/run-vitest.mjs src/agents/worktrees/service.gc-maintenance.test.ts --maxWorkers=1passed 5/5 on Hetzner Crabboxcbx_9f2e9cc6117c. Wall time 38.09 s, including 23.4 s of cold compiled-worker preparation. The real-Git regression took 3.724 s; it protects native reflog/object preservation that a command mock cannot prove.pnpm docs:listalso passed.node scripts/run-vitest.mjs src/agents/worktrees src/gateway/worktree-maintenance.test.tspassed all 4 shards on the same Hetzner lease: 49 files passed, 6 skipped; 555 tests passed. Wall time 6m39.84s. Platform-specific skips remain skips, not cross-platform proof.node scripts/check-changed.mjs --stagedpassed on the authorized Linux rig. The first substantive attempt was OOM-killed during UI chat types; the unchanged rerun passed with a softGOMEMLIMIT=4GiBtarget and lower host memory pressure. No checks were removed.Final changed-gate summary:
exit=0Infrastructure: Blacksmith did not admit a runner during a 120-minute window; both leases were stopped or disappeared. The approved AWS fallback could only allocate a 2 GiB
t3.smallafter standard-instance quota failures, and compiled-subprocess preparation was killed before any test executed. Validation therefore moved to the approved 32 GiB Hetzner fallback. These setup failures are not regression evidence.No live deployment was performed. Verification that the production journal class disappears remains a post-deployment check. CI run 37246454879 passed on head
5650a3b065abfcc3915eea681a1653c14bdac8ab, includingopenclaw/ci-gate: 460 s workflow wall time. No CI repair or rerun was needed. This is workflow time; the focused-file measurement above is reported separately.