[PR #2072] [MERGED] Fix Memory Recall read-behind filtering #5416

Closed
opened 2026-10-22 04:16:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2072
Author: @cha1latte
Created: 6/3/2026
Status: ✅ Merged
Merged: 6/3/2026
Merged by: @cha1latte

Base: refactor ← Head: fix/issue-2049-memory-read-behind


📝 Commits (2)

  • 89c21a4 Fix memory recall read behind
  • beb2325 Refresh discovery check event

📊 Changes

4 files changed (+114 additions, -0 deletions)

View changed files

📝 src-tauri/src/commands/storage/chats.rs (+26 -0)
📝 src/engine/contracts/types/chat.ts (+2 -0)
📝 src/engine/generation/prompt-assembly.ts (+62 -0)
📝 src/features/modes/shared/chat-ui/components/ChatSettingsDrawer.tsx (+24 -0)

📄 Description

Linked issue

Closes #2049

Why this change

  • Memory Recall could inject a chunk rebuilt from the newest generated assistant message. During swipes/regeneration, that allowed details from the previous active swipe to come back as recalled memory, causing echoing and alternate-response bleed.
  • The issue also requested a Read Behind offset so Memory Recall can skip immediate-context messages instead of spending prompt budget on fragments already visible in chat history.

What changed

  • Added message provenance to rebuilt Memory Recall chunks: messageIds, firstMessageId, and lastMessageId.
  • Added per-chat memoryRecallReadBehindMessages filtering in prompt assembly. The default is 1, so chunks sourced from the newest eligible visible message are skipped unless the user sets Read Behind to 0.
  • Added a Memory Recall Read Behind number control in chat settings.

Refactor impact

Primary owner:

  • Engine prompt assembly, Rust storage, shared chat settings UI

Impact areas reviewed:

  • Memory Recall prompt injection
  • Chat memory refresh/rebuild
  • Existing hidden-from-AI memory refresh filtering
  • Chat settings metadata persistence

Boundary notes:

  • Engine filtering stays in src/engine/generation/prompt-assembly.ts.
  • Rust storage only adds provenance fields while rebuilding chat.memories.
  • Feature UI only patches chat metadata through the existing settings mutation path.
  • No raw Tauri/fetch calls were added.

Pressure points touched:

  • None of the listed pressure points were touched.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • Scratch repro: pnpm exec vitest run --config scratch/vitest.issue-2049.config.ts
    • Before the fix, this failed because the assembled prompt included the latest assistant memory chunk despite Read Behind = 1.
    • After the fix, it passed and the latest-assistant memory chunk was excluded.
  • Targeted Rust test: cargo test --manifest-path src-tauri/Cargo.toml refresh_chat_memories_skips_legacy_and_current_hidden_flags passed.
  • TypeScript lane: pnpm typecheck passed.
  • Full pre-PR gate: pnpm check passed.
  • Bunny review gate: passed before opening the draft PR; optional marinara-proof-gate.mjs helper was not installed locally, so the scratch ledger gate could not be run.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • Bugfix for an existing Memory Recall setting surface; no new discovery entry added.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

  • N/A for the bug behavior; the core claim is prompt assembly filtering, proven by the scratch repro. The settings drawer received a small numeric control matching the existing Read Behind control pattern.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/2072 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 6/3/2026 **Status:** ✅ Merged **Merged:** 6/3/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/issue-2049-memory-read-behind` --- ### 📝 Commits (2) - [`89c21a4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/89c21a4790c4f927b97d93f028b6c2c7424c409a) Fix memory recall read behind - [`beb2325`](https://github.com/Pasta-Devs/Marinara-Engine/commit/beb2325d901abc5a2144274f2945654d3a5c40dc) Refresh discovery check event ### 📊 Changes **4 files changed** (+114 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/chats.rs` (+26 -0) 📝 `src/engine/contracts/types/chat.ts` (+2 -0) 📝 `src/engine/generation/prompt-assembly.ts` (+62 -0) 📝 `src/features/modes/shared/chat-ui/components/ChatSettingsDrawer.tsx` (+24 -0) </details> ### 📄 Description <!-- Target branch: `refactor`. Change the base to `refactor` before submitting unless a maintainer explicitly asked for another base. --> <!-- Keep all checkboxes unchecked until a human has actually verified them. --> ## Linked issue Closes #2049 ## Why this change - Memory Recall could inject a chunk rebuilt from the newest generated assistant message. During swipes/regeneration, that allowed details from the previous active swipe to come back as recalled memory, causing echoing and alternate-response bleed. - The issue also requested a Read Behind offset so Memory Recall can skip immediate-context messages instead of spending prompt budget on fragments already visible in chat history. ## What changed - Added message provenance to rebuilt Memory Recall chunks: `messageIds`, `firstMessageId`, and `lastMessageId`. - Added per-chat `memoryRecallReadBehindMessages` filtering in prompt assembly. The default is `1`, so chunks sourced from the newest eligible visible message are skipped unless the user sets Read Behind to `0`. - Added a Memory Recall Read Behind number control in chat settings. ## Refactor impact Primary owner: - Engine prompt assembly, Rust storage, shared chat settings UI Impact areas reviewed: - Memory Recall prompt injection - Chat memory refresh/rebuild - Existing hidden-from-AI memory refresh filtering - Chat settings metadata persistence Boundary notes: - Engine filtering stays in `src/engine/generation/prompt-assembly.ts`. - Rust storage only adds provenance fields while rebuilding `chat.memories`. - Feature UI only patches chat metadata through the existing settings mutation path. - No raw Tauri/fetch calls were added. Pressure points touched: - None of the listed pressure points were touched. ## Validation <!-- Check only what you personally ran or manually verified. Treat unchecked items as explicit TODOs. --> <!-- Do not submit *.test.ts or *.test.tsx files as PR proof; cite existing checks, command output, app/browser/Tauri verification, or manual notes instead. --> - [ ] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - Scratch repro: `pnpm exec vitest run --config scratch/vitest.issue-2049.config.ts` - Before the fix, this failed because the assembled prompt included the latest assistant memory chunk despite Read Behind = 1. - After the fix, it passed and the latest-assistant memory chunk was excluded. - Targeted Rust test: `cargo test --manifest-path src-tauri/Cargo.toml refresh_chat_memories_skips_legacy_and_current_hidden_flags` passed. - TypeScript lane: `pnpm typecheck` passed. - Full pre-PR gate: `pnpm check` passed. - Bunny review gate: passed before opening the draft PR; optional `marinara-proof-gate.mjs` helper was not installed locally, so the scratch ledger gate could not be run. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [x] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - Bugfix for an existing Memory Recall setting surface; no new discovery entry added. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [ ] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence - N/A for the bug behavior; the core claim is prompt assembly filtering, proven by the scratch repro. The settings drawer received a small numeric control matching the existing Read Behind control pattern. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:16:07 +07:00
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#5416
No description provided.