Repository navigation
fix(gateway): avoid unnecessary cold-start initialization - #192552
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: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
Extract the independent minification change from #192552. Preserve shared-runtime ownership markers and top-level bindings, retain function and class names, and verify relocated execution and lazy loading. Adapt the owner-label assertion to this stable line's existing region contract rather than importing the later bundled-module-regions helper. Retain 89 net regression lines with a matching allocation. (cherry picked from commit eaa8aeb) Co-authored-by: Vincent Koc <[email protected]> Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 19566d1365f2ac74d198ba5984d9cefd81726537)
Extract the independently reviewable lifecycle fix from #192552. Preserve manual execution, startup recovery, enabled scheduling, and joined shutdown while allowing disabled cron workers to retire. Co-authored-by: Vincent Koc <[email protected]> (cherry picked from commit 4e97c6e) Co-authored-by: RomneyDa <[email protected]>
Adapt upstream source 625945b to the beta3 runtime owners. Keep synchronous SDK compatibility while deferring tool, model, plugin, process and state-handler initialization. Integrate on 67cc5d9, preserving #195398, #196301, #196386, #196387, #189991 and #196448. Three automatically merged overlaps retain canonical assertion/mock baseline removals and worker-turn input gating; no new behavioral adaptation. Original source reviews and focused build/test evidence are retained. Fresh integration-only independent review found no actionable issues. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]>
Keep optional catalog, tool, plugin, sandbox, and database execution modules off headless Gateway startup paths. This is a partial improvement for #192547; constrained ARM acceptance remains open.
Scope
cdcef6c25f75fd7e2e2ddea93636a0ff629ce45abaseline, and latest catalog-refresh test correction. No additional main refresh was needed because the incoming head was mergeable.The original
startup-memory-regressions.txtallocation is now 853: 1,092 minus sibling allocations of 90 and 153, plus four lines isolating advisory native startup warmup. No shared scalar increase. The remaining diff has 253 paths, +6,514/-4,983 physical lines, net +1,531; this is not a claim of net production-code reduction.Current evidence
Current candidate:
ff3c57fefc93fb13ce323c6c5ba855e3628a53ad. The prior full build and 80-test proof below ran one81795267137263ce067d19842307ad91b97fc9e; the repair changes test isolation and allocation only.pnpm buildreached all final phases in 5m5.4s and emitted exact-candidate build metadata. The background process's exit handle was lost during a tool relay interruption; the final phase log and build identity were independently checked. UI-size messages were report-only warnings, not a build failure; UI/build/lock inputs are unchanged from the merge base and no budget was raised.CI repair
The native lifecycle logout assertion raced the independent default-native-model startup warmup added by #194417;
startupSettledintentionally does not join that advisory sidecar. Controlled scheduling of the real warmup reproduced the exact extra/native/modelsrequest. The test now isolates that unrelated demand with a restored spy; real HTTP discovery, configuration, refresh, and all RPC assertions remain unchanged. No production change. Controlled red/green proof and the final clean-source lifecycle file (3/3, 50.24s), Gateway-methods typecheck, targeted lint/format, diff check, and allocation ratchet pass. Independent review of this repair found no actionable issues.The prior CI run 42743142685 also had four unrelated failure groups (dependency tooling, context fences, detached admission, session fork), independently reproduced as 11 cases on its exact main baseline
4e97c6e5. New-head CI still must be assessed; these historical results are not a green-CI claim.Live pre/post performance measurements — November 9
The requested pre-merge measurement requirement is complete: 20 real Gateway boots (five interleaved baseline/candidate samples for each comparison) plus 10 real cron-worker lifecycle runs. Independent audit recomputed all summaries from raw samples and verified artifact and dependency identities. No merge was performed during measurement.
Gateway workload: macOS ARM64, Node 26.12.1, 32 logical CPUs, 512 GiB host RAM; fresh synthetic HOME/state/workspace per sample; token-authenticated loopback; browser/UI/channels disabled, cron enabled, default plugin loading. Node compile cache disabled; filesystem cache warm/uncontrolled. No concurrent task builds/tests. Require HTTP readiness and a successful authenticated sessions.list, then observe 20 seconds. RSS is sampled every 200 ms; idle RSS is the median of the final five seconds. CPU is process-tree CPU through startup plus that post-ready window, not steady-state inference CPU.
Cold-import memory and total CPU improved in every pair. Paired idle RSS reductions: 179.50–277.42 MiB; sampled peak reductions: 246.33–306.33 MiB; CPU reductions: 2.11–3.32 CPU-s. Usable-startup ranges overlap (baseline 7.008–8.045 s, candidate 6.924–7.610 s); no readiness speedup is established. Minification idle RSS ranges overlap, with one of five pairs higher after; its sampled peak and total CPU are lower in all five pairs. It is a modest runtime improvement, not a 20% RAM saving. Emitted JS under dist excluding Control UI is 345,070,972 → 287,210,918 bytes (-16.77%); file size is not RSS.
Runtime identities: cold-import baseline cdcef6c versus built e817952, whose runtime inputs are identical to published ff3c57f. Minification baseline d7aaafe versus 4eb00d9; the baseline checkout also contains only a measurement-driver commit, not production changes. All four arms share the same dependency lockfile, with workspace packages resolving to their own builds. Driver uses the existing Gateway benchmark environment, CLI, WebSocket and process-probe helpers. Raw samples, logs, exact entry hashes, manifests, driver and summary calculations are retained with the task evidence.
#196387 was separately measured through the real CronService, GatewayScheduler and native SQLite worker, with an empty store and automatic cron disabled. The existing memory-critical diagnostic signal triggers retirement without inducing a host OOM. This is an owner-level lifecycle benchmark, not full Gateway startup. Baseline retired 0/5 workers; fixed retired 5/5, median 53 ms (52–84 ms). Median paired avoided RSS growth is 8.375 MiB (7.844–8.422): baseline grew 10.6875 MiB, fixed grew 2.34375 MiB; neither showed an absolute RSS decline. The retired worker held 48.88 MiB used / 82.75 MiB allocated V8 heap, which is not equivalent to OS RSS reclaimed. No meaningful idle CPU improvement: paired -0.252 ms over approximately 4.9 seconds. Scheduler initialization median was 130 → 167 ms wall and 160 → 171 ms CPU, with broad overlapping ranges; no scheduler speedup is claimed.
Limitations: five samples per arm, shared host with recorded load, sampled rather than kernel-high-water RSS; CPU snapshots can omit already-exited child processes. All Gateways stayed alive and served real requests during measurement; teardown was task-directed SIGTERM, not a clean-exit-0 claim. These measurements do not establish constrained Linux ARM capacity, long-term soak, real-model reply performance or inference throughput. The ARM acceptance gap below remains open.
Remaining acceptance gap
Keep #192547 open. The prior combined ARM primary attempt OOMed before the reply completed. Local native Linux ARM64 cgroup setup has now been qualified, but product acceptance is unrun because no supported provider-credential injection into the isolated container is available.
Acceptance still requires the combined changes in a Linux-built artifact, Node 24.22.1, one CPU, zero swap, 1 GiB outer / 768 MiB service limits, V8 old 256/semi 4, an authenticated real-model marker reply, a 60-second soak, peak at most 928 MiB, and zero OOM events. The 512 MiB evaluation is conditional on a strict primary pass. No physical-device readiness, memory-capacity result, or issue closure is claimed.