Repository navigation
perf(git): reduce first-chat baseline startup - #167936
Conversation
Dispatch Git reads lazily from the existing worker and remove the eager read dispatcher. This avoids loading worktree and PR machinery for session baseline capture while preserving each operation owner and lifecycle. Sixty paired synthetic first turns passed on Crabbox AWS: cold baseline preparation improves roughly 1.9–2.0x and startup drops about 300 ms. Focused regression suites, import/export guards, the full changed-file gate, and independent review passed.
|
🦞👀 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: needs maintainer review before merge. What this changesThe Git worker loads only the implementation needed for each repository read, reducing preparation time before the first chat turn. Review scores
ProductKind: Performance · Worth it: Yes Merge readiness✅ Ready for maintainer review This PR remains useful: current main retains the eager dispatcher, the supplied measurements show a consistent startup improvement, and source review found no actionable defect. Required CI is still running. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway captures a checkout baseline before a session starts so later changes can be attributed to that session. Its Git worker performs repository reads while the Gateway retains subprocess supervision, authority, and cleanup. flowchart TD
A[First chat turn] --> B[Session baseline capture]
B --> C[Existing Git worker pool]
C --> D{Requested repository operation}
D --> E[Load baseline implementation]
D --> F[Load other read implementation]
E --> G[Gateway supervised Git and filesystem reads]
F --> G
G --> H[Repository facts returned to caller]
Technical reviewBest possible solution: Keep operation-specific lazy loading in the existing Git worker and retain the established leaf implementations and host lifecycle. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction; this is a performance improvement supported by a paired real-Gateway startup campaign and a source-visible eager import path on current main. Is this the best way to solve the issue? Yes. Moving lazy dispatch into the existing worker removes the unnecessary import closure while preserving operation owners, arguments, concurrency, and lifecycle. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e19bcd6bd11e. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -5, Other -1. Total -6 across 5 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 Reviewed October 9, 2026, 3:42 PM ET / 19:42 UTC. |
Dispatch Git reads lazily from the existing worker and remove the eager read dispatcher. This avoids loading worktree and PR machinery for session baseline capture while preserving each operation owner and lifecycle. Sixty paired synthetic first turns passed on Crabbox AWS: cold baseline preparation improves roughly 1.9–2.0x and startup drops about 300 ms. Focused regression suites, import/export guards, the full changed-file gate, and independent review passed.
What Problem This Solves
The first chat turn waits on a cold Git baseline worker whose dispatcher imports every Git read implementation, including worktree allocation and registry code that baseline capture never uses. The existing 30-second worker idle expiry lets that cold cost recur on a running Gateway.
User Impact
Cold first-turn startup improves by roughly 300 ms in fresh, large-workspace, and managed-worktree sessions. Baseline preparation is approximately 1.9–2.0× faster. This does not remove all startup delay: session initialization, compaction preflight, and worktree provisioning remain material costs.
Why This Change Was Made
The existing Git worker dispatches each read directly to its lazily loaded owner. Delete the redundant eager dispatcher and unused result type; update the wrapper inventory and test routing to follow the remaining owner. The same leaf functions, identity concurrency limit, cancellation, and filesystem custody remain in use.
Production LOC: −5; tooling: −1 (five files, 40 insertions / 46 deletions). No new runtime owner or cache.
Evidence
A fixed alternating AB/BA campaign ran ten pairs per scenario, with a new Gateway and synthetic state for every first turn. All 60/60 turns completed, appeared in history, and fully shut down. Every paired startup and model-request measurement improved; paired request sizes matched. No samples or outliers were discarded.
Cold Git baseline p50 fell 647 → 329 ms, 643 → 340 ms, and 599 → 316 ms, respectively. Overall startup improves about 8–10%, rather than 1.5×; the owner-level improvement and consistent tail reduction justify the smaller, simpler implementation.
Startup breakdown and measurement method
Fresh-session median spans, in milliseconds:
Managed-worktree preparation itself remains 1,088 → 1,087 ms. Reply context and prompt-body assembly are below 1 ms in the fresh fixture. These spans nest, overlap, and can extend beyond the startup event; they must not be added together.
The rig uses real
sessions.create,chat.send,agent.wait, andchat.historywith loopback mock inference. Bootstrap, skills, and normal tool preparation remain enabled. Startup is server ACK toonAgentRunStart(first accepted execution activity), not universally the model network call. HTTP arrival is measured separately from client submission; the worktree case includes the initial-messagesessions.createflow.Baseline:
432ade6f500de6cdb0bcd4b0948a07bf466672f1. The exact candidate patch was verified before execution. Node 24.19.0, pnpm 12.7.0. Independent core builds use identical frozen dependency inputs. Two unchanged packages (aiandgateway-protocol) use common complete build artifacts because their bundler partitioned its generated helper nondeterministically; source equality and before/after artifact fingerprints were verified. Both runtime snapshots omit.git, equally excluding development-only plugin discovery.With ten samples per variant/scenario, the reported p95 is the maximum observation, not a production-tail estimate. Filesystem caches stay in their natural state. Synthetic inference proves startup and request delivery, not external provider latency or a production deployment.
Remote validation and review
blacksmith-testbox, profileopenclaw-check, leasetbx_01m4grebdr7ze46m2hpyb0wzkb: baseline/candidate builds, four focused Vitest shards (163.78 s), export guard, and 135 closure/CI-plan cases (68.92 s) passed. The lease disappeared during the changed gate; that incomplete run is not counted as passing.Authorized AWS fallback, lease
cbx_d32aeaa197dd, validation runrun_ed158431e45268e5c5a86b105377622b: all commands below passed. Build: 321.3 s; four focused shards: 170.81 s; 135 closure/CI-plan tests: 89.75 s; full validation command: 32m48s.The paired rig ran on the same AWS lease as
run_b74466649b24e1694f5805744c804f44, usingpaired-runtime.mjs compare --pairs 10 --cases fresh,large,worktree: 60/60 passed, command 19m48s, exit 0. Both artifact fingerprints remained unchanged after timing. Earlier sequential timings were excluded as a comparison method because host drift made them unreliable; the complete fixed paired campaign is reported above.The published commit rebases the reviewed patch onto
5a292d07eb88without changing its stable patch ID. The affected worker contracts and implementation owners are unchanged from the measured base; the measurements and remote gates above are explicitly pre-rebase evidence.Independent Codex review returned scoped-clean through P2. No tests were added or changed. No local builds, test suites, or typechecks were run.