Skip to content

fix(git): rebuild stale worktree pack indexes - #165995

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-git-operations-worker-cost-20260919
Oct 6, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-git-operations-worker-cost-20260919

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes worktree pack-index repair failing with could not load pack when 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

  • Read-only production attribution: PR branch facts accounted for 480.4 of 495.4 Git-worker seconds in the sampled 15-minute window. Repeated shortstat processes reached the 120-second budget with unchanged index/base metadata. The repair log contained the same missing-pack failure reproduced by the regression.
  • Existing 50-worktree × 10-client owner-boundary rig: 1,500 warm polls produced zero Git spawns, with 785.9 ms aggregate worker duration. HEAD, index and base-ref invalidation and the unstaged fallback all preserved expected statistics. This established that the existing caller cache should remain the owner.
  • Regression: a real repository is repacked while an old MIDX is restored; the original repair fails with exit 255 / could not load pack. The candidate rebuild is checked with multi-pack-index verify and 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.

Measurement Stale MIDX Rebuilt MIDX
Summed Git child time 26.277 s 20.022 s
Wall time 13.148 s 10.017 s
Median shortstat 52.47 ms 39.63 ms
p95 shortstat 58.70 ms 45.67 ms

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, profile openclaw-check, through the installed Crabbox CLI. No suites, typechecks, or builds ran on the Mac.

Lease Command Result
tbx_01m47ym7tn7110a5bh901sn716 node scripts/run-vitest.mjs src/infra/git-read-cache.test.ts --maxWorkers=1 12 passed; Vitest 1.40 s. Dependencies installed once first.
Same node --import ./scripts/tsx.mjs .local/lane545/poll-rig.mjs /tmp/lane545-before.json Passed all 50-worktree/10-client baseline and invalidation assertions; 1,500 warm polls, zero Git spawns.
Same node scripts/run-vitest.mjs src/gateway/control-ui-session-prs-branch.test.ts --maxWorkers=1 55 passed; Vitest 62.00 s including cold worker preparation.
Same node .local/lane545/index-refresh-rig.mjs /tmp/lane545-index-refresh.json Synthetic stale-stat experiment: explicit refresh 74.8 ms vs automatic 182.6 ms; repeat diffs both ~3.5 ms. This did not reproduce the stale-MIDX repair defect and was not shipped.
Same node scripts/run-vitest.mjs src/agents/worktrees/service.gc-maintenance.test.ts --maxWorkers=1 on original production code Expected regression failure: could not load pack; five existing tests passed. Vitest 11.30 s.
Same Candidate tests + staged check, then one retry with sync diagnostics Both stopped before execution: native checksum sync exceeded its two-minute limit. Lease stopped.
tbx_01m480hnzamsd5wm47d4d39pkg node scripts/run-vitest.mjs src/agents/worktrees/service.gc-maintenance.test.ts --maxWorkers=1 Six passed; new regression 191 ms, test file 27.85 s including cold worker preparation, wrapper 29.46 s. Dependencies installed once.
Same Initial node scripts/check-changed.mjs --staged No-op because native sync leaves changes unstaged; not counted as gate proof. Exact three files staged before the real gate below.
Same node scripts/check-changed.mjs --staged Production types, all 27 core-test graphs, guards, formatting and dead-export scans passed. New test hit unicorn/prefer-set-has; corrected to a Set.
Same node scripts/check-changed.mjs --staged -- src/agents/worktrees/service.gc-maintenance.test.ts docs/concepts/managed-worktrees.md Passed after the mechanical test correction; reused unchanged production and other test-graph proof. Narrow test graph passed in 6.3 s.
Same node scripts/run-vitest.mjs src/agents/worktrees/service.gc-maintenance.test.ts --maxWorkers=1 after the lint fix Six passed; Vitest 7.77 s, wrapper 9.26 s, new regression 144 ms.
Same LANE545_FILES=1000 LANE545_PROMISOR_PACKS=1901 node .local/lane545/stale-midx-rig.mjs /tmp/lane545-stale-midx.json Passed repair, object completeness and identical-stat assertions; measured 23.8% child-time reduction.

