Skip to content

perf(worktrees): avoid redundant checkout waits and Git queries - #146722

Merged
steipete merged 1 commit into
mainfrom
codex/worktree-checkout-latency
Sep 13, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/worktree-checkout-latency

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Related: #146401 and #146586.

What Problem This Solves

Cached worktree creation runs redundant Git queries and can add another second of APFS timestamp waiting after the clone is already old enough for safe index validation.

User Impact

APFS checkouts avoid the redundant timestamp delay. Accelerated worktree creation uses fewer Git subprocesses, without new configuration or changes to ACL eligibility, cancellation, or edit detection.

Why This Change Was Made

Anchor the timestamp deadline at completion of the admitted clone, count subsequent Git metadata preparation toward it, and retain the per-file ctime and clone-provenance checks. Read template cleanliness and HEAD together, read destination HEAD and index path together, and overlap the two attribute-path probes while joining both before returning or throwing.

Git still owns registration, index validation, and fallback checkout. NUL-delimited status records and first-line-only HEAD parsing preserve unusual filename/path handling. This changes neither the cloning backend nor dependency versions.

Evidence

  • 48 focused worktree tests passed on macOS/APFS; 3 Linux-only cases skipped. Coverage includes ACL changes, cancellation/authority loss, restore, contaminated templates, wrong HEAD with identical contents, and metadata paths containing spaces, Unicode, and newlines.
  • The new deadline regression failed against the original code with clone timestamp boundary already passed, then passed with the repair. Existing same-size edits with restored mtimes remain detectable.
  • Live managed-service stress passed 42 create/reuse calls, six restores, ten cancellations, 45 removals, 32,508 file validations, four ACL policy cycles, and complete snapshot/template cleanup.
  • Independent P0–P2 review found no actionable defect. The subsequent rebase changed no file in this PR's five-file scope.

Captured timing results

Native APFS index preparation, after Git preparation has already crossed the completed clone's timestamp boundary, six trials per variant with 128 files:

                         Before       After
Median                   1011.97 ms     3.84 ms
Minimum                  1002.23 ms     3.26 ms
Maximum                  1056.85 ms     6.78 ms
Same-size edits detected      6/6         6/6

Both variants used the real native clone and Git status validation. The measurement starts after the timestamp-boundary precondition and includes the real index translation/write; it is not a whole-checkout speedup claim.

For a 2,049-file, 40 MiB fixture, twelve paired warm-create samples per variant started at matching positions within the wall-clock second, with alternating variant order:

Measurement Before After
Git subprocesses per warm create 20 18
Median complete create 1,239 ms 1,147 ms
Mean complete create 1,197 ms 1,229 ms
Maximum complete create 1,854 ms 2,287 ms
Median process RSS 432 MiB 427 MiB

The loaded host and second-boundary timing made complete-create results mixed; these samples do not establish a general end-to-end speedup. The deterministic improvements are two fewer Git processes and elimination of the redundant completed-boundary wait. All measured checkouts had clean Git status and correct payload sizes.

@clawsweeper

clawsweeper Bot commented Sep 13, 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: S maintainer Maintainer-authored PR labels Sep 13, 2026
@steipete
steipete marked this pull request as ready for review September 13, 2026 03:57
@steipete steipete self-assigned this Sep 13, 2026
@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 Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 12:08 AM ET / 04:08 UTC.

ClawSweeper review

What this changes

The PR reduces redundant Git queries and APFS timestamp waiting during managed worktree creation, with regression coverage and updated documentation.

Merge readiness

✅ Ready for maintainer review

Keep open: this remains a useful optimization absent from current main. The reviewed changes preserve checkout safeguards, and no actionable correctness or security defect was found.

Priority: P2
Reviewed head: 765cac05621cf44a55772dc1094d09e17a6eb775

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with useful native before/after evidence, meaningful regressions, and no blocking finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Captured native APFS and managed-service results exercise the changed checkout/index path, showing removal of the completed-boundary wait, fewer Git processes, clean checkouts, and preserved subsequent edit detection.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Captured native APFS and managed-service results exercise the changed checkout/index path, showing removal of the completed-boundary wait, fewer Git processes, clean checkouts, and preserved subsequent edit detection.
Evidence reviewed 8 items Pinned scope and current PR: Host introduction evidence identifies merge-base 4c47e8a and the reviewed head. The verified test merge contains only the intended worktree changes relative to its main parent. A live REST read confirms the PR remains open, unmerged, assigned to steipete, and at that head.
Optimization remains absent from main: Current main retains the unconditional next-second wait, separate template HEAD query, and separate destination metadata queries.
Latest release comparison: Neither checkout implementation file exists at the supplied latest release v2026.9.4; that release does not contain this optimization.
Findings None None.
Security None None.

