Repository navigation
perf(worktrees): overlap prompt preparation with index finalization - #184372
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR releases accelerated worktree prompt preparation before index finalization and fixes false session conflicts caused by hydrated owner field ordering. Example: Start a fresh managed-worktree turn in the measured 3,001-file APFS repository.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it provides a useful worktree startup optimization, and no actionable findings remain on the reviewed head. The earlier mock-export finding is fixed and the reported Gateway failures have been attributed; current-head CI is still pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherManaged worktree creation turns a selected Git commit into a session checkout; prompt readiness permits inference, while complete preparation admits workspace tools and turn completion. flowchart TD
A[New session turn] --> B[Managed worktree service]
B --> C[Clone committed files]
C --> D[Publish prompt readiness]
C --> E[Finalize Git index]
D --> F[Prepare prompt and inference]
E --> G[Complete workspace readiness]
G --> H[Workspace tools and completion]
Technical reviewBest possible solution: Retain the existing checkout and readiness owners, publish cloned prompt files early, and preserve complete-readiness and ownership checks. Do we have a high-confidence way to reproduce the issue? Current-main source shows accelerated clones completing index work before prompt release; the supplied counterbalanced native measurements exercise that delay, although this review ran no target code. Is this the best way to solve the issue? This is a focused extension of the existing readiness contract; the publication flag prevents unsafe file replacement, and the equality repair preserves complete owner comparisons. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0dc12b926cf8. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +22, Tests +143, Docs +2, Other +486. Total +653 across 10 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 26, 2026, 4:51 AM ET / 08:51 UTC (Revision 2). |
7e4abfc to
b09deb2
Compare
|
Fixed on The archive failure exposed a real owner-hydration ordering bug: expected/current session values were identical, but The separate @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Independently reproduced the deferred-workspace completion failure on unchanged main ( The two-file correction in |
|
Merged as Final CI run 40293467171 completed with 49 passing jobs, including all PostgreSQL conformance shards. The only non-aggregate failure was The introduced mock-export violation and owner-field-order conflict were repaired and verified before landing. Phase tables, native overlap evidence (543.73 ms mean readiness lead), resource measurements, and host-load limitations remain in the PR body. |
|
The correction is now on main in 505264e. The separate extraction is no longer needed; we’ll use and verify the landed fix. |
…penclaw#184372) * perf(worktrees): overlap prompt preparation with index finalization * fix(sessions): compare hydrated owner independently of field order
What Problem This Solves
Fresh turns using accelerated managed-worktree clones waited for Git index finalization even after all prompt files were available.
User Impact
Prompt preparation can now overlap index finalization. Workspace tools, completion, setup scripts, bootstrap hooks, and other existing full-readiness requirements retain their gates. No configuration, schema, or user action changes.
Why This Change Was Made
The current-main breakdown identified APFS index copying, timestamp safety waits, and metadata reads as the largest checkout component. Same-session warm turns already skip managed preparation; individual Git commands were substantially smaller. The accelerated clone owner now uses the existing prompt-readiness boundary after cloning all files and restoring the worktree marker. Once that boundary is published, errors cancel preparation through the existing cleanup instead of replacing files with a fallback checkout.
This is overlap, not caching or reduced Git work. Production delta is +22 lines: the existing readiness callback, its necessary no-fallback-after-publication state, three diagnostic phase timers, and a three-line session-owner comparison repair. Tests add 143 lines; measurement tooling adds 486 net lines. The simplification pass retained one checkout owner and no new cache or parallel preparation policy.
Evidence
CI-discovered correctness repair: retained session facts and SQL hydration can place the separately stored
ownerfield at different top-level positions. The old CAS equality treated that order difference as a conflict despite identical values. Earlier prompt release exposed it during final workspace publication; the unchanged main parent also failed later callback patches. Compare the complete owner value separately, as with the existing hydrated cold fields. No CAS or live-authority check is skipped. The production-path regression is red with the original equality owner, green with the repair, and still rejects a real owner reassignment before commit. All 11 session-patch operation tests pass, and the archived-child Gateway flow now passes with the combined repair.Native owner proof: five counterbalanced base/candidate pairs, real Git/APFS/index operations on a synthetic 3,001-file repository. Candidate prompt readiness preceded its own full checkout by 543.73 ms mean (88.73–1026.48 ms); baseline had no early release. Every arm produced identical prompt bytes and clean Git status. Cross-arm readiness was 1923.06→854.52 ms, but the direct within-operation lead is the defensible overlap measurement. Full completion also varied 1922.72→1398.25 ms; that entire difference is not attributed to this patch. Host load was 29.87–32.23.
The native fixture pre-prepares a template, ages its file timestamps, and replaces template acquisition/validation and sizing/admission callbacks; hydration and reservations are covered by the Gateway runs below. Native CPU excludes subprocesses. Baseline completion is recorded just before its prompt hash and candidate completion includes it, so completion timing is not exactly symmetric.
Owner CPU/allocation: five counterbalanced pairs per mode, 2,000 operations per arm, actual checkout orchestration with immediate synthetic I/O and the same prompt consumer. CPU 53.497→57.611 µs/op (+4.113 µs, +7.69%; mixed-sign pairs); sampled allocation 54,477→55,294 B/op (+817 B, +1.50%). Git/clone/index/admission/consumer counts stayed 10/1/1/3/1 per operation. This measures the small orchestration cost, not native I/O or latency savings. Timing and allocation were separate passes.
Correctness: the callback/publication and rejection regressions fail on the original owner and pass with the change. Three service cases cover early readiness, callback rejection, and index failure after publication, including cleanup and no fallback success. Eighty-six focused tests passed across acceleration, prompt checkout, service readiness, hooks, preparation timing, Gateway readiness, harness tool/capability readiness, and all 13 prompt-prefix stability cases. The prefix file passed after the patch-identical rebase. Core typecheck, scoped lint/format, export-collision guard, 25 closure tests, and two selected CI test-plan checks passed. Broad gates run in PR CI.
Review: independent subagent review (autoreview route unavailable). The configured autoreview preflight refused the provider route; configuration was not changed. Fresh independent review of runtime, docs, regression tests, and both measurement scripts found no actionable findings. A separate fresh review of the CI repair found a synthetic actor-ID omission in the new test; it was corrected, then re-reviewed clean. The new readiness mock also now preserves real module exports; its three tests and the failed mock-export ratchet pass.
Measurements use main
f85717fb9736a9bb2a6c6d5304ba7bdc2f8c831aplus phase-only instrumentation for baseline and this patch for candidate. Built checkout bundles were pinned: base SHA-256cbb6b9a1f946b4753096b296e1f19486dd8b9f0122d0d911ea61f553fb797e41, candidate68a9dcaee386b3c2170b737ed563dc737b428daf72f1d1aaf8e771db59561d84. APFS helper bundle hash was identical. The final two-commit patch rebased identically onto6b72c79119382fc4ae82d547db6efbcb888d0f50; checkout/equality owners were unchanged upstream. These are pre-rebase measurement results, not a claim that every later main change was benchmarked.Gateway phase and resource comparison, including limitations
Untraced built-Gateway arms, 20 fresh origin-advancing and 20 same-session warm turns per arm, 10,800 seeded sessions, 40 bundled plugins, 65 WebSocket clients, four concurrent mock turns with tool calls, sidebar/list/search churn. First-token delay is 200 ms. All turns, tool calls/results, and fanout checks completed. p95 below 200 samples is descriptive. The initial Trace2 diagnostic is separate from this timing comparison.
Index wait/metadata percentile samples include zero when an APFS index-copy operation emitted no wait/metadata phase. Neither arm emitted managed-worktree preparation during the 20 warm same-session turns. Inclusive phases overlap and must not be summed.
All 20 candidate starts demonstrably released prompt preparation before full worktree completion: in every four-turn burst, the smallest full managed duration exceeded the largest prompt-blocking duration (conservative per-burst lower bounds 453, 235, 891, 216, and 1190 ms). This does not require pairing identities. Chat phase diagnostics carry whole-stage report timestamps, so they cannot establish exact per-turn callback timestamps. Provider requests all followed every full completion in four bursts; one burst overlaps, leaving a conservative 0–4 provider-before-own-completion bound. No claim is made that all provider requests began before finalization.
The Gateway before/after numbers are descriptive: the host load differed materially and the candidate warm-idle hold was longer while required checks finished. The controlled, counterbalanced native-owner benchmark is the causal latency evidence. Main-thread utilization uses active turn windows; GC, loop, handler, and heap metrics span the full run including fresh-burst gaps. Poll counts differ because the windows differ. RSS polling began after round 0 identified the Gateway PID, so values are observed samples, not a whole-run peak guarantee. Allocation was not sampled in the Gateway timing arms; use the separate owner allocation pass. Warm first-provider p95 rose from 1491 to 3935 ms in 20 samples on an unchanged warm worktree path; it is disclosed as uncontrolled context, not attributed or rejected without matched controls. The GC change is +13.45 ms/min; maximum pause 50.96 ms remains below 2× base maximum 67.56 ms, and major GC counts are below 50. Client/handler p99 counts are below 1000 per side.
This was the requested bounded FAST PATH phase proof, not the canonical multi-pair ten-minute stress campaign. No production load or restart occurred. Recent production journal lines were read only; their deployment identity was not securely attributed, so they are not presented as current-build measurements.
Separate Git argv-class diagnostic
Trace2 baseline, fresh windows. Times are subprocess-local wall time, excluding spawn and worker queues. Concurrent sidebar work is included; nested operations cannot be summed into critical-path duration. All raw commands retain argv, session identity, and elapsed wall time in the harness output.
The untraced Gateway arms above add dedicated index-copy/wait/metadata phases. Benchmark usage is in each script's header; the shared perf README is unchanged.
CI attribution
Initial head
7e4abfcd811435bcdfec1de32b322412628e5634, run 40288770408: repaired the new mock-export violation and the false owner-order CAS conflict described above; no CI reruns were requested. The subsequent run validates the repaired head.One separate failure is inherited:
src/gateway/server.required-worker-profile.test.ts, “required workspace commit fences runtime authority after preparation,” expectsSession changed during worker admissionbut receivesSQLite session state changed while preparing session-entry.patch. The complete file reproduces on unchanged main parentf5eb9570aac03eccd09bf38d8a155d4039fc768f: 16 passed, 1 failed with that exact expected/received error. The failing empty-workspace path does not enter accelerated checkout; a real external execution-node mutation is rejected by the preimage check before the custom admission error. This patch does not relax either check.Focused CI-attribution/repair commands (single-worker runs, no suites):
Final CI on
b09deb226f061e5b354767b307f3845c539ae00c: run 40293467171 completed with 49 passing jobs, including all three PostgreSQL conformance shards. The sole non-aggregate failure is the exact inherited worker-admission case above (job 121474385958: 16 passed, 1 failed). Dependency and security-sensitive review gates passed on this exact head. Landing uses the maintainer-authorized inherited-failure exception; no failed run was retried.