[GH-ISSUE #3022] [Issue]: Conversation-mode generation permanently deletes character memories older than today, destroying "permanent" scene memories and breaking weekly schedule continuity #1592

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

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
Every conversation-mode generation silently and permanently deletes any character memory created on a previous calendar day. These memories are explicitly created as permanent — scene-conclusion memories ("[Scene on ...]") and in-chat [memory] commands — and other features depend on them lasting for at least a week. After the first next-day conversation generation, a character's prior-day memories are gone from durable storage, and weekly schedule continuity stops working.

How to reproduce (try it yourself)

  1. In a conversation chat, give a character a memory: run a scene that concludes and stores "[Scene on ...]" memories, or trigger a [memory:] command, so character.extensions.characterMemories gets an entry with createdAt = yesterday.
  2. Advance to the next calendar day (or set the clock forward past local midnight).
  3. Send any message in a conversation-mode chat with that character to trigger a normal generation.
  4. Inspect the character card's characterMemories.

You'll see: the prior-day memory is permanently gone; mergeConversationCharacterMemories computed validMemories = [] and wrote the pruned (empty) array back via chars.update. Subsequent weekly-schedule regeneration no longer sees it.
Expected: same-day memories surface in the prompt's <awareness> block, but stored memories are left intact so scene history, the [memory] command, and schedule continuity keep working.

Where it is
packages/server/src/services/generation/conversation-memory-context.ts:44-48 — line 44 filters to today-or-newer (validMemories), and lines 45-48 write that pruned list back to durable storage via chars.update. The function spans lines 15-62; the emit loop is 50-52.
Supporting: chars.update -> mergeCharacterData (packages/server/src/services/storage/characters.storage.ts:47-67) overwrites the array because mergeExtensions defaults to true, and persists via JSON.stringify (lines 203-249). Sole caller: generate.routes.ts:4354-4360 (gated on chatMode === "conversation"). Durable producers: scene.routes.ts:437-459, generate.routes.ts:9638-9653. Broken consumer: buildScheduleContinuityContext at conversation.routes.ts:326-338, which reads back to the start of the previous week.

What's happening
The function conflates "which memories to surface in today's awareness block" with "which memories to keep in storage." The today-midnight cutoff is correctly used to choose prompt lines, but the same filtered array is also persisted back to the character store. Because the memories carry full ISO timestamps from arbitrary prior days and are treated as durable by the rest of the system, writing the pruned array back is data loss, not a view filter.

Suggested fix
Delete the storage write-back; keep the today filter as an in-prompt freshness selector only. In packages/server/src/services/generation/conversation-memory-context.ts, remove lines 45-48:

if (validMemories.length !== memories.length) {
  const extensions = { ...(charData.extensions ?? {}), characterMemories: validMemories };
  await chars.update(characterId, { extensions });
}

Keep line 44 (const validMemories = memories.filter((memory) => new Date(memory.createdAt) >= today);) and the emit loop at 50-52 unchanged, so only same-day memories still surface in the <awareness> ## Memories section while the stored array is left intact. This is the minimal surgical change; nothing in the system depends on the destructive write-back. Do not substitute a different retention/pruning policy here — durable retention is not this function's responsibility, and any destructive policy risks the same data loss against scene history and the [memory] command.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3022 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** Every conversation-mode generation silently and permanently deletes any character memory created on a previous calendar day. These memories are explicitly created as permanent — scene-conclusion memories ("[Scene on ...]") and in-chat `[memory]` commands — and other features depend on them lasting for at least a week. After the first next-day conversation generation, a character's prior-day memories are gone from durable storage, and weekly schedule continuity stops working. **How to reproduce (try it yourself)** 1. In a conversation chat, give a character a memory: run a scene that concludes and stores "[Scene on ...]" memories, or trigger a `[memory:]` command, so `character.extensions.characterMemories` gets an entry with `createdAt` = yesterday. 2. Advance to the next calendar day (or set the clock forward past local midnight). 3. Send any message in a conversation-mode chat with that character to trigger a normal generation. 4. Inspect the character card's `characterMemories`. You'll see: the prior-day memory is permanently gone; `mergeConversationCharacterMemories` computed `validMemories = []` and wrote the pruned (empty) array back via `chars.update`. Subsequent weekly-schedule regeneration no longer sees it. Expected: same-day memories surface in the prompt's `<awareness>` block, but stored memories are left intact so scene history, the `[memory]` command, and schedule continuity keep working. **Where it is** `packages/server/src/services/generation/conversation-memory-context.ts:44-48` — line 44 filters to today-or-newer (`validMemories`), and lines 45-48 write that pruned list back to durable storage via `chars.update`. The function spans lines 15-62; the emit loop is 50-52. Supporting: `chars.update` -> `mergeCharacterData` (`packages/server/src/services/storage/characters.storage.ts:47-67`) overwrites the array because `mergeExtensions` defaults to true, and persists via `JSON.stringify` (lines 203-249). Sole caller: `generate.routes.ts:4354-4360` (gated on `chatMode === "conversation"`). Durable producers: `scene.routes.ts:437-459`, `generate.routes.ts:9638-9653`. Broken consumer: `buildScheduleContinuityContext` at `conversation.routes.ts:326-338`, which reads back to the start of the previous week. **What's happening** The function conflates "which memories to surface in today's awareness block" with "which memories to keep in storage." The today-midnight cutoff is correctly used to choose prompt lines, but the same filtered array is also persisted back to the character store. Because the memories carry full ISO timestamps from arbitrary prior days and are treated as durable by the rest of the system, writing the pruned array back is data loss, not a view filter. **Suggested fix** Delete the storage write-back; keep the today filter as an in-prompt freshness selector only. In `packages/server/src/services/generation/conversation-memory-context.ts`, remove lines 45-48: ```ts if (validMemories.length !== memories.length) { const extensions = { ...(charData.extensions ?? {}), characterMemories: validMemories }; await chars.update(characterId, { extensions }); } ``` Keep line 44 (`const validMemories = memories.filter((memory) => new Date(memory.createdAt) >= today);`) and the emit loop at 50-52 unchanged, so only same-day memories still surface in the `<awareness>` ## Memories section while the stored array is left intact. This is the minimal surgical change; nothing in the system depends on the destructive write-back. Do not substitute a different retention/pruning policy here — durable retention is not this function's responsibility, and any destructive policy risks the same data loss against scene history and the `[memory]` command. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed on staging in PR #3031 (merged as f542e282). Closing manually because GitHub auto-close keywords only close issues when merged into the default branch (main), not staging.

<!-- gh-comment-id:4834695914 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed on staging in PR #3031 (merged as f542e282). Closing manually because GitHub auto-close keywords only close issues when merged into the default branch (main), not staging.
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#1592
No description provided.