[GH-ISSUE #1778] [Issue]: Prompt snapshots are never evicted — unbounded per-chat storage growth (regression vs 1.6.1, all modes) #861

Closed
opened 2026-10-21 05:22:32 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @JorgeLTE on GitHub (Jun 1, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1778

Originally assigned to: @JorgeLTE on GitHub.

Summary

In the refactor, a full generation prompt snapshot is saved on every assistant message (and every swipe) and is never evicted, so per-chat storage grows without bound. v1.6.1 kept the snapshot only for the last 2 assistant messages; that eviction was dropped during the migration.

Expected behavior

Match v1.6.1: retain the saved prompt snapshot only for the most recent assistant messages (last 2). Older messages keep their text but drop the snapshot, and the prompt inspector shows "No saved prompt snapshot" for them.

Actual behavior

Every assistant message keeps its full prompt snapshot forever, in all three modes (conversation, roleplay, game). Because each snapshot embeds the entire assembled prompt up to that point (system + cards + lorebook + full history-to-date), storage grows roughly quadratically with conversation length, and the per-message generationPromptSnapshotsBySwipe map plus per-swipe copies compound it. This bloats the local DB and especially the Download Backup. (Imported 1.6.1 chats are unaffected — 1.6.1 already evicted to last-2 before export.)

Steps to reproduce

  1. Open a chat in the refactor (any mode) and generate a long run of assistant messages, with some swipes/regenerations.
  2. Open the prompt inspector on older assistant messages → every message still shows a saved prompt (in 1.6.1, only the last 2 did).
  3. Inspect the on-disk message records / a Download Backup → every assistant message retains extra.generationPromptSnapshot (and a generationPromptSnapshotsBySwipe map), and backup size grows disproportionately with chat length.

Environment

  • Marinara Engine version: refactor branch
  • Install type: source
  • OS + version: Windows 10

Logs, screenshots, or video

N/A — observable as growing DB / backup size and as old messages retaining inspectable prompts.

Additional context

Root cause: v1.6.1 evicted extra.cachedPrompt from all but the last 2 assistant messages on every generation (generate.routes.ts:8103), inside the shared persistence block (not mode-gated, so it applied to all three modes). The refactor renamed the field to extra.generationPromptSnapshot / generationPromptSnapshotsBySwipe but never ported the eviction, so native chats accumulate a snapshot per message and per swipe.

Separately noted: generationPromptSnapshotsBySwipe is written on every generation but stripped from every read path that reaches the inspector (Rust timeline whitelist + TS sanitizeTimelineMessageRecord / savedGenerationEventData), so it is effectively vestigial/half-wired — a candidate for a separate cleanup.

Fix: re-introduce v1.6.1's keep-last-2 eviction at the shared generation-commit path, clearing snapshots from older assistant messages (message extra + by-swipe map + each swipe's extra), non-destructive to legacy cachedPrompt.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @JorgeLTE on GitHub (Jun 1, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1778 Originally assigned to: @JorgeLTE on GitHub. ## Summary In the refactor, a full generation prompt snapshot is saved on every assistant message (and every swipe) and is never evicted, so per-chat storage grows without bound. v1.6.1 kept the snapshot only for the last 2 assistant messages; that eviction was dropped during the migration. ## Expected behavior Match v1.6.1: retain the saved prompt snapshot only for the most recent assistant messages (last 2). Older messages keep their text but drop the snapshot, and the prompt inspector shows "No saved prompt snapshot" for them. ## Actual behavior Every assistant message keeps its full prompt snapshot forever, in all three modes (conversation, roleplay, game). Because each snapshot embeds the entire assembled prompt up to that point (system + cards + lorebook + full history-to-date), storage grows roughly quadratically with conversation length, and the per-message `generationPromptSnapshotsBySwipe` map plus per-swipe copies compound it. This bloats the local DB and especially the Download Backup. (Imported 1.6.1 chats are unaffected — 1.6.1 already evicted to last-2 before export.) ## Steps to reproduce 1. Open a chat in the refactor (any mode) and generate a long run of assistant messages, with some swipes/regenerations. 2. Open the prompt inspector on older assistant messages → every message still shows a saved prompt (in 1.6.1, only the last 2 did). 3. Inspect the on-disk message records / a Download Backup → every assistant message retains `extra.generationPromptSnapshot` (and a `generationPromptSnapshotsBySwipe` map), and backup size grows disproportionately with chat length. ## Environment - Marinara Engine version: refactor branch - Install type: source - OS + version: Windows 10 ## Logs, screenshots, or video N/A — observable as growing DB / backup size and as old messages retaining inspectable prompts. ## Additional context Root cause: v1.6.1 evicted `extra.cachedPrompt` from all but the last 2 assistant messages on every generation (`generate.routes.ts:8103`), inside the shared persistence block (not mode-gated, so it applied to all three modes). The refactor renamed the field to `extra.generationPromptSnapshot` / `generationPromptSnapshotsBySwipe` but never ported the eviction, so native chats accumulate a snapshot per message and per swipe. Separately noted: `generationPromptSnapshotsBySwipe` is written on every generation but stripped from every read path that reaches the inspector (Rust timeline whitelist + TS `sanitizeTimelineMessageRecord` / `savedGenerationEventData`), so it is effectively vestigial/half-wired — a candidate for a separate cleanup. Fix: re-introduce v1.6.1's keep-last-2 eviction at the shared generation-commit path, clearing snapshots from older assistant messages (message extra + by-swipe map + each swipe's extra), non-destructive to legacy `cachedPrompt`. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:22:32 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@JorgeLTE commented on GitHub (Jun 1, 2026):

Merged!

<!-- gh-comment-id:4590289813 --> @JorgeLTE commented on GitHub (Jun 1, 2026): Merged!
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#861
No description provided.