Testbox 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 head 9160aba9a40f in 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 as 788f8f110316 after the gate passed.

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

clawsweeper Bot commented Oct 6, 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 agents Agent runtime and tooling size: XS labels Oct 6, 2026
@steipete
steipete enabled auto-merge (squash) October 6, 2026 07:46
@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 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 3:49 AM ET / 07:49 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 9160aba9a40f43e8f66ea84c6ad7bae7ebf0d195

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful real-Git evidence, an appropriate regression, and no blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied Testbox record exercises stale-index recovery with real Git, reports the original failure and successful rebuilt-index verification, and preserves object reads and statistics. The production-owner regression corroborates the boundary; broader production performance remains unclaimed. 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 (terminal): The supplied Testbox record exercises stale-index recovery with real Git, reports the original failure and successful rebuilt-index verification, and preserves object reads and statistics. The production-owner regression corroborates the boundary; broader production performance remains unclaimed. No stored-data format or migration contract changes.
Evidence reviewed 8 items Pinned introduced change: The verified main-to-head delta changes only the existing repair’s pack selection, its regression, and related documentation; it preserves the existing owner and guards.
Still necessary on main: Pinned main still invokes multi-pack-index write without an explicit pack list, retaining the reported stale-index failure mechanism.
Authoritative Git contract: Dependency relevance is established by the introduced --stdin-packs invocation. Git documents line-delimited pack-index basenames, and its writer bypasses reuse of the existing index when packs_to_include is supplied. Repository ownership was verified through the GitHub API. Source: https://github.com/git/git/blob/v2.51.0/midx-write.c#L1087.
Findings None None.
Security None None.

How this fits together

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

Before merge

None.

Agent review details

Security

None.

PR surface

Source +5, Tests +25, Docs 0. Total +30 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 2 +5
Tests 1 25 0 +25
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 33 3 +30

Review metrics

Metric Value Why it matters
Production versus regression growth production +5 lines, tests +25 lines Production growth is justified by streaming Git’s explicit pack inventory; regression coverage exercises recovery without adding a production test seam.

Technical review

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

Labels

Label changes:

  • add P2: This repairs a bounded repository-maintenance failure without evidence of a widespread urgent runtime regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied Testbox record exercises stale-index recovery with real Git, reports the original failure and successful rebuilt-index verification, and preserves object reads and statistics. The production-owner regression corroborates the boundary; broader production performance remains unclaimed. 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 (terminal): The supplied Testbox record exercises stale-index recovery with real Git, reports the original failure and successful rebuilt-index verification, and preserves object reads and statistics. The production-owner regression corroborates the boundary; broader production performance remains unclaimed. No stored-data format or migration contract changes.

Label justifications:

  • P2: This repairs a bounded repository-maintenance failure without evidence of a widespread urgent runtime regression.
  • 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 (terminal): The supplied Testbox record exercises stale-index recovery with real Git, reports the original failure and successful rebuilt-index verification, and preserves object reads and statistics. The production-owner regression corroborates the boundary; broader production performance remains unclaimed. No stored-data format or migration contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Testbox record exercises stale-index recovery with real Git, reports the original failure and successful rebuilt-index verification, and preserves object reads and statistics. The production-owner regression corroborates the boundary; broader production performance remains unclaimed. No stored-data format or migration contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 3c66417 adds src/agents/worktrees/git-maintenance.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3c66417c08e3; files: src/agents/worktrees/git-maintenance.ts)

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 788f8f1 into main Oct 6, 2026
131 of 132 checks passed
@steipete
steipete deleted the steipete/perf-micro-git-operations-worker-cost-20260919 branch October 6, 2026 07:57
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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: XS 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