Repository navigation
perf(worktrees): keep repository maintenance out of removal - #167695
Conversation
Let background maintenance own pack repair and consolidation, including repositories retained only by snapshots. Keep bounded pack work progressing when graph or loose-object tasks fail. Prevent snapshot operations from implicitly fetching missing promisor objects. Preserve native object validation and checkout custody so explicit repository repair can be followed by a safe retry.
|
🦞👀 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. What this changesManaged worktrees are isolated Git checkouts; this PR moves shared repository maintenance out of individual removal and preserves checkouts when snapshot objects are missing. Example: An operator removes a checkout whose README.md snapshot object is missing.
Review scores
ProductKind: Performance · Worth it: Yes Merge readiness✅ Ready for maintainer review This PR retains a distinct, measured improvement absent from current main. No actionable introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherOpenClaw gives agent sessions isolated Git checkouts and saves recoverable snapshots before removing them. Its cleanup service also maintains the shared repository that stores checkout and snapshot objects. flowchart TD
A[Removal request] --> B[Existing ownership and removal claim]
B --> C[Snapshot using local objects]
C --> D{Required objects available?}
D -->|Yes| E[Save snapshot and remove checkout]
D -->|No| F[Preserve checkout for repair and retry]
G[Periodic cleanup] --> H[Maintain repositories with live checkouts or snapshots]
Technical reviewBest possible solution: Keep repository-wide work in the existing maintenance owner and retain lossless snapshot failure and explicit repair-and-retry behavior. Do we have a high-confidence way to reproduce the issue? Yes: current main unconditionally repairs the shared index during removal, and the real-object-loss fixture exposes snapshot lazy fetching. The supplied remote runs report baseline failures; this read-only review did not rerun them. Is this the best way to solve the issue? Yes: the patch removes the competing removal maintenance path, uses the existing repository owner, and changes snapshot policy at the host Git broker without weakening native object validation or checkout custody. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 83c8fea9408f. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -3, Tests +130, Docs 0. Total +127 across 7 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel 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 Reviewed October 9, 2026, 3:53 AM ET / 07:53 UTC. |
…#167695) Let background maintenance own pack repair and consolidation, including repositories retained only by snapshots. Keep bounded pack work progressing when graph or loose-object tasks fail. Prevent snapshot operations from implicitly fetching missing promisor objects. Preserve native object validation and checkout custody so explicit repository repair can be followed by a safe retry.
What Problem This Solves
Removing one managed worktree rebuilds the shared repository's entire multi-pack index. Large partial clones pay that repository-wide cost for every removal. Snapshot creation can then spend another two minutes implicitly fetching missing objects through inconsistent commit-graph state.
User Impact
Individual removals stop rebuilding pack indexes. Snapshot Git operations use local objects and preserve the checkout when required objects are missing; an explicit fetch or repository repair followed by retry completes ordinary removal. Native object validation, pending recovery pins, ownership checks, timeout budgets, and the existing explicit force/capacity-eviction snapshot-loss policy remain intact. No configuration or schema migration is required.
Why This Change Was Made
The existing background maintenance owner now exclusively owns pack repair and consolidation. It includes retained snapshot repositories, so removing the last live checkout cannot strand a backlog. Commit-graph/loose-object failures suspend those tasks while bounded pack consolidation continues; a pack failure still requires explicit retry or restart.
The unconditional repair and timing stage originated in #165913. Consolidation from #167453 runs only in maintenance; #167473's fetch healing is not invoked by removal. This change removes the old removal call, exported internal repair helper, optional consolidation branch, and obsolete timing field. The snapshot broker applies its no-fetch policy to inventory, ordinary snapshots, and exact-state verification through one operation-owned environment.
Production LOC: 28 additions, 31 deletions; net -3.
Evidence
Real
ManagedWorktreeService.removeruns on a synthetic partial clone with 4,700 indexed packs, 2,405,376 filler objects, and 20,000 tracked files. Each of 30 samples adds one fresh indexed pack outside the removal timer. Both revisions start with the same maintained MIDX state and preserve dirty tracked/untracked content in snapshots.Cold-inclusive p99 is dominated by worker bootstrap; no cold-start improvement is claimed. A separate intentionally unindexed run measured p50 1,566 → 1,974 ms: without a MIDX, native reads are slower until maintenance builds one. This is the tradeoff for moving repository maintenance entirely off removal. Sample percentiles are not population-tail estimates, and synthetic data does not reproduce production filesystem pressure or complete history. Healthy benchmarks used the same no-fetch environment on both sides to isolate pack-repair cost.
Validation:
tbx_01m4fmt7geda3ef0ywp6t67ch6,openclaw-check: benchmark commandnode --import ./scripts/tsx.mjs .local/lane696/bench.mts --samples 30 --seed-midx --pack-churn, once per revision; combined run 255.1s, passed. Separate stale-MIDX probe confirms safe removal with an index referring to deleted packs. The lease was stopped after a later sync exceeded its fixed two-minute timeout before running tests.cbx_b7bb79c88d88:pnpm test src/agents/worktrees/service.gc-performance.test.ts --maxWorkers=1— 13 passed, 45.96s wall time including cold worker preparation (about 22.6s actual tests; the new missing-object case is 1.42s). Real Git/object loss and SQLite admission require this boundary.e670b178f9dbdde25a074913d9c97fa9b8b533b6. The missing-object regression also fails on that base, then proves the candidate preserves files withoutupload-pack, permits explicit repair, and succeeds on retry.node scripts/run-vitest.mjs src/agents/worktrees src/infra/git-worker.lifecycle.test.ts src/infra/git-worker.diagnostics.test.ts src/infra/git-operation-timing.retention.test.ts src/infra/git-content-budget.test.ts src/infra/git-exec.test.ts— 695 passed, 34 platform-specific skips, 58 passing / 6 skipped files, 508.44s on AWS. All 59 worktree sibling files were selected.node scripts/check-changed.mjs— production types, all 27 test type graphs, and preceding guards passed; dead-export scan fails identically on the unchanged base and candidate forbindCliQuestionAnswerAuthority,prepareSessionEventTargetForHost,readSessionEntryCreationTransition, andRESTART_CONTINUATION_CONTEXT_PREFIX. All are outside this diff. Candidate lint (zero warnings/errors), native schema, legacy-store, media-helper, runtime-sidecar, import-cycle, webhook-body, and pairing guards all pass. The full gate is recorded as an inherited failure, not green.pnpm build— passed, 308.8s on AWS. It emitted a non-blocking, unrelated UI startup gzip warning: 373,491 B versus a 373,454 B budget; no UI files are changed.Read-only journal evidence identifies
write-tree's implicit fetch as the observed two-minute snapshot failure. The regression exercises that fetch boundary and recoverability without recreating production corruption or sleeping through its timeout. This is service/native-Git boundary proof, not an installed CLI/Gateway end-to-end run. Hosted CI 37901007450 is green onf3aab3944acf6582b1f670bacfcb92c8422613e4(49 successful jobs, 25 intentional skips), as are CodeQL and OpenGrep. ClawSweeper reports no findings or before-merge requirements.CI test cost:
service.gc-performance.test.ts— 13 passed, 11.180s summed case time (missing-object regression 0.516s), in a 128s job;service.diagnostics.test.ts— 7 passed, 9.854s summed case time, in a 203s job. Job wall times include other tests and setup.