Skip to content

fix(scripts): build heap ignores its systemd memory budget and takes the full default - #123979

Merged
jesse-merhi merged 37 commits into
mainfrom
jesse/tsdown-heap-host-scaled
Aug 24, 2026
Merged

jesse-merhi merged 37 commits into
mainfrom
jesse/tsdown-heap-host-scaled

Conversation

@jesse-merhi

@jesse-merhi jesse-merhi commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

A systemd-managed build could size V8 from host RAM instead of the process's enforceable cgroup budget. On the observed 5 GiB slice, that selected a 12,288 MiB heap, drove the slice into reclaim, and contributed to unrelated services being OOM-killed.

This is the final layer of the original stack. #123975 and #123976 are merged; this PR targets main directly.

What changed

  • Resolve the process's applicable cgroup v1/v2 hierarchy, use the tightest readable hard limit, subtract competing charged usage, and ignore advisory v1 soft limits.
  • Fail closed before destructive output cleanup when membership, controller limits, hierarchy metadata, or mount translation cannot be proved. Confirmed unconstrained v2 roots and explicitly disabled v2 memory controllers still use host memory.
  • Freeze one bounded heap plan before cleanup and serialize canonical unified builds under that admitted budget. Explicit --no-config positional builds keep their dependency-owned single-process behavior.
  • Preserve runtime-only full/package builds by selecting their step graph from the runner-resolved environment.
  • Reject filesystem roots across POSIX, Windows drive, and UNC semantics before recursive cleanup.
  • Preserve orphan-watchdog identity across failed dedicated recovery so a healthy retry can retire the correct process.
  • Consolidate mountinfo path decoding in @openclaw/normalization-core; remove the duplicate script helper.
  • Prebuild the runtime in the two real-CLI CI shards that otherwise attempted a nested full build after Vitest workers had consumed the cgroup budget. Runtime and private-QA modes propagate through normal, compact, and changed-extension plans.
  • Document the measured 6 GiB source-build floor and direct smaller hosts to prebuilt images.

The architectural owners remain the build wrapper for admission/cleanup, normalization-core for mount-path decoding, CI planning for shard prerequisites, and workspace quiescence for watchdog lifecycle. No parallel fallback path was added.

Operator-visible proof

Full eleven-invocation build in a transient systemd unit with MemorySwapMax=0:

Before: 5 GiB slice -> NODE_OPTIONS=--max-old-space-size=12288
After:  5 GiB slice -> NODE_OPTIONS=--max-old-space-size=4352
        full tsdown build: exit 0, 11/11 invocations
        memory peak: 4730 MiB, swap: 0 B, oom_kill: 0

An automatically sized 4 GiB build now exits before output cleanup. The explicit operator recovery path remains available:

OPENCLAW_TSDOWN_MAX_OLD_SPACE_MB=4096
admission: continue with explicit 4096 MB request

Maintainer decision: accept fail-closed admission for constrained or unprovable Linux source builds, with the documented explicit heap override as the operator-owned escape hatch. The build, cleanup, CI-prerequisite, and watchdog safeguards are accepted as one coherent repair.

Review and verification

Exact head: 45e5acd41708003d80b08a7e3c28e05163a7743e

  • Native review: D70 fixed, then two consecutive clean passes on the unchanged head.
  • Independent cold review: D71 fixed, then a fresh exact-head pass found no actionable defects.
  • Review fixes: runtime-only runner environment propagation; lint-safe optional prebuild-mode assignment.
  • Final focused cold-review suite: 443 passed / 2 skipped; direct planner probes covered normal, compact PR, and changed-extension paths.
  • Local review-fix suite: 256 passed / 2 skipped; affected planner/workflow suite: 199 passed / 2 skipped.
  • pnpm lint:scripts, changed-file formatting, and git diff --check: passed.
  • Exact-head CI run 32684970145: passed. Build artifacts, script lint, the runtime-prebuilt compact shard, and the private-QA-prebuilt changed-extension shard all passed on a fresh checkout. Two unrelated transient jobs passed on the failed-only rerun without branch changes.
  • ClawSweeper containment finding disposition: rejected. isPathInside(base, target) returns true when target is equal to or below base; assertTsdownCleanOutputRoots therefore correctly passes (candidateRoot, cwd) to reject a candidate that is the checkout or an ancestor. The named roots: [".."] regression passed locally (1 passed / 155 skipped), and the bot's own exact-head run passed all 156 tests in that file.

Diff classification

Surface Added Removed Net
Tests 2,011 102 +1,909
Docs 19 13 +6
Build tooling 1,044 172 +872
Runtime source 38 23 +15
Manifests/config 10 2 +8

The positive tooling delta implements the cgroup-topology, argument-serialization, output-cleanup, cache, CI-prerequisite, and workspace-lifecycle contracts; tests cover the changed and sibling failure paths. The last review fix adds three production lines solely to satisfy the enforced no-map-spread rule while preserving planner output.

