Skip to content

perf(worktrees): avoid a duplicate cold object census - #186294

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-session-worktree-creation-latency-20261027
Oct 27, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-session-worktree-creation-latency-20261027

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cold managed-worktree creation walks every object in a complete commit to check availability, then walks the tree again to compute its disk budget. This repeats work before the checkout can become ready.

User Impact

Complete repositories avoid one full missing-object census on cold sizing. Capacity totals, isolated checkout ownership, hooks/filter exclusion, cached-fact rechecks, and partial-clone batch hydration remain unchanged. No configuration or migration is required.

Why This Change Was Made

The existing ls-tree --format=%(objectsize) scan already fails when a required tree or blob is missing. Let that scan establish availability while computing the budget. A failed cold scan only hydrates and retries when the existing missing-object owner actually finds missing OIDs. Cached and incremental estimates retain their availability census because they do not read every target blob.

Runtime +15 lines; tests +6; measurement tooling +178 (non-test diff +193: +227/−34). The runtime growth preserves the shipped partial-clone contract: one evidence-controlled retry, the existing batched fetch owner, cancellation/ref admission, and existing repair guidance. No cache or second sizing implementation is added. Partial clones can perform one failed size scan before hydration; a complete clone removes the census entirely.

Evidence

Acceptance declared in the measurement scripts: identical byte totals and checkout commit/files; one fewer cold object census; reduced owner CPU/allocation; native creation timings reported with host load, and no adverse conclusion from uncontrolled tails. The focused regression fails on the base because it observes one cold census instead of zero. The partial-clone regression retains exact fetched OIDs, unchanged refs/config, one fetch and one census, and bounds sizing to two attempts.

Owner comparison: two counterbalanced pairs, 2,000 operations per arm per pair (4,000 timing + 4,000 sampled-allocation operations per revision). Timing and allocation sampling run separately.

Per cold estimate Base Candidate Change
Owner CPU 759.46 µs 471.74 µs −37.9%
Sampled heap allocation 1,610,590 B 785,747 B −51.2%
Copied Git output buffers 475,737 B 61,555 B −87.1%
Missing-object censuses 1 0 removed
Successful full size scans 1 1 unchanged

Final timing pairs (base→candidate): 742.35→485.09 and 776.57→458.39 µs/op. Allocation pairs: 1,611,191→784,090 and 1,609,990→787,404 B/op. Return values match in every operation. These final runs include the protocol-deny guard.

The existing workload has 10,000 files; --cold keeps each operation on the uncached path. Synthetic Git copies output buffers like the subprocess boundary. Native child CPU, filesystem I/O and worker queues are excluded from this owner comparison.

Native comparison: completed serial batches A(5), B(5), B(10), A(5). The first B batch predates the transport-deny guard; the second B batch contains the final candidate. All fixtures contain complete objects, so neither B batch needed a transport. Fixture is a private shallow clone of OpenClaw commit 451ec41c26c67cca7d8a61b7da6b0188cf52249e, 60,922 tracked paths and a 190 MiB pack. The real service uses its state leases, worker queues, Git, source-only config and APFS templates; workers drain between samples. Source-loader startup is outside timing, worker startup is inside it. There is no setup script, ignored-file provisioning or remote fetch. Cold template creation remains included and is reported separately from warm templates.

The exploratory full-history shared-clone run completed in 383.259 s, including 23.462 s missing-object census, 14.521 s size scan and 13.153 s registration. Its donor had 6,608 pack-related files totaling about 29.2 GB, and initial fixture checkout overlapped the run. These are diagnostic observations, not comparative speedup evidence.

Validation so far: cold regression red on base; final owner and worker files 27 tests passed (20 + 7), including partial clones with the no-lazy-fetch environment setting deliberately ineffective. Required import-closure files 32 passed; export collision guard, focused formatting/lint, the one targeted core typecheck, and the test-lines ratchet passed (6,286,369 / 6,286,403 on the measured base). Independent subagent review (autoreview route unavailable): no remaining actionable P0/P1/P2 findings. Hosted Codex review also completed on the original published head with no findings; ClawSweeper reported no actionable code findings. The subsequent upstream-fix rebase preserves the exact patch (stable patch ID 89b0320991186a9470ce6752266d76c1432c660d) and runtime source bytes. Review found the older-Git lazy-fetch issue; the size read now explicitly denies transports, and only the admitted hydration owner may fetch. The full service-capacity file passed 24/24 on baseline and 24/24 on final candidate. Initial CI run 40580059748 passed the selected tests, typechecks and ratchets, but failed check-lint-core-2 on five inherited eslint(curly) errors in ui/src/pages/new-session/draft-body.browser.test.tsx and ui/src/pages/chat/chat-content-column.browser.test.tsx. Both files were byte-identical to the main parent e5d8882b76aea866fac2b13ef64b8cf50af21284; focused lint reproduced all five errors. Main already fixed them in 8b2b0997a578, so this branch was rebased onto current main with the four-file patch unchanged. Focused lint on those files now passes. Final CI run 40592428428 completed successfully on fbbc79ada6e004e0bc69e526e89dac95f777d0ae; both required openclaw/ci-gate checks are green. Selected tests, production/test types, core and extension lint, ratchets, build artifacts, and security checks passed. This PR is intentionally left open for maintainer landing.

