Skip to content

fix(update): prevent Doctor OOM during finalization - #126141

Closed
clawsweeper wants to merge 3 commits into
mainfrom
openclaw/fix-issue-126115-in-openclaw
Closed

clawsweeper wants to merge 3 commits into
mainfrom
openclaw/fix-issue-126115-in-openclaw

Conversation

@clawsweeper

@clawsweeper clawsweeper commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #126115

AI-assisted: yes (Codex / Roboclaw)

What Problem This Solves

Package-to-dev updates could reach post-update Doctor with Node's default roughly 2 GiB heap. Large recovered state could exhaust that heap, abort finalization, and leave the Gateway stopped until the operator supplied a manual NODE_OPTIONS override.

Why This Change Was Made

Apply the updater's existing 8 GiB heap budget at the CLI startup boundary for update commands other than update status. This covers normal updates, post-core finalization, and direct update repair before Doctor can load recovered state. The same small helper remains the source-build budget owner, preserves larger operator limits, and keeps unrelated Node options.

The earlier broad finalizer/Doctor rework was removed. Final PR scope is four files with one fast boundary assertion; there is no spawned-Node regression test or update-flow test expansion.

User Impact

Operators with large retained or recovered state can complete update finalization without discovering and supplying a manual heap override. Existing higher heap limits remain intact.

Evidence

  • Regression proof: the existing CLI respawn test now verifies that update repair upgrades a 1 GiB limit to 8 GiB while preserving unrelated startup environment; this assertion fails on the pre-fix code.
  • node scripts/run-vitest.mjs src/entry.respawn.test.ts src/infra/update-runner.test.ts — 93 tests passed across two shards; the added boundary assertion runs in the 9 ms respawn-test shard.
  • node scripts/check-changed.mjs -- src/entry.respawn.ts src/entry.respawn.test.ts src/infra/update-node-options.ts src/infra/update-runner-git-commands.ts — passed formatting, dead-export analysis, production/test typecheck, lint, import-cycle, architecture, and repository guards.
  • .agents/skills/autoreview/scripts/autoreview --mode local --stream-engine-output — clean; no accepted/actionable findings.
  • Final diff: 4 files, +38/-19, net +19.

The reporter's private recovered state fixture is unavailable, so this PR does not claim a replay of the exact reported corpus. The regression targets the startup resource boundary that must be established before V8 and Doctor begin work.

@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes commands Command implementations size: M maintainer Maintainer-authored PR labels Aug 19, 2026
@clawsweeper
clawsweeper marked this pull request as ready for review August 19, 2026 02:49
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. 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 Aug 19, 2026
@clawsweeper

clawsweeper Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 19, 2026, 12:15 AM ET / 04:15 UTC.

ClawSweeper review

What this changes

The PR applies an 8 GiB Node heap policy before update commands start and shares that policy with updater build work.

Merge readiness

⛔ Blocked by patch quality or review findings - 8 items remain

Needs changes before merge: two prior P1 concerns remain on the current head—valid inherited heap caps can be overridden, and the legacy root --update invocation misses the startup policy.

Priority: P1
Reviewed head: 6ff4daaef72ec47315ebed72c239729ac2bbb8f3

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is narrowly scoped but has two high-confidence startup/configuration regressions to resolve before merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; the supplied unit evidence remains useful but does not resolve the functional findings.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; the supplied unit evidence remains useful but does not resolve the functional findings.
Evidence reviewed 4 items Heap resolver misses valid Node syntax: The new resolver recognizes only the equals-form flag and appends 8192 otherwise. Direct Node 24.19.0 checks confirm underscore and quoted explicit forms are accepted, and a later 8192 flag becomes the effective cap.
Existing heap-parser contract: The Gateway heap parser already tokenizes quoted NODE_OPTIONS and recognizes canonical and underscore max-old-space-size flags.
Legacy update alias is normalized too late: The respawn plan classifies raw argv before the later Commander-path rewrite; root --update is converted to update only in run-main policy.
Findings 2 actionable findings [P1] Preserve valid inherited heap caps
[P1] Normalize the root update alias before classification
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/entry.respawn.test.ts src/infra/update-runner.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs src/entry.respawn.test.ts src/infra/update-runner.test.ts
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126141-WY41pN/target$ node scripts/run-vitest.mjs src/entry.respawn.test.ts src/infra/update-runner.test.ts
node scripts/run-vitest.mjs src/entry.respawn.test.ts src/infra/update-runner.test.ts
[test] starting test/vitest/vitest.unit-fast-isolated.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126141-WY41pN/target

 ✓  unit-fast-isolated  src/entry.respawn.test.ts (21 tests) 14ms

 Test Files  1 passed (1)
      Tests  21 passed (21)
   Start at  04:16:08
   Duration  539ms (transform 284ms, setup 98ms, import 265ms, tests 14ms, environment 0ms)

