[PR #7277] [MERGED] fix(memory): include decision-picked message excerpts and say why when they are left out #7657

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

📋 Pull Request Information

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

Base: staging ← Head: fix/decision-recall-excerpts


📝 Commits (3)

  • 2077832 fix(memory): include decision-picked message excerpts and say why when they are left out
  • 439f72a Merge remote-tracking branch 'origin/staging' into fix/decision-recall-excerpts
  • d780bf8 Merge origin/staging into fix/decision-recall-excerpts

📊 Changes

8 files changed (+180 additions, -47 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/agents/memory.md (+4 -4)
📝 packages/client/src/components/chat/AdvancedMemoryInspector.tsx (+4 -1)
📝 packages/client/src/components/chat/DecisionDebugPanel.tsx (+6 -0)
📝 packages/client/src/localization/locales/en.json (+3 -0)
📝 packages/server/src/services/advanced-memory.ts (+82 -42)
📝 packages/shared/src/types/advanced-memory.ts (+2 -0)
📝 scripts/regressions/advanced-memory-decisions.regression.ts (+78 -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 #7269

Why this change

Mari, testing Advanced Memory with Use Decision model on (min 1, max 2 messages per excerpt): "three scene summaries were correctly picked, but none of them had any message excerpts included … I just want to be sure that everything works correctly."

Tracing the recall path found one real bug and one missing explanation:

  • Bug. Each Decision excerpt was sized with Math.ceil(score). The Decision model's score is a 0..1 probability, so every excerpt held exactly Minimum messages per excerpt (at least one). Maximum was ignored. The model's other picks were thrown away and shown as Not selected in Decision diagnostics. Text matching (Decision off or failed) already reached Maximum, so Decision recall gave shorter excerpts than ordinary recall.
  • No explanation. A recalled scene can have no excerpt for three by-design reasons, and nothing said which:
    1. Summaries reserve their room first (documented, #6490), and nothing was left.
    2. The summary has {{#if char == "Name"}} parts. Each character still gets only their parts of the summary, but the raw messages stay narrator-only, because they can hold facts the summary kept from that character. In a group chat where characters reply one by one, the helper writes these sections, so this is the most likely cause of Mari's zero excerpts.
    3. None of the scene's messages can be quoted (excluded, not indexed, or not readable by everyone in a merged group).

Fixing only the size would make things worse in one way: a longer first excerpt could leave the next scene without its minimum. So every recalled scene now gets its minimum before any excerpt grows.

What changed

  • packages/server/src/services/advanced-memory.ts (recall excerpt build only):
    • The Decision model's best pick centres the excerpt. Its other picks widen it while the span stays within Maximum. Text matching keeps its old sizing exactly.
    • Fitting runs in two passes, best scene first: every scene gets its minimum (at least one message), then each grows into the room left. The shrink rule, the drop-below-minimum rule and the documented order (constants → summaries → excerpts) are unchanged.
    • When a recalled scene still has no excerpt, the receipt gets one reason: excerpt-no-room, excerpt-private-scene or excerpt-no-source. None is added when Maximum is 0 or Minimum 0 made the excerpt optional.
    • Decision diagnostics save these codes, plus decision-excerpt-fallback, as notes. They are fixed codes with no names, section text or message text.
  • packages/shared/src/types/advanced-memory.ts: optional notes on the saved Decision diagnostics, so older saved reports stay valid.
  • AdvancedMemoryInspector.tsx / DecisionDebugPanel.tsx / en.json: the memory receipt and Peek Prompt → Decision diagnostics show the three new reasons in plain words. The panel reuses the receipt's reason keys.
  • No model prompt changed, so the existing debug prompt logging is untouched.
  • Unchanged on purpose: canRecallExcerpt (narrator-only raw excerpts from conditional recaps). Relaxing it, even only for readers who see every section, breaks the intent of three existing regressions (advanced-memory-summary.regression.ts "matching the narrator's recap text does not grant a character access to raw private source messages", advanced-memory-decisions.regression.ts "private recap conditions withhold raw excerpts", and the duo case in advanced-memory-audience.regression.ts). That is a policy decision for Mari, so the receipt now says it happened instead.

Before / after (regression fixture: 2 recalled scenes, the Decision model picks messages #3–#4 and #8–#9, min 1 / max 2)

Before (origin/staging), recalled prompt block:

Scene summary:
Messages #1–#5; story timeframe: unknown (use message order).
TARGET_SCENE: The old oath concerned Cobalt refuge.

Excerpt:
Messages #3–#3; story timeframe: unknown (use message order).
#3 User: TARGET_SCENE Cobalt refuge is sworn at the dock. …

Decision diagnostics: #4 and #9 scored 0.99 but were Not selected.

After:

Scene summary:
Messages #1–#5; story timeframe: unknown (use message order).
TARGET_SCENE: The old oath concerned Cobalt refuge.

Excerpt:
Messages #3–#4; story timeframe: unknown (use message order).
#3 User: TARGET_SCENE Cobalt refuge is sworn at the dock. …
#4 Character: Cobalt refuge, I repeat at the dock. …

Decision diagnostics: all four picks Selected.

Receipt reasons:

Case Before After
Summaries fill the room (2 scenes, 0 excerpts) decision-recall decision-recall, excerpt-no-room ("Some recalled scenes have no message excerpt because no room was left after the summaries. Raise Summary and recall budget or lower Maximum recalled scenes to make room.")
Recap with a part only one character knows decision-recall decision-recall, excerpt-private-scene ("…their summaries have parts meant only for some characters. Each character still gets the parts meant for them, but only the narrator gets the original messages.")
Room for only the minimums 1 message each 1 message each (the first scene no longer grows and starves the second)

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

Commands the agent ran (results for the reviewer to confirm, not ticked boxes):

  • pnpm check: exit 0.
  • node ./scripts/run-regressions.mjs --filter advanced-memory: 15/15 passed.
  • --filter memory-recall 5/5, --filter summary 5/5, roleplay-user-private-memory 1/1, native-export-memory 1/1, pnpm regression:prompt passed.
  • New asserts in scripts/regressions/advanced-memory-decisions.regression.ts (added only; no existing assert changed) fail on origin/staging. Removing the minimum-first pass also makes them fail.
  • Local CodeRabbit: see the comment below. The first run was rate-limited.

Manual verification notes

  • Manually verify in a Roleplay chat with Advanced Memory and Use Decision model on, Minimum messages per excerpt 1 and Maximum 2: after a reply that recalls earlier scenes, open Peek Prompt and check that each recalled scene's excerpt holds the Decision model's picked messages (up to 2), and that Decision diagnostics → Advanced Memory activity marks those messages Selected.
  • Manually verify that lowering Summary and recall budget until excerpts disappear shows "Some recalled scenes have no message excerpt because no room was left after the summaries…" in the memory receipt (Access memories for this chat → receipt) and under the recall report in Decision diagnostics.
  • Manually verify in a group chat where characters reply one by one, with a scene summary that has a {{#if char == "Name"}} part: the summary still shows each character only their parts, the excerpt is missing for non-narrators, and the receipt and Decision diagnostics show the "parts meant only for some characters" reason.
  • Manually verify that an older saved recall report (from before this change) still opens in Decision diagnostics without errors.
  • Manually verify the new lines in light and dark mode and at a mobile width.

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)

docs/agents/memory.md (Moving context, Optional Decision model) and CHANGELOG.md [Unreleased] are updated. Translation follow-up: #7276.

UI evidence (if applicable)

New text lines only, in the existing receipt list and Decision diagnostics recall section; no layout or colour change.


🔄 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/7277 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/7/2026 **Status:** ✅ Merged **Merged:** 10/7/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/decision-recall-excerpts` --- ### 📝 Commits (3) - [`2077832`](https://github.com/Pasta-Devs/Marinara-Engine/commit/20778322d45882ffc5d24b7269be38d8d831ce86) fix(memory): include decision-picked message excerpts and say why when they are left out - [`439f72a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/439f72af9d384628d84cdc2e20c107d1e2f1d032) Merge remote-tracking branch 'origin/staging' into fix/decision-recall-excerpts - [`d780bf8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d780bf81236b45fbe92a92430b632a309e719c89) Merge origin/staging into fix/decision-recall-excerpts ### 📊 Changes **8 files changed** (+180 additions, -47 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/agents/memory.md` (+4 -4) 📝 `packages/client/src/components/chat/AdvancedMemoryInspector.tsx` (+4 -1) 📝 `packages/client/src/components/chat/DecisionDebugPanel.tsx` (+6 -0) 📝 `packages/client/src/localization/locales/en.json` (+3 -0) 📝 `packages/server/src/services/advanced-memory.ts` (+82 -42) 📝 `packages/shared/src/types/advanced-memory.ts` (+2 -0) 📝 `scripts/regressions/advanced-memory-decisions.regression.ts` (+78 -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 #7269 ## Why this change Mari, testing Advanced Memory with **Use Decision model** on (min 1, max 2 messages per excerpt): "three scene summaries were correctly picked, but none of them had any message excerpts included … I just want to be sure that everything works correctly." Tracing the recall path found one real bug and one missing explanation: - **Bug.** Each Decision excerpt was sized with `Math.ceil(score)`. The Decision model's score is a 0..1 probability, so every excerpt held exactly **Minimum messages per excerpt** (at least one). **Maximum** was ignored. The model's other picks were thrown away and shown as **Not selected** in Decision diagnostics. Text matching (Decision off or failed) already reached Maximum, so Decision recall gave *shorter* excerpts than ordinary recall. - **No explanation.** A recalled scene can have no excerpt for three by-design reasons, and nothing said which: 1. Summaries reserve their room first (documented, #6490), and nothing was left. 2. The summary has `{{#if char == "Name"}}` parts. Each character still gets only their parts of the *summary*, but the raw *messages* stay narrator-only, because they can hold facts the summary kept from that character. In a group chat where characters reply one by one, the helper writes these sections, so this is the most likely cause of Mari's zero excerpts. 3. None of the scene's messages can be quoted (excluded, not indexed, or not readable by everyone in a merged group). Fixing only the size would make things worse in one way: a longer first excerpt could leave the next scene without its minimum. So every recalled scene now gets its minimum before any excerpt grows. ## What changed - `packages/server/src/services/advanced-memory.ts` (recall excerpt build only): - The Decision model's best pick centres the excerpt. Its other picks widen it while the span stays within **Maximum**. Text matching keeps its old sizing exactly. - Fitting runs in two passes, best scene first: every scene gets its minimum (at least one message), then each grows into the room left. The shrink rule, the drop-below-minimum rule and the documented order (constants → summaries → excerpts) are unchanged. - When a recalled scene still has no excerpt, the receipt gets one reason: `excerpt-no-room`, `excerpt-private-scene` or `excerpt-no-source`. None is added when Maximum is 0 or Minimum 0 made the excerpt optional. - Decision diagnostics save these codes, plus `decision-excerpt-fallback`, as `notes`. They are fixed codes with no names, section text or message text. - `packages/shared/src/types/advanced-memory.ts`: optional `notes` on the saved Decision diagnostics, so older saved reports stay valid. - `AdvancedMemoryInspector.tsx` / `DecisionDebugPanel.tsx` / `en.json`: the memory receipt and **Peek Prompt → Decision diagnostics** show the three new reasons in plain words. The panel reuses the receipt's reason keys. - No model prompt changed, so the existing debug prompt logging is untouched. - Unchanged on purpose: `canRecallExcerpt` (narrator-only raw excerpts from conditional recaps). Relaxing it, even only for readers who see every section, breaks the intent of three existing regressions (`advanced-memory-summary.regression.ts` "matching the narrator's recap text does not grant a character access to raw private source messages", `advanced-memory-decisions.regression.ts` "private recap conditions withhold raw excerpts", and the duo case in `advanced-memory-audience.regression.ts`). That is a policy decision for Mari, so the receipt now says it happened instead. ### Before / after (regression fixture: 2 recalled scenes, the Decision model picks messages #3–#4 and #8–#9, min 1 / max 2) Before (`origin/staging`), recalled prompt block: ```text Scene summary: Messages #1–#5; story timeframe: unknown (use message order). TARGET_SCENE: The old oath concerned Cobalt refuge. Excerpt: Messages #3–#3; story timeframe: unknown (use message order). #3 User: TARGET_SCENE Cobalt refuge is sworn at the dock. … ``` Decision diagnostics: #4 and #9 scored 0.99 but were **Not selected**. After: ```text Scene summary: Messages #1–#5; story timeframe: unknown (use message order). TARGET_SCENE: The old oath concerned Cobalt refuge. Excerpt: Messages #3–#4; story timeframe: unknown (use message order). #3 User: TARGET_SCENE Cobalt refuge is sworn at the dock. … #4 Character: Cobalt refuge, I repeat at the dock. … ``` Decision diagnostics: all four picks **Selected**. Receipt reasons: | Case | Before | After | | --- | --- | --- | | Summaries fill the room (2 scenes, 0 excerpts) | `decision-recall` | `decision-recall`, `excerpt-no-room` ("Some recalled scenes have no message excerpt because no room was left after the summaries. Raise Summary and recall budget or lower Maximum recalled scenes to make room.") | | Recap with a part only one character knows | `decision-recall` | `decision-recall`, `excerpt-private-scene` ("…their summaries have parts meant only for some characters. Each character still gets the parts meant for them, but only the narrator gets the original messages.") | | Room for only the minimums | 1 message each | 1 message each (the first scene no longer grows and starves the second) | ## 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` Commands the agent ran (results for the reviewer to confirm, not ticked boxes): - `pnpm check`: exit 0. - `node ./scripts/run-regressions.mjs --filter advanced-memory`: 15/15 passed. - `--filter memory-recall` 5/5, `--filter summary` 5/5, `roleplay-user-private-memory` 1/1, `native-export-memory` 1/1, `pnpm regression:prompt` passed. - New asserts in `scripts/regressions/advanced-memory-decisions.regression.ts` (added only; no existing assert changed) fail on `origin/staging`. Removing the minimum-first pass also makes them fail. - Local CodeRabbit: see the comment below. The first run was rate-limited. ### Manual verification notes - Manually verify in a Roleplay chat with Advanced Memory and **Use Decision model** on, **Minimum messages per excerpt** 1 and **Maximum** 2: after a reply that recalls earlier scenes, open **Peek Prompt** and check that each recalled scene's excerpt holds the Decision model's picked messages (up to 2), and that **Decision diagnostics → Advanced Memory activity** marks those messages **Selected**. - Manually verify that lowering **Summary and recall budget** until excerpts disappear shows "Some recalled scenes have no message excerpt because no room was left after the summaries…" in the memory receipt (**Access memories for this chat** → receipt) and under the recall report in **Decision diagnostics**. - Manually verify in a group chat where characters reply one by one, with a scene summary that has a `{{#if char == "Name"}}` part: the summary still shows each character only their parts, the excerpt is missing for non-narrators, and the receipt and Decision diagnostics show the "parts meant only for some characters" reason. - Manually verify that an older saved recall report (from before this change) still opens in Decision diagnostics without errors. - Manually verify the new lines in light and dark mode and at a mobile width. ## 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) `docs/agents/memory.md` (Moving context, Optional Decision model) and `CHANGELOG.md` `[Unreleased]` are updated. Translation follow-up: #7276. ## UI evidence (if applicable) New text lines only, in the existing receipt list and Decision diagnostics recall section; no layout or colour change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:06:14 +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#7657
No description provided.