Skip to content

fix(worktrees): stop repeated Git maintenance failures - #165204

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-worktree-git-maintenance-20260919
Oct 5, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-worktree-git-maintenance-20260919

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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-deferred or 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, and gc calls on an isolated Linux rig (Node 26.8.1, Git 2.53.0), with shared worktrees and seeded missing reflog objects:

Measurement, three cleanup cycles Before After
Cycles reporting the repack/GC failure 3/3 0/3
Full-GC attempts 3 0
Maintenance-related Git subprocesses 18 3
Mean cleanup wall time, tiny fixture 1.018 s 1.058 s
Whole-process peak RSS, including cold runtime startup 1,143,084 KiB 1,255,636 KiB

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.

  • Regression negative control: the new tests fail on the original implementation for both intended reasons: repeated maintenance attempts, and references pruned commits / failed to run repack / task 'gc' failed.
  • Focused candidate: node scripts/run-vitest.mjs src/agents/worktrees/service.gc-maintenance.test.ts --maxWorkers=1 passed 5/5 on Hetzner Crabbox cbx_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:list also passed.
  • Worktree suites: node scripts/run-vitest.mjs src/agents/worktrees src/gateway/worktree-maintenance.test.ts passed 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.
  • Changed gate: node scripts/check-changed.mjs --staged passed on the authorized Linux rig. The first substantive attempt was OOM-killed during UI chat types; the unchanged rerun passed with a soft GOMEMLIMIT=4GiB target and lower host memory pressure. No checks were removed.
  • Review: the fresh post-test independent Codex review completed with a clean verdict through P2, using a 3,600-second engine budget.

Final changed-gate summary:

Check Result
Production typecheck Passed
Core test type partitions 27/27 passed
Changed-file lint 0 warnings, 0 errors
Dead export scans 0 entries in production, full tree, and scripts
Runtime import cycles 0
Remaining line-cap, formatting, schema, database, plugin, and lifecycle guards Passed
Final helper status exit=0

Infrastructure: 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.small after 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, including openclaw/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.

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.
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes agents Agent runtime and tooling size: S labels Oct 5, 2026
@steipete
steipete marked this pull request as ready for review October 5, 2026 00:10
@steipete
steipete enabled auto-merge (squash) October 5, 2026 00:10
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 8:15 PM ET / October 5, 2026, 00:15 UTC.

ClawSweeper review

What this changes

Managed 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
Reviewed head: 5650a3b065abfcc3915eea681a1653c14bdac8ab

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful native-Git verification and no identified blocking defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied Linux verification exercises real ManagedWorktreeService operations and native Git through the final maintenance module, showing avoided repeated GC failures, preserved reflog-only history, log-once suspension, and successful explicit retry. No stored-data format or migration contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied Linux verification exercises real ManagedWorktreeService operations and native Git through the final maintenance module, showing avoided repeated GC failures, preserved reflog-only history, log-once suspension, and successful explicit retry. No stored-data format or migration contract changes.
Evidence reviewed 9 items Pinned introduced change: Reviewed the merge-base-to-head diff for the five introduced paths. The maintenance block is replaced by one service-owned module; endpoint drift was not attributed to this PR.
Current main still needs the repair: Fetched main retains maintenance run --auto without explicit tasks or repository failure suspension. Each cleanup pass can therefore repeat the same maintenance failure.
Release inspection: Inspected the maintenance-related portion of the service at the supplied latest release, v2026.9.8, through GitHub contents. It does not contain this incremental-maintenance repair; no fixed release is established.
Findings None None.
Security None None.

How this fits together

Managed 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +41, Tests +83, Docs 0. Total +124 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 71 30 +41
Tests 1 88 5 +83
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 160 36 +124

Review metrics

Metric Value Why it matters
Production versus test growth production +41 net lines; tests +83 net lines Production growth is justified by service-lifetime suspension and the extracted maintenance owner; native Git coverage protects history preservation.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This addresses repeated maintenance failures and subprocess waste while ordinary worktree cleanup remains available.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied Linux verification exercises real ManagedWorktreeService operations and native Git through the final maintenance module, showing avoided repeated GC failures, preserved reflog-only history, log-once suspension, and successful explicit retry. No stored-data format or migration contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Linux verification exercises real ManagedWorktreeService operations and native Git through the final maintenance module, showing avoided repeated GC failures, preserved reflog-only history, log-once suspension, and successful explicit retry. No stored-data format or migration contract changes.

Label justifications:

  • P2: This addresses repeated maintenance failures and subprocess waste while ordinary worktree cleanup remains available.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Linux verification exercises real ManagedWorktreeService operations and native Git through the final maintenance module, showing avoided repeated GC failures, preserved reflog-only history, log-once suspension, and successful explicit retry. No stored-data format or migration contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Linux verification exercises real ManagedWorktreeService operations and native Git through the final maintenance module, showing avoided repeated GC failures, preserved reflog-only history, log-once suspension, and successful explicit retry. No stored-data format or migration contract changes.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head diff for the five introduced paths. The maintenance block is replaced by one service-owned module; endpoint drift was not attributed to this PR. (src/agents/worktrees/git-maintenance.ts:14, 5650a3b065ab)
  • Current main still needs the repair: Fetched main retains maintenance run --auto without explicit tasks or repository failure suspension. Each cleanup pass can therefore repeat the same maintenance failure. (src/agents/worktrees/service.ts, 6de5ce9777a6)
  • Release inspection: Inspected the maintenance-related portion of the service at the supplied latest release, v2026.9.8, through GitHub contents. It does not contain this incremental-maintenance repair; no fixed release is established. (src/agents/worktrees/service.ts:1290, fc23bc864e45)
  • Native Git task contract: The introduced module directly executes Git maintenance, establishing the dependency signal. Git's v2.53.0 documentation explains explicit task selection, threshold gating, duplicate-only loose-object deletion, and incremental pack replacement: https://github.com/git/git/blob/v2.53.0/Documentation/git-maintenance.adoc. These support the intended preservation behavior without full GC. (Documentation/git-maintenance.adoc)
  • Real production-boundary verification: The complete supplied PR body reports real service create/remove/gc calls on isolated Linux with Git 2.53.0: failures changed from 3/3 cycles to 0/3, and maintenance subprocesses from 18 to 3. Forced thresholds preserved a surviving worktree's reflog-only commit through the final extracted module. A native MIDX lock failure yielded one attempt and warning across three cycles, followed by successful explicit retry after lock removal. No latency, memory, or deployed-journal improvement is claimed. (src/agents/worktrees/git-maintenance.ts:38, 5650a3b065ab)
  • Regression value and reported validation: Read the complete changed test file. Coverage protects shared-repository deduplication, failure suspension, explicit retry, cancellation, inventory failure, and native reflog/object preservation. The body reports intended baseline failures, 5/5 focused tests, 555 passing worktree tests, and a passing changed gate. Focused wall time was 38.09 seconds, including 23.4 seconds of cold worker preparation; the real-Git regression took 3.724 seconds. These checks were not rerun during this read-only review. (src/agents/worktrees/service.gc-maintenance.test.ts:164, 5650a3b065ab)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 22af012 into main Oct 5, 2026
215 of 217 checks passed
@steipete
steipete deleted the steipete/perf-micro-worktree-git-maintenance-20260919 branch October 5, 2026 00:18
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant