Skip to content

perf(worktrees): bound Git pack maintenance to verified batches - #182204

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-midx-maintenance-memory-20260919
Oct 24, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-midx-maintenance-memory-20260919

Conversation

@steipete

@steipete steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Hourly managed-worktree housekeeping can rebuild a multi-pack index over every repository object, despite selecting only a bounded pack batch. Both the explicit final write and Git's implicit rebuild inside multi-pack-index expire escape the batch budget.

User Impact

Pack maintenance now retires verified batches without repository-wide MIDX allocation. Git reads objects through individual pack indexes. Pack groups continue making bounded, size-based progress below the old 16-pack threshold. No configuration or schema migration is required.

Why This Change Was Made

Remove MIDX writing/expiry and retire only selected inputs after index-pack publishes their replacement. Preserve unreachable objects, separate promisor/local groups, kept/cruft packs, an output already matching an input, cancellation, and corrupt-input protection. Invalidate both monolithic and incremental MIDX entry points so stale metadata cannot override pack-local lookup.

The 512 MiB/1,024-pack batch budget now also caps index input at 32 MiB, bounding object metadata independently of compression. Trim dominant packs until the smaller inputs together reach the largest selected pack's size; consolidate only if at least two remain. This avoids repeatedly rewriting a large pack for tiny additions while allowing byte-limited batches to continue converging. It does not promise one final pack. CPU/IO priority, single-thread packing, hourly throttling, and five-minute verification/rewrite budgets remain.

This is an input bound, not an OS RSS hard limit. The host-exec memory watcher does not own this Git execution path. Production delta: +23 lines; the growth implements the metadata bound and safe input retirement while deleting full-repository indexing/expiry. No production API or module is added.

Evidence

  • Baseline regressions fail for the intended reasons: no-work maintenance launches a MIDX writer; stale lookup repair recreates the full MIDX. Both pass with the fix.
  • Final focused run: node scripts/run-vitest.mjs src/agents/worktrees/service.gc-performance.test.ts src/agents/worktrees/service.removal-budget.test.ts src/agents/worktrees/service.gc-empty-maintenance.test.ts --maxWorkers=1: 36 passed, 1 Linux-only skip on macOS, 125.72 s Vitest / 142.60 s wrapper wall time. Real Git integration covers snapshots, partial clones, corrupt inputs, byte/index caps, failed publication, output identity, late pinning, and small-pack convergence without rewriting the dominant pack.
  • Changed-file oxlint, oxfmt, and git diff --check passed. The earlier implementation passed local pnpm tsgo:core; final typecheck and broad platform proof use PR CI. No full local suite/build or Testbox lease.
  • Independent subagent review (autoreview route unavailable): final changes have no P0–P2 findings. Corrected stale docs and clarified the exact size rule. Autoreview preflight refused the requested provider because it did not match operator configuration; configuration was not changed.

Native probe: 2,097,152 unique 16-byte blobs, 32 MiB payload, approximately 92 MiB packed storage. Linux/Git 2.53.0 measured the removed full MIDX writer at 339.320 ms / 181.648 MiB peak RSS (0.25 s user + 0.06 s system CPU). The candidate launches zero MIDX writers; this is eliminated native work, not a measured total-Gateway RSS reduction or a reproduction of the reported multi-gigabyte incident.

The initial unchanged 32-pack Linux layout showed a real lookup tradeoff: four warmed 4,096-object batches averaged 19.512 ms with MIDX → 29.570 ms without, +10.059 ms / +51.55% (+2.456 µs/object). This result is retained, not labeled noise.

A subsequent native macOS/Git 2.56.0 probe applied the bounded selection twice: 32 → 15 → 2 packs, with all 2,097,152 objects retained and every sampled object identity/type/size verified. On the resulting two-pack layout:

4,096-object batch Four samples, ms Mean, ms
With MIDX 25.741, 34.289, 29.466, 26.049 28.886
Without MIDX 27.330, 28.281, 25.605, 26.824 27.010

Delta: −1.876 ms / −6.50%, treated as neutral context, not a speedup claim. Earlier Mac 32-pack and 15-pack baselines were unstable; they do not establish a throughput improvement. The Linux follow-up was cancelled before execution after an exclusive-slot wait; fresh Mac baselines were used, never cross-host timing comparisons.

Reproduce with committed scripts/perf/managed-git-maintenance-measure.ts: --mode prepare-midx --packs 32 --blobs-per-pack 65536, then --mode measure-midx; --consolidate applies one bounded native batch before measuring reads. These probes exercise native Git commands, not the complete maintenance owner. Consolidation itself, total process-tree RSS, V8 GC/promotion, and Gateway RPC latency were not measured. No short GC/pause percentile or uncalibrated relative outlier was used as a rejection gate. The landing rationale is removed unbounded work, real Git integrity proof, and neutral resulting-layout context rather than a claimed latency win. Many retained oversized packs may still incur a pack-local lookup cost; no production deployment or live before/after claim is made.

Related: #182086.

@clawsweeper

clawsweeper Bot commented Oct 24, 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.

@steipete
steipete marked this pull request as ready for review October 24, 2026 04:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T05:03:43.255549Z f25d137 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts agents Agent runtime and tooling size: M labels Oct 24, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@steipete
steipete force-pushed the steipete/perf-micro-midx-maintenance-memory-20260919 branch from 984ed9f to 4fd450f Compare October 24, 2026 04:39
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR replaces repository-wide multi-pack indexing and expiry with verified pack-batch replacement and direct retirement of covered inputs.

Example: Hourly maintenance finds 32 eligible packs in one group.

  • Before: A bounded consolidation can still trigger a multi-pack index rebuild covering the whole repository.
  • After: Maintenance verifies and rewrites inputs within the 512 MiB pack and 32 MiB index budgets, then retires covered inputs without rebuilding the repository-wide index.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported change with real-Git integration coverage and green exact-head CI, limited by harness-level proof and an unresolved measured performance tradeoff.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; real-Git integration results and a native MIDX probe support the change, but the probe explicitly bypasses the complete maintenance owner.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Background housekeeping can allocate repository-wide object metadata despite selecting a bounded pack batch.
Reason: The maintainer-authored direction removes unnecessary global work through the established owner without introducing configuration or public contracts.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open: it removes unbounded repository-wide indexing through the existing maintenance owner, with no discrete correctness finding; the acknowledged lookup-performance tradeoff remains unresolved.

Priority: P2
Reviewed head: 4fd450f49932e14bce8b72a26d67b11a84364cb1
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should landing wait for the promised consolidated-layout lookup results, or is the recorded read slowdown acceptable in exchange for eliminating repository-wide MIDX allocation?
  • Recommendation: Wait for the promised comparison: Review lookup performance after the candidate's bounded consolidation before deciding whether the tradeoff is acceptable.
  • Why: The author acknowledges an adverse fixed-layout result and promises a follow-up before landing, but neither that result nor explicit acceptance of the slowdown is recorded.

Before merge

  • Resolve merge risk - Before merge, the area owner should resolve the measured lookup slowdown by reviewing the promised consolidated-layout results or explicitly accepting the read-cost tradeoff.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied native probe does not exercise the shipped worktree GC entry point or measure its resulting lookup performance.
Agent review details

How this fits together

Managed-worktree housekeeping inventories registered repositories, shares Git mutation ownership with managed fetches, and produces consolidated packs and maintenance progress receipts.

flowchart TD
  A[Hourly housekeeping or explicit GC] --> B[Managed worktree service]
  B --> C[Repository maintenance owner]
  C --> D[Git mutation queue and content slot]
  D --> E[Bounded pack verification]
  E --> F[Native replacement publication]
  F --> G[Selected input retirement]
  G --> H[Pack indexes and progress receipts]
