Skip to content

perf(worktrees): publish reserved checkouts without allocation waits - #169178

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-worktree-prep-unattributed-time-20260919
Oct 11, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-worktree-prep-unattributed-time-20260919

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Completed managed checkouts can wait behind unrelated worktree allocation before becoming usable, and existing preparation logs hide most of that wait.

User Impact

An already reserved checkout publishes without reacquiring global allocation. Its retained checkout lease, source authority, disk admission, and atomic pending-to-live transaction remain enforced. No new setting, migration, or stored-shape change.

Why This Change Was Made

Publication exchanges one pending slot for one live record; capacity does not change. The writer already verifies pending identity and retained checkout custody. The second global admission and its recovery pass therefore add contention without protecting another invariant.

The existing diagnostic record now attributes allocation/mutation/capacity waits, repository/source preparation, reservation, base refresh/hydration/fast-forward/share wait, registration, disk admission, provisioning, publication, index refresh, and custody release. Nested phase times remain inclusive; unattributedMs measures uncovered wall time without subtracting overlapping phases twice.

Production LOC: +75 net, required by the requested diagnostic fields and coverage accounting. The performance change deletes the redundant admission path; it adds no cache, alternate path, or compatibility shim.

Related: #169070. The historical comparison does not establish that shared refresh caused the reported long remainder. Twenty “fetch succeeded” messages are per-worktree reporting: all three historical bursts performed one actual fetch. Local-default fast-forward ran twenty times before that change and once afterward.

Evidence

Controlled contention through ManagedWorktreeService.createWithOutcome: publication 2,167.138 ms → 6.614 ms while another real allocation lease was held for two seconds. The candidate published while that holder was still active. This used a synthetic repository setup script gated by FIFOs and the actual lease/registry path, with no mocked Git.

The permanent regression fails on the original code with “Publication waited for the unrelated allocation holder” and passes after the change. The existing refusal test now revokes the retained checkout lease, preserving its authority check instead of requiring the removed allocation lease.

Twenty-create full-repository bursts all completed successfully. The first pair measured median 16.031 → 13.2645 s, but reverse order measured 12.1255 s baseline versus 11.858 s candidate (2.2%), with slightly worse candidate tail. Do not read the first pair as a universal 20% throughput improvement. The robust benefit is eliminating publication's dependency on unrelated allocation; global allocation acquisitions fall from 40 to 20 per twenty-create burst.

Conditions: Linux Blacksmith Testbox, openclaw-check, 16 vCPU, Node 24.19, full blob:none OpenClaw source at 38f456226f626dd3868c2a4e754e75bf37b59e68, same-process warmup, synthetic state, and pinned local origin. Setup, ignored-file provisioning, and acceleration were disabled for full-tree timing. The reported 21-second production remainder was not reproduced; no production host was accessed. The initial shared-rig attempt hit disk-reserve pressure and was discarded.

The tested patch was rebased without changes onto main 289d859c2babddd9f5aee9dda96fbb94c5107f70; final candidate 860acf01abf7e020019ca9061e64dd48f73c2e2d has the same stable patch ID.

Remote proof:

  • blacksmith-testbox / tbx_01m4nm1zf7b2nnwxr7fnhw5k6r: original-code regression failure, then 48 focused tests passed; first full20 baseline/candidate pair; node scripts/check-changed.mjs --base 3a697ca4265b8302dca2b0191748a231c7c16432 passed every check except inherited dead exports (26m22s).
  • blacksmith-testbox / tbx_01m4nnahysgwrfxrjxcf2x2v7a: all three historical full20 bursts, reverse pair, controlled real-lease measurement, and all 55 remaining worktree sibling files covered. Two initial fixture failures were caused by placing TMPDIR inside a Git checkout; both passed with external TMPDIR. The obsolete allocation-authority assertion was corrected and its file passed.
  • The dead-export failure reproduces on completely unchanged 3a697ca4265b8302dca2b0191748a231c7c16432, with the exact same 61 reported entries, all outside the touched files. Examples include UI renderProviderFallbackIcon/renderDocsLink and subagent loadSubagentMaintenanceCandidatesInDatabase. This is recorded as inherited, not a passing gate.
  • Independent review of the final diff: no actionable P0–P2 findings.

Single-worker test costs: pnpm test src/agents/worktrees/preparation-timing.test.ts --maxWorkers=1 2.71 s; pnpm test src/agents/worktrees/service.pending-slots.test.ts --maxWorkers=1 28.50 s; repaired registry-read.test.ts 76.74 s. The latter is the existing real SQLite worker publication/lifecycle suite; the change replaces one authority target and introduces no extra boot or timer.

Full first-pair phase table (baseline → candidate)

Values are median / p95 / maximum in milliseconds; phases are inclusive and must not be added. p95 is nearest-rank over20 samples.

