Skip to content

fix: prevent source builds from exhausting host memory - #108790

Merged
steipete merged 3 commits into
openclaw:mainfrom
Sedrak-Hovhannisyan:codex/reduce-tsdown-build-memory
Jul 16, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
Sedrak-Hovhannisyan:codex/reduce-tsdown-build-memory

Conversation

@Sedrak-Hovhannisyan

Copy link
Copy Markdown
Contributor

AI-assisted: yes. I reviewed the implementation, test results, and final diff.

What Problem This Solves

Fixes an issue where contributors running a normal source build on memory-constrained Linux hosts could have the kernel kill tsdown while declaration generation was active. The failure reproduced on a 12 GB host with no swap because the package declaration graphs and the much larger unified graph ran concurrently.

Why This Change Was Made

Declaration-enabled builds now run the AI config, package configs, and unified config in order. This prevents their peak memory use from overlapping. No-DTS builds keep the existing two-invocation fast path, and caller-provided tsdown filters keep the original single-main-invocation behavior.

The group names live in one shared module so the tsdown config and build wrapper cannot drift independently.

User Impact

Contributors can complete ordinary source builds on hosts where the previous concurrent declaration build exhausted system memory. Docker and other no-DTS builds retain their existing performance characteristics.

Evidence

  • Confirmed the generic issue remained on current main through 011d0279; the existing Docker OOM fix does not cover ordinary Linux pnpm build.
  • Before: three normal build attempts triggered kernel OOM kills on a 11,956 MiB, no-swap VPS. The killed Node process reached roughly 9-10 GB RSS while build children consumed the remaining memory.
  • Isolation: disabling declarations completed in 19 seconds at about 2.7 GiB peak RSS. A declaration build with an 8 GB V8 cap avoided kernel OOM but failed inside V8 at about 9.9 GiB aggregate RSS.
  • Candidate: package configs followed by the unified config completed with the repository's existing heap calculation, no swap, no low-memory guard trigger, and about 8.24 GiB peak aggregate RSS.
  • Patched real path: pnpm build passed on current-main commit 0f32033d plus this patch in 550 seconds. Peak aggregate RSS was 8,358,492 KiB, swap remained disabled, and the low-memory guard did not trigger.
  • Fast path: OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 node scripts/tsdown-build.mjs completed in 14 seconds with the existing 2/2 invocation shape.
  • Focused tests: 46/46 passed in test/scripts/tsdown-build.test.ts and test/scripts/tsdown-config.test.ts.
  • Focused lint and formatting: 0 warnings, 0 errors; all six changed files passed oxfmt --check.
  • Repository check: production, scripts, and root-test typechecks passed; core, extension, and script lint passed with 0 warnings/errors; formatting and import-cycle checks passed. The only failure was the existing temp-path guard finding in src/gateway/worker-environments/workspace-reconcile.ts, reproduced after stashing this patch on clean main.
  • Fresh repository autoreview: clean after preserving forwarded --filter and -F behavior.

A repository-wide 282-shard test run was not used as proof. It surfaced unrelated gateway-suite failures outside the changed files and was stopped; the affected build tests and complete production build passed.

Agent Transcript

Sanitized Codex session transcript
source: local Codex session
scope: build-memory diagnosis, implementation, review, and validation
omitted: unrelated installation and OAuth work, raw tool output, reasoning, local paths, host address, credentials, keys, auth details, and session metadata

[user]
Ok. Now let's look at the high processor issue you were having. Maybe it's PR worthy?

[assistant]
The VPS is idle now, but the kernel recorded three OOM kills during the build attempts. Each killed Node process was at roughly 9-10 GB resident memory on an 11 GB, no-swap host. This points to a build-memory problem, not persistent high CPU.

[assistant]
Current OpenClaw main gives tsdown an 11,188 MiB V8 heap on this host, leaving only 768 MiB for Linux, native bundler memory, page tables, and child processes. The existing Docker OOM fix skips declarations for Docker builds; it does not cover an ordinary bare-Linux pnpm build.

[user]
Do it.

[user]
Just make sure the issue isn't fixed already before doing tests and pr

[assistant]
Confirmed before continuing: current main still runs all main tsdown configs together, and the current upstream tsdown release still executes config arrays concurrently. No existing generic bare-Linux fix was found.

