Repository navigation
fix: resolve issue #157575 β [Bug]: Managed Gateway heap flag overrides per-worker old-space limits - #158201
xydigitLybnnnn wants to merge 4 commits into
Conversation
A managed Node Gateway install injected an automatic process-wide --max-old-space-size into the service argv. V8 applies that flag to every worker isolate, so it silently overrode the smaller resourceLimits.maxOldGenerationSizeMb budgets (512 MiB) requested by the model-catalog, SQLite, transcript, and state workers. Stop adding the automatic flag. Fresh Node installs keep Node's default main-isolate heap, which leaves the declared per-worker budgets effective. Operator-owned heap controls already stored in the service argv or NODE_OPTIONS are still preserved. Bun keeps its existing environment budget because it does not share V8's process-flag precedence. Fixes openclaw#157575
|
π¦π 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: blocked before merge. What this changesThe branch stops automatically adding a process-wide Node heap flag to newly generated Gateway service commands while preserving stored heap controls. Example: Install a fresh managed Node Gateway on a 24 GiB host
Review scores
ProductKind: Bug fix Β· Worth it: Needs a maintainer decision Β· Fix scope: Partial Merge readinessβ Blocked before merge - 3 items remain This PR addresses a real, unresolved policy conflict, but the previously reported existing-service defect remains. Its useful contribution warrants keeping it open while the heap-default direction is settled. Priority: P2 Decision needed
Before merge
Findings
Tests
Agent review detailsHow this fits togetherManaged Gateway installation builds the command used by the operating system to launch OpenClaw. Nodeβs process-wide heap settings affect both the main Gateway and worker threads that request smaller memory budgets. flowchart TD
A[Fresh installation or service repair] --> B[Stored service command]
B --> C[Managed heap policy]
C --> D[Generated Node launch command]
D --> E[Gateway main heap]
D --> F[Worker memory budgets]
F --> G[Effective worker heap ceiling]
Technical reviewBest possible solution: Align effective worker budgets with managed heap sizing while preserving intentional operator controls and adequate main-isolate capacity. Do we have a high-confidence way to reproduce the issue? Yes: current-main command generation and Nodeβs documented precedence establish the conflict, corroborated by supplied worker-ceiling measurements; no reviewer-side execution was performed. Is this the best way to solve the issue? No, not as a complete repair: stopping fresh flag generation leaves installed generated flags effective and changes a main-capacity policy established for sustained workloads. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b0c330d27df4. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -4, Tests +51, Docs +4. Total +51 across 8 files. Added test files: 0. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label 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 HistoryReview history (2 earlier review cycles)Reviewed October 8, 2026, 10:12 PM ET / October 9, 2026, 02:12 UTC (Revision 3). |
|
Additional first-hand field evidence for #157575, beyond the worker-ceiling probe already in this PR (OpenClaw 2026.9.6, Linux x64, Node 24.21.0):
This adds observed operational impact to the existing-service upgrade concern already raised in review: correcting fresh-install defaults alone does not remove a previously generated flag from an installed service. No pre-restart allocation profile was captured, so this evidence does not identify a retaining edge or establish that #159448 repairs this installation's growth. It is not validation of this PR's candidate code or upgrade path, and the memory samples do not establish sustained CPU consumption or total energy use. |
β¦ged-gateway-heap-flag- # Conflicts: # docs/plugins/architecture.md # src/cli/daemon-cli/install.integration.test.ts # src/daemon/program-args.test.ts
Upstream added a test asserting the managed install sets a process-wide 16 GiB heap flag. This branch removes that automatic flag so worker old-space budgets stay effective (openclaw#157575), so the test now checks that the Gateway and a spawned child both stay on the runtime default heap.
## Problem A process-wide Node heap flag overrides `Worker.resourceLimits`, allowing catalog and storage workers to inherit the Gateway's much larger heap budget. Clearing a worker's argv or environment cannot fix V8's process-wide precedence. Removing the Gateway's heap budget would reduce main-isolate capacity and leave operator-supplied flags unfixed. ## Change Clear V8's old-space and total-heap overrides after the main isolate initializes, at the shared worker construction owner. The main isolate keeps its configured budget; new workers use their resource limits. This covers CLI, direct service and library entrypoints without changing early CLI recovery. Explicit V8 flag-freezing/abort-on-contradictory modes preserve their existing behavior and warn rather than aborting natively. No new configuration or raised catalog budget. Thanks to @valkyriweb for the V8 reset mechanism and @xydigitLybnnnn for the managed-service diagnosis and comparative measurements. Fixes #157575. Fixes #157630. Supersedes #158201. ## Size and validation - Six changed files; +1 production TypeScript line under the source-directory filter, +18 runtime lines including the packaged JavaScript helper. No changelog changes. - Secretless AWS, Node 24.21.0 and 26.11.1: argv, NODE_OPTIONS, underscore, total-heap and percentage flags preserve the main ceiling and restore a 128 MiB worker budget (224/176 MiB total V8 ceiling instead of 1120/1072 MiB). These are heap ceilings, not RSS measurements. - Final head: heap regression 7/7 (5.79 s wall), launcher 130 passed / 2 platform skips (344.49 s cold, including the runtime build), worker lifecycle 6/6 (33.43 s), extracted wrapper 17/17 (25.97 s). - Final type-aware lint, formatting, export-name collision guard, core types, SDK surface and full build pass (283.23 s). Every candidate Knip finding was independently reproduced on clean main 6e06137. - Independent correctness review and diff cleanup completed. The runtime and packaging regressions found during validation were repaired and retested. ## Inherited CI disposition Broad CI remains red and is not represented as green. The exact untouched-main Node 24.19 replay reproduces node/paired-worker terminal failures and the steering acceptance/cleanup failure. Unchanged mock-export/import-boundary, nested-runner resolution and duplicate-code failures are separately qualified. The SQLite verifier carries no heap flags, so the added reset effect is not executed there; its baseline replay passes, without claiming that a passing replay fixes the intermittent terminal-status failure. Scoped proof and full build pass on the candidate. Native merge admission could not settle its mergeability projection despite REST reporting the exact head mergeable. The authorized head-pinned REST fallback is used with the inherited-failure evidence retained by the maintainer. Low-priority follow-ups from review: the diagnostic V8 exit-on-contradictory-flags mode is not handled by the current guard, and the warning can name the blocking flag and recovery action more explicitly. No security, user-data-loss or money-risk finding was identified. Co-authored-by: Luke <[email protected]> Co-authored-by: xydigitLybnnnn <[email protected]>
|
Thanks @xydigitLybnnnn for tracing the managed-service heap flag to V8's process-wide override and for the before/after worker measurements. That diagnosis informed the final fix in #166581, which preserves the Gateway's configured main-isolate heap while restoring per-worker limits for argv and environment flags, including total-heap and percentage controls. Your contribution is included in the final Co-authored-by credit alongside @valkyriweb. Closing this competing implementation in favor of the landed fix. Thank you! |
β¦166581) ## Problem A process-wide Node heap flag overrides `Worker.resourceLimits`, allowing catalog and storage workers to inherit the Gateway's much larger heap budget. Clearing a worker's argv or environment cannot fix V8's process-wide precedence. Removing the Gateway's heap budget would reduce main-isolate capacity and leave operator-supplied flags unfixed. ## Change Clear V8's old-space and total-heap overrides after the main isolate initializes, at the shared worker construction owner. The main isolate keeps its configured budget; new workers use their resource limits. This covers CLI, direct service and library entrypoints without changing early CLI recovery. Explicit V8 flag-freezing/abort-on-contradictory modes preserve their existing behavior and warn rather than aborting natively. No new configuration or raised catalog budget. Thanks to @valkyriweb for the V8 reset mechanism and @xydigitLybnnnn for the managed-service diagnosis and comparative measurements. Fixes openclaw#157575. Fixes openclaw#157630. Supersedes openclaw#158201. ## Size and validation - Six changed files; +1 production TypeScript line under the source-directory filter, +18 runtime lines including the packaged JavaScript helper. No changelog changes. - Secretless AWS, Node 24.21.0 and 26.11.1: argv, NODE_OPTIONS, underscore, total-heap and percentage flags preserve the main ceiling and restore a 128 MiB worker budget (224/176 MiB total V8 ceiling instead of 1120/1072 MiB). These are heap ceilings, not RSS measurements. - Final head: heap regression 7/7 (5.79 s wall), launcher 130 passed / 2 platform skips (344.49 s cold, including the runtime build), worker lifecycle 6/6 (33.43 s), extracted wrapper 17/17 (25.97 s). - Final type-aware lint, formatting, export-name collision guard, core types, SDK surface and full build pass (283.23 s). Every candidate Knip finding was independently reproduced on clean main be77efa. - Independent correctness review and diff cleanup completed. The runtime and packaging regressions found during validation were repaired and retested. ## Inherited CI disposition Broad CI remains red and is not represented as green. The exact untouched-main Node 24.19 replay reproduces node/paired-worker terminal failures and the steering acceptance/cleanup failure. Unchanged mock-export/import-boundary, nested-runner resolution and duplicate-code failures are separately qualified. The SQLite verifier carries no heap flags, so the added reset effect is not executed there; its baseline replay passes, without claiming that a passing replay fixes the intermittent terminal-status failure. Scoped proof and full build pass on the candidate. Native merge admission could not settle its mergeability projection despite REST reporting the exact head mergeable. The authorized head-pinned REST fallback is used with the inherited-failure evidence retained by the maintainer. Low-priority follow-ups from review: the diagnostic V8 exit-on-contradictory-flags mode is not handled by the current guard, and the warning can name the blocking flag and recovery action more explicitly. No security, user-data-loss or money-risk finding was identified. Co-authored-by: Luke <[email protected]> Co-authored-by: xydigitLybnnnn <[email protected]>
## Problem A process-wide Node heap flag overrides `Worker.resourceLimits`, allowing catalog and storage workers to inherit the Gateway's much larger heap budget. Clearing a worker's argv or environment cannot fix V8's process-wide precedence. Removing the Gateway's heap budget would reduce main-isolate capacity and leave operator-supplied flags unfixed. ## Change Clear V8's old-space and total-heap overrides after the main isolate initializes, at the shared worker construction owner. The main isolate keeps its configured budget; new workers use their resource limits. This covers CLI, direct service and library entrypoints without changing early CLI recovery. Explicit V8 flag-freezing/abort-on-contradictory modes preserve their existing behavior and warn rather than aborting natively. No new configuration or raised catalog budget. Thanks to @valkyriweb for the V8 reset mechanism and @xydigitLybnnnn for the managed-service diagnosis and comparative measurements. Fixes #157575. Fixes #157630. Supersedes #158201. ## Size and validation - Six changed files; +1 production TypeScript line under the source-directory filter, +18 runtime lines including the packaged JavaScript helper. No changelog changes. - Secretless AWS, Node 24.21.0 and 26.11.1: argv, NODE_OPTIONS, underscore, total-heap and percentage flags preserve the main ceiling and restore a 128 MiB worker budget (224/176 MiB total V8 ceiling instead of 1120/1072 MiB). These are heap ceilings, not RSS measurements. - Final head: heap regression 7/7 (5.79 s wall), launcher 130 passed / 2 platform skips (344.49 s cold, including the runtime build), worker lifecycle 6/6 (33.43 s), extracted wrapper 17/17 (25.97 s). - Final type-aware lint, formatting, export-name collision guard, core types, SDK surface and full build pass (283.23 s). Every candidate Knip finding was independently reproduced on clean main 6e06137. - Independent correctness review and diff cleanup completed. The runtime and packaging regressions found during validation were repaired and retested. ## Inherited CI disposition Broad CI remains red and is not represented as green. The exact untouched-main Node 24.19 replay reproduces node/paired-worker terminal failures and the steering acceptance/cleanup failure. Unchanged mock-export/import-boundary, nested-runner resolution and duplicate-code failures are separately qualified. The SQLite verifier carries no heap flags, so the added reset effect is not executed there; its baseline replay passes, without claiming that a passing replay fixes the intermittent terminal-status failure. Scoped proof and full build pass on the candidate. Native merge admission could not settle its mergeability projection despite REST reporting the exact head mergeable. The authorized head-pinned REST fallback is used with the inherited-failure evidence retained by the maintainer. Low-priority follow-ups from review: the diagnostic V8 exit-on-contradictory-flags mode is not handled by the current guard, and the warning can name the blocking flag and recovery action more explicitly. No security, user-data-loss or money-risk finding was identified. Co-authored-by: Luke <[email protected]> Co-authored-by: xydigitLybnnnn <[email protected]> (cherry picked from commit 5ed6a30) Adapted for 2026.9.x: docs and wrapper-component list resolved against the 9.x text; registered the helper with check-duplicates and the test as Node-required in ci-test-runtime.
What Problem This Solves
Issue #157575: [Bug]: Managed Gateway heap flag overrides per-worker old-space limits
Bug type
Behavior bug (incorrect output/state without crash)
Beta release blocker
No
Summary
The managed Gateway's automatic Node heap flag overrides the smaller old-generation limits requested by its workers, so the intended per-worker memory budgets are not enforced under the generated service command.
Steps to reproduce
--max-old-space-size=8192, and the running LaunchAgent includes that flag. The model-catalog worker requestsresourceLimits.maxOldGenerationSizeMb: 512.worker-budget.cjs. It uses only Node built-ins and does not start OpenClaw or allocate a large heap:Why This Change Was Made
Root cause. The managed Node Gateway auto-sizes its main V8 old-generation heap by
injecting
--max-old-space-size=<N>into the service program arguments(
src/daemon/gateway-heap.ts:139resolveGatewayHeapExecArgv, spliced into the command atsrc/daemon/program-args.ts:201). V8 applies that flag process-wide, so everyworker_threads.Workerisolate created afterwards inherits the raised ceiling. Nodedocuments that the process CLI flag overrides
resourceLimits.maxOldGenerationSizeMb, so theper-worker budgets OpenClaw declares are silently ineffective:
CATALOG_WORKER_HEAP_LIMIT_MB = 512atsrc/agents/prepared-model-catalog-worker.ts:120,applied at
src/agents/prepared-model-catalog-worker.ts:162.resourceLimits: { maxOldGenerationSizeMb: 512 }(
src/config/sessions/session-accessor.sqlite-archive.ts:42,src/infra/sqlite-worker-broker-lifecycle.ts:52,src/state/openclaw-state-read-worker.ts:78,src/config/sessions/session-transcript-worker-resources.ts:54, and others).code-mode-node.ts:121-123computes a per-worker limit the same way.The automatic flag is deliberately placed in service argv instead of
NODE_OPTIONSso thatspawned Node child processes do not inherit it (
src/daemon/program-args.ts:198-202,src/daemon/program-args.test.ts:86-123). That intent holds for child processes but not forworker threads, which are additional V8 isolates in the same process.
User Impact
See the linked issue for the reported before/after behavior; this change is limited to the paths shown in the PR diff.
Evidence
Real behavior proof through the product entry point, before and after this change.
Every command below was executed in the reproduction container (see Environment).
After fix β the same entry point runs to completion:
Before fix β reproduction of the reported failure:
Environment (reproduction container):
What was not tested:
Artifacts:
/media/vdb/AutoDigit/workspace/logs/reproduction/issue-157575-evidence/media/vdb/AutoDigit/workspace/logs/reproduction/issue-157575-analysis.log/media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-evidence/media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-evidence/terminal-output.txt/media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-fix.log/media/vdb/AutoDigit/workspace/logs/reproduction/container-tools.txtLocal validation commands:
Linked context
Closes #157575
Tests and validation
Commands run (local CI equivalent checks):
Local CI equivalent check report:
Risk checklist
Current review state
π€ AI Participation Disclosure
π€ AI-assisted: This PR was developed with AI assistance (opencode + auto_fix_bot).
Development Process
Problem Reproduction (Human-led)
Solution Generation (AI-led, Human-decided)
/media/vdb/AutoDigit/workspace/logs/opencode/issue-157575-solutions.mdImplementation (AI-led)
Validation (Human-led)
Role Breakdown
Human contributions:
AI contributions:
Rollback Plan
Risk Level: Low
Rollback command:
Observable failure symptoms:
Appendix: Evidence Directories
/media/vdb/AutoDigit/workspace/logs/reproduction/issue-157575-evidence/media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-evidence/media/vdb/AutoDigit/workspace/logs/reproduction/issue-157575-analysis.log/media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-fix.log/media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-evidence/terminal-output.txt/media/vdb/AutoDigit/workspace/logs/opencode/issue-157575-solutions.mdCloses #157575.