[test] starting test/vitest/vitest.infra.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126141-WY41pN/target


































Assertions:

  • PASS expect_output: passed

How this fits together

The CLI can respawn itself before dispatching a command so Node startup settings take effect. Update and repair commands then run Doctor and finalization in that child process.

flowchart LR
A[Update command] --> B[CLI startup]
B --> C[Respawn policy]
C --> D[Heap option handling]
D --> E[Update process]
E --> F[Doctor finalization]
Loading

Before merge

  • Preserve valid inherited heap caps (P1) - This only matches the canonical equals-form. Node accepts forms such as --max_old_space_size=16384 and --max-old-space-size="16384"; this code appends --max-old-space-size=8192, which becomes the effective final cap and silently reduces the operator’s limit. Reuse the existing token-based heap parsing contract and cover accepted forms.
  • Normalize the root update alias before classification (P1) - openclaw --update is rewritten to update later in run-main, but this respawn decision reads the raw argv first. Its primary command is therefore absent here, so this supported update path never receives the heap policy. Normalize the alias before this invocation check and add a boundary case.
  • Resolve merge risk (P1) - A valid explicit NODE_OPTIONS heap cap can be silently reduced to 8 GiB when written with an accepted alternate Node spelling.
  • Resolve merge risk (P1) - The documented legacy root --update path reaches command rewriting only after the respawn decision, leaving its Doctor finalization at the original heap limit.
  • Resolve merge risk (P1) - Production code is net +15 lines for a policy that duplicates existing Node-option parsing logic; centralize that contract rather than retaining divergent parsers.
  • Complete next step (P2) - Both blockers have a narrow mechanical repair on the PR branch; no product or security decision is needed.
  • Improve patch quality - Use a token-aware shared parser that preserves explicit accepted heap caps.
  • Improve patch quality - Apply the startup policy to the legacy root --update alias and add focused regression coverage.

Findings

  • [P1] Preserve valid inherited heap caps — src/infra/update-node-options.ts:7-15
  • [P1] Normalize the root update alias before classification — src/entry.respawn.ts:106-107
Agent review details

Security

None.

PR surface

Source +15, Tests +4. Total +19 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 31 16 +15
Tests 1 7 3 +4
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 38 19 +19

Review metrics

Metric Value Why it matters
Production vs test LOC production +31/-16, tests +7/-3 The net production increase adds a second Node-option policy surface despite an existing parser covering this contract.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/entry.respawn.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair the shared startup policy (recommended)
    Reuse or extract the canonical Node-options parser and normalize the root update alias before selecting the update heap policy.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve valid explicit Node heap caps, normalize legacy --update before startup classification, and add regression coverage for accepted alternate cap syntax plus the root alias.

Technical review

Best possible solution:

Centralize Node-option tokenization and explicit heap-cap detection, preserve every valid inherited cap, and normalize the legacy update alias before startup classification; use 8 GiB only when no cap exists.

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

Yes. Source inspection and direct Node runtime checks show valid alternate heap-cap syntax is overwritten, while raw --update is normalized only after the respawn decision.

Is this the best way to solve the issue?

No. The current helper is a plausible mitigation but does not preserve Node’s accepted explicit cap forms or cover the existing root update alias.

Full review comments:

  • [P1] Preserve valid inherited heap caps — src/infra/update-node-options.ts:7-15
    This only matches the canonical equals-form. Node accepts forms such as --max_old_space_size=16384 and --max-old-space-size="16384"; this code appends --max-old-space-size=8192, which becomes the effective final cap and silently reduces the operator’s limit. Reuse the existing token-based heap parsing contract and cover accepted forms.
    Confidence: 0.99
  • [P1] Normalize the root update alias before classification — src/entry.respawn.ts:106-107
    openclaw --update is rewritten to update later in run-main, but this respawn decision reads the raw argv first. Its primary command is therefore absent here, so this supported update path never receives the heap policy. Normalize the alias before this invocation check and add a boundary case.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6c26bc7e2bab.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P1: The remaining defects leave real update-finalization paths without the intended memory protection or lower an operator-selected limit.
  • merge-risk: 🚨 compatibility: The change rewrites existing NODE_OPTIONS configuration and currently mishandles valid inherited forms.
  • merge-risk: 🚨 availability: The selected V8 old-space limit determines whether Doctor can complete update finalization without OOM.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; the supplied unit evidence remains useful but does not resolve the functional findings.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/entry.respawn.test.ts src/infra/update-runner.test.ts.
  • [P1] node scripts/check-changed.mjs -- src/entry.respawn.ts src/entry.respawn.test.ts src/infra/update-node-options.ts src/infra/update-runner-git-commands.ts.