[assistant]
The isolation was decisive. With declarations disabled, tsdown completed in 19 seconds at about 2.7 GiB peak RSS. With declarations enabled and an 8 GB V8 cap, it reached about 9.9 GiB aggregate RSS and failed inside V8. The high CPU burst was normal bundling; declaration graph overlap was the memory problem.

[assistant]
Running the first sixteen configurations separately removed the stacked graphs, but the final unified configuration alone needed more than a 6 GB heap. Isolating it with an 8 GB heap passed in 7m34s at about 7.4 GiB peak RSS, with no swap and no low-memory guard trigger.

[assistant]
A smaller two-group experiment also passed: package configs together, then the unified config alone. It completed in 471 seconds at about 8.24 GiB peak aggregate RSS. This preserved package-build parallelism while preventing the largest declaration graph from overlapping it.

[assistant]
The implementation keeps no-DTS builds unchanged and splits only unfiltered declaration builds into AI, package, and unified invocations. Shared group constants keep the tsdown config and wrapper aligned.

[assistant]
The real patched pnpm build passed on a fresh current-main checkout with no swap: exit 0, 550 seconds, peak aggregate RSS 8,358,492 KiB, and no guard abort. Focused tests passed 42/42 before review.

[assistant]
Autoreview found that caller-provided --filter arguments would combine with the internal group filters and could duplicate work. The implementation was corrected to preserve the original single-main-invocation behavior whenever the caller supplies --filter or -F.

[assistant]
After that fix: focused tests passed 46/46, changed-file lint and formatting were clean, and the mandatory autoreview reported no actionable findings. The broad repository check passed typechecking, lint, formatting, and import-cycle checks; its only failure was reproduced on clean main in an unrelated temp-path guard.

[user]
Include it if it's there

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S labels Jul 16, 2026
@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. P2 Normal backlog priority with limited blast radius. labels Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed July 16, 2026, 4:55 AM ET / 08:55 UTC.

Summary
The PR assigns names to package and unified tsdown configurations and runs declaration-enabled build groups sequentially to reduce peak source-build memory.

PR surface: Tests +49, Other +35. Total +84 across 6 files.

Reproducibility: yes. The PR provides a concrete current-main reproduction on an approximately 12 GB Linux host without swap, including repeated kernel OOM kills and before/after peak-memory measurements.

Review metrics: 1 noteworthy metric.

  • Build invocation shape: 2 to 3 for ordinary DTS builds; 2 for env-disabled DTS builds. The extra process boundary is the mechanism that lowers peak memory, so every declaration-disabled entry path should be classified consistently.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

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

Rank-up moves:

  • [P2] Preserve forwarded --no-dts as a two-invocation build and add focused coverage for that argument path.

Next step before merge

  • [P2] The blocker is a mechanical argument-classification defect with a clear two-file repair and focused validation path.

Security
Cleared: The patch changes local build orchestration and focused tests without adding dependencies, downloads, lifecycle hooks, secret access, workflow permissions, or publishing behavior.

Review findings

  • [P2] Preserve the CLI --no-dts fast path — scripts/tsdown-build.mjs:616
Review details

Best possible solution:

Keep the supported configuration-group split, but derive the invocation plan from the effective declaration mode so environment- and CLI-disabled declaration builds both retain the existing two-pass path.

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

Yes. The PR provides a concrete current-main reproduction on an approximately 12 GB Linux host without swap, including repeated kernel OOM kills and before/after peak-memory measurements.

Is this the best way to solve the issue?

No, not quite. Named tsdown filters and sequential groups are a narrow, dependency-supported fix, but the planner must first preserve every supported no-declaration fast path, including forwarded --no-dts.

Full review comments:

  • [P2] Preserve the CLI --no-dts fast path — scripts/tsdown-build.mjs:616
    forwardedArgs can contain tsdown's supported --no-dts override, but this branch recognizes only the environment-based no-DTS mode. Consequently node scripts/tsdown-build.mjs --no-dts now runs AI plus two filtered main invocations instead of the prior AI-plus-main shape, regressing the declaration-disabled fast path described by the PR. Derive the split from the effective DTS mode or recognize --no-dts, and add the corresponding invocation test.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P2: The PR addresses a reproducible source-build failure on memory-constrained hosts, but the remaining defect is a bounded build-performance regression rather than a runtime emergency.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body gives convincing after-fix proof from the real pnpm build path on the affected no-swap Linux setup, with observed completion and measured peak RSS compared with repeated current-main OOM failures.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body gives convincing after-fix proof from the real pnpm build path on the affected no-swap Linux setup, with observed completion and measured peak RSS compared with repeated current-main OOM failures.

