[PR #8911] [MERGED] fix(shared): build shared types within Termux's 1 GiB heap (#8902) #8876

Closed
opened 2026-11-07 17:40:24 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8911
Author: @SpicyMarinara
Created: 11/6/2026
Status: ✅ Merged
Merged: 11/6/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/termux-shared-build-heap


📝 Commits (1)

  • 457d96b fix(shared): build shared types within Termux's 1 GiB heap (#8902)

📊 Changes

4 files changed (+101 additions, -3 deletions)

View changed files

📝 android/README.md (+1 -1)
📝 packages/shared/package.json (+2 -2)
➕ packages/shared/scripts/tsc-build.mjs (+47 -0)
➕ scripts/regressions/launcher/termux-shared-build.regression.mjs (+51 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #8902

Why this change

After updating to 2.5.2, switching to staging, or reinstalling, Marinara Engine no longer starts in Termux. Every screenshot in the Discord thread shows the same failure. During "Building shared types", tsc in packages/shared hits the 1024 MiB heap the launcher gives Node and aborts: FATAL ERROR: Ineffective mark-compacts near heap limit … JavaScript heap out of memory, exit 134.

The cause is growth in the shared package. From 2.5.1 to 2.5.2 it gained about 53,000 lines, mostly schemas/ruleset.schema.ts (26,486 lines of zod) and features/ruleset-combat/*. Measured on staging:

Shared build Heap used
tsc --noEmit (type-check only) ~1018 MiB
full build (type-check + declarations) ~1.3 GiB
tsc --noCheck, no declarations ~470 MB, same JavaScript byte for byte

The server already transpiles with esbuild on Android, and the client already skips its type-check there. The shared package was the only build still type-checking on a phone.

What changed

  • New packages/shared/scripts/tsc-build.mjs. Both build and build:preserve now end with node scripts/tsc-build.mjs instead of tsc.
    • On Android, or with MARINARA_LOW_MEMORY_BUILD=1 (the server's and client's existing low-memory test), it runs tsc --noCheck with no declarations, composite or incremental output.
    • Everywhere else it runs plain tsc, so desktop and CI builds still type-check and emit declarations.
  • Nothing on Android reads the declarations. The server is transpiled with esbuild, and Vite reads the JavaScript.
  • The launcher, the in-app updater and the manual update command all run --filter @marinara-engine/shared build, so all three get the fix.
  • New regression scripts/regressions/launcher/termux-shared-build.regression.mjs checks:
    • the platform and env switch;
    • that both scripts go through the runner;
    • that the low-memory build of the real shared package succeeds under --max-old-space-size=1024 and writes constants/defaults.js, the file the launcher checks for, with no declarations.
  • android/README.md: one sentence on the shared build's low-memory path.

Workaround until this reaches main: on a phone with about 4 GB of RAM or more, start with NODE_OPTIONS="--max-old-space-size=1536" ./start-termux.sh. This is the documented heap override, and the full shared build fits within it (about 1.5 GB peak RSS here).

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Manually verify on an Android phone in Termux: switch to staging with this change, run ./start-termux.sh, and confirm "Building shared types…" prints [build] Android/low-memory shared build: emitting JavaScript without type-checking. and the app starts.
  • Manually verify that an in-app update on Termux completes its shared build.
  • Manually verify that a desktop pnpm build still writes packages/shared/dist/**/*.d.ts.

Agent-run checks:

  • pnpm check: passes.
  • Launcher regressions: 10/10 pass, including the new one.
  • open-issues regression (which pins build:preserve): passes.
  • The new regression fails without the package.json change.
  • Measured locally: MARINARA_LOW_MEMORY_BUILD=1 NODE_OPTIONS=--max-old-space-size=1024 pnpm --filter @marinara-engine/shared build passes at 675 MB peak RSS. The normal build still emits 344 .js and 344 .d.ts files.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Only android/README.md changed; nothing under docs/, so no translated pack needs updating.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/8911 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/6/2026 **Status:** ✅ Merged **Merged:** 11/6/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/termux-shared-build-heap` --- ### 📝 Commits (1) - [`457d96b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/457d96bf3c30fea167197cfd6a376a7808868f7f) fix(shared): build shared types within Termux's 1 GiB heap (#8902) ### 📊 Changes **4 files changed** (+101 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `android/README.md` (+1 -1) 📝 `packages/shared/package.json` (+2 -2) ➕ `packages/shared/scripts/tsc-build.mjs` (+47 -0) ➕ `scripts/regressions/launcher/termux-shared-build.regression.mjs` (+51 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #8902 ## Why this change After updating to 2.5.2, switching to staging, or reinstalling, Marinara Engine no longer starts in Termux. Every screenshot in the Discord thread shows the same failure. During "Building shared types", `tsc` in `packages/shared` hits the 1024 MiB heap the launcher gives Node and aborts: `FATAL ERROR: Ineffective mark-compacts near heap limit … JavaScript heap out of memory`, exit 134. The cause is growth in the shared package. From 2.5.1 to 2.5.2 it gained about 53,000 lines, mostly `schemas/ruleset.schema.ts` (26,486 lines of zod) and `features/ruleset-combat/*`. Measured on staging: | Shared build | Heap used | | --- | --- | | `tsc --noEmit` (type-check only) | ~1018 MiB | | full build (type-check + declarations) | ~1.3 GiB | | `tsc --noCheck`, no declarations | ~470 MB, same JavaScript byte for byte | The server already transpiles with esbuild on Android, and the client already skips its type-check there. The shared package was the only build still type-checking on a phone. ## What changed - New `packages/shared/scripts/tsc-build.mjs`. Both `build` and `build:preserve` now end with `node scripts/tsc-build.mjs` instead of `tsc`. - On Android, or with `MARINARA_LOW_MEMORY_BUILD=1` (the server's and client's existing low-memory test), it runs `tsc --noCheck` with no declarations, composite or incremental output. - Everywhere else it runs plain `tsc`, so desktop and CI builds still type-check and emit declarations. - Nothing on Android reads the declarations. The server is transpiled with esbuild, and Vite reads the JavaScript. - The launcher, the in-app updater and the manual update command all run `--filter @marinara-engine/shared build`, so all three get the fix. - New regression `scripts/regressions/launcher/termux-shared-build.regression.mjs` checks: - the platform and env switch; - that both scripts go through the runner; - that the low-memory build of the real shared package succeeds under `--max-old-space-size=1024` and writes `constants/defaults.js`, the file the launcher checks for, with no declarations. - `android/README.md`: one sentence on the shared build's low-memory path. **Workaround until this reaches `main`:** on a phone with about 4 GB of RAM or more, start with `NODE_OPTIONS="--max-old-space-size=1536" ./start-termux.sh`. This is the documented heap override, and the full shared build fits within it (about 1.5 GB peak RSS here). ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Manually verify on an Android phone in Termux: switch to staging with this change, run `./start-termux.sh`, and confirm "Building shared types…" prints `[build] Android/low-memory shared build: emitting JavaScript without type-checking.` and the app starts. - Manually verify that an in-app update on Termux completes its shared build. - Manually verify that a desktop `pnpm build` still writes `packages/shared/dist/**/*.d.ts`. Agent-run checks: - `pnpm check`: passes. - Launcher regressions: 10/10 pass, including the new one. - `open-issues` regression (which pins `build:preserve`): passes. - The new regression fails without the `package.json` change. - Measured locally: `MARINARA_LOW_MEMORY_BUILD=1 NODE_OPTIONS=--max-old-space-size=1024 pnpm --filter @marinara-engine/shared build` passes at 675 MB peak RSS. The normal build still emits 344 `.js` and 344 `.d.ts` files. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Only `android/README.md` changed; nothing under `docs/`, so no translated pack needs updating. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:40:24 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8876
No description provided.