What I checked:

  • Heap resolver misses valid Node syntax: The new resolver recognizes only the equals-form flag and appends 8192 otherwise. Direct Node 24.19.0 checks confirm underscore and quoted explicit forms are accepted, and a later 8192 flag becomes the effective cap. (src/infra/update-node-options.ts:7, 6ff4daaef72e)
  • Existing heap-parser contract: The Gateway heap parser already tokenizes quoted NODE_OPTIONS and recognizes canonical and underscore max-old-space-size flags. (src/daemon/gateway-heap.ts:68, 6ff4daaef72e)
  • Legacy update alias is normalized too late: The respawn plan classifies raw argv before the later Commander-path rewrite; root --update is converted to update only in run-main policy. (src/entry.respawn.ts:106, 6ff4daaef72e)
  • Patch provenance: Current-head blame attributes the new startup heap policy and helper to the PR-head merge commit. (src/infra/update-node-options.ts:7, 6ff4daaef72e)

Likely related people:

  • RoboClaw: Current-head blame attributes the added startup heap policy and shared helper to this commit author. (role: current patch author; confidence: high; commits: 6ff4daaef72e; files: src/entry.respawn.ts, src/infra/update-node-options.ts, src/infra/update-runner-git-commands.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-19T02:59:16.250Z sha 01e4cf0 :: found issues before merge. :: [P1] Preserve explicit inherited heap caps
  • reviewed 2026-08-19T03:46:20.158Z sha 7264f5d :: needs changes before merge. :: [P1] Preserve valid inherited heap caps | [P1] Normalize the root update alias before classification

@openclaw-barnacle openclaw-barnacle Bot added size: S and removed gateway Gateway runtime cli CLI command changes commands Command implementations size: M labels Aug 19, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 19, 2026
@steipete

Copy link
Copy Markdown
Contributor

Closing this approach in favor of the owner-level repair in #126115.

The reported failure is real, and the larger heap successfully demonstrates a containment path. However, the stronger current-source match is Doctor repeatedly materializing the complete SQLite session corpus: full entry_json parsing, retained cache projections, cloned whole-store lists, and a second main-session recovery listing. Raising the updater process to a fixed 8 GiB limit moves that failure threshold without bounding the allocating owner.

The startup-respawn implementation also does not cover the documented no-respawn and root --update paths consistently, and its NODE_OPTIONS parser can lower valid operator limits that use other Node-supported spellings.

I am keeping #126115 open and replacing this with a bounded Doctor/session-accessor refactor plus a generated large-corpus, low-heap regression and before/after memory measurements. Hannes remains credited for the report and reproduction evidence.

@steipete

Copy link
Copy Markdown
Contributor

Follow-up: the owner-level replacement has landed in #126353 as 61221c4c20ec511ba239648a5f4f7998d5c35459.

Thank you, Hannes, for the detailed reproduction and for demonstrating that an 8 GiB heap allowed the stranded update to recover. That evidence was the key lead, but the final repair went deeper than the heap workaround in this PR.

The root cause was Doctor and session SQLite migration/repair code retaining complete entry_json corpora across several passes. The landed change moves those paths to ordered bounded scans, compact promoted-column projections, selective candidate hydration, stale-decision revalidation, and bounded writes. It removes the obsolete whole-entry repair/list path and does not add a heap override, config, dependency, protocol change, or SQLite schema-version bump.

We proved the real built Node 24 Doctor flow under a 768 MiB old-space cap:

  • 660 sessions × 384 KiB (~247 MiB logical JSON): passed at 227.8 MiB post-GC heap.
  • 2,640 sessions × 384 KiB (~990 MiB logical JSON): passed at 227.6 MiB post-GC heap.
  • Exact session-node/window counts, validity state, and representative payload hashes were preserved.

Exact-head CI passed, including 205 focused assertions, the broader 331-test pass, build/check gates, and clean autoreview. Your credit is preserved in the landed squash commit via Co-authored-by.

#126115 is now closed. The fix is merged to main but has not yet been released.

@RomneyDa
RomneyDa deleted the openclaw/fix-issue-126115-in-openclaw branch October 22, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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]: package-to-dev update Doctor OOMs on large recovered session state

3 participants