Repository navigation
perf(gateway): prewarm first Control UI requests while idle - #158555
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: needs maintainer review before merge. Reviewed September 26, 2026, 12:37 AM ET / 04:37 UTC (Revision 4). ClawSweeper reviewWhat this changesThe branch prepares Control UI connection and chat handlers, local skills, context data, and memory retrieval in a sequenced idle task after Gateway readiness. Merge readiness✅ Ready for maintainer review Keep this PR open. Current main still lacks the proposed first-use Gateway preparation, and the related merged memory warmup covers a different cold path. The latest merge left the reviewed prewarm implementation unchanged; the PR body records acceptance of its two known performance limits. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway receives Control UI connections and chat requests, then loads handlers and agent workspace data needed to serve them. This change moves some of that first-use work into idle time while keeping normal request loaders authoritative. flowchart LR
A[Gateway ready] --> B[Idle task]
C[Foreground requests] --> D{Gateway busy?}
D -->|Yes| B
B --> D
D -->|No| E[Prepare handlers and local skills]
E --> F[Prepare context and memory]
F --> G[First Control UI request]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +14, Tests +109. Total +123 across 10 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the unified idle sequence and authoritative request loaders; revisit worker-backed local skill discovery if production Gateway traces show material client stalls. Do we have a high-confidence way to reproduce the issue? No high-confidence full-client reproduction was established in this read-only review. Current main shows deferred first-use loaders, and the PR reports a scoped before-and-after component benchmark. Is this the best way to solve the issue? Yes. The branch extends the existing idle owner and keeps request-time loading authoritative; its remaining synchronous scan limitation is explicitly recorded. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b458b9f1c6bc. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
Merge origin/main into the reviewed Control UI prewarm branch. Keep Memory Core retrieval in the shared idle sequence and honor foreground cancellation after imports. Preserve cold-import proof separately from inactive-plugin selection so Vitest module caching does not invalidate the fixture.
Merge main with the retained-assets type import correction da8149b. The prewarm implementation and focused tests are unchanged; all 131 focused tests pass again. The prior hosted failure was reproduced on main and its exact typecheck stripe passes with the owning repair.
|
Merged via squash.
|
…#158555) * perf(gateway): prewarm first-use chat paths while idle * fix(gateway): validate idle prewarm handler lookup * test(gateway): normalize idle prewarm fixture paths * test(gateway): narrow prewarm call order assertion
What Problem This Solves
The first Control UI connections, history reads, and chat turns after Gateway startup can pause other clients while loading shared modules and scanning primary-workspace skills.
User Impact
An idle Gateway prepares the common chat paths before clients need them. Foreground requests retain priority, including requests arriving while an optional module import is pending. Immediate requests continue to use the normal authoritative loaders.
Why This Change Was Made
One sequenced idle owner now prepares connection, history, send, session-list, and agent-event modules, local primary-workspace skill discovery, and the existing context cache. Skill watcher acquisition precedes discovery so first-turn watcher setup does not discard the warmed cache. Remote workspace discovery stays request-owned. Plugin-catalog preparation follows the chat work so its network fetch cannot hold up skill preparation.
The separate context-cache scheduler is removed. Its five-second minimum delay, current-config lookup, foreground priority, cancellation, and shutdown join are retained. Prewarm does not execute requests, construct connection-bound handlers, or fetch live provider catalogs. No protocol, configuration, or database schema changes.
Evidence
server-startup-handler-prewarm.test.ts,server-idle-task.lifecycle.test.ts, andserver-startup-post-attach.test.ts; command wall time 54.57 seconds withnode scripts/run-vitest.mjs <files> --maxWorkers=1.pnpm buildcompleted runtime and declaration generation, CLI bootstrap import guard, plugin SDK export guard, and UI performance budgets. Its final CLI startup-metadata step timed out rendering sourcenodeshelp at 120 seconds; that exact step passed separately in 114.03 seconds after build work settled. Aggregate build wall time was 8,082.60 seconds; the aggregate command did not exit green./healthzin 91.30 seconds and/readyzin 115.74 seconds, used 20.65 seconds CPU and 605.7 MiB max RSS, and shut down cleanly. This demonstrates startup/shutdown, not a passing startup latency budget. A clean Testbox attempt was cancelled while staging local sources, before any lease or remote command; its owned wrapper completed cleanup.incidentCombined --runs 1 --warmup 0 --timeout-ms 60000failed to reach either health endpoint within the existing 60-second budget. Its 80,000-file fixture was fully removed; the whole command took 1,212.47 seconds including fixture setup/cleanup. A clean-machine startup-budget run is still needed.node scripts/check-changed.mjs: passed in 3,966.06 seconds, including all 25 selected core test type graphs, core lint, dead-export scans, and runtime import-cycle guards.Landing reconciliation
Merged current main (including #158563) into the branch without rebasing. Control UI handlers, local skills, the delayed context cache, Memory Core retrieval, and plugin catalog preparation share one sequential idle owner. Memory retrieval also observes the existing foreground/shutdown cancellation predicate after awaited imports.
node scripts/run-vitest.mjs src/gateway/server-startup-handler-prewarm.test.ts src/gateway/server-idle-task.lifecycle.test.ts src/gateway/server-startup-post-attach.test.ts --maxWorkers=1).format-render.tsscenario reference. Main commit a991028 (refactor: share filesystem admission and cleanup with fs-safe #158313), included by this merge, removes that stale reference. No hosted run was rerun to obtain green.Hosted run 36216839983 failed in
check-test-types-core-1with TS2459 in the unchanged retained-assets E2E fixture:ControlUiRootStatewas imported from the former owner. This reproduced on clean main. The type-only correction passed the entire original--stripe 1/5 --concurrency 2typecheck selection in 51.02 seconds. Another maintainer landed the identical repair as da8149b while verification completed; the branch now incorporates that fix by merging main. All 131 focused prewarm/lifecycle/post-attach tests passed again in 40.13 seconds on the merged candidate. No failed CI run was rerun.The maintainer landing decision retains the reviewed prewarm design. ClawSweeper's remaining P2 concerns are retained performance limitations: an individual local skill scan is synchronous once started, and foreground interruption may leave an optional context fill unfinished until request-time loading. The context owner clears the failed/cancelled load promise and retains the authoritative request path; this does not corrupt or permanently poison the cache. Worker-backed skill discovery and rescheduling interrupted optional fills remain possible follow-ups, outside this approved reconciliation.