[PR #5587] [MERGED] fix: Termux heap default and profile-restore .native marker regressions #6837

Closed
opened 2026-10-23 04:14:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5587
Author: @Romuromylus
Created: 8/28/2026
Status: ✅ Merged
Merged: 8/29/2026
Merged by: @Romuromylus

Base: staging ← Head: fix/5585-termux-heap-default


📝 Commits (10+)

  • 43a085d fix(termux): scale the default Node heap with profile size and device RAM
  • 7ea6711 test(launcher): clarify the flat-2GB guard message
  • 4b8af77 Merge branch 'staging' into fix/5585-termux-heap-default
  • 94eb5e4 Merge remote-tracking branch 'pasta/staging' into fix/5585-termux-heap-default
  • f098e67 Merge branch 'staging' into fix/5585-termux-heap-default
  • f88f1f2 docs: document the unknown-device-memory 1536 MiB heap fallback
  • ed50304 Merge remote-tracking branch 'pasta/staging' into fix/5585-termux-heap-default
  • b1736a1 docs: state the heap change as restored headroom under device caps
  • 4cbedfd fix(import): tolerate the seeder's empty .native markers in profile restores
  • fad9082 Merge remote-tracking branch 'pasta/staging' into fix/5585-termux-heap-default

📊 Changes

6 files changed (+62 additions, -13 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 android/README.md (+1 -1)
📝 packages/server/src/services/import/profile-import-assets.ts (+13 -1)
📝 scripts/regressions/launcher/format-guard.regression.mjs (+5 -2)
📝 scripts/regressions/profile-import-asset-security.regression.ts (+29 -0)
📝 start-termux.sh (+12 -9)

📄 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 #5585
Closes #5619

Why this change

  • Since v2.4.4, Termux installs with large structured profiles crash with FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory (exit 134) during normal chat use. v2.4.4 replaced the flat 2 GiB launcher heap default with an adaptive default computed as on-disk profile size + a flat 512 MiB allowance, hard-capped at 1536 MiB (#5471, #5515). That model undershoots real heap need: the file-backed store keeps every row in memory, V8's object representation runs well above the serialized JSON byte size, and flushes serialize dirty tables on top of the live rows. A profile that ran comfortably inside the old 2 GiB default can exceed 1536 MiB and abort.

  • The reporter's setup is literally the pinned regression fixture: resolve_default_node_heap_mb 1153434 8388608 (a ~1.1 GiB profile on an 8 GiB device) resolved 1536, and their diagnostics show a 1632 MiB heap limit (--max-old-space-size=1536 plus V8's non-old spaces) with 1097 MiB already in use shortly after a restart, then a Mark-Compact at 1594 MiB reclaiming only ~82 MB before the abort — a live working set, not garbage churn.

  • I also swept the whole v2.4.3..v2.4.4 server diff for a genuine leak before touching the launcher: no unbounded live-retention accumulator landed in that window (the only new module-level container in the entire server is the bounded fileTableShardStrategies map). The regression is the heap budget, not a leak.

  • Folded in per maintainer decision: restoring a full profile backup fails on the game-asset seeder's own .native directory markers. ensureNativeMarkers (seed-game-assets.ts) writes an empty .native file into every bundled asset directory, profile export archives those directories verbatim, and the 2.4.4 import asset validation rejects the marker as an unsupported image under game-assets/sprites/, aborting the entire restore — fatal for a user restoring onto a fresh device (#5619, reported on Discord).

What changed

  • start-termux.sh: resolve_default_node_heap_mb now budgets roughly twice the on-disk structured profile plus 512 MiB of headroom (still 128 MiB steps, still the 1 GiB floor). The quarter-of-physical-RAM device cap remains the small-phone bound and now also enforces the 1 GiB floor on very low-RAM devices; the conservative flat 1536 MiB clamp applies only when /proc/meminfo cannot be read. Explicit NODE_OPTIONS heap limits remain authoritative, and the flat 2 GiB automatic default stays gone — a large grant now requires a device whose RAM justifies it.
  • scripts/regressions/launcher/format-guard.regression.mjs: the reporter-shaped fixture (~1.1 GiB profile, 8 GiB device) now expects 2048; added fixtures for a mid-size profile (1536), a 3 GiB device (floored at 1024), and unknown device memory (clamped at 1536). Zero-profile and 4 GiB-device fixtures are unchanged at 1024.
  • android/README.md: updated the heap-selection description.
  • CHANGELOG.md: Unreleased fix entry.

Resolved defaults before → after: ~1.1 GiB profile / 8 GiB device: 1536 → 2048 (what pre-2.4.4 gave it). Fresh install / 8 GiB: 1024 → 1024. ~1.1 GiB profile / 4 GiB device: 1024 → 1024. ~1.1 GiB profile / unknown RAM: 1536 → 1536.

  • packages/server/src/services/import/profile-import-assets.ts: import now tolerates exactly the seeder's marker — a file named .native under game-assets/, only when empty — and keeps image validation for everything else; a non-empty file using the marker name is still rejected, so the smuggling posture is unchanged.
  • scripts/regressions/profile-import-asset-security.regression.ts: two new cases — empty .native markers under game-assets/sprites/ and game-assets/backgrounds/pack/ stage successfully; a non-empty .native is rejected.
  • CHANGELOG.md: Unreleased fix entry for #5619.

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

  • Ran node scripts/run-regressions.mjs --filter profile-import-asset-security locally — passes with the new .native marker cases.

  • Ran pnpm check locally (passes).

  • Ran the full regression:launcher-update lane script-by-script (all seven pass, including the format guard with the new heap fixtures).

  • The Docker/EasyPanel deploy path does not execute start-termux.sh, so the running-app checks don't exercise this change; the launcher regression lane is the executable coverage.

  • The Playwright smoke lanes (desktop-chromium, mobile-chromium, mobile-webkit) fail on this PR the same way they fail on the current staging head run (different flaky client e2e cases per run); this PR touches no client or server code, so those lanes cannot exercise it. complete-node-regressions, pnpm-validate, and container-build-test are green.

  • Still needs a real-device confirmation: a Termux install with a large profile should log Node.js heap limit set to 2048 MiB for this profile and device on an 8 GiB phone and survive a long chat session. I'd appreciate the reporter confirming on their device once this lands on staging.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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)

UI evidence (if applicable)

Not applicable — Termux launcher and regression fixtures only.

Summary by CodeRabbit

  • Bug Fixes

    • Improved default Node.js heap sizing in Termux based on profile storage and available device memory.
    • Added safeguards for low-memory and unknown-memory devices.
    • Preserved support for explicit NODE_OPTIONS overrides.
    • Fixed profile backup restoration for valid empty game-asset markers while rejecting conflicting files.
  • Documentation

    • Updated Termux memory-sizing documentation and the unreleased changelog.
  • Tests

    • Expanded regression coverage for memory limits and profile asset validation.

🔄 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/5587 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 8/28/2026 **Status:** ✅ Merged **Merged:** 8/29/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `staging` ← **Head:** `fix/5585-termux-heap-default` --- ### 📝 Commits (10+) - [`43a085d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/43a085de289ecad8187e40bbdc659d828901aca7) fix(termux): scale the default Node heap with profile size and device RAM - [`7ea6711`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7ea6711fb6c7e99042e3e5b3d939a59ad49340db) test(launcher): clarify the flat-2GB guard message - [`4b8af77`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4b8af770bca02a1682caeeba02b4d0791334938e) Merge branch 'staging' into fix/5585-termux-heap-default - [`94eb5e4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/94eb5e40967a34188891a0b9ab5363b890bb7814) Merge remote-tracking branch 'pasta/staging' into fix/5585-termux-heap-default - [`f098e67`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f098e670d7e323385b600d2abecabd6256a5237d) Merge branch 'staging' into fix/5585-termux-heap-default - [`f88f1f2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f88f1f2f0306e65dd07d1a5c76181e3e04b7a213) docs: document the unknown-device-memory 1536 MiB heap fallback - [`ed50304`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ed503044a287b2c7e9cfce5d04416cc862920b17) Merge remote-tracking branch 'pasta/staging' into fix/5585-termux-heap-default - [`b1736a1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b1736a1ae066fa9a628c830a70959f92d21e3d14) docs: state the heap change as restored headroom under device caps - [`4cbedfd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4cbedfd54cca8b0a135f41dd29e7b4198633f262) fix(import): tolerate the seeder's empty .native markers in profile restores - [`fad9082`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fad908224b08543305c40366f993b1fdfcff9c70) Merge remote-tracking branch 'pasta/staging' into fix/5585-termux-heap-default ### 📊 Changes **6 files changed** (+62 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `android/README.md` (+1 -1) 📝 `packages/server/src/services/import/profile-import-assets.ts` (+13 -1) 📝 `scripts/regressions/launcher/format-guard.regression.mjs` (+5 -2) 📝 `scripts/regressions/profile-import-asset-security.regression.ts` (+29 -0) 📝 `start-termux.sh` (+12 -9) </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`. ## Linked issue Closes #5585 Closes #5619 ## Why this change - Since v2.4.4, Termux installs with large structured profiles crash with `FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory` (exit 134) during normal chat use. v2.4.4 replaced the flat 2 GiB launcher heap default with an adaptive default computed as on-disk profile size + a flat 512 MiB allowance, hard-capped at 1536 MiB (#5471, #5515). That model undershoots real heap need: the file-backed store keeps every row in memory, V8's object representation runs well above the serialized JSON byte size, and flushes serialize dirty tables on top of the live rows. A profile that ran comfortably inside the old 2 GiB default can exceed 1536 MiB and abort. - The reporter's setup is literally the pinned regression fixture: `resolve_default_node_heap_mb 1153434 8388608` (a ~1.1 GiB profile on an 8 GiB device) resolved 1536, and their diagnostics show a 1632 MiB heap limit (`--max-old-space-size=1536` plus V8's non-old spaces) with 1097 MiB already in use shortly after a restart, then a Mark-Compact at 1594 MiB reclaiming only ~82 MB before the abort — a live working set, not garbage churn. - I also swept the whole v2.4.3..v2.4.4 server diff for a genuine leak before touching the launcher: no unbounded live-retention accumulator landed in that window (the only new module-level container in the entire server is the bounded `fileTableShardStrategies` map). The regression is the heap budget, not a leak. - Folded in per maintainer decision: restoring a full profile backup fails on the game-asset seeder's own `.native` directory markers. `ensureNativeMarkers` (seed-game-assets.ts) writes an empty `.native` file into every bundled asset directory, profile export archives those directories verbatim, and the 2.4.4 import asset validation rejects the marker as an unsupported image under `game-assets/sprites/`, aborting the entire restore — fatal for a user restoring onto a fresh device (#5619, reported on Discord). ## What changed - `start-termux.sh`: `resolve_default_node_heap_mb` now budgets roughly **twice** the on-disk structured profile plus 512 MiB of headroom (still 128 MiB steps, still the 1 GiB floor). The quarter-of-physical-RAM device cap remains the small-phone bound and now also enforces the 1 GiB floor on very low-RAM devices; the conservative flat 1536 MiB clamp applies only when `/proc/meminfo` cannot be read. Explicit `NODE_OPTIONS` heap limits remain authoritative, and the flat 2 GiB automatic default stays gone — a large grant now requires a device whose RAM justifies it. - `scripts/regressions/launcher/format-guard.regression.mjs`: the reporter-shaped fixture (~1.1 GiB profile, 8 GiB device) now expects 2048; added fixtures for a mid-size profile (1536), a 3 GiB device (floored at 1024), and unknown device memory (clamped at 1536). Zero-profile and 4 GiB-device fixtures are unchanged at 1024. - `android/README.md`: updated the heap-selection description. - `CHANGELOG.md`: Unreleased fix entry. Resolved defaults before → after: ~1.1 GiB profile / 8 GiB device: 1536 → **2048** (what pre-2.4.4 gave it). Fresh install / 8 GiB: 1024 → 1024. ~1.1 GiB profile / 4 GiB device: 1024 → 1024. ~1.1 GiB profile / unknown RAM: 1536 → 1536. - `packages/server/src/services/import/profile-import-assets.ts`: import now tolerates exactly the seeder's marker — a file named `.native` under `game-assets/`, only when empty — and keeps image validation for everything else; a non-empty file using the marker name is still rejected, so the smuggling posture is unchanged. - `scripts/regressions/profile-import-asset-security.regression.ts`: two new cases — empty `.native` markers under `game-assets/sprites/` and `game-assets/backgrounds/pack/` stage successfully; a non-empty `.native` is rejected. - `CHANGELOG.md`: Unreleased fix entry for #5619. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Ran `node scripts/run-regressions.mjs --filter profile-import-asset-security` locally — passes with the new `.native` marker cases. - Ran `pnpm check` locally (passes). - Ran the full `regression:launcher-update` lane script-by-script (all seven pass, including the format guard with the new heap fixtures). - The Docker/EasyPanel deploy path does not execute `start-termux.sh`, so the running-app checks don't exercise this change; the launcher regression lane is the executable coverage. - The Playwright smoke lanes (desktop-chromium, mobile-chromium, mobile-webkit) fail on this PR the same way they fail on the current `staging` head run (different flaky client e2e cases per run); this PR touches no client or server code, so those lanes cannot exercise it. `complete-node-regressions`, `pnpm-validate`, and `container-build-test` are green. - Still needs a real-device confirmation: a Termux install with a large profile should log `Node.js heap limit set to 2048 MiB for this profile and device` on an 8 GiB phone and survive a long chat session. I'd appreciate the reporter confirming on their device once this lands on `staging`. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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) ## UI evidence (if applicable) Not applicable — Termux launcher and regression fixtures only. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved default Node.js heap sizing in Termux based on profile storage and available device memory. * Added safeguards for low-memory and unknown-memory devices. * Preserved support for explicit `NODE_OPTIONS` overrides. * Fixed profile backup restoration for valid empty game-asset markers while rejecting conflicting files. * **Documentation** * Updated Termux memory-sizing documentation and the unreleased changelog. * **Tests** * Expanded regression coverage for memory limits and profile asset validation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:14:10 +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#6837
No description provided.