[PR #7203] [MERGED] fix(memory): keep scene audiences, honest recall receipts and fresh recall on swipes #7619

Closed
opened 2026-10-24 04:05:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7203
Author: @SpicyMarinara
Created: 10/6/2026
Status: ✅ Merged
Merged: 10/7/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/memory-recall-followups-7184


📝 Commits (10+)

  • ff81293 fix(memory): keep scene audiences, honest recall receipts and fresh recall on swipes
  • e8620bf fix(memory): treat a null audience as missing and move past failed older-scene checks
  • aa52e96 Merge remote-tracking branch 'origin/staging' into fix/memory-recall-followups-7184
  • d7e438f docs(memory): say no earlier scenes were available, not that none were saved
  • b260792 docs(changelog): limit the swipe note to scenes the character could recall
  • 2f55ee6 fix(memory): keep loose participant names away from the user's persona and other characters
  • 5c20fad Merge remote-tracking branch 'origin/staging' into fix/memory-recall-followups-7184
  • b05bc6a fix(memory): hash the same timeline-enriched scenes when validating a swipe
  • 6abb5d5 Merge remote-tracking branch 'origin/staging' into fix/memory-recall-followups-7184
  • c3c6bc0 docs(changelog): shorten the Advanced Memory follow-ups entry (#7184)

📊 Changes

11 files changed (+653 additions, -55 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/agents/memory.md (+4 -2)
📝 packages/client/src/components/chat/AdvancedMemoryInspector.tsx (+20 -6)
📝 packages/client/src/components/chat/AdvancedMemorySettings.tsx (+1 -0)
📝 packages/client/src/localization/locales/en.json (+4 -0)
📝 packages/server/src/services/advanced-memory.ts (+205 -45)
📝 packages/server/src/services/generation/advanced-memory-context.ts (+6 -2)
📝 packages/shared/src/types/advanced-memory.ts (+4 -0)
📝 scripts/regressions/advanced-memory-audience.regression.ts (+4 -0)
➕ scripts/regressions/advanced-memory-recall-followups.regression.ts (+402 -0)
📝 scripts/regressions/advanced-memory-recovery.regression.ts (+2 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7184

Why this change

While fixing #7182, four Advanced Memory recall problems were reproduced. They lose memories silently or make the recall receipt misleading:

  • Scene participants disappear (silent data loss). If the Helper model wrote "Kaito" for a card named "Kaito Nakamura", or left out the audience key, the scene was saved as narrator-only with no warning. In a 1:1 chat that scene could never be recalled for the character, and the Decision model was never asked.
  • The receipt claimed things that did not happen. "No relevant earlier scenes or messages were recalled" also appeared when there was nothing to recall yet or no room left, so relevance looked judged when it never was. (#7187 already reworded decision-recall so it no longer claims a selection; this builds on that.)
  • Swipes locked in a missed recall. A swipe reused the first reply's memory whenever its recorded IDs were still valid, so a scene saved after that reply was never considered.
  • Older scene summaries stayed narrator-only. Summaries saved before the participant check existed only got checked by an explicit Prepare existing history, never by the automatic after-reply preparation.

What changed

  • Participant names (advanced-memory.ts): the helper's names match by ID, then by full name (case and punctuation ignored), then by a unique partial name. A partial name can be shorter ("Kaito" for "Kaito Nakamura"), or longer when it starts with the card's full name ("Pantalone Bisognosi" for "Pantalone").
    • No wrong grants: the user's persona names (and "User") compete in the same match. "Mari" for a persona Mari therefore never gives the scene to a character named "Mari Rossi". It is flagged instead, and the persona alone is a user-only scene, not a mistake.
    • Only plain names match partially. Annotations ("Kaito Nakamura (mentioned only)"), objects and descriptions ("sister of Kaito Nakamura") grant nothing and are flagged. Ambiguous names (two characters called Kaito) still grant nothing.
    • A missing audience key or null is a format slip. In a chat with one character it keeps that character. With several characters it cannot be guessed, so the scene stays narrator-only, as advanced-memory-audience.regression.ts requires ("missing audience is narrator-only, including a user-only scene"). Any other shape is flagged and grants nothing.
    • Unmatched names, or no names in a group, log a Pino warning and mark the scene with a scene-audience-unmatched dependency (shared constant). The mark shows a status warning in the Advanced Memory drawer and enables the existing review and save flow in Access memories, with its own help text. Saving the scene's access clears the mark.
  • Recall receipts: when nothing is recalled, the receipt now says why:
    • no-recall-candidates: no earlier scene this character can recall.
    • no-recall-budget: no room, or relevant scenes did not fit.
    • no-relevant-recall: candidates were judged and none fit.
    • With Maximum recalled scenes at 0, recall is off and no reason is added.
  • Swipes: each receipt stores an archiveRevision, a hash of the finished scenes outside the reply's live messages that this audience could recall. validatePrepared checks it only for a swipe's cached snapshot, using the same scene set as preparation. A scene saved after the reply within its live messages cannot be recalled yet, so a plain swipe still reuses its memory and makes no extra Decision calls. Generation-time validation is unchanged. Snapshots saved before this change recall once more, then are reused.
  • Older summaries: after-reply preparation (closedOnly) runs the participant check for up to three older scenes per run (ponytail: constant). A failed check there is logged and marks the scene, so it never blocks archiving the scene that just ended, and later runs move on to other scenes. Prepare existing history still checks all of them and retries failed ones.
  • Small reuse: recordRevision() replaces two copies of the same revision hash, and the persona list reuses #7192's speakerName().
  • English strings in en.json, plus docs/agents/memory.md and the CHANGELOG.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Automated runs by the agents (the boxes above are left for the human reviewer). All runs were on the final head, which includes staging with #7191 and #7192:

  • pnpm check: passed.
  • node scripts/run-regressions.mjs --filter memory: 20/20 passed. This includes the new advanced-memory-recall-followups.regression.ts, #7192's advanced-memory-visibility.regression.ts and every existing Advanced Memory regression.
  • playwright test e2e/advanced-memory.e2e.ts --project=desktop-chromium: 17/17 passed.
  • Also passed: roleplay-regeneration-context, chat-branch-lineage, roleplay-interrupt-generation, the two roleplay-whisper regressions and pnpm regression:prompt.
  • The new regression fails against staging's code. Run against the first version of this PR, its persona, description, object, odd-shape, plain-swipe and recall-off checks failed.
  • advanced-memory-audience.regression.ts now also checks for the new warning. advanced-memory-recovery.regression.ts now also covers "Pantalone Bisognosi" → Pantalone and the narrator's partial name "Powers" → narrator-only. No existing assertion was changed or removed.
  • Review:
    • GitHub CodeRabbit's earlier findings were addressed: null audiences, repeatedly failing older-scene checks, and translated docs (follow-up #7204).
    • Local CodeRabbit on the verifier's changes raised one trivial point: swipe validation hashed scenes without the source timeframes that preparation adds. It is fixed by using the same scene set in both.

Manual verification notes

  • Manually verify in a Roleplay chat with one character whose card has a full name (e.g. "Kaito Nakamura"): prepare history with a real Helper model, open Access memories for this chat, and confirm the scenes list the character, not Narrator only.
  • Manually verify with a persona that shares a first name with a character (e.g. persona "Mari", character "Mari Rossi"). After preparing history, scenes where only the persona took part must not list Mari Rossi.
  • Manually verify that a scene whose participants could not be matched shows the new warning in the Advanced Memory drawer and the new help text in Access memories. Then save its access with Edit character access and confirm the warning clears.
  • Manually verify with an archive from before 2.5.0, or a scene shown with the older-memories help text: let a reply finish a scene, then confirm up to three older scenes get their participants without Prepare existing history.
  • Manually verify swipes with Use Decision model on:
    • A swipe right after a reply whose user message ended a scene should reuse the memory, with no new Decision calls in the debug log.
    • After a scene outside the visible history is saved or re-enabled, a swipe should recall again and can include it.
  • Manually verify the receipt wording under Last generation memory in three cases: a fresh chat with nothing saved, a tight Summary and recall budget, and Maximum recalled scenes set to 0, which should show no "nothing recalled" line.
  • Check the new strings in light and dark mode and on a phone-width drawer.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Changed: CHANGELOG.md ([Unreleased]) and docs/agents/memory.md, which now covers participant matching and the persona and description rules, older-scene checks, swipe refresh limited to scenes outside the chat history, and receipt reasons. Translation follow-up: #7204. No version or storage-format change. Receipts only gain an optional field, and old snapshots stay readable.

Known conflict, kept on purpose: the issue asks that a missing audience key never mean "nobody". An existing regression treats it as narrator-only in group chats, so a group keeps that rule but is now flagged rather than silent. Only one-character chats assume the character was present. If you want group chats to guess too, that test's decision needs changing first.

Follow-up worth considering: #7192 added its own characterIdsNamed() for visibility answers (exact name, else a unique first name). It does not consider personas. Sharing one matcher would keep the two rules aligned, but changing #7192's visibility behaviour is outside this PR.

UI evidence (if applicable)

No layout changes: two new receipt lines, one drawer warning and one help line, all reusing existing components.

Summary by CodeRabbit

  • New Features
    • Advanced Memory identifies scene participants more carefully. Scenes with unmatched participants are marked narrator-only, with guidance to review character access.
    • Swiping to recall memory reflects accessible scenes saved, edited, enabled, or disabled since the reply. Scenes still in the reply’s history aren’t recalled yet.
    • Older scene summaries are checked incrementally after replies, with up to three checked at a time.
    • Recall explanations distinguish between no earlier scenes, no remaining memory budget, and no relevant matches.

🔄 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/7203 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/6/2026 **Status:** ✅ Merged **Merged:** 10/7/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/memory-recall-followups-7184` --- ### 📝 Commits (10+) - [`ff81293`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ff81293db63e581e7ea37dd752ea72ca8c545908) fix(memory): keep scene audiences, honest recall receipts and fresh recall on swipes - [`e8620bf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e8620bf0f2e6ed65cd668ad27791f0b480b2524a) fix(memory): treat a null audience as missing and move past failed older-scene checks - [`aa52e96`](https://github.com/Pasta-Devs/Marinara-Engine/commit/aa52e96847627577c49bbd717ad7ec3f751fb8dd) Merge remote-tracking branch 'origin/staging' into fix/memory-recall-followups-7184 - [`d7e438f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d7e438fe8e38a197f071270eab084bc91be37e4f) docs(memory): say no earlier scenes were available, not that none were saved - [`b260792`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b2607922f8d5da79afcb210bff3b1337c15e55d4) docs(changelog): limit the swipe note to scenes the character could recall - [`2f55ee6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2f55ee66cecf111bb46eeeeebdfe86f6a076fbf6) fix(memory): keep loose participant names away from the user's persona and other characters - [`5c20fad`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5c20faddcb91777c4453b36d83a1477a49a3fd67) Merge remote-tracking branch 'origin/staging' into fix/memory-recall-followups-7184 - [`b05bc6a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b05bc6a3c464f7840ac17c32c34d242ea0f94074) fix(memory): hash the same timeline-enriched scenes when validating a swipe - [`6abb5d5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6abb5d57bb903d024d0f0e6527061173b500a9aa) Merge remote-tracking branch 'origin/staging' into fix/memory-recall-followups-7184 - [`c3c6bc0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c3c6bc05ccda095776ed551dd47ed6500b97bcb4) docs(changelog): shorten the Advanced Memory follow-ups entry (#7184) ### 📊 Changes **11 files changed** (+653 additions, -55 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/agents/memory.md` (+4 -2) 📝 `packages/client/src/components/chat/AdvancedMemoryInspector.tsx` (+20 -6) 📝 `packages/client/src/components/chat/AdvancedMemorySettings.tsx` (+1 -0) 📝 `packages/client/src/localization/locales/en.json` (+4 -0) 📝 `packages/server/src/services/advanced-memory.ts` (+205 -45) 📝 `packages/server/src/services/generation/advanced-memory-context.ts` (+6 -2) 📝 `packages/shared/src/types/advanced-memory.ts` (+4 -0) 📝 `scripts/regressions/advanced-memory-audience.regression.ts` (+4 -0) ➕ `scripts/regressions/advanced-memory-recall-followups.regression.ts` (+402 -0) 📝 `scripts/regressions/advanced-memory-recovery.regression.ts` (+2 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7184 ## Why this change While fixing #7182, four Advanced Memory recall problems were reproduced. They lose memories silently or make the recall receipt misleading: - **Scene participants disappear (silent data loss).** If the Helper model wrote "Kaito" for a card named "Kaito Nakamura", or left out the `audience` key, the scene was saved as narrator-only with no warning. In a 1:1 chat that scene could never be recalled for the character, and the Decision model was never asked. - **The receipt claimed things that did not happen.** "No relevant earlier scenes or messages were recalled" also appeared when there was nothing to recall yet or no room left, so relevance looked judged when it never was. (#7187 already reworded `decision-recall` so it no longer claims a selection; this builds on that.) - **Swipes locked in a missed recall.** A swipe reused the first reply's memory whenever its recorded IDs were still valid, so a scene saved after that reply was never considered. - **Older scene summaries stayed narrator-only.** Summaries saved before the participant check existed only got checked by an explicit **Prepare existing history**, never by the automatic after-reply preparation. ## What changed - **Participant names** (`advanced-memory.ts`): the helper's names match by ID, then by full name (case and punctuation ignored), then by a unique partial name. A partial name can be shorter ("Kaito" for "Kaito Nakamura"), or longer when it starts with the card's full name ("Pantalone Bisognosi" for "Pantalone"). - **No wrong grants:** the user's persona names (and "User") compete in the same match. "Mari" for a persona Mari therefore never gives the scene to a character named "Mari Rossi". It is flagged instead, and the persona alone is a user-only scene, not a mistake. - Only plain names match partially. Annotations ("Kaito Nakamura (mentioned only)"), objects and descriptions ("sister of Kaito Nakamura") grant nothing and are flagged. Ambiguous names (two characters called Kaito) still grant nothing. - A missing `audience` key or `null` is a format slip. In a chat with one character it keeps that character. With several characters it cannot be guessed, so the scene stays narrator-only, as `advanced-memory-audience.regression.ts` requires ("missing audience is narrator-only, including a user-only scene"). Any other shape is flagged and grants nothing. - Unmatched names, or no names in a group, log a Pino warning and mark the scene with a `scene-audience-unmatched` dependency (shared constant). The mark shows a status warning in the Advanced Memory drawer and enables the existing review and save flow in **Access memories**, with its own help text. Saving the scene's access clears the mark. - **Recall receipts**: when nothing is recalled, the receipt now says why: - `no-recall-candidates`: no earlier scene this character can recall. - `no-recall-budget`: no room, or relevant scenes did not fit. - `no-relevant-recall`: candidates were judged and none fit. - With **Maximum recalled scenes** at 0, recall is off and no reason is added. - **Swipes**: each receipt stores an `archiveRevision`, a hash of the finished scenes outside the reply's live messages that this audience could recall. `validatePrepared` checks it only for a swipe's cached snapshot, using the same scene set as preparation. A scene saved after the reply within its live messages cannot be recalled yet, so a plain swipe still reuses its memory and makes no extra Decision calls. Generation-time validation is unchanged. Snapshots saved before this change recall once more, then are reused. - **Older summaries**: after-reply preparation (`closedOnly`) runs the participant check for up to three older scenes per run (`ponytail:` constant). A failed check there is logged and marks the scene, so it never blocks archiving the scene that just ended, and later runs move on to other scenes. **Prepare existing history** still checks all of them and retries failed ones. - Small reuse: `recordRevision()` replaces two copies of the same revision hash, and the persona list reuses #7192's `speakerName()`. - English strings in `en.json`, plus `docs/agents/memory.md` and the CHANGELOG. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Automated runs by the agents (the boxes above are left for the human reviewer). All runs were on the final head, which includes staging with #7191 and #7192: - `pnpm check`: passed. - `node scripts/run-regressions.mjs --filter memory`: 20/20 passed. This includes the new `advanced-memory-recall-followups.regression.ts`, #7192's `advanced-memory-visibility.regression.ts` and every existing Advanced Memory regression. - `playwright test e2e/advanced-memory.e2e.ts --project=desktop-chromium`: 17/17 passed. - Also passed: `roleplay-regeneration-context`, `chat-branch-lineage`, `roleplay-interrupt-generation`, the two `roleplay-whisper` regressions and `pnpm regression:prompt`. - The new regression fails against `staging`'s code. Run against the first version of this PR, its persona, description, object, odd-shape, plain-swipe and recall-off checks failed. - `advanced-memory-audience.regression.ts` now also checks for the new warning. `advanced-memory-recovery.regression.ts` now also covers "Pantalone Bisognosi" → Pantalone and the narrator's partial name "Powers" → narrator-only. No existing assertion was changed or removed. - Review: - GitHub CodeRabbit's earlier findings were addressed: `null` audiences, repeatedly failing older-scene checks, and translated docs (follow-up #7204). - Local CodeRabbit on the verifier's changes raised one trivial point: swipe validation hashed scenes without the source timeframes that preparation adds. It is fixed by using the same scene set in both. ### Manual verification notes - Manually verify in a Roleplay chat with one character whose card has a full name (e.g. "Kaito Nakamura"): prepare history with a real Helper model, open **Access memories for this chat**, and confirm the scenes list the character, not **Narrator only**. - Manually verify with a persona that shares a first name with a character (e.g. persona "Mari", character "Mari Rossi"). After preparing history, scenes where only the persona took part must not list Mari Rossi. - Manually verify that a scene whose participants could not be matched shows the new warning in the Advanced Memory drawer and the new help text in **Access memories**. Then save its access with **Edit character access** and confirm the warning clears. - Manually verify with an archive from before 2.5.0, or a scene shown with the older-memories help text: let a reply finish a scene, then confirm up to three older scenes get their participants without **Prepare existing history**. - Manually verify swipes with **Use Decision model** on: - A swipe right after a reply whose user message ended a scene should reuse the memory, with no new Decision calls in the debug log. - After a scene outside the visible history is saved or re-enabled, a swipe should recall again and can include it. - Manually verify the receipt wording under **Last generation memory** in three cases: a fresh chat with nothing saved, a tight **Summary and recall budget**, and **Maximum recalled scenes** set to 0, which should show no "nothing recalled" line. - Check the new strings in light and dark mode and on a phone-width drawer. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Changed: `CHANGELOG.md` (`[Unreleased]`) and `docs/agents/memory.md`, which now covers participant matching and the persona and description rules, older-scene checks, swipe refresh limited to scenes outside the chat history, and receipt reasons. Translation follow-up: #7204. No version or storage-format change. Receipts only gain an optional field, and old snapshots stay readable. **Known conflict, kept on purpose:** the issue asks that a missing `audience` key never mean "nobody". An existing regression treats it as narrator-only in group chats, so a group keeps that rule but is now flagged rather than silent. Only one-character chats assume the character was present. If you want group chats to guess too, that test's decision needs changing first. **Follow-up worth considering:** #7192 added its own `characterIdsNamed()` for visibility answers (exact name, else a unique first name). It does not consider personas. Sharing one matcher would keep the two rules aligned, but changing #7192's visibility behaviour is outside this PR. ## UI evidence (if applicable) No layout changes: two new receipt lines, one drawer warning and one help line, all reusing existing components. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Advanced Memory identifies scene participants more carefully. Scenes with unmatched participants are marked narrator-only, with guidance to review character access. - Swiping to recall memory reflects accessible scenes saved, edited, enabled, or disabled since the reply. Scenes still in the reply’s history aren’t recalled yet. - Older scene summaries are checked incrementally after replies, with up to three checked at a time. - Recall explanations distinguish between no earlier scenes, no remaining memory budget, and no relevant matches. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:05:55 +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#7619
No description provided.