Skip to content

fix(memory): reduce constrained Gateway startup pressure - #197801

Merged
vincentkoc merged 27 commits into
mainfrom
fix/cardputer-first-turn-memory-20261112
Nov 13, 2026
Merged

vincentkoc merged 27 commits into
mainfrom
fix/cardputer-first-turn-memory-20261112

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Memory-constrained Gateways load unused runtimes during startup and can run out of memory before their first agent reply.

User Impact

Defer optional execution and skill-status runtimes until their owning operation needs them, and emit smaller runtime JavaScript while preserving names, module provenance, update recovery and standalone code generation.

This is an incremental startup-memory improvement, not Cardputer qualification. The 768 MiB service still OOMs before its first reply; the original issue remains open for follow-up.

Why This Change Was Made

  • Narrow startup imports for agent, CLI, Code Mode, cron and execution review. Preserve configuration capture, cancellation, deadlines, authority and parent-owned cleanup.
  • Reuse the startup publication reader, avoid database imports for disk scans, and skip optional warmups when a constrained process has at most 20% memory available.
  • Compact emitted JavaScript while preserving module labels and source-map positions. Update existing provenance readers and keep declaration output outside the JavaScript hook.
  • Defer both skill-status import paths. Keep per-workspace environment ordering and serialize completed worker results.
  • Load cron read handlers only for cron queries, removing the redundant predicate while preserving preparation before fresh database admission.
  • Load the OpenAI SDK only inside model-request work. Keep synchronous client factories in their existing construction owner and preserve SDK error identity.
  • Update build/recovery tests and the native PR-wrapper inventory for the changed output.

No new configuration, dependency, persistence contract or cleanup owner is added. Net runtime production growth is 60 lines; net test/helper growth is 400 lines against the 400-line allowance, without allocation credit or an allocation file.

Evidence

Current candidate: 333572898b080f5c6082d7da8d1a42b49eae1ef2, based on d90d52cc. Current-head native packaging, ARM construction and image qualification pass. The original-cap runtime still fails as detailed below.

  • Five runtime chunks shrink from 2,256,643 to 1,873,728 bytes (16.97%); all 176 module labels, declaration owners and cooked literals remain equivalent. The packaged skill-discovery static graph shrinks from 293 chunks / 1,456,375 bytes to 248 chunks / 1,269,523 bytes. These are source-size measurements, not RSS savings.
  • Import/build regressions fail before their fixes and pass afterward. All 121 targeted skill, remote-host, resource, install, snapshot and worker tests pass. Retained proof covers unchanged execution-review cancellation/cleanup, prompt-prefix stability, build markers, provenance, update deadlines and package replacement. Four scoped typechecks, lint and formatting pass. The existing external-buffer accounting test has an investigated baseline failure; its assertion was not weakened.
  • The cron-reader repair passes 53 focused state, cron and lifecycle tests. Its import-boundary regression fails on the prior head and passes after the fix; core/state typechecks, lint and formatting pass. Independent review found no actionable defects. The conservative startup-reader graph removes 70 modules / 408,991 source bytes, falling to 11 modules / 58,463 bytes after the proactive reader is used; no sustained RSS saving is claimed.
  • The SDK import regression fails before its fix and passes afterward. All 188 selected Responses/Completions tests pass, as do response-hook, session-header and prompt-prefix stability suites. Core and package-test typechecks, lint, formatting and the 400-line test budget pass. Fresh independent review found no actionable defects. Packaged AST inspection confirms the 910,807-byte SDK chunk and its 2,330-byte construction owner stay outside the five AI entry points’ static import closure; all five deferred imports remain inside request work.
  • Fresh full-range independent review of d90d52cc..33357289 inspected all 88 files and found no actionable correctness or security regressions. Current-head native packaging passes (241.35s, 11 joined commands), ARM64 construction passes (59.59s, 21 joined commands), and immutable-image/native-module checks pass (10 joined commands). The source checkout is clean.
  • CI run 43351311520 remains failed: two Node jobs and one UI job. Its actual merge checkout is ca062042, with main parent a83f7437. The admission and invalid-profile assertions inherit #197978: the unchanged logger now creates stateDir/logs; test data and the logger are identical to the actual main parent. Stored config, database and credential hashes remain unchanged.
  • The UI failure is the Mermaid blocked-frame request count remaining zero. Source review attributes it outside this PR: the complete UI and renderer trees, dependency inputs and E2E entrypoints are unchanged, and the fixture builds and serves isolated Vite assets through a mocked Gateway. It does not run the changed Gateway/tsdown output. The shared singleton change adds only an uncalled export; the changed CLI-worker build entry is not served to the browser. This is scoped unrelatedness attribution, not a matching-main-failure claim; the exact scheduling/renderer cause remains unknown. Both focused UI cases pass locally, which is nonreproduction only. The separate failure-capture exporter also lacked python. Landing uses the native attributed-CI exception under the operator's standing instruction, with these failures retained rather than marked green.
  • The current-head original runtime test fails: service OOM exit 137, client exit 1, outer peak 857,219,072 bytes (817.51 MiB), zero swap/restarts, no verified reply or soak. Parent-local max/OOM/kill counters stay zero; descendant OOM counters and the service exit identify the service-side limit. Ready-time RSS is 734.8 MiB. All 25 commands join and owned cleanup passes.
  • A preceding-head diagnostic captures 30 worker creations and 20 exits around readiness, including repeated reader, SQLite, logging and discovery replacements. The service reaches its 768 MiB cap before readiness and is later OOM-killed. This identifies churn but does not establish an active-work ownership violation or satisfy acceptance. All 25 commands join and owned cleanup passes.

Physical-device readiness still requires a real OpenAI CARDPUTER_GATEWAY_OK response and 60-second healthy soak, with a 1 GiB outer limit, 768 MiB service limit, one CPU, original 256 MiB old-space / 4 MiB semi-space flags, zero swap/OOM/restarts, and outer peak at most 928 MiB. Larger diagnostic runs do not satisfy that gate.

Related: #192547

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

clawsweeper Bot commented Nov 12, 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 size: XS docs Improvements or additions to documentation gateway Gateway runtime labels Nov 12, 2026
@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 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head c92ce4234b1f92593574d339f917a2feab6d82af, but the PR head is now 64a28c45f802e0a0333bfce5be314ae602fa2bb2. 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-12T15:48:01.114Z sha c92ce42 :: needs changes before merge. :: none

@vincentkoc
vincentkoc marked this pull request as ready for review November 12, 2026 16:17
@vincentkoc
vincentkoc marked this pull request as draft November 12, 2026 16:28
@vincentkoc vincentkoc changed the title fix(memory): reclaim idle workers before constrained hosts exhaust memory fix(gateway): narrow reply runtime prewarm imports Nov 12, 2026
@vincentkoc vincentkoc changed the title fix(gateway): narrow reply runtime prewarm imports fix(memory): reduce constrained Gateway startup pressure Nov 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Nov 12, 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 12, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 12, 2026 17:43
@github-actions

github-actions Bot commented Nov 12, 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: 333572898b080f5c6082d7da8d1a42b49eae1ef2
  • Maintainer: @vincentkoc
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/exec-auto-reviewer.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/gateway/resolve-configured-secret-input-string.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Nov 12, 2026
@vincentkoc
vincentkoc force-pushed the fix/cardputer-first-turn-memory-20261112 branch from 886ef57 to ea56dc2 Compare November 12, 2026 23:13
@vincentkoc
vincentkoc merged commit d8eca04 into main Nov 13, 2026
222 of 228 checks passed
@vincentkoc
vincentkoc deleted the fix/cardputer-first-turn-memory-20261112 branch November 13, 2026 04:00
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 13, 2026
…7801)

* fix(memory): reclaim constrained process headroom earlier

* docs(memory): clarify constrained process retirement threshold

* fix(gateway): narrow reply runtime prewarm imports

* fix(memory): retain early reclamation with narrow startup imports

* fix(memory): defer unused Gateway reply and CLI runtimes

* test(gateway): preserve reply helpers in startup mocks

* fix(memory): serialize startup publication reads

* test(gateway): remove redundant shared reply mocks

* fix(memory): defer Gateway secret providers until needed

* test(gateway): document provider import isolation

* fix(memory): defer disk scan ownership imports until needed

* fix(memory): defer agent runtime imports until first use

* fix(memory): keep CLI inspection and cleanup demand-loaded

* fix(cli): preserve lightweight service inspection boundaries

* fix(gateway): defer optional work under memory pressure

* test(gateway): report unexpected startup cleanup failures

* fix(gateway): load skill archive runtimes on demand

* fix(gateway): defer cron agent execution runtimes

* fix(gateway): defer exec reviewer completion runtime

* fix(ci): include identity protocol in PR wrapper closure

* fix(build): compact runtime source without losing module origins

* fix(build): skip declaration chunks when compacting module labels

* fix(workers): collect small heaps after first idle period

* revert: drop unproven first-idle worker collection

* perf(skills): defer status readers during discovery

* fix: load cron readers only for cron state queries

* fix: load the OpenAI SDK only for model requests
fuller-stack-dev added a commit that referenced this pull request Nov 13, 2026
* test(qa): find built Gateway chunks by exported bindings

The Telegram model-picker replacement proof located its hashed dist
chunks by whitespace-sensitive export text. #197801 (d8eca04)
switched the build to compact codegen, so chunks now read
`export{startGatewayServer,truncateCloseReason}` and the markers no
longer match: the case failed with "Could not resolve built
prepared-model-runtime- module" before starting a Gateway.

Parse the candidate chunks and match the names the bootstrap script
imports, so formatting, export order and unrelated exports no longer
decide which module is found. Product behavior is unchanged; the case
passes again with its assertions untouched.

* test(qa): read the whole current turn in timeout-recovery mock

The mock provider in the timeout-recovery subagent proof treated the
last Responses input item as the current turn. #198100 (bf0b800)
pins the system prompt on every route and appends prompt updates after
the turn's input, so the completion event was no longer last. The mock
answered the delivery turn as a plain retry and the reply sequence
assertion failed, although the Gateway still delivered the child
completion once.

Read everything after the previous assistant reply, the same rule
#198177 applied to the other subagent prompt tests. Assertions are
unchanged.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
* test(qa): find built Gateway chunks by exported bindings

The Telegram model-picker replacement proof located its hashed dist
chunks by whitespace-sensitive export text. openclaw#197801 (2721e3d)
switched the build to compact codegen, so chunks now read
`export{startGatewayServer,truncateCloseReason}` and the markers no
longer match: the case failed with "Could not resolve built
prepared-model-runtime- module" before starting a Gateway.

Parse the candidate chunks and match the names the bootstrap script
imports, so formatting, export order and unrelated exports no longer
decide which module is found. Product behavior is unchanged; the case
passes again with its assertions untouched.

* test(qa): read the whole current turn in timeout-recovery mock

The mock provider in the timeout-recovery subagent proof treated the
last Responses input item as the current turn. openclaw#198100 (709602d)
pins the system prompt on every route and appends prompt updates after
the turn's input, so the completion event was no longer last. The mock
answered the delivery turn as a plain retry and the reply sequence
assertion failed, although the Gateway still delivered the child
completion once.

Read everything after the previous assistant reply, the same rule
openclaw#198177 applied to the other subagent prompt tests. Assertions are
unchanged.
mmango7474 added a commit to alinaos-org/openclaw-nix that referenced this pull request Nov 25, 2026
11.10 builds with minify codegen (openclaw/openclaw#197801): no whitespace inside code,
one-line //! module labels instead of //#region pairs, short local names. Every patch
keeps its 11.9 behaviour and its exact-once anchors; the anchors now match both the
spaced (<= 2026.11.9) and compacted shapes, or a 2026.11.10 branch does. 11.10 is cut
from main, not from the 11.x line: release-gated name tables carry explicit 11.10
entries. The chain passes all 24 patch and test steps on 2026.11.10 and on 2026.11.9.

Ported by Codex (gpt-6.2-astra); spawn-target-owned-mcp's compact branch by ALINA.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mmango7474 added a commit to alinaos-org/openclaw-nix that referenced this pull request Nov 25, 2026
11.10 builds with minify codegen (openclaw/openclaw#197801): no whitespace inside code,
one-line //! module labels instead of //#region pairs, short local names. Every patch
keeps its 11.9 behaviour and its exact-once anchors; the anchors now match both the
spaced (<= 2026.11.9) and compacted shapes, or a 2026.11.10 branch does. 11.10 is cut
from main, not from the 11.x line: release-gated name tables carry explicit 11.10
entries. The chain passes all 24 patch and test steps on 2026.11.10 and on 2026.11.9.

Ported by Codex (gpt-6.2-astra); spawn-target-owned-mcp's compact branch by ALINA.

Co-Authored-By: Claude Opus 5.5 <[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 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.

1 participant