Loading

Technical review

Best possible solution:

Keep the single bounded maintenance owner and settle the object-lookup tradeoff before landing.

Do we have a high-confidence way to reproduce the issue?

Current-main source shows bounded pack selection followed by repository-wide MIDX writing, and the PR reports two baseline-failing regressions; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch removes the global operation at its existing owner, preserves native pack publication and verification, and avoids a second scheduler or memory watcher; its lookup-cost tradeoff still needs resolution.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6f88c26dcf82.

Merge-risk options

Maintainer options:

  1. Resolve the pending lookup comparison (recommended)
    The PR owner supplies the promised consolidated-layout result for the area owner to assess.
  2. Accept slower object lookup
    The area owner explicitly accepts the reported read-cost increase for bounded maintenance allocation.

Provenance checked

  • Pack consolidation and MIDX expiry changes intended behavior with a stated reason (69e3876: Native consolidation and batch expiry reduced fragmented shared-clone packs while preserving promisor separation and locally available objects.)
  • Repository-wide rebuild after expiry changes intended behavior with a stated reason (c142649: The prior repair reduced repeated global rebuilds and extended their timeout; this PR removes the remaining global allocation instead.)
  • Stale pack-index recovery changes intended behavior with a stated reason (788f8f1: Rebuilding from current pack filenames repaired stale MIDX references; the replacement invalidates optional lookup metadata and retains pack-local reads.)
  • Existing measurement harness keeps the original intent (8720a81: The harness measured synthetic managed-clone maintenance and verified retained objects; the PR extends it with an explicitly separate native MIDX probe.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +20, Tests +99, Docs 0, Other +176. Total +295 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 59 39 +20
Tests 2 113 14 +99
Docs 1 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 206 30 +176
Total 5 380 85 +295

Review metrics

Metric Value Why it matters
Production versus test LOC Production +59/-39; tests +113/-14 Production growth implements the index-input bound and selected-input retirement; added integration coverage protects distinct publication, identity, pinning, and budget failures.

Labels

Label changes:

  • add merge-risk: 🚨 other: Removing MIDX increases measured object-lookup latency on the supplied fixed-pack workload; the resulting-layout tradeoff remains unsettled.
  • remove status: 👀 ready for maintainer look: Current PR status no longer selects a status label.

Label justifications:

  • P2: This improves background Git maintenance resource use without evidence of an urgent current outage.
  • merge-risk: 🚨 other: Removing MIDX increases measured object-lookup latency on the supplied fixed-pack workload; the resulting-layout tradeoff remains unsettled.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Resolve the promised consolidated-layout lookup comparison or record explicit owner acceptance of the read-cost increase.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 24, 2026, 12:56 AM ET / 04:56 UTC.

Remove repository-wide MIDX writing and expiry from hourly housekeeping. Retire only verified inputs after replacement publication, preserve promise groups and pinned packs, and cap index bytes as well as pack bytes. Small duplicate groups defer until the consolidation threshold.
@steipete
steipete force-pushed the steipete/perf-micro-midx-maintenance-memory-20260919 branch from 4fd450f to f25d137 Compare October 24, 2026 05:01
@steipete
steipete merged commit 99aed8a into main Oct 24, 2026
134 of 135 checks passed
@steipete
steipete deleted the steipete/perf-micro-midx-maintenance-memory-20260919 branch October 24, 2026 05:15
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…claw#182204)

* perf(worktrees): bound Git pack maintenance to verified batches

Remove repository-wide MIDX writing and expiry from hourly housekeeping. Retire only verified inputs after replacement publication, preserve promise groups and pinned packs, and cap index bytes as well as pack bytes. Small duplicate groups defer until the consolidation threshold.

* test(perf): compare lookups after bounded pack consolidation

* perf(worktrees): let bounded pack batches converge by size
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 merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant