Skip to content

fix: prevent tiny-pack storms during agent history reads - #197259

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-per-blob-lazy-fetch-storm-20260919
Nov 11, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-per-blob-lazy-fetch-storm-20260919

Conversation

@steipete

@steipete steipete commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes bursts of tiny promisor packs when parallel agents read file history in shared blobless Git worktrees.

User Impact

Path-scoped patch/stat logs, ordinary blame, and repeated show rev:path reads hydrate bounded historical blob sets in one fetch. Command output stays unchanged. Native diff already batches endpoint blobs and keeps that implementation.

Warm history reads have extra offline discovery work: final Linux medians are log 41.79→69.68 ms and blame 17.82→30.07 ms (three additional Git processes). Loaded macOS controls showed increases of 79–88 ms; shared-host timing noise is recorded. Peter explicitly accepted this tradeoff on 2026-11-11: +28 ms for warm log and +12 ms for warm blame is acceptable for cold log 13.5 s→76 ms, cold blame 12.6 s→63 ms, and collapsing roughly 600 single-blob promisor packs into one. Production evidence supplied with that decision: 596 single-blob promisor packs appeared during 13:45–13:52Z, contributing to the shared base growing from 1,032 to 1,643 packs. This is acceptance of the measured regression, not a claim of production validation after deployment. No new configuration, persistent cache, dependency, or schema.

Why This Change Was Made

The PATH shim already prepares missing commits, but history traversal leaves blobs to individual lazy fetches. Git's offline raw changes supply old/new IDs—including range and count boundaries—without scanning unrelated tree contents. A common-directory lock and missing-object check under that lock coalesce identical/overlapping readers.

Batches cap candidate IDs at 2,048 and 128 KiB; raw discovery stops at 8 MiB. These bound discovery/request size, not unknown remote blob payload sizes. Unsupported forms, content/rename tracking, oversized batches, prefetch errors, and bounded lock waits retain native lazy hydration. Present show objects skip history preparation; absent show objects prepare path history reachable from HEAD and the requested revision, covering loops in either order.

Known blob-only batches use Git's native noop negotiation. Advertising a commit as a have can suppress its promised blobs: a retained synthetic fixture produced an empty negotiated pack followed by individual lazy fetches. Blob-only roots transfer only requested blobs; missing-commit preparation still negotiates history.

Evidence

Acceptance rule: on a fresh blobless shared clone with 62,000 stable paths (~1.116 GB logical content) and 600 append-only historical file versions, preserve output and transferred object counts while reducing promisor packs/transport starts from per-blob to one. Cold and warm runs are separate; a warm regression over 20% requires explicit acceptance.

Five counterbalanced A/B pairs per command, cached Linux environment with networking disabled, native filesystem, 2 CPUs, Git 2.47.3:

Cold read Baseline → candidate
Log wall median / p95 13,486 / 55,979 → 76 / 475 ms
Blame wall median / p95 12,621 / 14,362 → 63 / 69 ms
Log native CPU median 9,527 → 68 ms
Blame native CPU median 10,358 → 58 ms
Log new promisor packs 599 → 1
Blame new promisor packs 600 → 1
Log wire pack bytes 401,567 → 25,348
Blame wire pack bytes 402,824 → 25,348

Every sample transfers exactly 600 blob objects and preserves output hashes. A/A log control was 29.29→10.72 s (substantial startup/host drift); blame was 11.72→11.12 s. The shared host is busy, so counts and CPU are stronger evidence than wall tails. macOS Git 2.56 independently reproduced 600 tiny packs; a full-scale candidate used one pack in ~0.5 s. Native allocation requests fall 4,969,628→102,312 for log and 5,328,179→81,996 for blame. Cumulative requested bytes fall 1,917,393,829→164,732,426 and 1,964,552,946→148,843,295 (91–92% less). These are observable malloc-family requests across Git children, not live heap; separate A/A byte drift is 0.0017% and zero. Five allocator-only pairs are separate from timing runs. Final-source warm and cold smoke pass; the final locale correction is ASCII-equivalent for the full fixture.

