Repository navigation
perf(gateway): skip redundant startup history prewarming - #184438
Conversation
Use cold-only history prewarming at the owner and remove the private caller switch. Recovery already activates fully prepared foreground readers; real reads keep their normal database admission and concurrency. Add synthetic warm-owner and crash/restart worker census measurements.
|
🦞👀 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 changesMake Gateway history prewarming cold-only by default and add opt-in startup measurement tooling. Example: Restart a Gateway with four configured agents after recovery has activated the foreground history pool.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR removes verified redundant startup work without changing reader admission or concurrency; no actionable defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway startup and authenticated operator connections request best-effort history preparation; the transcript worker owner admits databases and serves subsequent history reads. flowchart TD
A[Gateway startup] --> C[History prewarm owner]
B[Authenticated operator connection] --> C
C --> D[Foreground pool cold check]
D --> E[Skip redundant preparation]
D --> F[Discover configured databases]
F --> G[Existing worker admission]
H[Normal history reads] --> G
Technical reviewBest possible solution: Keep the cold-only decision in the existing prewarm owner while preserving normal first-read admission. Do we have a high-confidence way to reproduce the issue? Current-main source shows startup can discover and prewarm configured stores despite an active history lane; the supplied boot measurements corroborate this path, but no target code was executed during review. Is this the best way to solve the issue? This is the smallest runtime fix: reuse the existing pool-cold predicate at its current owner, remove the redundant caller option, and retain the existing regression scenarios. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 54408a978fc9. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -1, Tests -1, Other +293. Total +291 across 7 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 26, 2026, 5:24 AM ET / 09:24 UTC. |
…4438) Use cold-only history prewarming at the owner and remove the private caller switch. Recovery already activates fully prepared foreground readers; real reads keep their normal database admission and concurrency. Add synthetic warm-owner and crash/restart worker census measurements.
What Problem This Solves
Startup can submit another history prewarm after recovery has already activated the foreground history pool. That repeats store discovery and can start an extra reader while the first reader is busy.
User Impact
Avoid redundant startup work while preserving cold-history preparation, cancellation, and restart recovery. Recovery scheduling and reader concurrency limits are unchanged. Other configured databases that have not been read yet still open through normal first-read admission.
Why This Change Was Made
Make cold-only prewarming the operation's default and remove the private
onlyIfColdswitch. The authenticated connection path already requested this behavior. Each foreground history worker loads the history modules at creation, including workers first activated by recovery, so an active pool does not need a separate startup warmup.This is a small cleanup of startup demand, not a reduction of every transcript pool. Main-session orphan marking and resumption already run serially; discovery, projection, maintenance, usage, and model-context work retain their separate owners.
Evidence
The existing warm-store test now calls the default API and fails on the baseline because it discovers/prewarms stores despite an active history pool. It passes with the change. The other cold-store/error/cancellation cases and connection/startup scheduling tests pass: 71 tests across three files. All 193 existing main-session restart-recovery tests pass (305.07 seconds test-file duration).
Real-owner microbenchmark, AB/BA, 3,000 calls per arm, two samples per revision, 1,000-session synthetic database, native allocation counter (no allocation sampling or forced GC):
These percentages apply only to redundant warm calls, not total Gateway CPU. Reproduce with
node --import ./scripts/tsx.mjs scripts/perf/session-history-prewarm-measure.mjs --state-dir <synthetic-fixture> --iterations 3000; baseline uses--source-file <frozen-baseline-owner.ts>.Boot/recovery comparison: three interleaved pairs (AB, BA, AB), separately built baseline
2499f2be3e88and the same source with this patch. Each fresh fixture has 10,000 sessions, four agents, 3,981 settled subagent runs, 8 MiB of transcript text, 65 WebSocket clients, and four real mock-provider turns interrupted by killing the owned Gateway. The recovery window is 75 seconds from restart spawn, including startup and reconnect polling. All 24 interrupted turns resumed; zero connection/RPC errors.Mean recovery time: 21.099 → 20.957 s (−0.142 s, −0.67%). RSS high-water: 2811.2 → 2826.7 MiB (+15.5 MiB, +0.55%). The memory/latency changes are mixed across pairs; no overall speed or memory win is claimed. Main CPU/allocation through the first one-second sample after readiness averaged 9.485 → 8.897 s / 5994.5 → 5742.5 MiB; these include cold module loading and are diagnostic. macOS native
resourceUsage().maxRSSis reported, not Linux/procVmHWM.The reliable work-count win is four prewarm tasks → zero in every boot. Both arms had five transcript workers by readiness, seven started during recovery, and one burst worker retired before teardown. First-boot concurrent turns reached eight workers in both arms. Real history work still needs the second history worker: this patch does not shrink the aggregate pool budget.
Client
sessions.listp99, base/candidate: 545/621 ms (799/780 samples), 511/577 ms (780/780), and 463/915 ms (726/780). Every arm is below the 1,000-sample tail gate; these are context, not an adverse verdict or a throughput claim. This targeted cold-start deletion used the short recovery proof rather than a ten-minute steady-state campaign. Server-handler latency, GC, and event-loop p99 were not measured; no conclusions about those metrics are drawn. No shared or production Gateway was used.Reproduce each fresh arm with
scripts/perf/team-shape-fixture.ts --sessions 10000 --runs 3981 --settled-runs --team-stress --transcript-mib 8 --approvals 0 --cron 0 --projects 0, followed byscripts/perf/post-restart-burst-measure.ts --state-dir <fixture> --entry dist/entry.js --port 41825 --mock-port 41826 --clients 65 --runs 4 --seconds 75 --poll-ms 5000 --worker-census(both invoked withnode --import ./scripts/tsx.mjs; fixture also requires--state-dirand--port). Alternate the complete builtdisttrees at the same entry path, only after the previous Gateway exits. The source rebase was patch-identical; broad proof is exact-head PR CI.Format, changed-file lint, export-collision guard, and both eager-import/PR-wrapper closure guards pass (26 closure tests). Independent subagent review (autoreview route unavailable): clean after fixing a benchmark observer startup-listener issue. The corrected observer waits for the real server's message listener; a delayed-listener smoke verifies startup-port delivery, callback removal, and payload omission.
Runtime production change: net −1 line; non-test diff including performance scripts is +295/−3 lines, of which 293 additions are measurement tooling. Added benchmark code records native worker births/tasks, main-thread CPU/allocation, RSS high-water mark, host load, and time until all interrupted requests resume; it is opt-in tooling and adds no Gateway runtime path. The shared performance README is unchanged.