[GH-ISSUE #6288] Deleted chat messages leave agent-written lorebook entries live (no attribution, no cascade) #3508

Closed
opened 2026-10-21 06:03:46 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Ejmathewp on GitHub (Sep 17, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6288

Originally assigned to: @SpicyMarinara on GitHub.

Symptom

After deleting an assistant message (or regenerating/swiping it away), subsequent generations are still steered by "facts" the lorebook-keeper extracted from the deleted turn. Entries keep being injected into the prompt — including when the keeper rewrote an older, innocent entry in place, so even triaging entries by creation date misses carriers — and the model argues with the user's corrections using current-state lore that no longer has a source.

Root cause

  1. DELETE /api/chats/:chatId/messages/:messageId -> storage.removeMessage() (packages/server/src/services/storage/chats.storage.ts) only:

    • deletes local memoryChunks via invalidateMemoryChunksFrom() (memory-recall layer)
    • deletes game state rows

    Advanced Memory records are NOT the problem: recordValid() in packages/server/src/services/advanced-memory.ts fingerprints covered message ids and self-invalidates records when a source message disappears.

  2. Agent lorebook writes have no message linkage:

    • createLorebookEntryWriter (packages/server/src/services/generation/tool-resolution-runtime.ts) persists via lorebooksStore.createEntry() — no source-message field on entries.
    • The keeper also updates existing entries in place with new "current state" derived from the latest generation.

    Message deletion therefore never cascades to these entries. Same gap on the regenerate/swipe-discard path: entries written during a discarded attempt survive it.

Proposed fix

  1. Attribute: store the covering message-id range (or generation receipt) on every agent-written lorebook entry (schema + createEntry/updateEntry).
  2. Cascade: in removeMessage/removeMessages (and the swipe/regenerate path), stale-mark or delete agent-authored entries whose source range intersects the removed messages (manual entries left untouched).
  3. UX: expose entry-to-source linkage so the UI can offer "purge lore from deleted message" instead of silent orphaning.

Workaround until fixed

Treat message deletion and lore purge as one manual operation: find entries created (or updated) at the deleted generation's timestamp, delete/patch them, then POST /api/generate/dryRun {"chatId":"...","returnPrompt":true} and grep the joined prompt to confirm the content is gone.

Originally created by @Ejmathewp on GitHub (Sep 17, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6288 Originally assigned to: @SpicyMarinara on GitHub. ## Symptom After deleting an assistant message (or regenerating/swiping it away), subsequent generations are still steered by "facts" the lorebook-keeper extracted from the deleted turn. Entries keep being injected into the prompt — including when the keeper rewrote an older, innocent entry in place, so even triaging entries by creation date misses carriers — and the model argues with the user's corrections using current-state lore that no longer has a source. ## Root cause 1. `DELETE /api/chats/:chatId/messages/:messageId` -> `storage.removeMessage()` (`packages/server/src/services/storage/chats.storage.ts`) only: - deletes local memoryChunks via `invalidateMemoryChunksFrom()` (memory-recall layer) - deletes game state rows Advanced Memory records are NOT the problem: `recordValid()` in `packages/server/src/services/advanced-memory.ts` fingerprints covered message ids and self-invalidates records when a source message disappears. 2. Agent lorebook writes have no message linkage: - `createLorebookEntryWriter` (`packages/server/src/services/generation/tool-resolution-runtime.ts`) persists via `lorebooksStore.createEntry()` — no source-message field on entries. - The keeper also updates existing entries in place with new "current state" derived from the latest generation. Message deletion therefore never cascades to these entries. Same gap on the regenerate/swipe-discard path: entries written during a discarded attempt survive it. ## Proposed fix 1. **Attribute**: store the covering message-id range (or generation receipt) on every agent-written lorebook entry (schema + `createEntry`/`updateEntry`). 2. **Cascade**: in `removeMessage`/`removeMessages` (and the swipe/regenerate path), stale-mark or delete agent-authored entries whose source range intersects the removed messages (manual entries left untouched). 3. **UX**: expose entry-to-source linkage so the UI can offer "purge lore from deleted message" instead of silent orphaning. ## Workaround until fixed Treat message deletion and lore purge as one manual operation: find entries created (or updated) at the deleted generation's timestamp, delete/patch them, then `POST /api/generate/dryRun {"chatId":"...","returnPrompt":true}` and grep the joined prompt to confirm the content is gone.
bsakaguchi 2026-10-21 06:03:46 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Sep 17, 2026):

Implemented in #6289 and included in the staging sweep #6295. Agent lore now records message/swipe sources; deletion removes new entries or restores the prior snapshot, inactive swipes are excluded, and human edits are preserved. Regression coverage includes tool writes made before the reply is saved, scoped and partial bulk deletion, concurrent metadata edits and stale embeddings. Legacy entries without provenance are preserved because their sources cannot be reconstructed reliably.

<!-- gh-comment-id:5721305216 --> @SpicyMarinara commented on GitHub (Sep 17, 2026): Implemented in #6289 and included in the staging sweep #6295. Agent lore now records message/swipe sources; deletion removes new entries or restores the prior snapshot, inactive swipes are excluded, and human edits are preserved. Regression coverage includes tool writes made before the reply is saved, scoped and partial bulk deletion, concurrent metadata edits and stale embeddings. Legacy entries without provenance are preserved because their sources cannot be reconstructed reliably.
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#3508
No description provided.