Skip to content

fix(daemon): prevent gateway OOM crash loops under sustained load - #96250

Merged
steipete merged 3 commits into
openclaw:mainfrom
xydt-tanshanshan:fix/gateway-daemon-heap-96203
Jul 17, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
xydt-tanshanshan:fix/gateway-daemon-heap-96203

Conversation

@xydt-tanshanshan

@xydt-tanshanshan xydt-tanshanshan commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #96203

What Problem This Solves

Fixes an issue where a managed Gateway under sustained multi-agent load could exhaust Node's old-space heap, enter a rapid crash loop, and block agent workflows. The incident in #96203 reproduced this with roughly 30 agents and more than 2,000 restarts in one day; an explicit heap limit stopped the loop.

Why This Change Was Made

Managed Gateway installs now derive a heap-only NODE_OPTIONS value from the smaller of Node's constrained-memory result and physical RAM. The adaptive default targets 50% of available memory, uses a 2048 MiB floor when native headroom allows, keeps 25% headroom on smaller hosts, and caps old space at 8192 MiB.

The policy applies only to the Gateway service because the reported failure and evidence are Gateway-specific. Node services remain unchanged. A heap-size flag already present in the installed service is preserved and normalized, while ambient or adjacent startup flags such as preload and inspector options remain blocked. No config key, CLI flag, or public environment knob is added.

User Impact

After Gateway service installation or regeneration, operators get a host-appropriate old-space limit instead of relying on Node's generic default. openclaw gateway status and openclaw doctor show the applied limit and its derivation, including whether the installed service uses a distinct explicit setting.

Release note: Managed Gateway services now use a constrained-memory-aware Node heap limit to prevent sustained-load OOM crash loops.

Evidence

  • Focused regression proof: node scripts/run-vitest.mjs across heap math/parser, service environment, install planning, status gather/print, and doctor suites — 254 tests passed.
  • Hosted changed gate: formatting, core and core-test typechecks, full core lint, SDK/boundary checks, import cycles, and repository guards passed on Blacksmith Testbox.
  • Security boundary: tests prove ambient NODE_OPTIONS is ignored, only an installed heap-size flag is retained, quoted Node-compatible values are normalized, and node services receive no Gateway heap default.
  • Incident proof and operational workaround: Gateway crash-loops with default Node heap (~4 GB) — make 'openclaw daemon install' set NODE_OPTIONS or accept a --heap-mb flag #96203.
  • Source-blind local status probe was limited because this host has no installed Gateway service; no host service was installed or modified for validation.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Jun 24, 2026
@xydt-tanshanshan

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 15, 2026, 10:49 PM ET / July 16, 2026, 02:49 UTC.

Summary
The PR adds a generated heap-only NODE_OPTIONS=--max-old-space-size=8192 value to managed gateway and node service environments and tests that ambient Node startup flags are discarded.

PR surface: Source +14, Tests +67. Total +81 across 2 files.

Reproducibility: Partially yes: current source clearly reproduces the absence of a managed-service heap setting, and the linked issue contains strong live crash-loop evidence. This review did not rerun the full sustained-load failure.

Review metrics: 1 noteworthy metric.

  • Managed startup defaults: 1 added, 0 tuning surfaces added. A forced reinstall will introduce a new service-owned heap ceiling without a first-class operator override.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #96203
Summary: This PR remains the active candidate fix for the canonical gateway heap crash-loop issue; broader configurable and CLI-argument alternatives closed unmerged.

Members:

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

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] A fixed 8192 MiB V8 old-space ceiling can trade a controlled V8 heap abort for host-level memory pressure on constrained machines if actual usage grows beyond available memory.
  • [P1] A forced service reinstall will replace operator-added or ambient NODE_OPTIONS, so existing custom Node startup behavior will no longer apply to the managed service.
  • [P1] The proof validates generated Linux systemd metadata but does not rerun the sustained 30-agent workload or demonstrate launchd and Windows service startup behavior.

Maintainer options:

  1. Accept the fixed mitigation (recommended)
    Land the heap-only 8192 MiB default after explicitly owning the forced-reinstall and constrained-host behavior.
  2. Add durable sizing before landing
    Pause for an approved config or CLI contract with fresh-install and upgrade proof on representative memory sizes.
  3. Decline the fixed default
    Close this branch if maintainers do not want a fixed cross-platform managed-service ceiling.

Next step before merge

  • [P2] A maintainer must accept or reject the fixed cross-platform heap default and upgrade tradeoff; there is no narrow contributor-facing defect for an automated repair worker.

Maintainer decision needed

  • Question: Should managed gateway and node services adopt a fixed 8192 MiB V8 old-space ceiling now despite constrained-host and custom-NODE_OPTIONS upgrade tradeoffs?
  • Rationale: The patch is technically sound and addresses a severe observed crash loop, but startup defaults, affected service scope, and operator override behavior are intentional compatibility choices that source inspection cannot decide.
  • Likely owner: steipete — The strongest available history signal covers the service environment, install plan, and renderer boundaries needed to own this decision.
  • Options:
    • Accept emergency default (recommended): Land the heap-only 8192 MiB generated default now and track durable host-specific tuning separately.
    • Require tuning first: Pause until an approved config or CLI contract defines constrained-host behavior and has fresh-install and upgrade proof.
    • Narrow service scope: Apply the mitigation only to gateway services if independently managed node services should retain their current startup behavior.

Security
Cleared: The diff adds no dependency or permission surface and generates a constant heap-only value instead of accepting ambient Node preload, inspector, or other execution-control flags.

Review details

Best possible solution:

Adopt the heap-only generated default only after maintainers explicitly accept its cross-platform resource and upgrade behavior, keep all ambient startup-control flags blocked, and track any durable host-specific tuning contract separately.

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

Partially yes: current source clearly reproduces the absence of a managed-service heap setting, and the linked issue contains strong live crash-loop evidence. This review did not rerun the full sustained-load failure.

Is this the best way to solve the issue?

Yes technically, subject to maintainer acceptance: this is the narrowest heap-only install mitigation and avoids preserving ambient startup-control flags, but the fixed value and service scope are product-owned tradeoffs.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 04221fc91ef4.

Label changes

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster. Replaced prior rating: 🐚 platinum hermit.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P0: The linked report describes an unusable core gateway crash loop with thousands of restarts and blocked workflow processing.
  • merge-risk: 🚨 compatibility: Forced service regeneration replaces existing custom or ambient NODE_OPTIONS behavior with the generated heap-only value.
  • merge-risk: 🚨 availability: The fixed ceiling changes memory-failure behavior across host sizes while mitigating the observed V8 OOM restart loop.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster. Replaced prior rating: 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes an after-fix Linux install-path transcript and generated systemd entry, with terminal checks confirming ambient preload and debugger flags are absent.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes an after-fix Linux install-path transcript and generated systemd entry, with terminal checks confirming ambient preload and debugger flags are absent.
Evidence reviewed

PR surface:

Source +14, Tests +67. Total +81 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 14 0 +14
Tests 1 67 0 +67
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 81 0 +81

What I checked:

  • Current-main behavior: The common managed-service environment on current main includes service-owned state, TLS, proxy, home, temp, and path values but does not generate a Node heap limit. (src/daemon/service-env.ts:489, 04221fc91ef4)
  • Patch implementation: The branch adds a constant heap-only service value and deliberately does not compose ambient NODE_OPTIONS, preventing host preload and debugger flags from entering the managed service. (src/daemon/service-env.ts:480, bfb8afcc6262)
  • Regression coverage: The added tests cover the default value, replacement of ambient heap and miscellaneous flags, rejection of --require, --inspect, and --expose-gc, and the node-service environment path. (src/daemon/service-env.test.ts:728, bfb8afcc6262)
  • Install ownership boundary: The gateway install planner filters durable environment input before adding the generated service-owned environment with final precedence, so this constant is generated policy rather than untrusted host-env pass-through. (src/commands/daemon-install-helpers.ts:794, 04221fc91ef4)
  • Security policy context: Current policy blocks NODE_OPTIONS from ambient and durable host-environment ingestion; the PR preserves that boundary by replacing ambient input with one fixed heap flag. (src/infra/host-env-security-policy.json:5, 04221fc91ef4)
  • Real behavior proof: The PR body provides an after-fix Linux install transcript showing Environment=NODE_OPTIONS=--max-old-space-size=8192 in the generated systemd unit and zero matches for preload or inspector flags. (src/daemon/service-env.ts:496, bfb8afcc6262)