How this fits together

Managed worktrees give agent tasks isolated Git checkouts. The checkout service validates reusable source templates, clones eligible filesystems, and lets Git validate the resulting checkout or complete a fallback.

flowchart TD
  A[Create or restore request] --> B[Check acceleration eligibility]
  B --> C[Validate source template]
  B --> F[Ordinary Git checkout]
  C --> D[Clone source files]
  D --> E[Prepare index after safe timestamp]
  E --> G[Git validates checkout]
  E --> F
  F --> H[Isolated task workspace]
  G --> H
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +37, Tests +109, Docs 0. Total +146 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 51 14 +37
Tests 2 111 2 +109
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 163 17 +146

Review metrics

Metric Value Why it matters
Warm-create Git processes 20 → 18 in supplied paired measurements This supports the reduced-query claim without implying a general end-to-end latency improvement.
Production versus test growth Production net +37 lines; tests net +109 lines Production growth implements safe combined-output parsing and deadline handling; tests cover contamination and edit-detection invariants.

Technical review

Best possible solution:

Keep checkout preparation within the existing owner, eliminating redundant work while preserving Git validation, ACL fallback, and cancellation settlement.

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

Yes: current main unconditionally waits for another second boundary even when clone preparation has already crossed it; supplied native before/after measurements exercise that condition. This review did not execute the runtime.

Is this the best way to solve the issue?

Yes: the patch removes redundant work in the existing checkout owner while retaining conservative validation and fallback, without adding configuration or competing implementations.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: A bounded checkout-performance improvement with concrete native measurements and no urgent user-facing regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Captured native APFS and managed-service results exercise the changed checkout/index path, showing removal of the completed-boundary wait, fewer Git processes, clean checkouts, and preserved subsequent edit detection.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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): Captured native APFS and managed-service results exercise the changed checkout/index path, showing removal of the completed-boundary wait, fewer Git processes, clean checkouts, and preserved subsequent edit detection.

Label justifications:

  • P2: A bounded checkout-performance improvement with concrete native measurements and no urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Captured native APFS and managed-service results exercise the changed checkout/index path, showing removal of the completed-boundary wait, fewer Git processes, clean checkouts, and preserved subsequent edit detection.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured native APFS and managed-service results exercise the changed checkout/index path, showing removal of the completed-boundary wait, fewer Git processes, clean checkouts, and preserved subsequent edit detection.

Evidence

What I checked:

  • Pinned scope and current PR: Host introduction evidence identifies merge-base 4c47e8a and the reviewed head. The verified test merge contains only the intended worktree changes relative to its main parent. A live REST read confirms the PR remains open, unmerged, assigned to steipete, and at that head. (765cac05621c)
  • Optimization remains absent from main: Current main retains the unconditional next-second wait, separate template HEAD query, and separate destination metadata queries. (src/agents/worktrees/checkout-apfs.ts:137, 70fe5d707523)
  • Latest release comparison: Neither checkout implementation file exists at the supplied latest release v2026.9.4; that release does not contain this optimization. (3a9d69db306c)
  • Timestamp and edit-detection safety: The deadline starts at completed cloning. Per-file ctime, source stat, clone identity, and allocation-authority checks remain before publishing the index; uncertain entries retain ordinary Git validation. (src/agents/worktrees/checkout-apfs.ts:139, 765cac05621c)
  • Combined queries preserve validation: Attribute probes settle together before cleanup can proceed. Template reuse requires complete successful NUL-delimited status output and exactly the expected HEAD; destination parsing separates only the first line, preserving embedded newlines in metadata paths. Existing Git fallback and ACL eligibility remain intact. (src/agents/worktrees/checkout.ts:107, 765cac05621c)
  • Focused regression coverage: Read both changed test files fully. Coverage checks expired timestamp waits, subsequent same-size edits with restored mtimes, six template-contamination cases, and unusual metadata paths through the production managed-worktree service. Tests were inspected, not executed during this read-only review. (src/agents/worktrees/service.acceleration.test.ts:138, 765cac05621c)

Likely related people:

  • Peter Steinberger: Raw commit 9b59fe4 adds src/agents/worktrees/checkout-apfs.ts:160 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9b59fe4ef7da; files: src/agents/worktrees/checkout-apfs.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 7e17935 into main Sep 13, 2026
262 checks passed
@steipete
steipete deleted the codex/worktree-checkout-latency branch September 13, 2026 04:25
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 maintainer Maintainer-authored PR 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: S 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