Repository navigation
perf(sessions): reduce new worktree creation latency - #184253
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 avoids duplicate Git discovery during fresh worktree session creation by returning the source root from the existing creation owner. Example: Create a worktree session from /repo/..notes/app with worktree: true.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR provides a focused performance improvement, and the previous replay-assertion finding is fixed; no new actionable defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway turns session workspace selections into managed Git checkouts, then binds the resulting worktree and working directory to the session. flowchart TD
A[Session create RPC] --> B[Session worktree preparation]
B --> C[Managed worktree creation]
C --> D[Git checkout discovery]
D --> C
C --> E[Worktree record and source root]
E --> B
B --> F[Bound session and nested cwd]
Technical reviewBest possible solution: Reuse the creation owner’s resolved source root while retaining discovery for existing bindings and early prompts. Do we have a high-confidence way to reproduce the issue? Current-main source shows both discovery calls, and the supplied real-Git regression reports baseline failure and candidate success; no target code was executed during this review. Is this the best way to solve the issue? The patch follows the smallest complete approach: carry an existing owner’s fact to its consumer, preserve required preflights, and remove the redundant wrapper. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f0d422a7cb48. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +6, Tests +53, Other +613. Total +672 across 12 files. Added test files: 0. 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, 2:16 AM ET / 06:16 UTC (Revision 2). |
Reuse the source checkout root resolved by the managed-worktree creation owner instead of discovering it again during fresh session preparation. Preserve nested cwd mapping, existing-binding and early-prompt preflights, and source/commit authority checks. This removes three serial Git subprocesses from sessions.create with a new worktree. Add a real work-count regression and reproducible owner/RPC measurements; retain the existing incognito invalidation assertions at the actual creation discovery boundary.
f601400 to
a8c74fa
Compare
|
Fixed on a8c74fa: the pending-slot reuse assertion now includes the resolved sourceRoot while retaining the exact record/materialized checks. All 17 tests in service.pending-slots.test.ts pass. The separate script type failure was an implicit-any result array; it now uses the inferred run return type, and pnpm tsgo:scripts passes. Changed-file lint and independent review are clean. The PR body contains both repairs and the current proof; fresh exact-head CI is running. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
* perf(sessions): avoid duplicate worktree repository discovery Reuse the source checkout root resolved by the managed-worktree creation owner instead of discovering it again during fresh session preparation. Preserve nested cwd mapping, existing-binding and early-prompt preflights, and source/commit authority checks. This removes three serial Git subprocesses from sessions.create with a new worktree. Add a real work-count regression and reproducible owner/RPC measurements; retain the existing incognito invalidation assertions at the actual creation discovery boundary. * fix(sessions): repair create measurement and outcome checks
What Problem This Solves
Fresh managed-worktree session creation discovers the same Git checkout twice, adding three serial subprocesses before the session is ready.
User Impact
Creating a new session with
worktree: trueavoids that duplicate discovery. Created session/worktree state, nested working directories, replay checks, early prompts, and source/commit authority remain unchanged. This is a small creation-path improvement, not a claim to fix all session-create tail latency.Why This Change Was Made
The managed-worktree creation owner already resolves the checkout source root. Return that fact to session preparation, which consumes it for nested cwd mapping. Retain the earlier discovery where an existing binding or early prompt requires it. No cache, new configuration, schema, or provider behavior changes.
Runtime production changes total +6 lines across three files: the existing source-root fact crosses the owner boundary to preserve nested cwd. The redundant service forwarding method is removed, and the identical nested-cwd mapping now lives with worktree bindings. Both previously oversized files shrink. The non-test diff totals +653/−34 (+619): runtime +6 and reproducible measurement scripts +613. The scripts provide the requested built-Gateway phase/state proof and separate CPU/allocation workload using existing fixture, transport, and profiling helpers. Usage lives in their header comments; the shared perf README is unchanged.
Evidence
The real nested-workspace regression fails on the baseline with two discoveries and passes with one, while checking cwd and registry state. Final extraction validation passed 70 tests: 23 project/spawn cases, 4 worktree-preparation cases, 21 canonical service cases, and 22 source-closure cases. The earlier unchanged selection and incognito checks passed 9 additional tests, for 79 distinct passing tests across seven focused files. Baseline and candidate runtime builds completed successfully.
Five alternating-order owner pairs, 100 operations per arm per pair, use real Git and assert identical resolved roots. A separate sampled-allocation pass uses the same workload (2,000 logical operations across both passes):
These numbers measure the duplicate-plus-required repository discovery composition, not full session creation. Every pair favored the candidate for CPU and allocation. Shared-host wall time is context.
The isolated built Gateway workload uses 10,800 synthetic sessions, 40 enabled plugins, and 25 warmed creates each for plain sessions, worktree sessions, and initial mock-provider turns with a 150 ms response delay. Repository-discovery Git launches fell 7→4 in every measured worktree create; total observed Git launches fell 36→33. Matched adapter overhead p50/p95 was 224/475→5/16 ms. All 25 normalized durable worktree states matched, and both arms passed session identity, registry/checkout, and completed mock-response verification. Whole-create timing is confounded by host load, so the much larger overall latency reduction is not attributed to this patch.
The focused fast-path scope does not run a multi-pair ten-minute whole-Gateway stress campaign: it removes duplicate subprocess discovery on new worktree creation and does not change a frequent Gateway loop. The 25-sample p95 values below are context, not tail gates; no adverse conclusion is drawn from uncontrolled host timing.
Independent subagent review (autoreview route unavailable) found one obsolete test pause at the removed caller discovery. The pause now targets the creation owner's real discovery, retaining all lifecycle/intent invalidation assertions. Follow-up review found no remaining P0–P2 findings.
Formatting and the export-name collision guard pass. Changed-file core lint reports only the inherited file-size limit: the same rule counts baseline 724 and final 723 nonblank/noncomment lines against a 700-line budget. The final change shrinks both capped files, and the tracked no-growth ratchet passes. No lint rule, baseline, or suppression changed. Scripts and repaired authority-test lint pass. PR CI supplies the broad checks on the final head.
Measurements used baseline
29397d2a185c29d4b4d79d2ad41af0f7cf1f6a9band the same built source plus this change. The first prepublication rebase left all eleven reviewed files byte-identical. After measurement, the commit hook required the two oversized files to stop growing: the redundant forwarding method was removed and identical nested-cwd mapping moved to the existing binding module. Independent review confirmed unchanged discovery work and cwd/authority behavior; affected final tests cover that extraction. Timing results remain evidence for the earlier measured build, not a new timing claim for the extraction or subsequent main integration. No live Team load or production-state copy was used.Initial PR CI identified two defects: the measurement script's result array needed an explicit inferred-return type, and the merged test run included a new exact-outcome assertion from #184138 that needed the returned
sourceRoot. The branch integrates that main change and fixes both, preserving its workspace acquisition behavior. These were repaired rather than rerun unchanged. All 17 pending-slot tests, the targeted scripts typecheck, changed-file lint, and formatting pass; a fresh independent review found no actionable findings.Full Gateway phase and resource measurements, state proof, and limitations
Each cell is base → candidate. 25 measured creates per kind/arm after 3 warmups; every RPC/phase p95 has fewer than 200 samples and is context. CPU covers create/readback cycles; initial also waits for the completed turn.
Latency: p50 / p95 ms.
Resource context.
Managed-worktree phases are inclusive/nested and cannot be summed. All 25 measured logs were captured per arm.
The repository subphase begins inside
createWithOutcomeand measures retained owner discovery. Adapter overhead subtracts the matched managed duration from the aggregate worktree stage: discovery/binding/accept overhead, not pure discovery. Its mean fell 249.52→6.28 ms. Repository identity Git launches were 7→4 in every measured worktree sample; total Git launches 36→33, other operation buckets unchanged. Interval counters can include background launches; the owner regression establishes the duplicate-call deletion.The candidate ran under substantially lighter host load. The unchanged initial-message flow improved greatly too, so whole-run latency, CPU and memory deltas are contextual, not causal estimates. Worktree GC per create fell 24.56→18.15 ms while throughput increased, making GC per time rise 0.300→0.407 s/min; this is not an adverse verdict. Major GC counts are below 50 per arm. No A/A or 10-minute stress campaign ran under the requested fast-path protocol. Allocation comes from the separate owner microbenchmark only; no whole-Gateway allocation claim.
sessions.listwas startup inventory only, without a latency distribution.Both arms used 10,800 synthetic fixture sessions, 40 enabled plugins, seed 1826, 128 MiB transcripts and the same older fixture anchor 1791892800000 (2026-10-13), with maintenance unchanged. Actual startup retained count was 10,804 base (after 4 setup smoke creates) and 10,800 candidate. Each arm completed 75 measured creates; 56 mock requests including warmups consumed the 150 ms provider delay. All 25 initial sessions retained the expected assistant response. All 25 worktree bindings matched durable session rows and live registry entries, with exact source README and managed Git registration; 25 normalized stable states matched across arms, retaining UUID slug truncation/collision shape. Nested source is covered by focused tests, not this Gateway fixture. Placement is local only. Both owned Gateways stopped; candidate logged clean shutdown.