Phase Baseline Candidate
total 16031 / 18433 / 18628 13264.5 / 17368 / 17486
repository 177 / 180 / 180 262 / 281 / 282
mutationWait 366.5 / 371 / 371 376.5 / 381 / 381
sources 10 / 14 / 18 9.5 / 12 / 13
allocationWait 2250.5 / 5397 / 6327 2932 / 10103 / 10717
reservation 88.5 / 315 / 330 123 / 436 / 903
base 0 / 0 / 119 0 / 0 / 135
baseWait 0 / 0 / 115 0 / 0 / 131
baseRefresh 0 / 0 / 22 0 / 0 / 36
baseHydration 0 / 0 / 88 0 / 0 / 93
baseFastForward 0 / 0 / 8 0 / 0 / 7
registration 24.5 / 127 / 163 50.5 / 181 / 216
diskAdmission 159 / 419 / 442 344 / 1101 / 1420
checkout 12143 / 13375 / 13701 7661 / 9895 / 10091
provision 0 / 0 / 0 0 / 0 / 0
publication 18.5 / 72 / 109 54 / 172 / 289
leaseRelease — 108.5 / 468 / 534
sourceRelease — 0 / 0 / 1
unattributed 165 / 264 / 296 58.5 / 172 / 195

Unentered phases are shown as zero by the comparison; lease/source release instrumentation was added afterward and is absent from the baseline. Shared refresh/hydration/fast-forward occur once, so their maxima show that operation rather than a median over zero-filled borrowers. Times are inclusive and cannot be summed.

Historical phase table on the same host and source
Phase 390f0f0 a17bd67 Current
total 13538 / 17412 / 17731 13634 / 17709 / 17910 15392.5 / 18761 / 18893
allocate 359 / 363 / 364 375 / 378 / 378 345.5 / 350 / 350
history.service-preparation.resolveRepository 205 / 208 / 208 223.5 / 226 / 226 163 / 165 / 166
history.allocation.wait 4224 / 11503 / 12450 5352 / 13206 / 13765 2813 / 8692 / 9488
unattributedOriginal 4497 / 11644 / 12544 5813 / 13150 / 13690 3076.5 / 8757 / 9431
history.base-ref.resolveWorktreeCreationBase 19.5 / 50 / 155 0 / 0 / 144 0 / 4 / 123
history.base-ref.fetchRemoteDefault 0 / 0 / 36 0 / 0 / 23 0 / 0 / 23
history.base-ref.fastForwardLocalDefault 19 / 40 / 50 0 / 0 / 6 0 / 0 / 7
history.capacity.estimateWorktreeGitBytes 54 / 186 / 218 60 / 138 / 140 46 / 105 / 163
history.service.reserveForRepository 85 / 232 / 424 170.5 / 345 / 355 74 / 227 / 341
history.service-preparation.prepareWorktreeDestination 24 / 63 / 71 24 / 60 / 63 17 / 58 / 101
checkout 7611 / 8884 / 9551 7033.5 / 8546 / 8699 11133.5 / 12407 / 12438
history.service.completeRepositoryWorktreeSetup 0 / 0 / 0 0 / 0 / 0 0 / 0 / 0
finalPublication 469 / 2309 / 6069 563.5 / 5777 / 9381 229.5 / 1085 / 1325

The historical allocation.wait includes initial checkout custody and both global allocation acquisitions. finalPublication is the derived interval after materialization/setup through return, including global reacquisition. The oldest/intermediate/current code ran in that comparison's documented current → oldest → intermediate order; this is diagnosis, not a causal throughput claim.

Full reverse-order phase table
Phase Baseline (second) Candidate (first)
total 12125.5 / 17297 / 17354 11858 / 17572 / 17814
repository 162 / 167 / 168 250 / 252 / 253
mutationWait 354.5 / 358 / 359 346.5 / 350 / 351
sources 10.5 / 17 / 17 10 / 13 / 13
allocationWait 3924 / 12487 / 12994 2904.5 / 8557 / 9065
reservation 61.5 / 654 / 724 199.5 / 544 / 655
base 0 / 0 / 110 0 / 0 / 141
baseWait 0 / 0 / 107 0 / 0 / 136
baseRefresh 0 / 0 / 20 0 / 0 / 25
baseHydration 0 / 0 / 74 0 / 0 / 110
baseFastForward 0 / 0 / 16 0 / 0 / 6
registration 40 / 196 / 583 43 / 111 / 313
diskAdmission 165 / 1721 / 1876 321.5 / 816 / 1033
checkout 6585 / 8442 / 8447 7981 / 9964 / 10069
provision 0 / 0 / 0 0 / 0 / 0
publication 25.5 / 152 / 212 24 / 440 / 557
leaseRelease — 92.5 / 173 / 797
sourceRelease — 0 / 0 / 0
unattributed 137 / 651 / 725 0.5 / 1 / 1

CI disposition

Exact-head CI 38150167763 stopped on checks-ui-e2e (1/2): chat-panel-layout.e2e.test.ts:379, “preserves live content and saved geometry across main, dock, focus, and narrow layouts,” times out after 30 seconds waiting for the terminal canvas to become visible. The same test, line, locator, and hidden-canvas failure already occur in scheduled main CI 38147604740, commit 6233a19ea75bbcd079ec4dbe4660bfef9b9321ed. The actual tested merge 567fc8fcf1c10bc4ceaaa771c1ac02691985a7a3 contains no UI delta from its main parent 698cac4c78b806d5db143008e4b83fd588a33583.

