Repository navigation
fix(git): rebuild stale worktree pack indexes - #165995
Conversation
Build the multi-pack index from the current pack inventory so a removed pack named by the previous index cannot prevent repair. Preserve Git's native publication and the existing maintenance/removal ownership. Cover stale-index recovery through real Git, verify retained HEAD content, and document repair after pack replacement. Keep the existing PR statistics revision cache and unstaged/untracked refresh behavior unchanged.
|
🦞👀 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 6, 2026, 3:49 AM ET / 07:49 UTC. ClawSweeper reviewWhat this changesThe PR rebuilds managed-worktree pack indexes from current pack filenames and adds a real-Git regression plus documentation for recovery after pack replacement. Merge readiness✅ Ready for maintainer review Keep open: this is a useful, focused repair still missing from pinned main. No actionable correctness or security findings remain, and the supplied Git-boundary evidence supports recovery. Priority: P2 Review scores
Verification
How this fits togetherManaged-worktree maintenance and removal repair Git’s shared object lookup before further maintenance or recovery snapshots. The repair consumes the repository’s pack inventory and lets Git publish the replacement index. flowchart TD
A[Background maintenance] --> C[Pack-index repair]
B[Worktree removal] --> C
C --> D[Current pack inventory]
D --> E{Pack indexes present?}
E -->|Yes| F[Git atomic index writer]
E -->|No| G[Continue existing workflow]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +5, Tests +25, Docs 0. Total +30 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep Git’s native atomic writer and the existing shared repair owner, rebuilding lookup from the current pack inventory while preserving objects and lifecycle guards. Do we have a high-confidence way to reproduce the issue? Yes: restoring an old multi-pack index after replacing its packs gives a concrete failure path, supported by the supplied before/after Git results and current-main source. This read-only review did not execute it. Is this the best way to solve the issue? Yes: supplying current pack-index basenames uses Git’s existing writer and fixes the shared owner without deleting live metadata or adding competing recovery logic. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ca43d1919788. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Build the multi-pack index from the current pack inventory so a removed pack named by the previous index cannot prevent repair. Preserve Git's native publication and the existing maintenance/removal ownership. Cover stale-index recovery through real Git, verify retained HEAD content, and document repair after pack replacement. Keep the existing PR statistics revision cache and unstaged/untracked refresh behavior unchanged.
What Problem This Solves
Fixes worktree pack-index repair failing with
could not load packwhen an old multi-pack index references a pack that has already been replaced. The failure suspends repository maintenance and can leave Git-backed session statistics and cleanup expensive.User Impact
Managed-worktree maintenance and removal can rebuild the stale index while preserving all repository objects. PR statistics retain their existing revision cache and five-minute refresh for unstaged/untracked edits. There are no config or schema changes.
Why This Change Was Made
Git normally reads every pack named by the old MIDX before discovering current files; one stale entry aborts the repair. Pass the existing shallow directory inventory to
multi-pack-index write --stdin-packs, which uses Git's native atomic writer without reusing the stale index. OpenClaw does not delete or rename the live MIDX or modify packs.Production delta: +5 lines. Git's explicit-pack writer requires streaming the current index filenames; this replaces its implicit stale-index reuse without adding a cache, retry branch, or second repair owner.
Evidence
could not load pack. The candidate rebuild is checked withmulti-pack-index verifyand a HEAD content read.Synthetic pack-lookup rig: 50 worktrees × 10 polls, 1,000 tracked files, 1,901 reachable-blob promisor packs plus one metadata pack, two concurrent Git children. The old repair failed with exit 255; the rebuilt MIDX verified successfully. All 500 reads in each phase reported identical statistics.
Measured child-time reduction: 23.8%, below the campaign's 80% target. This is direct Git-boundary proof, not a full Gateway/UI load test. The fixture does not reproduce the full production object database; OS caches are warm and the baseline runs first. The deterministic repair failure is the reason to ship this fix.
No live deployment or production pack rewrite was performed. The 80% production worker-time target remains unverified until the repaired index is deployed and the same workload is measured.
Remote run record
All runs used
blacksmith-testbox, profileopenclaw-check, through the installed Crabbox CLI. No suites, typechecks, or builds ran on the Mac.tbx_01m47ym7tn7110a5bh901sn716node scripts/run-vitest.mjs src/infra/git-read-cache.test.ts --maxWorkers=1node --import ./scripts/tsx.mjs .local/lane545/poll-rig.mjs /tmp/lane545-before.jsonnode scripts/run-vitest.mjs src/gateway/control-ui-session-prs-branch.test.ts --maxWorkers=1node .local/lane545/index-refresh-rig.mjs /tmp/lane545-index-refresh.jsonnode scripts/run-vitest.mjs src/agents/worktrees/service.gc-maintenance.test.ts --maxWorkers=1on original production codecould not load pack; five existing tests passed. Vitest 11.30 s.tbx_01m480hnzamsd5wm47d4d39pkgnode scripts/run-vitest.mjs src/agents/worktrees/service.gc-maintenance.test.ts --maxWorkers=1node scripts/check-changed.mjs --stagednode scripts/check-changed.mjs --stagedunicorn/prefer-set-has; corrected to aSet.node scripts/check-changed.mjs --staged -- src/agents/worktrees/service.gc-maintenance.test.ts docs/concepts/managed-worktrees.mdnode scripts/run-vitest.mjs src/agents/worktrees/service.gc-maintenance.test.ts --maxWorkers=1after the lint fixLANE545_FILES=1000 LANE545_PROMISOR_PACKS=1901 node .local/lane545/stale-midx-rig.mjs /tmp/lane545-stale-midx.jsonTestbox proof used base
4304c49a8ea7. The reviewed three-file patch was replayed cleanly onto current main; its stable patch ID is unchanged. Both leases were stopped. Independent Codex autoreview of the final diff completed scoped-clean, P0–P2, with no accepted/actionable findings. CI run 37431710121 passed on exact head9160aba9a40fin 646 elapsed seconds (07:45:54–07:56:40 UTC), with all scheduled jobs successful and no CI reruns. The lead’s watcher merged the PR as788f8f110316after the gate passed.