Skip to content

fix(daemon): pin Node heap ceiling via CLI flag for managed services - #97334

Closed
CCcassiusdjs wants to merge 1 commit into
openclaw:mainfrom
CCcassiusdjs:fix/daemon-service-heap-96203
Closed

CCcassiusdjs wants to merge 1 commit into
openclaw:mainfrom
CCcassiusdjs:fix/daemon-service-heap-96203

Conversation

@CCcassiusdjs

Copy link
Copy Markdown
Contributor

Closes #96203

Relationship to #96250: that open PR fixes the same issue by setting
NODE_OPTIONS=--max-old-space-size in the service environment. NODE_OPTIONS
is a host-env-security blockedEverywhere key, and the builder output is not
run through that filter, so the value leaks into the generated plist unfiltered
— the exact key the policy says must never be a managed env var. This PR takes
the alternative shape requested in the issue title ("set NODE_OPTIONS or ...")
by pinning the heap as a Node CLI argument instead, which sidesteps the policy.
Offered as a security-aligned alternative; happy to fold the approach into #96250
if maintainers prefer.

What Problem This Solves

Fixes an issue where operators running the managed gateway under sustained load
experience repeated OOM crash-loops. openclaw daemon install generated launchd/systemd launch commands
that started the gateway under Node's default V8 old-space ceiling
(~min(host RAM/2, 4 GB)). Under sustained multi-agent load with accumulated
cron/journal state, the heap overshoots that ceiling and the gateway OOM
crash-loops (reported: 2314 restarts in one day), blocking all workflow
processing.

Why This Change Was Made

The naive fix — setting NODE_OPTIONS=--max-old-space-size=... in the service
environment — is wrong here: NODE_OPTIONS is on the host-env-security
blockedEverywhere key list (src/infra/host-env-security-policy.json). The
builder output is not run through that filter and renderEnvDict does not strip
it, so the value would leak into the generated plist — exactly the key the
security policy says must never be a managed env var.

Instead, this pins --max-old-space-size=8192 as a Node CLI argument in the
launch command (resolveCliProgramArguments in src/daemon/program-args.ts),
which feeds both launchd ProgramArguments and systemd ExecStart. This
sidesteps the env-key policy entirely. The flag is injected only for the Node
runtime; bun uses its own allocator and ignores the V8 flag, and an operator
OPENCLAW_WRAPPER owns its own runtime flags.

User Impact

Managed gateway/node services get a stable heap ceiling out of the box. The
ceiling is a cap, not an allocation — steady-state RSS is unaffected (reported
~700 MB). No new config/env surface added. Bun and wrapper installs are
unchanged.

Evidence

  • TDD: new node-runtime tests failed for the right reason (missing flag), pass
    after the fix; bun/wrapper negative tests stay green.
  • Artifact-level proof: a test renders the real buildSystemdUnit and
    buildLaunchAgentPlist from the real builder output and asserts
    --max-old-space-size=8192 appears in the systemd ExecStart and the launchd
    plist ProgramArguments.
  • program-args.test.ts: 13/13. Consumer suites (launchd, systemd, service,
    daemon-install-helpers, node-daemon-install-helpers, doctor-gateway-daemon-flow,
    configure.daemon, service-audit, inspect, schtasks): 397 passed, 0 failed.
  • oxlint clean; tsgo:core and tsgo:core:test clean.

Proof boundary

Verified at the rendered-artifact level (unit/plist text), not live on a
running macOS launchd daemon. Demonstration branch.

openclaw daemon install generated launchd/systemd commands that launched
the gateway under Node's default old-space ceiling (~min(host RAM/2, 4 GB)).
Under sustained multi-agent load with accumulated cron/journal state the heap
overshoots that ceiling and the gateway OOM crash-loops (reported: 2314
restarts/day), blocking all workflow processing.

Inject --max-old-space-size=8192 as a Node CLI argument in the launch command
(launchd ProgramArguments / systemd ExecStart), not via NODE_OPTIONS: that env
key is on the host-env-security blocked-everywhere list, so setting it would be
stripped/insecure. The flag is added only for the Node runtime; bun uses its own
allocator and an operator wrapper owns its runtime flags.

Fixes #96203
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Jun 28, 2026
@clawsweeper

clawsweeper Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep this PR open but not merge-ready: the CLI-flag approach avoids the blocked NODE_OPTIONS env key, but it shifts managed Node argv without updating an existing service start-repair invariant, and the external PR only provides mocked/rendered-artifact proof.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #96203
Summary: This PR is one candidate fix for the open managed Gateway heap crash-loop issue; #96250 is a competing same-root-cause implementation with a different service-env shape.

Members:

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

Canonical path: Close this PR as superseded by #96250.

So I’m closing this here and keeping the remaining discussion on #96250.

Review details

Best possible solution:

Close this PR as superseded by #96250.

Do we have a high-confidence way to reproduce the issue?

No for the full 30-agent OOM crash loop in this read-only review; the linked issue has strong live evidence and source inspection confirms current main lacks a managed heap flag. The PR-introduced repair regression is source-reproducible from the new argv shape and the existing programArguments.slice(0, 2) check.

Is this the best way to solve the issue?

No, not yet. The CLI-arg approach is a promising security-aligned mitigation, but the best fix must also update downstream argv consumers and include real daemon install proof.

Security review:

Security review cleared: Cleared: the diff adds no dependencies, permissions, or secret handling, and the CLI-flag shape avoids generating the blocked NODE_OPTIONS env key.

AGENTS.md: found and applied where relevant.

What I checked:

  • linked superseding PR: fix(daemon): prevent gateway OOM crash loops under sustained load #96250 ([AI] fix(daemon): set default NODE_OPTIONS --max-old-space-size in gateway service env) is still open as the canonical replacement.
  • cluster evidence: the durable review links that PR in the work cluster or recommended risk path.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • joshavant: Current blame attributes both collectGatewayServiceStartRepairIssues and the current resolveCliProgramArguments body to the recent commit that carried these daemon paths into current main. (role: recent area contributor; confidence: high; commits: cee2aca40912; files: src/daemon/service.ts, src/daemon/program-args.ts)
  • steipete: History search for resolveCliProgramArguments points to the earlier exec-host/node-daemon feature commit that added the node daemon install path and daemon program-argument construction. (role: original node daemon contributor; confidence: medium; commits: ae0b4c49903d; files: src/daemon/program-args.ts, src/commands/node-daemon-install-helpers.ts)

Codex review notes: model internal, reasoning high; reviewed against 3630d502eb9b.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6973a25149

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const cliEntrypointPath = await resolveCliEntrypointPathForService();
return {
programArguments: [nodePath, cliEntrypointPath, ...params.args],
programArguments: [nodePath, NODE_SERVICE_HEAP_FLAG, cliEntrypointPath, ...params.args],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update service-command parsers for inserted Node flags

When gateway install now writes [node, --max-old-space-size=8192, entrypoint, gateway], consumers still assume the old [node, entrypoint, gateway] shape: resolveManagedServiceNodeRunner reads args[gatewayIndex - 2] in src/cli/update-cli/update-command.ts:1496-1501, so openclaw update no longer detects/uses the service Node, and collectGatewayServiceStartRepairIssues checks only programArguments.slice(0, 2) in src/daemon/service.ts:155, so missing entrypoints at index 2 are no longer caught. This affects newly installed Node services during updates or restart repair; please teach those parsers to skip Node flags or share a normalized service-command parser before changing the generated command shape.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 28, 2026
@clawsweeper

clawsweeper Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

  • Action: closed this PR.
  • Close reason: duplicate or superseded.
  • Evidence: durable ClawSweeper review.
  • Coverage proof: PR B clearly carries PR A's core useful intent: a default managed-service Node heap ceiling for the same OOM crash-loop, using a different implementation shape. PR A's CLI-flag-specific details and review concerns are either incidental to its alternative implementation or can be reviewed as part of the canonical PR B approach. Covering PR: fix(daemon): prevent gateway OOM crash loops under sustained load #96250.

@clawsweeper clawsweeper Bot closed this Jun 28, 2026
@CCcassiusdjs

Copy link
Copy Markdown
Contributor Author

Thanks for the review — the start-repair point was correct and I've fixed it.

Regression you flagged: collectGatewayServiceStartRepairIssues validated programArguments.slice(0, 2), which assumes the entrypoint script is at index 1. The heap flag shifts it to index 2, so the entrypoint stopped being checked for missing/temp paths (the heap flag itself is harmless there — isMissingProgramPath/isTemporaryProgramPath early-return on non-absolute values).

Fix (new commit f1e049c): validate the first two non-flag tokens (executable + entrypoint) instead of fixed indices — restores entrypoint validation and is robust to interleaved Node flags. Wrapper installs (no flag) are unchanged. Added a regression test that fails on the old slice(0, 2) and passes now.

On the remaining points:

  • Existing installs: the new argv only applies on (re)install; already-installed services keep their old command until openclaw doctor/reinstall, same as any program-args change. Happy to add a doctor migration if you want existing services refreshed.
  • Live proof: still artifact-level only (systemd ExecStart + launchd ProgramArguments rendered text asserted) — I don't have a macOS launchd host to run the full daemon repro.

Still offered as the security-aligned alternative to #96250 (CLI flag vs the blockedEverywhere NODE_OPTIONS env key); glad to fold this into #96250 if that's the preferred path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway crash-loops with default Node heap (~4 GB) — make 'openclaw daemon install' set NODE_OPTIONS or accept a --heap-mb flag

1 participant