Skip to content

fix(gateway): avoid unnecessary cold-start initialization - #192552

Merged
RomneyDa merged 53 commits into
mainfrom
fix/cold-catalog-config-isolation-20261104
Nov 10, 2026
Merged

RomneyDa merged 53 commits into
mainfrom
fix/cold-catalog-config-isolation-20261104

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

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

  • Use lightweight catalog/config owners and demand-loaded execution paths while preserving public facades, configured provider scope, later catalog refreshes, and request-time authority checks.
  • Keep the cohesive cold-import cutover here. Independent runtime minification is now improve(build): reduce runtime source retained by module loaders #196386; disabled-cron lease retirement is fix(cron): release idle workers when automatic scheduling is disabled #196387. Both preserve Vincent Koc's authorship and extract the latest contributor-reviewed versions.
  • Preserve the original contributor ancestry, integrated cdcef6c25f75fd7e2e2ddea93636a0ff629ce45a baseline, and latest catalog-refresh test correction. No additional main refresh was needed because the incoming head was mergeable.

The original startup-memory-regressions.txt allocation 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 on e81795267137263ce067d19842307ad91b97fc9e; the repair changes test isolation and allocation only.

  • 80 focused tests pass across cold tool imports, Gateway import boundaries, worker-turn execution, native model lifecycle, model discovery, and prompt-prefix stability. The worker-turn suite includes admission, cancellation, ownership and credential-boundary siblings.
  • Core typecheck, targeted lint/format, diff checks and the test-line ratchet pass: 6,609,855 lines against 6,610,075 (220 slack).
  • Full pnpm build reached 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.
  • Independent source inspection plus a completed full committed-range local ClawSweeper review found no actionable correctness or security defects (high confidence). This source review does not establish constrained-device acceptance.
  • Prior selected source-test results remain historical evidence for unchanged owners, not a cumulative current-head test count. Exact published-head CI/security remains required.

CI repair

The native lifecycle logout assertion raced the independent default-native-model startup warmup added by #194417; startupSettled intentionally does not join that advisory sidecar. Controlled scheduling of the real warmup reproduced the exact extra /native/models request. 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.

Comparison Idle RSS, median Sampled peak RSS, median Startup + 20 s CPU, median Usable startup, median
This PR: cold imports 1428.19 → 1225.41 MiB (-14.20%) 1482.92 → 1225.42 MiB (-17.36%) 13.31 → 10.69 CPU-s (-19.68%) 7.416 → 7.519 s (+1.39%)
#196386: minification 1463.61 → 1436.42 MiB (-1.86%) 1498.14 → 1461.50 MiB (-2.45%) 13.50 → 13.29 CPU-s (-1.56%) 7.873 → 7.222 s (-8.27%)

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.

@vincentkoc vincentkoc self-assigned this Nov 4, 2026
@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: XL labels Nov 4, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 4, 2026 05:12
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: ff3c57fefc93fb13ce323c6c5ba855e3628a53ad
  • Maintainer: @vincentkoc
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/models-config.providers.discovery-auth.runtime.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/sessions/auth-storage.core.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/sessions/auth-storage.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/sessions/model-registry-request-auth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/workspace-sandbox.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 4, 2026
@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 247a35c37eb6d40b9341162aaecefde758ab3364, but the PR head is now 9fee9c5aee8052fa83b207c0262801fe016027d4. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-11-04T05:29:05.202Z sha 247a35c :: needs changes before merge. :: [P2] Update the remaining catalog test interceptors to the core entry points | [P2] Prepare runtime snapshots in the plugin-status fixtures

@vincentkoc vincentkoc changed the title fix(models): reduce cold catalog memory fix(gateway): avoid unnecessary cold-start initialization Nov 4, 2026
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes app: web-ui App: web-ui extensions: deep-research and removed app: web-ui App: web-ui labels Nov 5, 2026
RomneyDa added a commit that referenced this pull request Nov 12, 2026
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)
RomneyDa added a commit that referenced this pull request Nov 12, 2026
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]>
RomneyDa added a commit that referenced this pull request Nov 12, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes docs Improvements or additions to documentation extensions: openai gateway Gateway runtime P2 Normal backlog priority with limited blast radius. scripts Repository scripts security-sensitive-changed size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants