[GH-ISSUE #2305] [Issue]: 09-CHAT-RUNTIME-memory-recall-chunks stale after edits/swipes and partial rebuilds #1141

Closed
opened 2026-10-21 05:27:44 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

`09-CHAT-RUNTIME-memory-recall-chunks`: refactor Memory Recall stores chunks in the chat `memories` array and exposes the list/rebuild/delete/clear UI, but it does not preserve legacy invalidation/rebuild semantics after message edits or swipe-visible-content changes. Refactor rebuild also writes a partial newest chunk, while legacy only created complete 5-message chunks.

Linked parity tracker: #2268.

Expected behavior

Legacy behavior should be preserved for `09-CHAT-RUNTIME-memory-recall-chunks`:

  • Editing a visible message should remove, prune, or rebuild any local Memory Recall chunk at or after the edited message timestamp before stale text can be recalled.
  • Adding an active swipe, switching the active swipe, or deleting the active swipe should invalidate local chunks for the affected message when the visible message content changes.
  • Manual and generation-triggered rebuild should match legacy chunking semantics: store complete 5-message chunks and leave newest incomplete groups unchunked until enough eligible messages exist.
  • List/delete/clear/rebuild UI and embedded/remote command paths should continue to work.
  • Existing delete/bulk-delete cleanup from #2293 should remain compatible with the same invalidation helper or storage path.
  • Add focused Rust/storage proof or equivalent local harness covering edit, swipe active-content change, and incomplete-newest-group rebuild behavior.

Actual behavior

Refactor has visible controls and command wrappers for Memory Recall list/delete/clear/rebuild, and generation refresh calls `refreshChatMemories` after successful saved generation. However, mutation paths that change already-chunked visible message content do not prune `chat.memories`.

The prompt assembler reads stored memories through `storage.listChatMemories` or `chat.memories`, ranks them, and injects matching content into a `` block. That means stale edited/swiped-away text can remain prompt-visible until a later full rebuild, and manual rebuild can include a partial newest group that legacy would have left pending.

Steps to reproduce

  1. On refactor, create a conversation chat with at least one rebuilt Memory Recall chunk that includes a visible message.
  2. Edit that message, or switch/add/delete the active swipe so the visible message content changes.
  3. Inspect Memory Recall chunks or generate with a query matching the old content.

Expected: affected local chunks are gone or rebuilt, and newest incomplete groups are not stored.

Actual: existing `chat.memories` entries are not invalidated by those mutation paths, and rebuild chunks all visible groups including partial newest chunks.

Impact area

  • App shell, navigation, startup, or providers
  • Catalog resources
  • Chat mode
  • Roleplay mode
  • Game mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Professor Mari or shell tools
  • React-free engine behavior, contracts, agents, or capability ports
  • Shared API wrapper or remote runtime routing
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime
  • Docs, contributor workflow, or templates

Environment

  • Branch or commit: refactor static trace at `refactor@37585ab9` from #2268; rechecked current `refactor` worktree during Batch 14
  • Run mode: Tauri/refactor storage path and embedded/remote invoke path
  • OS + version: not runtime-tested
  • Node + pnpm versions: not runtime-tested
  • Rust version, if relevant: not runtime-tested
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: Memory Recall / prompt assembly

Logs, screenshots, or video

Static parity proof only; no runtime logs.

Files inspected:

  • Legacy `main:packages/shared/src/types/chat.ts:118` defines the public `ChatMemoryChunk` shape and embedding display status.
  • Legacy `main:packages/server/src/db/schema/chats.ts:103` stores Memory Recall chunks in the `memory_chunks` sidecar table.
  • Legacy `main:packages/server/src/services/memory-recall.ts:121` skips chunking until at least 5 unchunked messages exist, and `main:packages/server/src/services/memory-recall.ts:131` only stores complete 5-message groups.
  • Legacy `main:packages/server/src/services/storage/chats.storage.ts:140` defines `invalidateMemoryChunksFrom`.
  • Legacy `main:packages/server/src/services/storage/chats.storage.ts:633` invalidates after message edit.
  • Legacy `main:packages/server/src/services/storage/chats.storage.ts:797` invalidates after active swipe add/switch to new generated content.
  • Legacy `main:packages/server/src/services/storage/chats.storage.ts:832` invalidates after active swipe switch.
  • Legacy `main:packages/server/src/services/storage/chats.storage.ts:900` invalidates after deleting the active swipe.
  • Refactor `src/engine/contracts/types/chat.ts:118` keeps `ChatMemoryChunk` and adds source/message-id metadata fields.
  • Refactor `src/shared/api/chat-command-api.ts:8` exposes Memory Recall commands.
  • Refactor `src/features/catalog/chats/hooks/use-chats.ts:316` wires list/delete/clear/refresh/import/export hooks.
  • Refactor `src/features/modes/shared/chat-ui/components/ChatSettingsDrawer.tsx:6471` renders the Memory Recall modal, including embedding status display at `src/features/modes/shared/chat-ui/components/ChatSettingsDrawer.tsx:6628`.
  • Refactor `src-tauri/src/http_dispatch.rs:543` routes embedded/remote invoke memory commands.
  • Refactor `src-tauri/src/commands/storage/commands/chats.rs:7` exposes list/delete/clear/refresh commands.
  • Refactor `src-tauri/src/commands/storage/chats.rs:781` rebuilds chat-array memories and `src-tauri/src/commands/storage/chats.rs:790` chunks every visible remainder, including partial newest groups.
  • Refactor `src-tauri/src/commands/storage/chats.rs:352`, `src-tauri/src/commands/storage/chats.rs:462`, `src-tauri/src/commands/storage/chats.rs:482`, and `src-tauri/src/commands/storage/chats.rs:564` update message/swipe visible content without pruning `memories`.
  • Refactor `src/engine/generation/prompt-assembly.ts:1835` reads stored memories and `src/engine/generation/prompt-assembly.ts:3048` injects recalled chunks into the prompt.
  • Refactor `src/engine/generation/start-generation.ts:1744` refreshes after generation, but this does not cover immediate edit/swipe mutation invalidation.

Regression notes

This worked on legacy `main`: Memory Recall local chunks were sidecar rows and mutation paths called `invalidateMemoryChunksFrom` when visible message content changed. Refactor moved Memory Recall to chat-array records and did not mirror those invalidation hooks for edit/swipe mutation paths. Delete/bulk-delete stale memory cleanup is already tracked separately by #2293.

Additional context

Surface ID: `09-CHAT-RUNTIME-memory-recall-chunks`.

Batch 14 parityscan result for #2268: gap. Import/export proof stays with Target 20 and was not chased. Provider/embedding transport was not chased beyond confirming refactor exposes lexical/provider embedding status fields and prompt recall consumes stored vectors/content.

Template check

Please uncheck 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 @Promansis on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2305 Originally assigned to: @Promansis on GitHub. ## Summary \`09-CHAT-RUNTIME-memory-recall-chunks\`: refactor Memory Recall stores chunks in the chat \`memories\` array and exposes the list/rebuild/delete/clear UI, but it does not preserve legacy invalidation/rebuild semantics after message edits or swipe-visible-content changes. Refactor rebuild also writes a partial newest chunk, while legacy only created complete 5-message chunks. Linked parity tracker: #2268. ## Expected behavior Legacy behavior should be preserved for \`09-CHAT-RUNTIME-memory-recall-chunks\`: - Editing a visible message should remove, prune, or rebuild any local Memory Recall chunk at or after the edited message timestamp before stale text can be recalled. - Adding an active swipe, switching the active swipe, or deleting the active swipe should invalidate local chunks for the affected message when the visible message content changes. - Manual and generation-triggered rebuild should match legacy chunking semantics: store complete 5-message chunks and leave newest incomplete groups unchunked until enough eligible messages exist. - List/delete/clear/rebuild UI and embedded/remote command paths should continue to work. - Existing delete/bulk-delete cleanup from #2293 should remain compatible with the same invalidation helper or storage path. - Add focused Rust/storage proof or equivalent local harness covering edit, swipe active-content change, and incomplete-newest-group rebuild behavior. ## Actual behavior Refactor has visible controls and command wrappers for Memory Recall list/delete/clear/rebuild, and generation refresh calls \`refreshChatMemories\` after successful saved generation. However, mutation paths that change already-chunked visible message content do not prune \`chat.memories\`. The prompt assembler reads stored memories through \`storage.listChatMemories\` or \`chat.memories\`, ranks them, and injects matching content into a \`<memories>\` block. That means stale edited/swiped-away text can remain prompt-visible until a later full rebuild, and manual rebuild can include a partial newest group that legacy would have left pending. ## Steps to reproduce 1. On refactor, create a conversation chat with at least one rebuilt Memory Recall chunk that includes a visible message. 2. Edit that message, or switch/add/delete the active swipe so the visible message content changes. 3. Inspect Memory Recall chunks or generate with a query matching the old content. Expected: affected local chunks are gone or rebuilt, and newest incomplete groups are not stored. Actual: existing \`chat.memories\` entries are not invalidated by those mutation paths, and rebuild chunks all visible groups including partial newest chunks. ## Impact area - [ ] App shell, navigation, startup, or providers - [ ] Catalog resources - [x] Chat mode - [ ] Roleplay mode - [ ] Game mode - [x] Shared mode UI - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics - [ ] Professor Mari or shell tools - [x] React-free engine behavior, contracts, agents, or capability ports - [x] Shared API wrapper or remote runtime routing - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Environment - Branch or commit: refactor static trace at \`refactor@37585ab9\` from #2268; rechecked current \`refactor\` worktree during Batch 14 - Run mode: Tauri/refactor storage path and embedded/remote invoke path - OS + version: not runtime-tested - Node + pnpm versions: not runtime-tested - Rust version, if relevant: not runtime-tested - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: Memory Recall / prompt assembly ## Logs, screenshots, or video Static parity proof only; no runtime logs. Files inspected: - Legacy \`main:packages/shared/src/types/chat.ts:118\` defines the public \`ChatMemoryChunk\` shape and embedding display status. - Legacy \`main:packages/server/src/db/schema/chats.ts:103\` stores Memory Recall chunks in the \`memory_chunks\` sidecar table. - Legacy \`main:packages/server/src/services/memory-recall.ts:121\` skips chunking until at least 5 unchunked messages exist, and \`main:packages/server/src/services/memory-recall.ts:131\` only stores complete 5-message groups. - Legacy \`main:packages/server/src/services/storage/chats.storage.ts:140\` defines \`invalidateMemoryChunksFrom\`. - Legacy \`main:packages/server/src/services/storage/chats.storage.ts:633\` invalidates after message edit. - Legacy \`main:packages/server/src/services/storage/chats.storage.ts:797\` invalidates after active swipe add/switch to new generated content. - Legacy \`main:packages/server/src/services/storage/chats.storage.ts:832\` invalidates after active swipe switch. - Legacy \`main:packages/server/src/services/storage/chats.storage.ts:900\` invalidates after deleting the active swipe. - Refactor \`src/engine/contracts/types/chat.ts:118\` keeps \`ChatMemoryChunk\` and adds source/message-id metadata fields. - Refactor \`src/shared/api/chat-command-api.ts:8\` exposes Memory Recall commands. - Refactor \`src/features/catalog/chats/hooks/use-chats.ts:316\` wires list/delete/clear/refresh/import/export hooks. - Refactor \`src/features/modes/shared/chat-ui/components/ChatSettingsDrawer.tsx:6471\` renders the Memory Recall modal, including embedding status display at \`src/features/modes/shared/chat-ui/components/ChatSettingsDrawer.tsx:6628\`. - Refactor \`src-tauri/src/http_dispatch.rs:543\` routes embedded/remote invoke memory commands. - Refactor \`src-tauri/src/commands/storage/commands/chats.rs:7\` exposes list/delete/clear/refresh commands. - Refactor \`src-tauri/src/commands/storage/chats.rs:781\` rebuilds chat-array memories and \`src-tauri/src/commands/storage/chats.rs:790\` chunks every visible remainder, including partial newest groups. - Refactor \`src-tauri/src/commands/storage/chats.rs:352\`, \`src-tauri/src/commands/storage/chats.rs:462\`, \`src-tauri/src/commands/storage/chats.rs:482\`, and \`src-tauri/src/commands/storage/chats.rs:564\` update message/swipe visible content without pruning \`memories\`. - Refactor \`src/engine/generation/prompt-assembly.ts:1835\` reads stored memories and \`src/engine/generation/prompt-assembly.ts:3048\` injects recalled chunks into the prompt. - Refactor \`src/engine/generation/start-generation.ts:1744\` refreshes after generation, but this does not cover immediate edit/swipe mutation invalidation. ## Regression notes This worked on legacy \`main\`: Memory Recall local chunks were sidecar rows and mutation paths called \`invalidateMemoryChunksFrom\` when visible message content changed. Refactor moved Memory Recall to chat-array records and did not mirror those invalidation hooks for edit/swipe mutation paths. Delete/bulk-delete stale memory cleanup is already tracked separately by #2293. ## Additional context Surface ID: \`09-CHAT-RUNTIME-memory-recall-chunks\`. Batch 14 parityscan result for #2268: gap. Import/export proof stays with Target 20 and was not chased. Provider/embedding transport was not chased beyond confirming refactor exposes lexical/provider embedding status fields and prompt recall consumes stored vectors/content. ## Template check Please uncheck 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:27:44 +07:00
  • closed this issue
  • added the
    bug
    label
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#1141
No description provided.