Rank-up moves

  • Exact-head CI is green on the pushed head.
  • The maintainer decision to accept fail-closed admission and the coupled repair scope is recorded above.
  • Cleanup-boundary patch request skipped because its argument-order premise is reversed; changing the call would create the escape the current code prevents. The exact ancestor regression is green.
  • Branch refresh skipped because the exact-head CI merge simulation already merged this head into current main and passed; GitHub reports the PR mergeable.

@clawsweeper

clawsweeper Bot commented Aug 15, 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 scripts Repository scripts size: S maintainer Maintainer-authored PR labels Aug 15, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 11:25 PM ET / August 24, 2026, 03:25 UTC.

ClawSweeper review

What this changes

This PR derives build heap limits from the process cgroup hierarchy, prevents unsafe cleanup, updates CI prebuild planning, and documents the source-build memory floor.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. Current main still probes only static cgroup-root paths, so it does not solve systemd slice budgeting; the remaining merge decision is whether the intentional fail-closed behavior is acceptable for existing low-memory source builds.

Priority: P1
Reviewed head: 45e5acd41708003d80b08a7e3c28e05163a7743e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has focused source coverage and a coherent repair boundary; the remaining blocker is the deliberate compatibility policy.
Proof confidence 🌊 off-meta tidepool Not applicable: This member-authored PR is exempt from the external-contributor proof gate; its body nevertheless records an after-fix transient-systemd build result.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored PR is exempt from the external-contributor proof gate; its body nevertheless records an after-fix transient-systemd build result.
Evidence reviewed 6 items Current main remains affected: Current main defines only static v2 and v1 root paths, then falls back to host memory when neither produces a limit; it does not resolve a systemd slice from the process hierarchy.
Branch owner-boundary repair: The PR reads mountinfo and process cgroup records, maps them to visible controller paths, and walks applicable ancestors before choosing a limit.
Focused regression coverage: Tests cover a systemd slice, inherited namespace views, escaped mount paths, v1 controller mounts, and refusal before cleanup.
Findings None None.
Security None None.

Live Verification

Command: node --import tsx scripts/tsdown-build.mts --help

Result: PASS (completed)

node --import tsx scripts/tsdown-build.mts --help
runner@runnervm76f27:/tmp/clawsweeper-live-proof-123979-CDhTiP/target$ node --import tsx scripts/tsdown-build.mts --help
Usage: node --import tsx scripts/tsdown-build.mts [tsdown args...]

Builds OpenClaw with tsdown and validates emitted import diagnostics.

Options:
  -h, --help  Show this help without starting tsdown.

Other arguments are forwarded to tsdown.
runner@runnervm76f27:/tmp/clawsweeper-live-proof-123979-CDhTiP/target$ node --import tsx scripts/tsdown-build.mts --help
Usage: node --import tsx scripts/tsdown-build.mts [tsdown args...]

Builds OpenClaw with tsdown and validates emitted import diagnostics.

Options:
  -h, --help  Show this help without starting tsdown.

Other arguments are forwarded to tsdown.
runner@runnervm76f27:/tmp/clawsweeper-live-proof-123979-CDhTiP/target$































Assertions:

  • PASS expect_output: Show this help without starting tsdown.

How this fits together

The build wrapper starts tsdown and clears generated outputs before rebuilding artifacts. This change turns Linux cgroup information into a bounded heap plan used by local builds and selected CI shards.

flowchart LR
  A[Build or CI shard] --> B[Build planner]
  B --> C[Cgroup budget reader]
  C --> D[Heap admission decision]
  D --> E[Output cleanup and tsdown]
  E --> F[Artifacts or visible refusal]
Loading

Decision needed

Question Recommendation
Should constrained or unprovable Linux source builds fail before cleanup by default, with the existing explicit heap override as the operator-owned escape hatch? Accept fail-closed admission: Keep the documented override and reject unsafe default source builds before cleanup.

Why: This is an intentional compatibility and operator-experience choice that source review cannot settle alone.

Before merge

  • Resolve merge risk (P1) - The new default can stop existing constrained source builds until operators increase memory or provide the documented explicit heap override.
  • Resolve merge risk (P1) - The bug fix adds about production/tooling +1,092/-197 alongside tests +2,011/-102; the coupled cgroup, cleanup, CI, and lifecycle scope needs maintainer confirmation that it cannot be reduced without losing required owner-boundary coverage.
Agent review details

Security

None.

PR surface

Source +15, Tests +1909, Docs +6, Config +20, Other +860. Total +2810 across 25 files.

View PR surface stats
Area Files Added Removed Net
Source 5 38 23 +15
Tests 8 2011 102 +1909
Docs 4 19 13 +6
Config 4 22 2 +20
Generated 0 0 0 0
Other 4 1032 172 +860
Total 25 3122 312 +2810

Review metrics

Metric Value Why it matters
Production versus tests production/tooling +1,092/-197; tests +2,011/-102; docs +19/-13 The repair materially expands build and CI policy beyond regression coverage, which matters for a compatibility-sensitive bug fix.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-state-integrity.ts, persistent cache schema: test/scripts/build-all.test.ts, unknown-data-model-change: src/gateway/worker-environments/workspace-quiescence-scripts.ts, unknown-data-model-change: src/gateway/worker-environments/workspace-sync-scripts.test.ts, vector/embedding metadata: scripts/build-all.mts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Accept the documented admission change (recommended)
    Merge with the explicit override and prebuilt-image guidance as the supported recovery path for affected operators.
  2. Keep low-memory compatibility by default
    Redesign the policy so strict admission is opt-in and cover both compatibility and strict paths.