The committed workload is node --import ./scripts/tsx.mjs scripts/perf/agent-git-probes.mts --history-blobs --commits 600 --files 62000 --samples 5 --baseline-shim <saved-baseline-shim> --scratch-parent <isolated-directory>; --aa-only, --ab-only, and --warm select separate controls.

Real-Git regressions pass (3 tests): original log/blame 11 packs, show loop 3 packs, concurrent identical reads 11 packs → one each; output/path scope, offline probes, bounded/ranged log boundaries and oversized fallback are preserved. Existing owner tests pass (2 tests). A 100-path native diff control transfers exactly 200 endpoint blobs in one pack. New tests take ~5 s on the initial run (~15 s under later host load); the exact 190-line allocation covers these distinct boundaries.

Independent Codex autoreview of the implementation and follow-ups is clean through P2. Core and test typechecks pass. pnpm check:changed caught benchmark indexing/shadowing errors, now fixed with passing targeted scripts typecheck, lint and formatting. Its remaining unused-export findings reproduce identically on exact main parent 54bfcd8fd601618108b65f6637beb3f611f2e28e: 57 production, 32 full-tree, 0 script, no resolution errors. Introducing commits are attributed; no new finding appears beyond the previously reported main regressions. The full check is not claimed green. Exact-head CI run 43048946201 is green. ClawSweeper found no correctness or security issues on the final head; its sole open item was explicit warm-regression acceptance, now granted above. A final re-review with zero open items is required before landing.

Production growth: 145 lines, required for bounded command selection, native raw-object enumeration, and cross-process coordination where no blob-batching owner existed. No UI-imported modules changed. No deployment or production pack-rate validation is claimed.

Prepare bounded path-history blob sets before agent log, blame, and repeated show reads. Serialize common-directory prefetches and recheck missing objects under the lock so parallel readers share transfers. Keep native diff batching and negotiated commit acquisition; known blob-only wants use native noop negotiation to avoid falsely claiming missing blob closure.
Count raw discovery bytes under the C locale and use explicit benchmark sample values to satisfy strict indexing checks without changing sample order.
@clawsweeper

clawsweeper Bot commented Nov 11, 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 scripts Repository scripts size: M labels Nov 11, 2026
Use the constructed history length in workspace metadata and avoid shadowed variables in warm and allocator proof paths. Measured commands and sample ordering are unchanged.
@steipete
steipete marked this pull request as ready for review November 11, 2026 15:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T15:32:58.024815Z 6903215 Draft marked ready
ℹ️ 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.

@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. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR batches historical Git blob downloads and coordinates overlapping readers across shared worktrees.

Example: An agent reads 600 historical versions with git blame in a shared blobless clone.

  • Before: The supplied baseline produces 600 promisor packs and takes a median 12,621 ms.
  • After: The candidate produces one pack and takes a median 63 ms with identical output.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused implementation with real-command comparative evidence, meaningful regressions, successful exact-head CI, and the prior performance decision resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied measurements exercise the actual generated Git shim with native Git and file transport in isolated shared blobless clones, preserving output and object counts while reducing historical log/blame hydration to one pack; separate warm measurements document the accepted overhead.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Agent history reads create hundreds of tiny packs and spend seconds repeatedly starting Git transports.
Reason: The supplied measurements show large cold-read and pack-count improvements, and the feature owner explicitly accepts the measured warm-read regression.

Merge readiness

✅ Ready for maintainer review

The explicit maintainer acceptance satisfies the prior review’s sole open item. Final head 6903215 has zero open review items; no correctness or security findings remain.

Priority: P2
Reviewed head: 69032150beeea2f73c1b217b1e980b5d478bf426

Before merge

None.

Findings

None.

Agent review details

How this fits together

The agent PATH Git shim prepares repository objects before native Git runs, preserving command arguments and output while reducing repeated blob fetches.

