Skip to content

fix: resolve issue #157575 β€” [Bug]: Managed Gateway heap flag overrides per-worker old-space limits - #158201

Closed
xydigitLybnnnn wants to merge 4 commits into
openclaw:mainfrom
xydigitLybnnnn:fix/157575-bug-managed-gateway-heap-flag-
Closed

xydigitLybnnnn wants to merge 4 commits into
openclaw:mainfrom
xydigitLybnnnn:fix/157575-bug-managed-gateway-heap-flag-

Conversation

@xydigitLybnnnn

Copy link
Copy Markdown
Contributor

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

  1. Inspect the managed Node Gateway command and the worker options in 2026.9.6. On this 24 GiB machine, the built-in service policy selects --max-old-space-size=8192, and the running LaunchAgent includes that flag. The model-catalog worker requests resourceLimits.maxOldGenerationSizeMb: 512.
  2. Save this standalone probe as worker-budget.cjs. It uses only Node built-ins and does not start OpenClaw or allocate a large heap:
const { Worker } = require("node:worker_threads");
const worker = new Worker(`

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:139 resolveGatewayHeapExecArgv, spliced into the command at
src/daemon/program-args.ts:201). V8 applies that flag process-wide, so every
worker_threads.Worker isolate created afterwards inherits the raised ceiling. Node
documents that the process CLI flag overrides resourceLimits.maxOldGenerationSizeMb, so the
per-worker budgets OpenClaw declares are silently ineffective:

  • CATALOG_WORKER_HEAP_LIMIT_MB = 512 at src/agents/prepared-model-catalog-worker.ts:120,
    applied at src/agents/prepared-model-catalog-worker.ts:162.
  • SQLite / transcript / state workers with 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-123 computes a per-worker limit the same way.
    The automatic flag is deliberately placed in service argv instead of NODE_OPTIONS so that
    spawned 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 for
    worker 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:

# Executed INSIDE container openclaw-repro (image openclaw-repro:toolchain)
#   canonical form: docker exec -u $(id -u):$(id -g) -e HOME=/tmp/openclaw-repro-home -w /workspace/repo openclaw-repro bash -lc '<command>'
# Repository: /workspace/repo (branch fix/157575-bug-managed-gateway-heap-flag-, HEAD dd7b3279d92)
# HOME=/tmp/openclaw-repro-home. User uid:gid 1001:1001. Node v24.21.0, Ubuntu 22.04.5, Linux x86_64.
#
# Post-fix verification for issue #157575
# [Bug]: Managed Gateway heap flag overrides per-worker old-space limits
$ node /workspace/bot/logs/real_behavior/issue-157575-evidence/verify-after.mjs
{
  "node": "v24.21.0",
  "platform": "linux/x64",
  "managedServiceProgramArguments": [
    "/usr/bin/node",
    "/workspace/repo/dist/index.js",
    "gateway",
    "--port",
    "18789"
  ],
  "resolvedNativeFlags": [],
  "ownerResolveGatewayHeapExecArgv": [],
  "ownerResolveGatewayHeapExecArgvWithStoredCommand": [],
  "catalogWorkerDeclaredOldSpaceMiB": 512,
  "issueHostRecommendationMiB": 8192
}
{
  "AFTER_managed_flags": {
    "processHeapFlag": null,
    "mainHeapMiB": 4288,
    "workerDeclaredOldSpaceMiB": 512,
    "effectiveWorkerHeapCeilingMiB": 704,

Before fix β€” reproduction of the reported failure:

### repository revision under test
$ docker exec -u 1001:1001 -e HOME=/tmp/openclaw-repro-home -w /workspace/repo openclaw-repro bash -lc 'git rev-parse HEAD; git status -sb'
168d454d32c853072d23ad83ffdc8f522d491d03
## main...upstream/main
exit=0
### environment
$ docker exec -u 1001:1001 -e HOME=/tmp/openclaw-repro-home -w /workspace/repo openclaw-repro bash -lc 'node --version; uname -srm; grep PRETTY_NAME /etc/os-release; grep MemTotal /proc/meminfo'
v24.21.0
Linux 5.10.134-14.zncgsl6.x86_64 x86_64
PRETTY_NAME="Ubuntu 22.04.5 LTS"
MemTotal:       32688968 kB
exit=0
### owner of the managed-service flag inserts it into the service command
$ docker exec -u 1001:1001 -e HOME=/tmp/openclaw-repro-home -w /workspace/repo openclaw-repro bash -lc 'grep -n resolveGatewayHeapExecArgv src/daemon/program-args.ts'
14:import { resolveGatewayHeapExecArgv } from "./gateway-heap.js";
201:    result.programArguments.splice(1, 0, ...resolveGatewayHeapExecArgv(params.existingCommand));
exit=0
======================================================================
# Real OpenClaw worker entrypoint: declared 512 MiB old-space budget
======================================================================
### real worker <no process heap flag>
$ docker exec -u 1001:1001 -e HOME=/tmp/openclaw-repro-home -w /workspace/repo openclaw-repro bash -lc 'node  /workspace/bot/logs/reproduction/issue-157575-evidence/probe-worker-heap.mjs'
{"node":"v24.21.0","platform":"linux/x64","processExecArgv":[],"processHeapFlag":null,"managedServiceRecommendationMiB_issueHost24GiB":8192,"managedServiceRecommendationMiB_actualHost":8192,"actualHostCapacityMiB":16384,"workerDeclaredOldSpaceMiB":512,"workerReportedOldSpaceMiB":512,"effectiveWorkerHeapCeilingMiB":704,"workerHeapUsedMiB":6.79,"perWorkerBudgetEnforced":true}
exit=0
### real worker --max-old-space-size=8192
$ docker exec -u 1001:1001 -e HOME=/tmp/openclaw-repro-home -w /workspace/repo openclaw-repro bash -lc 'node --max-old-space-size=8192 /workspace/bot/logs/reproduction/issue-157575-evidence/probe-worker-heap.mjs'
{"node":"v24.21.0","platform":"linux/x64","processExecArgv":["--max-old-space-size=8192"],"processHeapFlag":"--max-old-space-size=8192","managedServiceRecommendationMiB_issueHost24GiB":8192,"managedServiceRecommendationMiB_actualHost":8192,"actualHostCapacityMiB":16384,"workerDeclaredOldSpaceMiB":512,"workerReportedOldSpaceMiB":512,"effectiveWorkerHeapCeilingMiB":8384,"workerHeapUsedMiB":6.81,"perWorkerBudgetEnforced":false}
exit=0
### real worker --max-old-space-size=4096
$ docker exec -u 1001:1001 -e HOME=/tmp/openclaw-repro-home -w /workspace/repo openclaw-repro bash -lc 'node --max-old-space-size=4096 /workspace/bot/logs/reproduction/issue-157575-evidence/probe-worker-heap.mjs'

Environment (reproduction container):

=== Reproduction container tool check ===
time: 2026-09-25T22:42:48+08:00
container: openclaw-repro (image openclaw-repro:toolchain)
container data dir: /media/vdb/AutoDigit/workspace/container
docker data-root: /media/vdb/AutoDigit/workspace/container/docker
toolchain: provisioned inside the container (/tmp/openclaw-repro-home); host tools are not used
workdir: /workspace/repo
run user: 1001:1001 (matches host uid to avoid root-owned files on mounted volumes)
--- required tools ---
OK   git
OK   curl
OK   tar
OK   gzip
OK   xz
OK   jq
OK   python3
OK   make
OK   gcc
OK   pkg-config
--- UI/desktop reproduction tools ---
OK   xvfb-run
OK   dbus-run-session
OK   import
OK   identify
OK   xdotool
--- runtime versions (inside the container) ---
node:   v24.21.0
pnpm:   12.4.2
cargo:  cargo 1.98.1 (797e8a9bc 2026-08-05)
python: Python 3.10.12

What was not tested:

Artifacts:

  • Reproduction evidence directory: /media/vdb/AutoDigit/workspace/logs/reproduction/issue-157575-evidence
  • Reproduction log: /media/vdb/AutoDigit/workspace/logs/reproduction/issue-157575-analysis.log
  • Post-fix evidence directory: /media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-evidence
  • Post-fix terminal capture: /media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-evidence/terminal-output.txt
  • Fix verification log: /media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-fix.log
  • Container tool self-check: /media/vdb/AutoDigit/workspace/logs/reproduction/container-tools.txt

Local validation commands:

# CI install gate: verify pnpm-lock.yaml matches package.json
pnpm install --frozen-lockfile

# Build and typecheck
pnpm build

# Code quality checks (lint, format, typecheck) - incremental: changed scope only
pnpm check:changed

# Run tests - incremental: only shards for changed files (TEST_MODE=full runs the full pnpm test)
pnpm test:changed

# Specific test for this fix (if applicable)
node scripts/run-vitest.mjs <relevant-test-file>

# Git diff check
git diff --check origin/main...HEAD

Linked context

Closes #157575

Tests and validation

Commands run (local CI equivalent checks):

# 1. pnpm install --frozen-lockfile (CI install gate)
# 2. pnpm build
# 3. pnpm oxfmt --check
# 4. pnpm oxlint
# 5. pnpm tsgo:core && pnpm tsgo:test
# 6. pnpm vitest run --config test/vitest/vitest.unit.config.ts --changed origin/main
# 7. pnpm knip (dead code detection)
# ... see full CI report for all 20 checks

Local CI equivalent check report:

  βœ… lockfile_sync: passed
  ⏭️ build: skipped
  βœ… shrinkwrap: passed
  ⏭️ quality_check: skipped
  ⏭️ test: skipped
  βœ… loc_ratchet: passed
  ⏭️ tsgo_core: skipped
  ⏭️ tsgo_test: skipped
  ⏭️ lint: skipped
  ⏭️ format_check: skipped
  ⏭️ no_conflict_markers: skipped
  ⏭️ host_env_policy_swift: skipped
  βœ… duplicates_coverage: passed
  ⏭️ import_cycles: skipped
  ⏭️ bundled_channel_config: skipped
  ⏭️ deadcode_dependencies: skipped
  ⏭️ deadcode_unused_files: skipped
  ⏭️ deps_patches: skipped
  ⏭️ vitest_unit_tests: skipped
  βœ… ci_gate: passed
  ⏭️ check_changed_full: skipped

Risk checklist

  • Did user-visible behavior change? No β€” no UI/front-end paths changed
  • Did config, environment, or migration behavior change? Yes β€” environment/config path changed: docs/cli/gateway/service.md docs/gateway/diagnostics.md docs/gateway/troubleshooting/gateway-service-and-process.md docs/plugins/architecture.md src/cli/daemon-cli/install.integration.test.ts src/daemon/gateway-heap.test.ts src/daemon/gateway-heap.ts src/daemon/program-args.test.ts src/daemon/program-args.ts
  • Did security, auth, secrets, network, or tool execution behavior change? No β€” no auth/secret/security paths changed
  • What is the highest-risk area? docs/cli docs/gateway docs/plugins
  • How is that risk mitigated? Covered by the automated checks listed below
  • What was not tested? All targeted checks above ran; see the evidence section for real-run coverage.

Current review state

  • Next action: Review and merge
  • What is still waiting on author, maintainer, CI, or external proof? CI verification and real-behavior proof
  • Which bot or reviewer comments were addressed? N/A

πŸ€– AI Participation Disclosure

πŸ€– AI-assisted: This PR was developed with AI assistance (opencode + auto_fix_bot).

Development Process

  1. Problem Reproduction (Human-led)

    • βœ… Human verified the issue exists in local environment
    • βœ… Human collected reproduction evidence (logs, screenshots, terminal outputs)
    • AI analyzed reproduction steps and documented the process
  2. Solution Generation (AI-led, Human-decided)

    • AI analyzed codebase and issue context
    • AI generated 3 solution options with detailed analysis (pros/cons, risk, effort)
    • βœ… Human reviewed all options and selected the preferred approach
    • Solution analysis saved to: /media/vdb/AutoDigit/workspace/logs/opencode/issue-157575-solutions.md
  3. Implementation (AI-led)

    • AI implemented the selected solution
    • AI wrote/updated tests
    • AI generated initial documentation
  4. Validation (Human-led)

    • βœ… Human re-ran reproduction steps to verify the fix
    • βœ… Human collected post-fix evidence
    • βœ… Human compared before/after behavior

Role Breakdown

Human contributions:

  • Verified problem reproduction in real environment
  • Selected solution from AI-generated options (critical decision)
  • Ran real environment verification after fix
  • Collected and reviewed all evidence
  • Made final decision to submit PR

AI contributions:

  • πŸ€– Analyzed issue description and codebase
  • πŸ€– Generated multiple solution options with pros/cons
  • πŸ€– Implemented the selected fix (code changes)
  • πŸ€– Generated tests and documentation draft
  • πŸ€– Ran automated checks

Rollback Plan

Risk Level: Low

Rollback command:

git revert HEAD

Observable failure symptoms:

  • Test failures in CI
  • Recurrence of original issue behavior
  • Runtime errors (if applicable)

Appendix: Evidence Directories

  • Reproduction evidence: /media/vdb/AutoDigit/workspace/logs/reproduction/issue-157575-evidence
  • Post-fix evidence: /media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-evidence
  • Reproduction log: /media/vdb/AutoDigit/workspace/logs/reproduction/issue-157575-analysis.log
  • Fix log: /media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-fix.log
  • Post-fix real-run capture: /media/vdb/AutoDigit/workspace/logs/real_behavior/issue-157575-evidence/terminal-output.txt
  • Solution analysis: /media/vdb/AutoDigit/workspace/logs/opencode/issue-157575-solutions.md

Closes #157575.

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
@clawsweeper

clawsweeper Bot commented Sep 25, 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 docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: S labels Sep 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

The 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

  • Before: The generated --max-old-space-size=8192 flag raises a worker’s effective heap ceiling despite its requested 512 MiB budget.
  • After: The command omits that flag, and the supplied Node 24.21.0 probe measures a 704 MiB worker heap ceiling.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful runtime evidence supports the fresh-command change, but the partial fix and unresolved default policy limit confidence.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (terminal): The supplied Linux Node 24.21.0 after-fix output links the changed managed-command owner to omitted native flags and a measured 704 MiB worker ceiling for a 512 MiB request, supporting the fresh-command effect. Existing stored service definitions remain a compatibility gap: no published-service upgrade demonstrates resolving their generated flag while preserving intentional controls.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix Β· Worth it: Needs a maintainer decision Β· Fix scope: Partial
User problem: Workers can consume far more memory than their advertised budgets under a managed Gateway’s automatically generated heap setting.
Reason: Effective worker containment is valuable, but this implementation reaches fresh commands and changes the established main-heap default without owner approval.

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
Reviewed head: f518b5393f77c0dcda11a4edea3f41cee16ac99e
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should managed Node services abandon automatic main-heap sizing, or should this repair preserve main capacity while making worker budgets effective?
  • Recommendation: Preserve main capacity: Require a verified policy that keeps appropriate main-heap capacity and effective worker budgets for fresh and existing services without guessing operator intent.
  • Why: Automatic sizing was introduced for observed sustained-load crash loops, and current discussion reports main-isolate workloads near Node’s default ceiling; no recorded owner decision accepts this default change.

Before merge

  • Handle flags generated by existing managed services (P1) - For a published managed service containing node --max-old-space-size=8192 … gateway, install and Doctor pass the stored command into this function, which returns the same flag. Regeneration therefore continues overriding the worker’s requested 512 MiB budget. This is the previously raised, still-unfixed case, not a new discovery. Complete the existing-service path without treating matching numeric defaults as proof of automatic provenance, or explicitly obtain approval to limit this repair to fresh services.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P1] Handle flags generated by existing managed services β€” src/daemon/gateway-heap.ts:146-149

Tests

  • Missing end-to-end proof: An installed-service upgrade from a published definition and a representative Gateway workload under the default main heap remain unshown; base/head tests were not executed in this read-only review.
Agent review details

How this fits together

Managed 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]
Loading

Technical review

Best 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:

  • [P1] Handle flags generated by existing managed services β€” src/daemon/gateway-heap.ts:146-149
    For a published managed service containing node --max-old-space-size=8192 … gateway, install and Doctor pass the stored command into this function, which returns the same flag. Regeneration therefore continues overriding the worker’s requested 512 MiB budget. This is the previously raised, still-unfixed case, not a new discovery. Complete the existing-service path without treating matching numeric defaults as proof of automatic provenance, or explicitly obtain approval to limit this repair to fresh services.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b0c330d27df4.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 3fb0ba1 adds src/daemon/gateway-heap.ts:135 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3fb0ba15e982; files: src/daemon/gateway-heap.ts)

PR surface

Source -4, Tests +51, Docs +4. Total +51 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 13 17 -4
Tests 2 61 10 +51
Docs 4 17 13 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 91 40 +51

Review metrics

Metric Value Why it matters
Managed Node heap default Capacity-based sizing becomes Node’s native default This changes the main-isolate capacity contract independently of the worker-budget improvement.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #157575
Summary: This PR is a partial candidate fix for the canonical managed-heap and worker-budget conflict.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded managed-service policy repair with concrete operational value and unresolved owner direction.
  • merge-risk: 🚨 compatibility: The branch changes fresh-service heap defaults while installed services retain previously generated controls.
  • merge-risk: 🚨 availability: Removing automatic main-heap sizing may constrain workloads for which adaptive sizing previously prevented crash loops.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-25T16:24:23.254Z sha dd7b327 :: blocked before merge. :: [P1] Cover existing generated service flags before claiming the fix
  • reviewed 2026-09-25T23:01:36.730Z sha 1f32b54 :: blocked before merge. :: [P1] Handle flags generated by existing managed services

Reviewed October 8, 2026, 10:12 PM ET / October 9, 2026, 02:12 UTC (Revision 3).

@pestelence2k

Copy link
Copy Markdown

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):

  • With the managed Gateway running --max-old-space-size=8192 and the catalog worker declaring a 512 MiB old-generation limit, process RSS rose from approximately 6.32 to 10.87 GiB over 165 minutes. prepared-model-catalog.worker.js heapUsed rose from 3.40 to 6.99 GiB; the main isolate was much smaller near the peak. Repeated critical-memory diagnostics were logged.
  • After removing the process flag and restarting, an initial ten-second sample showed approximately 2.72 GiB process RSS and 19% CPU. This was short-term containment, not proof of repaired retention or long-term stability; the restart itself also resets accumulated memory.

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
@openclaw-barnacle openclaw-barnacle Bot removed the cli CLI command changes label Oct 9, 2026
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.
steipete pushed a commit that referenced this pull request Oct 11, 2026
## 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]>
@steipete

Copy link
Copy Markdown
Contributor

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!

@steipete steipete closed this Oct 11, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…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]>
RomneyDa pushed a commit that referenced this pull request Oct 26, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Managed Gateway heap flag overrides per-worker old-space limits

3 participants