Label justifications:

  • P2: The PR addresses a reproducible source-build failure on memory-constrained hosts, but the remaining defect is a bounded build-performance regression rather than a runtime emergency.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body gives convincing after-fix proof from the real pnpm build path on the affected no-swap Linux setup, with observed completion and measured peak RSS compared with repeated current-main OOM failures.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body gives convincing after-fix proof from the real pnpm build path on the affected no-swap Linux setup, with observed completion and measured peak RSS compared with repeated current-main OOM failures.
Evidence reviewed

PR surface:

Tests +49, Other +35. Total +84 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 52 3 +49
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 4 38 3 +35
Total 6 90 6 +84

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs test/scripts/tsdown-build.test.ts test/scripts/tsdown-config.test.ts.
  • [P1] node scripts/check-changed.mjs -- scripts/tsdown-build.mjs test/scripts/tsdown-build.test.ts.
  • [P1] git diff --check.

What I checked:

  • Current-main behavior: Current main builds the AI declarations first and then invokes the complete main tsdown configuration array, allowing its declaration graphs to overlap. (scripts/tsdown-build.mjs:597, a5d1d9e473ba)
  • Proposed grouping: The PR changes ordinary unfiltered declaration builds to three sequential invocations: AI, package configurations, then the unified graph. (scripts/tsdown-build.mjs:601, 2a42d5585e3c)
  • No-DTS path gap: The split is bypassed only for OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 or a forwarded filter; a forwarded --no-dts option still takes the new three-invocation path. (scripts/tsdown-build.mjs:616, 2a42d5585e3c)
  • Dependency contract: tsdown documents --no-foo as the CLI form for disabling an option, and specifically exposes declaration generation through --dts; it also documents --filter as matching configuration working directories or names. (tsdown.dev)
  • Real behavior proof: The PR body reports three current-main kernel OOM kills on an approximately 12 GB no-swap host, followed by a successful patched pnpm build at 8,358,492 KiB peak aggregate RSS and focused 46/46 test results. (2a42d5585e3c)
  • Feature history: The tsdown build system appears to date to cpojer's commit 68ba1afb34, which moved the repository build and watch path to tsdown. (code.uocat.com) (scripts/tsdown-build.mjs:1, 68ba1afb34)

Likely related people:

  • cpojer: Introduced the repository's tsdown-based build and watch path in commit 68ba1afb34, making them the strongest available historical routing candidate. (code.uocat.com) (role: introduced behavior; confidence: medium; commits: 68ba1afb34; files: scripts/tsdown-build.mjs, tsdown.config.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.

@steipete steipete self-assigned this Jul 16, 2026
@steipete
steipete force-pushed the codex/reduce-tsdown-build-memory branch from 2a42d55 to 6441abb Compare July 16, 2026 12:42
@steipete
steipete force-pushed the codex/reduce-tsdown-build-memory branch from 6441abb to f178b71 Compare July 16, 2026 12:49
@steipete

Copy link
Copy Markdown
Contributor

Maintainer deep review complete. I rebased the branch and kept the core grouping design: AI declarations, package declarations, then the unified declaration graph run sequentially, while configs inside the package group remain parallel.

I also repaired three forwarded-argument regressions before landing:

  • CLI --no-dts retains the two-invocation fast path, and explicit --dts can override the skip environment.
  • Caller -F / --filter selectors are kept off the AI prebuild and applied once to the main config.
  • Caller -c / --config / --no-config selectors run once without repository group filters.

Proof:

The contributor's 12 GB no-swap source-build proof peaked at 8.36 GiB. The measured grouping cost was about 17 seconds versus unified-only declaration proof; the no-DTS path remains unchanged. Exact-head CI is now the remaining merge gate.

@steipete
steipete merged commit cc34a46 into openclaw:main Jul 16, 2026
102 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
* fix: reduce peak memory in source builds

* fix(build): preserve CLI no-dts fast path

* fix(build): preserve forwarded tsdown selectors

---------

Co-authored-by: openclaud11-sys <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
* fix: reduce peak memory in source builds

* fix(build): preserve CLI no-dts fast path

* fix(build): preserve forwarded tsdown selectors

---------

Co-authored-by: openclaud11-sys <[email protected]>
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

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. scripts Repository scripts 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.

2 participants