flowchart LR
  A[Agent Git command] --> B[Existing PATH shim]
  B --> C[Bounded raw history discovery]
  C --> D[Shared lock and missing object check]
  D --> E[Native Git blob fetch]
  E --> F[Original Git command and output]
Loading

Technical review

Best possible solution:

Land the bounded batching in the existing Git shim with the recorded warm-read tradeoff accepted.

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

The supplied real-Git baseline measurements establish repeated single-blob hydration, and current-main source leaves historical blobs to that path; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch uses the existing Git query and fetch owner, preserves native diff batching and fallback behavior, and adds no persistent cache; its measured warm-read cost now has explicit owner acceptance.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7f5697b3bf9d.

Provenance checked

  • Missing-object fetch preparation keeps the original intent (83d8323: Prepare absent revision roots with history negotiation to avoid retransmitting existing commit and tree history.)
  • Native historical blob hydration changes intended behavior with a stated reason (b6d8eb2: Keep probes offline while allowing ordinary content commands to hydrate missing blobs.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +145, Tests +190, Docs +1, Other +124. Total +460 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 148 3 +145
Tests 1 190 0 +190
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 2 134 10 +124
Total 5 473 13 +460

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus regression coverage Runtime production +145 net lines; tests +190 lines The growth implements bounded discovery and cross-process sharing in the existing owner; the real-Git tests cover output, path scope, overlapping readers, offline behavior, and oversized fallback.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove merge-risk: 🚨 other: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on maintainer: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This addresses substantial Git history-read overhead and pack proliferation in shared blobless worktrees without an established core-runtime outage.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-11T15:44:40.671Z sha 6903215 :: blocked before merge. :: none

Reviewed November 11, 2026, 10:57 AM ET / 15:57 UTC (Revision 2).

@steipete

Copy link
Copy Markdown
Contributor Author

Addressing the latest ClawSweeper review, item 1 — Await maintainer action, on final head 69032150beeea2f73c1b217b1e980b5d478bf426:

Peter explicitly accepted the measured warm-read regression on 2026-11-11. Warm log increases from 41.79 to 69.68 ms (approximately +28 ms), and warm blame from 17.82 to 30.07 ms (approximately +12 ms). He accepts this cost for cold log 13.5 s→76 ms, cold blame 12.6 s→63 ms, and collapsing roughly 600 single-blob promisor packs into one.

Production evidence supplied with the decision: 596 single-blob promisor packs during 13:45–13:52Z, contributing to the shared base growing from 1,032 to 1,643 packs that morning. These are the peer's pre-fix observations; no deployment or post-deploy production validation is claimed.

The accepted cost comes from bounded offline raw-history discovery at agent-git-shim.ts:228–250 and missing-object preparation at lines 319–340. Already-present sets return before acquiring the shared lock; no persistent cache was added. No code changed for this acceptance. The PR body now records the decision and exact measurements. CI run 43048946201 is green on this head.

@clawsweeper re-review

Please verify item 1 is satisfied by the explicit maintainer acceptance and report the open-item count for this final head.

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. clawsweeper:intake:bug Preliminary submission classification; full source review pending. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 11, 2026
@steipete
steipete merged commit a07cbf5 into main Nov 11, 2026
231 of 232 checks passed
@steipete
steipete deleted the steipete/perf-micro-per-blob-lazy-fetch-storm-20260919 branch November 11, 2026 16:00
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
…7259)

* fix: batch historical blob reads in shared worktrees

Prepare bounded path-history blob sets before agent log, blame, and repeated show reads. Serialize common-directory prefetches and recheck missing objects under the lock so parallel readers share transfers. Keep native diff batching and negotiated commit acquisition; known blob-only wants use native noop negotiation to avoid falsely claiming missing blob closure.

* fix: make blob discovery byte bounds locale-independent

Count raw discovery bytes under the C locale and use explicit benchmark sample values to satisfy strict indexing checks without changing sample order.

* fix: keep historical blob benchmark checks precise

Use the constructed history length in workspace metadata and avoid shadowed variables in warm and allocator proof paths. Measured commands and sample ordering are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts size: M 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