An earlier candidate run failed the disk-headroom concurrency case (both checkouts rejected instead of one succeeding); its isolated replay passed. The full baseline and final-candidate runs then both passed without test or admission changes. Existing reservations can plausibly make both postchecks reject after the test drops capacity to the exact reserve floor, but the original rejection reasons were not captured: this remains an investigated, unattributed local failure, not a claimed fix or proven inherited failure.

This bounded duplicate-scan removal follows the requested fast proof route. No production server was contacted. The native measurement is the creation service, not a built Gateway load test; no whole-Gateway CPU/GC, event-loop or sessions.list improvement is claimed. Benchmark usage lives in each script's header; the shared perf README and test-line ceiling are unchanged.

Native creation phases and host context

Four serial batches: A1 baseline (5), B1 preliminary candidate (5), B2 final candidate (10), A2 baseline (5). Inclusive durations overlap and must not be summed. Each batch includes its first cold template; no rows were excluded. B1 predates the transport-deny guard and is supplementary; B2 supplies all ten final-candidate creations.

Mean per creation, seconds unless noted A1 (5) B1 (5) B2 final (10) A2 (5)
Total wall 110.665 51.948 78.813 41.249
Prompt ready 91.592 41.805 63.294 31.571
Git worktree add 0.688 0.102 0.203 0.160
Git config 0.151 0.147 0.125 0.142
Missing-object census 0.076 0.000 0.000 0.177
Full size scan 1.073 0.689 0.714 0.636
Git read-tree 42.299 10.255 23.205 6.626
Source preparation 9.037 7.092 8.789 7.430
Mutation admission wait 14.384 9.624 11.607 9.699
Allocation wait 0.049 0.023 0.034 0.017
Template preparation 46.777 13.065 26.738 8.526
Template apply 18.352 10.131 14.014 3.980
Index metadata 16.132 9.049 13.946 8.356
Index refresh 2.292 0.724 0.988 0.764
Publication 0.020 0.013 0.017 0.021
Main-thread CPU, ms 487.99 397.49 397.96 436.40
Main-thread allocation, MiB 209.93 202.22 194.06 199.71
RSS / used heap, MiB 779.7 / 119.2 884.1 / 123.7 833.1 / 116.9 889.4 / 124.4
Host load range, one minute 55.4–80.4 48.3–57.9 42.0–81.8 65.0–84.1

All 25 checkouts matched the requested commit and had clean Git status. Baseline creations each issued one missing-object census and one size scan; both candidate batches issued zero censuses and one size scan. Source-only Git suppresses hooks and filter programs; this fixture has no sparse profile, setup/dependency provisioning, remote fetch, or model turns. Mutation/source phases include state-worker admission and cold worker startup, so they do not establish lock contention by another writer.

Pooled baseline mean wall time was 75.957 s; final candidate was 78.813 s. This is inconclusive, not a speedup or adverse finding: the identical baseline batches averaged 110.665 and 41.249 s, and first-creation wall time ranged 70.964–377.597 s across batches. No controlled whole-creation tail or retained-memory claim is made. RSS/heap snapshots are not GC-aligned. The repeatable evidence is the eliminated census and the separately controlled owner CPU/allocation reduction.

@clawsweeper

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T22:10:08.024633Z fbbc79a 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 scripts Repository scripts agents Agent runtime and tooling size: M labels Oct 27, 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 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets the full cold checkout-size scan establish object availability, reserving a missing-object census and batched hydration retry for failures.

Example: Cold sizing of the complete 60,922-path repository used in the native measurements.

  • Before: Creation performs one missing-object census and one full size scan.
  • After: Creation performs zero missing-object censuses and one full size scan, preserving the requested commit and clean checkout.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused and coherent implementation with useful real-Git and native-service evidence; proof stops below the shipped entry point and whole-creation latency remains inconclusive.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its supplied native-service comparison exercises the changed sizing owner with real Git, worker queues, leases, and clean checkout verification.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Fresh managed-worktree preparation repeats a complete object inventory before computing the same checkout's disk budget.
Reason: The maintainer-authored direction removes demonstrated work with bounded runtime growth and preserves the existing partial-clone and admission contracts.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it removes verified duplicate work that remains on current main, preserves the existing partial-clone safeguards, and has no actionable code findings. Exact-head CI remains pending.

Priority: P2
Reviewed head: a530a1dafba7ed1bd1ddcb744e6c47ea2ffc6b1b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied native creation-service measurements do not exercise a shipped CLI or Gateway entry point.
Agent review details

How this fits together

Managed-worktree creation and snapshot restoration ask the Git worker to estimate checkout allocation; the worker returns byte totals and uses the existing admitted Git owner to hydrate missing objects.

