mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #4730] Server crashes with "JavaScript heap out of memory" on Android/Termux every few messages in large installs #2597
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#2597
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Aug 7, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4730
Originally assigned to: @SpicyMarinara on GitHub.
From a user report (Android, Termux, staging): sending a message shows "Failed to fetch" in the chat UI, and the Termux terminal shows the backend dying with:
It happens every few messages. Their GC trace is the important clue — about 100 seconds after a fresh restart, a full Mark-Compact still had ~1010 MB live, against a heap limit of ~1 GB:
So this is not a leak — the install's data no longer fits in the heap V8 picked on that phone, and normal per-message allocation spikes push it over the edge.
Three things stack up
The file-native store keeps every table in memory. All of
data/storage/tables/*.jsonis loaded at boot and stays resident (packages/server/src/db/file-backed-store.ts). A long-running roleplay install (large message history, swipes, summary history, long-term memory) produces a permanent live set of many hundreds of MB.No launcher sets a heap size. There is no
--max-old-space-size/NODE_OPTIONSanywhere instart.sh,start.bat,start-termux.sh, or the Android docs. Node falls back to V8's physical-memory heuristic, which on phones lands around 1 GB — far less than desktops get, on exactly the platform where installs are hardest to debug.Per-message allocation spikes are proportional to total table size, not message size.
const nextRows = target.map(cloneRow)(file-backed-store.ts:1100, also the update path at:1144). On a messages table with tens of thousands of rows, that's a full-array copy several times per send. (Pattern introduced in37bb8f758, "Enforce file-native unique keys".)JSON.stringify(rows)(file-backed-store.ts:1445insaveFileSnapshots). For a big messages table that is a single allocation of hundreds of MB.With a ~800 MB baseline and a ~1 GB cap, whichever send happens to coincide with a flush dies. That's why it fails "every few messages" instead of deterministically.
Try it yourself
On any machine, artificially shrink the heap to phone scale and use a large profile (or generate one — a chat with tens of thousands of messages):
Send messages in a large roleplay chat. Within a few sends, the flush after a generation OOMs the server the same way the Termux trace shows.
Suggested directions
start.sh/start.bat/start-termux.shcan exportNODE_OPTIONS="--max-old-space-size=..."(respecting a user-provided value), sized from available RAM. Even a flat 2048 on Android would have absorbed this user's workload.JSON.stringifyof the whole table. The profile-ZIP exporter already writes JSONL per table (backup.routes.ts), so there's precedent and a reader for the format.Workaround for affected users (worth adding to docs/TROUBLESHOOTING.md)
In Termux, before launching:
(Use 3072 on phones with 8 GB+ RAM. Add the
exportto~/.bashrcto make it permanent.)@SpicyMarinara commented on GitHub (Aug 7, 2026):
SpicyMarinara/Codex is implementing this in draft PR #4736 on
agent/assigned-issues-4718-4734.