Technical review

Best possible solution:

Accept the cgroup resolver at the build-owner boundary only with an explicit maintainer decision on fail-closed admission and a recorded justification for the coupled production growth.

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

Yes, source-reproducible: current main’s two root paths cannot discover a systemd slice limit, while the PR’s focused fixtures exercise that hierarchy. No tests were run because this review is read-only.

Is this the best way to solve the issue?

Unclear: resolving cgroups at the build owner is the right technical boundary, but default fail-closed admission needs maintainer product judgment.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member-authored PR is exempt from the external-contributor proof gate; its body nevertheless records an after-fix transient-systemd build result.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.
  • remove merge-risk: 🚨 other: Current PR review merge-risk labels are merge-risk: 🚨 compatibility, merge-risk: 🚨 availability.

Label justifications:

  • P1: Incorrect heap sizing can make builds consume a constrained host’s budget and affect other processes.
  • merge-risk: 🚨 compatibility: Existing low-memory source-build workflows can now refuse to proceed without operator action.
  • merge-risk: 🚨 availability: The patch determines whether local and CI build flows run under constrained memory.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member-authored PR is exempt from the external-contributor proof gate; its body nevertheless records an after-fix transient-systemd build result.

Evidence

What I checked:

  • Current main remains affected: Current main defines only static v2 and v1 root paths, then falls back to host memory when neither produces a limit; it does not resolve a systemd slice from the process hierarchy. (scripts/tsdown-build.mts:50, c337919f6d4f)
  • Branch owner-boundary repair: The PR reads mountinfo and process cgroup records, maps them to visible controller paths, and walks applicable ancestors before choosing a limit. (scripts/tsdown-build.mts:650, 45e5acd41708)
  • Focused regression coverage: Tests cover a systemd slice, inherited namespace views, escaped mount paths, v1 controller mounts, and refusal before cleanup. (test/scripts/tsdown-build.test.ts:1117, 45e5acd41708)
  • Caller preserves pre-cleanup admission: Full and package profiles resolve the heap plan before running any build step, including the package profile’s explicit dist cleanup. (scripts/build-all.mts:1025, 45e5acd41708)
  • Current-main provenance: Blame attributes the static cgroup-root implementation on current main to commit 3dd3003; later current-main commit c337919 still retains it. (scripts/tsdown-build.mts:50, 3dd3003f49ce)
  • Release/main check: The latest supplied release is v2026.7.1-2 at 0790d9f, while current main is c337919; neither contains this open PR’s implementation. (c337919f6d4f)

Likely related people:

  • samson1357924: Blame attributes the static root-only cgroup limit logic in current main to this commit. (role: current-main implementation author; confidence: high; commits: 3dd3003f49ce; files: scripts/tsdown-build.mts)
  • Peter Steinberger: Recent history includes multiple build-all and tsdown cache/packaging repairs. (role: recent build-system contributor; confidence: medium; commits: f92e9367e8c7, 74c1900e630f; files: scripts/build-all.mts, scripts/tsdown-build.mts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record or reconfirm maintainer acceptance of the low-memory fail-closed default and explicit override recovery path.

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 (44 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-21T17:15:21.329Z sha 9c362fe :: found issues before merge. :: [P3] Document the small-heap opt-out
  • reviewed 2026-08-21T17:35:50.910Z sha cfc8af7 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-21T18:37:26.125Z sha cfc8af7 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-21T18:56:39.362Z sha cfc8af7 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-23T15:15:06.977Z sha 8d5137c :: needs maintainer review before merge. :: none
  • reviewed 2026-08-23T15:55:51.659Z sha 8d5137c :: needs changes before merge. :: [P1] Reject inherited /.. cgroup mount views
  • reviewed 2026-08-24T00:28:39.296Z sha 322ed1f :: needs maintainer review before merge. :: none
  • reviewed 2026-08-24T03:09:47.335Z sha 45e5acd :: found issues before merge. :: [P1] Reverse the containment arguments for cleanup roots

@jesse-merhi

Copy link
Copy Markdown
Member Author

/clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 15, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@jesse-merhi

Copy link
Copy Markdown
Member Author

/clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 15, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@jesse-merhi

Copy link
Copy Markdown
Member Author

/clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 15, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@jesse-merhi

Copy link
Copy Markdown
Member Author

/clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 15, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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 15, 2026
@jesse-merhi

Copy link
Copy Markdown
Member Author

/clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 15, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 15, 2026
@jesse-merhi

Copy link
Copy Markdown
Member Author

/clawsweeper re-review

@clawsweeper

Copy link
Copy Markdown
Contributor

/clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 23, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

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

Labels

commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation gateway Gateway runtime 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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL 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.

3 participants