flowchart TD
A[Worktree creation or restoration] --> B[Git worker sizing owner]
B --> C[Cached or incremental estimate]
B --> D[Cold full size scan]
C --> E[Existing availability and hydration owner]
D -->|Missing objects| E
E --> D
D --> F[Byte budget for disk admission]
C --> F
Loading

Technical review

Best possible solution:

Use the existing full scan for cold availability proof while preserving admitted batched hydration and cached or incremental availability checks.

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

Current-main source unconditionally inventories availability before the cold full size scan; the PR reports a base-failing work-count regression and native-service confirmation, which were inspected but not rerun.

Is this the best way to solve the issue?

The change removes redundant work at its existing owner, adds no cache or parallel sizing implementation, and retains the recovery machinery justified by earlier partial-clone incidents.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Cold availability census changes intended behavior with a stated reason (fix: surface subagent worktree setup failures and stop per-blob fetches during worktree sizing #141537: Prevent per-blob lazy fetching that stalled partial-clone worktree sizing; later worker and hydration changes retained this protection.)
  • Cached and incremental checkout sizing keeps the original intent (0c6a286: Reuse bounded immutable-commit size facts and changed-blob accounting while retaining target hydration, replacement handling, and fallback sizing.)
  • Batched hydration and real-Git regression coverage keeps the original intent (9bea925: Fetch exact missing objects with --refetch through existing serialization, authority, cancellation, and cleanup owners.)
  • Worker execution ownership keeps the original intent (f0fafba: Workers perform inventory processing while the Gateway owns subprocesses, mutation authority, and cleanup.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced change and current-main comparison: The pinned diff changes cold sizing only; fetched main still calls hydrateCommitObjects before every uncached full scan. The relevant existing files match the pinned base. (src/agents/worktrees/capacity.runtime.ts:163, a530a1dafba7)
  • Bounded recovery and transport exclusion: Cold ls-tree explicitly denies transports; only a census finding missing OIDs permits one hydration retry. Cached and incremental estimates retain their census and existing cache ownership. (src/agents/worktrees/capacity.runtime.ts:184, a530a1dafba7)
  • Preserved partial-clone contract: The earlier incident repair required batched hydration without per-blob fetches; the subsequent repair required exact missing-object delivery and unchanged refs/config. This PR preserves those owners and strengthens real-Git coverage with lazy-fetch suppression deliberately disabled. (src/agents/worktrees/capacity.test.ts:145, 9bea925e27aa)
  • Final-effect authority remains host-owned: Worker Git requests still receive the host's signal and assertCurrent callback immediately through the existing execution owner; hydration continues through ref-mutation admission rather than a new transport path. (src/infra/git-worker.ts:356, a530a1dafba7)
  • Supplied measurements and discussion: The full PR body reports ten final-candidate native service creations with clean checkouts and no census, plus counterbalanced owner measurements showing lower CPU and sampled allocation. It explicitly treats whole-creation latency as inconclusive and records the unattributed local concurrency failure without claiming a fix. (scripts/perf/worktree-creation-measure.ts:131, a530a1dafba7)
  • Current checks and merge state: GitHub reports this head mergeable with queued CI and a pending gate; no observed check establishes a diff-caused failure. (a530a1dafba7)

PR surface

Source +15, Tests +6, Other +178. Total +199 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 46 31 +15
Tests 1 28 22 +6
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 181 3 +178
Total 4 255 56 +199

Labels

Label changes:

  • add P2: Removes measurable CPU, allocation, and Git inventory work from cold managed-worktree preparation without establishing an urgent availability regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Removes measurable CPU, allocation, and Git inventory work from cold managed-worktree preparation without establishing an urgent availability regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 27, 2026, 4:55 PM ET / 20:55 UTC.

Let the full size scan prove local object availability for cold estimates. Preserve cached/incremental availability checks and one admitted batch hydration retry for partial clones, with implicit transports disabled during sizing.

Owner proof: CPU -37.9%, sampled allocation -51.2%, one census removed. Ten baseline and ten final-candidate native creations preserve clean checkout contents; total creation latency remains inconclusive under host I/O variation. Runtime growth is 15 lines to preserve partial-clone repair behavior.
@steipete
steipete force-pushed the steipete/perf-session-worktree-creation-latency-20261027 branch from a530a1d to fbbc79a Compare October 27, 2026 22:08
@steipete
steipete merged commit c7e4a59 into main Oct 27, 2026
127 of 128 checks passed
@steipete
steipete deleted the steipete/perf-session-worktree-creation-latency-20261027 branch October 27, 2026 22:26
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
Let the full size scan prove local object availability for cold estimates. Preserve cached/incremental availability checks and one admitted batch hydration retry for partial clones, with implicit transports disabled during sizing.

Owner proof: CPU -37.9%, sampled allocation -51.2%, one census removed. Ten baseline and ten final-candidate native creations preserve clean checkout contents; total creation latency remains inconclusive under host I/O variation. Runtime growth is 15 lines to preserve partial-clone repair behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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