Likely related people:

  • steipete: The strongest history signal spans managed-service environment construction, install planning, and systemd rendering—the full boundary affected by this default. (role: historical daemon service contributor; confidence: high; commits: 407f4777d2e8, 4eb3d1fae941, 97d2d40fb75b; files: src/daemon/service-env.ts, src/commands/daemon-install-helpers.ts, src/daemon/systemd-unit.ts)
  • TurboTheTurtle: Recent service-identity and launchd-regeneration work touched the same managed-service environment lifecycle. (role: recent daemon service contributor; confidence: medium; commits: 3fea2196923b, ca2f4c0d6772; files: src/daemon/service-env.ts, src/daemon/launchd.ts)
  • vincentkoc: Review and co-author history connects this person to service-environment and launchd regeneration changes near the affected path. (role: recent reviewer and adjacent contributor; confidence: medium; commits: f5148aff2505, ca2f4c0d6772, 900a834c6088; files: src/daemon/service-env.ts, src/daemon/launchd.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (1 earlier review cycle)
  • reviewed 2026-06-25T02:20:16.287Z sha 87740071bf77399a52cdfb6580502f102c51647f :: needs maintainer review before merge. :: none

@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: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 24, 2026
@xydt-tanshanshan

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jun 24, 2026
@xydt-tanshanshan

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 24, 2026
@xydt-tanshanshan

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@xydt-tanshanshan

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jun 24, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 25, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 12, 2026
@xydt-tanshanshan
xydt-tanshanshan force-pushed the fix/gateway-daemon-heap-96203 branch from 8774007 to bfb8afc Compare July 15, 2026 06:59
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jul 16, 2026
@steipete steipete self-assigned this Jul 17, 2026
@steipete
steipete force-pushed the fix/gateway-daemon-heap-96203 branch from bfb8afc to a1b4157 Compare July 17, 2026 01:52
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes commands Command implementations size: M and removed size: S labels Jul 17, 2026
@steipete steipete changed the title [AI] fix(daemon): set default NODE_OPTIONS --max-old-space-size in gateway service env fix(daemon): prevent gateway OOM crash loops under sustained load Jul 17, 2026
@steipete
steipete force-pushed the fix/gateway-daemon-heap-96203 branch 4 times, most recently from b0ffa77 to a302bc9 Compare July 17, 2026 02:16
xydt-tanshanshan and others added 3 commits July 17, 2026 03:54
…rvice env

Generate a managed NODE_OPTIONS with --max-old-space-size=8192 for the
gateway systemd service, discarding ambient host NODE_OPTIONS to prevent
--require/--inspect persistence.  8192 MB is chosen as a safe default
that prevents the common OOM crash-loop with the default Node ~4 GB heap
under sustained load.

Related to openclaw#96203
@steipete
steipete force-pushed the fix/gateway-daemon-heap-96203 branch from a302bc9 to 3a7ad7a Compare July 17, 2026 02:54
@steipete
steipete merged commit a3e526a into openclaw:main Jul 17, 2026
119 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
…enclaw#96250)

* [AI] fix(daemon): set default --max-old-space-size=8192 in gateway service env

Generate a managed NODE_OPTIONS with --max-old-space-size=8192 for the
gateway systemd service, discarding ambient host NODE_OPTIONS to prevent
--require/--inspect persistence.  8192 MB is chosen as a safe default
that prevents the common OOM crash-loop with the default Node ~4 GB heap
under sustained load.

Related to openclaw#96203

* fix(daemon): adapt gateway heap limit to host memory

* fix(daemon): keep gateway heap helpers internal

---------

Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…enclaw#96250)

* [AI] fix(daemon): set default --max-old-space-size=8192 in gateway service env

Generate a managed NODE_OPTIONS with --max-old-space-size=8192 for the
gateway systemd service, discarding ambient host NODE_OPTIONS to prevent
--require/--inspect persistence.  8192 MB is chosen as a safe default
that prevents the common OOM crash-loop with the default Node ~4 GB heap
under sustained load.

Related to openclaw#96203

* fix(daemon): adapt gateway heap limit to host memory

* fix(daemon): keep gateway heap helpers internal

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

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

2 participants