[GH-ISSUE #8895] [Issue]: [Bug] JavaScript heap OOM and full-table residency despite chat memory cap (v2.5.1) #8542

Closed
opened 2026-11-07 16:43:40 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @tlsiddl on GitHub (Nov 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8895

Summary

Marinara Engine v2.5.1 repeatedly crashes with JavaScript heap out-of-memory errors during roleplay generation, causing HTTP 502 errors and automatic Docker restarts.

Logs also show that 21 lazy-loaded storage tables repeatedly become fully resident, potentially defeating MARINARA_MAX_RESIDENT_CHATS=8.

Expected behavior

  • Roleplay generation should not cause repeated server crashes.
  • Lazy-loaded chat tables should remain eligible for memory eviction.
  • Automatic backups should ideally avoid permanently loading all chat data into memory.
  • Memory-constrained installations should be able to use the resident chat cap effectively.

Actual behavior

During normal roleplay generation, the server intermittently returns HTTP 502 and the Docker container automatically restarts.

Observed results:

  • Docker restart count increased from 25 to 27 during testing.
  • Docker recorded abnormal process exits with code 134.
  • V8 repeatedly reported Reached heap limit.
  • Garbage collection failed to reclaim significant memory at approximately 815–816 MB of heap usage.
  • Setting MARINARA_MAX_RESIDENT_CHATS=8 did not prevent subsequent crashes.
  • Logs showed 21 lazy tables becoming fully resident approximately 25–26 times each over the collected log period.

Affected tables include messages, message_swipes, memory_chunks, advanced_memory_records, agent_runs, chat_images, and several game-state tables.

Steps to reproduce

The following describes the environment and observed sequence. The issue has not yet been reproduced on a clean installation.

  1. Run Marinara Engine v2.5.1 in Docker on a Linux VPS with approximately 1.6 GiB RAM and 2.3 GiB swap, using an existing large profile and additional runtime extensions.
  2. Enable automatic backups and configure MARINARA_MAX_RESIDENT_CHATS=8.
  3. Open an existing roleplay conversation and generate responses.
  4. Observe intermittent HTTP 502 errors and container restarts.
  5. Inspect Docker logs for JavaScript heap OOM errors and Lazy table ... is now fully resident (unbounded access) messages.

Environment

  • Marinara Engine version: v2.5.1
  • Install type: Docker
  • OS + version: Linux VPS (distribution/version not yet confirmed)
  • Browser or app shell: Web browser
  • RAM: 1.6 GiB
  • Swap: 2.3 GiB
  • Node.js heap limit: Approximately 915 MB, measured in a separate Node.js process
  • Storage: File-backed storage
  • Resident chat cap: 8
  • Additional runtime extensions and preload patches are installed

Logs, screenshots, or video

V8 heap errors

Mark-Compact (reduce) 815.8 (825.2) -> 815.8 (822.2) MB
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Mark-Compact 815.1 (823.0) -> 815.0 (827.2) MB
Mark-Compact 816.0 (828.2) -> 815.8 (828.2) MB
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Full-table residency log counts

25 Lazy table advanced_memory_records is now fully resident
26 Lazy table agent_memory is now fully resident
26 Lazy table agent_runs is now fully resident
26 Lazy table chat_images is now fully resident
26 Lazy table conversation_call_messages is now fully resident
26 Lazy table conversation_call_sessions is now fully resident
25 Lazy table conversation_notes is now fully resident
26 Lazy table game_checkpoints is now fully resident
26 Lazy table game_dice_pools is now fully resident
26 Lazy table game_engine_state is now fully resident
26 Lazy table game_scene_videos is now fully resident
26 Lazy table game_state_snapshots is now fully resident
26 Lazy table game_turn_storyboards is now fully resident
26 Lazy table game_world_snapshots is now fully resident
25 Lazy table mari_workspace_context is now fully resident
25 Lazy table memory_chunks is now fully resident
26 Lazy table messages is now fully resident
26 Lazy table message_swipes is now fully resident
26 Lazy table message_trash is now fully resident
25 Lazy table ooc_influences is now fully resident
26 Lazy table spatial_context_snapshots is now fully resident

Automatic backup failure

[backup] Automatic backup failed
Not enough free space for the automatic backup:
1.5 GiB free, about 3.7 GiB needed.

Disk usage was subsequently reduced from 97% to 46%, but the heap OOM crashes continued.

Additional context

Possible cause: unscoped reads during automatic backup

In v2.5.1, buildProfileArchiveSources() in packages/server/src/routes/backup.routes.ts iterates over FILE_BACKED_TABLES and performs an unscoped read:

const rows = (await app.db.select().from(table as any)) as Array<Record<string, unknown>>;

In file-backed-store.ts, an unscoped query may call ensureTableLoaded(), causing a lazy table to become fully resident for the lifetime of the process.

The automatic backup path invokes buildProfileArchiveSources(). This appears to be a plausible explanation for the repeated full-table residency messages.

However, the causal relationship between automatic backups, full-table residency, and the OOM crashes has not yet been conclusively established. Other unscoped queries, extensions, or memory-intensive generation operations may also contribute.

It may be worth investigating whether profile backup/export operations can read table data in bounded batches or use a streaming approach without permanently leasing every lazy table.

  • #5611 — Remaining unscoped queries silently make lazy tables fully resident (defeats the chat memory cap)

Request

Could the maintainers investigate whether automatic backup operations or other unscoped queries are causing excessive table residency and heap exhaustion?

Sanitized diagnostics can be provided if needed. Full logs may contain private roleplay content and API configuration details.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @tlsiddl on GitHub (Nov 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8895 ## Summary Marinara Engine v2.5.1 repeatedly crashes with JavaScript heap out-of-memory errors during roleplay generation, causing HTTP 502 errors and automatic Docker restarts. Logs also show that 21 lazy-loaded storage tables repeatedly become fully resident, potentially defeating `MARINARA_MAX_RESIDENT_CHATS=8`. ## Expected behavior - Roleplay generation should not cause repeated server crashes. - Lazy-loaded chat tables should remain eligible for memory eviction. - Automatic backups should ideally avoid permanently loading all chat data into memory. - Memory-constrained installations should be able to use the resident chat cap effectively. ## Actual behavior During normal roleplay generation, the server intermittently returns HTTP 502 and the Docker container automatically restarts. Observed results: - Docker restart count increased from 25 to 27 during testing. - Docker recorded abnormal process exits with code `134`. - V8 repeatedly reported `Reached heap limit`. - Garbage collection failed to reclaim significant memory at approximately 815–816 MB of heap usage. - Setting `MARINARA_MAX_RESIDENT_CHATS=8` did not prevent subsequent crashes. - Logs showed 21 lazy tables becoming fully resident approximately 25–26 times each over the collected log period. Affected tables include `messages`, `message_swipes`, `memory_chunks`, `advanced_memory_records`, `agent_runs`, `chat_images`, and several game-state tables. ## Steps to reproduce The following describes the environment and observed sequence. The issue has not yet been reproduced on a clean installation. 1. Run Marinara Engine v2.5.1 in Docker on a Linux VPS with approximately 1.6 GiB RAM and 2.3 GiB swap, using an existing large profile and additional runtime extensions. 2. Enable automatic backups and configure `MARINARA_MAX_RESIDENT_CHATS=8`. 3. Open an existing roleplay conversation and generate responses. 4. Observe intermittent HTTP 502 errors and container restarts. 5. Inspect Docker logs for JavaScript heap OOM errors and `Lazy table ... is now fully resident (unbounded access)` messages. ## Environment - Marinara Engine version: **v2.5.1** - Install type: **Docker** - OS + version: **Linux VPS (distribution/version not yet confirmed)** - Browser or app shell: **Web browser** - RAM: **1.6 GiB** - Swap: **2.3 GiB** - Node.js heap limit: **Approximately 915 MB**, measured in a separate Node.js process - Storage: **File-backed storage** - Resident chat cap: **8** - Additional runtime extensions and preload patches are installed ## Logs, screenshots, or video **V8 heap errors** ```text Mark-Compact (reduce) 815.8 (825.2) -> 815.8 (822.2) MB FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory Mark-Compact 815.1 (823.0) -> 815.0 (827.2) MB Mark-Compact 816.0 (828.2) -> 815.8 (828.2) MB FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory ``` **Full-table residency log counts** ```text 25 Lazy table advanced_memory_records is now fully resident 26 Lazy table agent_memory is now fully resident 26 Lazy table agent_runs is now fully resident 26 Lazy table chat_images is now fully resident 26 Lazy table conversation_call_messages is now fully resident 26 Lazy table conversation_call_sessions is now fully resident 25 Lazy table conversation_notes is now fully resident 26 Lazy table game_checkpoints is now fully resident 26 Lazy table game_dice_pools is now fully resident 26 Lazy table game_engine_state is now fully resident 26 Lazy table game_scene_videos is now fully resident 26 Lazy table game_state_snapshots is now fully resident 26 Lazy table game_turn_storyboards is now fully resident 26 Lazy table game_world_snapshots is now fully resident 25 Lazy table mari_workspace_context is now fully resident 25 Lazy table memory_chunks is now fully resident 26 Lazy table messages is now fully resident 26 Lazy table message_swipes is now fully resident 26 Lazy table message_trash is now fully resident 25 Lazy table ooc_influences is now fully resident 26 Lazy table spatial_context_snapshots is now fully resident ``` **Automatic backup failure** ```text [backup] Automatic backup failed Not enough free space for the automatic backup: 1.5 GiB free, about 3.7 GiB needed. ``` Disk usage was subsequently reduced from 97% to 46%, but the heap OOM crashes continued. ## Additional context ### Possible cause: unscoped reads during automatic backup In v2.5.1, `buildProfileArchiveSources()` in `packages/server/src/routes/backup.routes.ts` iterates over `FILE_BACKED_TABLES` and performs an unscoped read: ```ts const rows = (await app.db.select().from(table as any)) as Array<Record<string, unknown>>; ``` In `file-backed-store.ts`, an unscoped query may call `ensureTableLoaded()`, causing a lazy table to become fully resident for the lifetime of the process. The automatic backup path invokes `buildProfileArchiveSources()`. This appears to be a plausible explanation for the repeated full-table residency messages. However, **the causal relationship between automatic backups, full-table residency, and the OOM crashes has not yet been conclusively established**. Other unscoped queries, extensions, or memory-intensive generation operations may also contribute. It may be worth investigating whether profile backup/export operations can read table data in bounded batches or use a streaming approach without permanently leasing every lazy table. ### Related issue - #5611 — Remaining unscoped queries silently make lazy tables fully resident (defeats the chat memory cap) ### Request Could the maintainers investigate whether automatic backup operations or other unscoped queries are causing excessive table residency and heap exhaustion? Sanitized diagnostics can be provided if needed. Full logs may contain private roleplay content and API configuration details. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-11-07 16:43:40 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@SpicyMarinara commented on GitHub (Nov 5, 2026):

After the new release.

<!-- gh-comment-id:6668090417 --> @SpicyMarinara commented on GitHub (Nov 5, 2026): After the new release.
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#8542
No description provided.