The aggregate CI gate failed downstream and fail-fast cancelled other jobs; those cancellations are not passing proof. Landing uses the maintainer-authorized inherited-failure exception, backed by the focused, sibling, typecheck, and independent-review evidence above. No CI rerun or update-branch was requested.

@clawsweeper

clawsweeper Bot commented Oct 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 gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 11, 2026
@steipete
steipete marked this pull request as ready for review October 11, 2026 15:10
@clawsweeper clawsweeper Bot added 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. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR removes redundant global allocation admission when publishing a reserved worktree and adds preparation timing diagnostics.

Example: A completed checkout publishes while another creator holds the global allocation lease for two seconds.

  • Before: The reported controlled measurement took 2,167.138 ms to publish.
  • After: Publication took 6.614 ms and completed while the unrelated holder remained active.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch preserves the existing invariants and has useful production-owner evidence; supplied proof remains in-process rather than through a shipped entry point.
Proof confidence 🦐 gold shrimp (3/6) The supplied maintainer-authored classification exempts this PR from the ordinary contributor proof gate; its body reports real service/Git/SQLite contention measurements and successful creation bursts, with no shipped-entry-point recording supplied.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: A fully prepared managed checkout can remain unavailable while unrelated work holds global allocation.
Reason: The maintainer-authored direction removes a demonstrated dependency with a small owner-level repair and preserves existing admission contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR removes a real publication bottleneck still present on main while preserving checkout custody and atomic slot accounting. No introduced correctness defect was found; exact-head CI has an unattributed terminal UI failure and cancelled checks.

Priority: P2
Reviewed head: 860acf01abf7e020019ca9061e64dd48f73c2e2d

Before merge

None.

Findings

None.

Agent review details

How this fits together

ManagedWorktreeService turns session or CLI creation requests into Git checkouts and registry records; allocation reserves capacity, checkout custody owns preparation, and the SQLite worker atomically exchanges pending slots for live records.

flowchart TD
A[Creation request] --> B[Checkout custody]
B --> C[Global slot reservation]
C --> D[Git checkout and setup]
D --> E[Source and disk admission]
E --> F[Atomic worker publication]
F --> G[Ready worktree]
Loading

Technical review

Best possible solution:

Publish reserved checkouts through the existing worker under retained checkout custody, preserving source authority, disk admission, and atomic slot accounting.

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

Current main visibly reacquires the global allocation lease after materialization, so an unrelated holder delays publication; the PR reports a controlled before/after reproduction through the real service.

Is this the best way to solve the issue?

The change fixes the owning publication path directly: pending-to-live publication preserves capacity, and the existing transaction already checks checkout custody and pending identity.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Reserved-checkout publication changes intended behavior with a stated reason (c6168a9: Pending slots enabled parallel preparation while retaining serialized capacity admission and atomic publication.)
  • Preparation diagnostics keeps the original intent (404d388: Attribute setup latency without exposing repository paths, session keys, or setup output.)
  • Shared default-source preparation keeps the original intent (16ae2d7: Share refresh, hydration, and local-default decisions across creation cohorts while retaining cancellation and source safety.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

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

PR surface

Source +75, Tests +57, Docs +6. Total +138 across 11 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 203 128 +75
Tests 3 61 4 +57
Docs 1 10 4 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 274 136 +138

Review metrics

Metric Value Why it matters
Production versus test LOC Production +203/-128 (net +75); tests +61/-4 (net +57) Production growth primarily attributes preparation phases and overlapping coverage; the performance repair removes the redundant admission path, and added tests protect contention and timing contracts.

Labels

Label changes:

  • add P2: This removes avoidable contention during concurrent managed-worktree creation without changing configuration or public contracts.
  • 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: This removes avoidable contention during concurrent managed-worktree creation without changing configuration or public contracts.
  • 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 11, 2026, 11:17 AM ET / 15:17 UTC.

@steipete
steipete merged commit f8381bf into main Oct 11, 2026
185 of 218 checks passed
@steipete
steipete deleted the steipete/perf-micro-worktree-prep-unattributed-time-20260919 branch October 11, 2026 15:32
@steipete

Copy link
Copy Markdown
Contributor Author

Landed as f8381bf using the maintainer-authorized inherited-failure exception.

Exact-head CI 38150167763 failed checks-ui-e2e (1/2) on chat-panel-layout.e2e.test.ts:379 while waiting for a hidden terminal canvas. The identical test, line, and locator already failed in scheduled main CI 38147604740, job 114494370832. The tested merge has no UI delta from its main parent. The aggregate gate failure and fail-fast cancellations are downstream; cancelled jobs are not claimed as passing.

Scoped proof passed: 48 focused tests; all 55 worktree sibling files covered (49 passed, six platform skips); core and dependent test typechecks; independent review with no actionable findings. The separate unused-export audit reproduced the same 61 entries on unchanged baseline. No CI rerun or update-branch was used to chase green.

The native merge helper stopped before dispatch because its installed trusted-tooling dependency did not match the required frozen version. The authorized REST fallback pinned the reviewed 860acf0 head; merge state and main ancestry were verified afterward.

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