[PR #7255] [MERGED] fix(memory): skip summaries whose sections all render empty #7647

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

📋 Pull Request Information

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

Base: staging ← Head: fix/memory-empty-summary-header


📝 Commits (2)

  • bdf9507 fix(memory): skip summaries whose sections all render empty
  • b360595 fix(memory): keep dated empty-summary headers only for readers of that range

📊 Changes

5 files changed (+123 additions, -1 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/services/advanced-memory.ts (+7 -1)
📝 scripts/regressions/advanced-memory-audience.regression.ts (+81 -0)
📝 scripts/regressions/advanced-memory-post-generation.regression.ts (+31 -0)
📝 scripts/regressions/advanced-memory-summary.regression.ts (+3 -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 #7250

Why this change

The builder of #7239 (the fix for #7237) found that Advanced Memory adds a bare range header for a Chat Summary that has nothing for the character replying. When every conditional section of an entry renders empty for the reader, the prompt still gets Messages #a–#b; source timeframe (summary corrections take precedence): unknown (use message order). with nothing under it. This happens in Individual and merged group chats and in one-character chats, in the prompt sent to the model and in Peek Prompt. The header also counts against the memory budget.

This happens most to a character who joins a group later. Every summary the earlier cast wrote for themselves turns into an empty header in the newcomer's prompt. It tells the model nothing and wastes about 25 tokens per entry.

Mari's design for merged chats (2026-10-07) is "things should not break; the who-remembers-what is more informative for the model". This change keeps that. Merged prompts still label private content with who knows it. The only change is that an entry with nothing for anyone replying no longer leaves a header behind. Entries that have content are byte-identical to staging.

What changed

  • prepareImpl (packages/server/src/services/advanced-memory.ts): when renderEntry returns empty text for the reader, the entry is left out of the Chat Summary block, header included. Its tokens no longer count toward the budget, the receipt estimate or excerpt fitting. Peek Prompt uses the same prepare path (readOnly: true), so it matches.
  • Exception for known story dates. If the reader can read at least one of the entry's messages and those messages have a known story date (sourceTimeline(covered) is not null), the dated header stays exactly as before. On 2026-09-25 (fd8f408d4), Mari decided that scene dates are shared with every participant, even when some messages are hidden. advanced-memory-summary.regression.ts asserts that every reader's Chat Summary contains June 12. For the borrower, that date comes only from the header of an entry whose text is for others. Dropping every bare header would have broken that test, so a dated header stays only for a reader who saw part of that range (the borrower read message #1). A character who read none of it, such as a newcomer whose knowledge starts later, gets no header at all, dated or not. Without that limit, a newcomer in a dated chat still got Messages #3–#4; source timeframe …: June 12. with nothing under it for every scene before they joined.
  • Constant compaction (updateConstantSummariesAfterGeneration): an entry with no text for a view no longer adds a \n\n separator to that view's 70% count. Compaction never counted headers, only entry text, so it now counts exactly the entries recall shows text for. Before, every empty entry between two others added about half a token to the count.
  • No change to the policy revision. A swipe snapshot prepared before the update may still contain the old bare header, which is harmless and goes away on the next preparation.
  • CHANGELOG entry at the top of [Unreleased]. No docs change: docs/ does not describe these headers, so no [docs-i18n] follow-up is needed.

Prompt text, before and after

Individual group chat, reading as Cara, who joined after Maukie and Pantalone wrote CONST_SHARED scoped to themselves:

Before (staging):

Messages #3–#4; source timeframe (summary corrections take precedence): unknown (use message order).


Messages #1–#2; source timeframe (summary corrections take precedence): unknown (use message order).
CONST_PLAIN The compass promise.

After:

Messages #1–#2; source timeframe (summary corrections take precedence): unknown (use message order).
CONST_PLAIN The compass promise.

Merged chat (Maukie, Pantalone, Narrator, Cara) with an extra entry {{#if char == "Narrator"}}NARRATOR_ONLY_NOTE{{/if}} on messages #5–#6. Before, the prompt ended with:

CONST_PLAIN The compass promise. [Known only to Maukie: CONST_MAUKIE] [Known only to Maukie: MIXED_SECRET]

Messages #5–#6; source timeframe (summary corrections take precedence): unknown (use message order).

After, it ends at …[Known only to Maukie: MIXED_SECRET]. That is the same text, byte for byte, as when the narrator-only entry does not exist (estimated tokens 606 → 580).

Dated partial scene (unchanged): the borrower keeps Messages #1–#2; source timeframe (summary corrections take precedence): June 12.. Pantalone and the narrator lose the bare Messages #1–#1; … unknown (use message order). header from the borrower-only entry.

Byte-identity check against staging

I dumped chatSummary, recalledScenes, the receipt's estimatedTokensAfter, reasons and recalled/record counts from the same fixtures, on this branch and on origin/staging:

  • With no empty entries, output is byte-identical to staging for Individual chats (Maukie, Pantalone, Narrator), merged chats (all four audiences) and the one-character chat. The one exception is Cara, whose CONST_SHARED entry is empty for her, which is the bug.
  • With an empty entry added (narrator-only, or for an absent Pantalone in the one-character chat), this branch's output for everyone else is byte-identical to staging's output without that entry, in Individual mode, merged mode and the one-character chat. The reader the entry is written for, the narrator, gets it exactly as on staging.
  • In the dated partial scene, the borrower's Chat Summary is byte-identical to staging.

New and extended regression coverage

  • advanced-memory-audience.regression.ts: Cara's exact Individual Chat Summary has no bare header, and still none after the earlier scenes get Date: lines, while Pantalone, who read the narrator-only range, keeps its dated header. In Individual and merged modes, adding a narrator-only entry leaves every other reader's chatSummary, recalledScenes and estimated tokens unchanged. The narrator still gets it with its header. In a one-character chat, an entry only for an absent character changes nothing. On staging this fails at no bare header for Cara. With that assertion skipped, it fails at individual maukie: an empty summary adds no header and no tokens.
  • advanced-memory-post-generation.regression.ts (per-character constant budgets): Maukie's entries sit just under his 7k share, with 40 Pantalone-only entries between them. On staging, their separators push him over and trigger a paid compaction call. Fails on staging at another character's entries do not push Maukie over his share.
  • advanced-memory-summary.regression.ts: one added assertion, Messages #1–#1; appears only for the borrower. That is the dated header kept for the shared date, and no bare undated header for anyone else. Fails on staging. No existing assertion was changed or removed.

Not changed here (pre-existing, for a follow-up)

  • In merged and one-character chats, compaction measures the "" view with renderEntry(ctx, content, []). That reads conditions as the first chat character, not the labelled any-present-reader view #7239 gave recall. Compaction can therefore under-count a merged chat's constants after a newcomer joins. This is the same as on staging.
  • In non-Individual chats, an entry that is empty for every current character still goes into a compaction group, and is disabled once the group is combined. Individual mode already skips such entries (if (ctx.individual && !audience.length) continue;).

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, all passing:

  • pnpm check: exit 0.
  • All 15 Advanced Memory regressions (node scripts/run-regressions.mjs --filter advanced-memory).
  • memory-recall-exclusivity, memory-recall-revectorize and the 3 advanced-memory-recall* regressions (--filter memory-recall).
  • conversation-summary, semantic-summary-settings, semantic-summary-cancellation, roleplay-user-private-memory, native-export-memory, prompt-token-counters, capability-prompt-preview.
  • pnpm regression:prompt (prompt, prompt-attachments, context-fit).
  • The three new or extended checks fail against origin/staging's advanced-memory.ts, as described above.

Manual verification notes

  • Manually verify in an Individual Roleplay group chat with Advanced Memory ready that a Chat Summary entry written only for another character, such as {{#if char == "OtherName"}}secret{{/if}} on a range outside live history, no longer shows a Messages #…; source timeframe …: unknown (use message order). line with nothing under it in Peek Prompt for the replying character, and that it still shows with its text for the character it names.
  • Manually verify in a merged group chat that a narrator-only summary entry leaves no empty Messages #… line in Peek Prompt, while entries known to some characters still show [Known only to …] marks.
  • Manually verify in a one-character chat that a summary entry only for a character who isn't in the chat leaves no empty range line in Peek Prompt.
  • Manually verify that an entry whose messages carry a story date (for example a message starting Date: June 12) still shows Messages #…; source timeframe …: June 12. for a character who can read some of those messages but not the entry's text.
  • Manually verify in an Individual group chat that a character added later (knowledge range starting after those messages) gets no dated Messages #… line with nothing under it for scenes before they joined.
  • Manually verify that the Peek Prompt token estimate for the Chat Summary drops by the removed lines and that generation still works.

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)

CHANGELOG.md gains one entry under [Unreleased]. No docs/ page changes, so no [docs-i18n] follow-up.

UI evidence (if applicable)

No UI change. This changes prompt text only; see the before and after above.

Summary by CodeRabbit

  • Bug Fixes
    • Chat Summaries and Peek Prompts no longer show empty message-range headers for characters with no readable summary content.
    • Characters who joined after a scene no longer see a date for a scene they did not witness. Characters who saw part of the scene can still see its story date, even when no summary text is available to them.
    • Empty entries no longer use up a character’s memory budget or trigger unnecessary summary compaction.

🔄 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/7255 **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/memory-empty-summary-header` --- ### 📝 Commits (2) - [`bdf9507`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bdf95072ae9b7c9e817f59f2af4de269f17f651f) fix(memory): skip summaries whose sections all render empty - [`b360595`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b36059571c18e1f8efa1a305f75d17d5fa4b3f03) fix(memory): keep dated empty-summary headers only for readers of that range ### 📊 Changes **5 files changed** (+123 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/services/advanced-memory.ts` (+7 -1) 📝 `scripts/regressions/advanced-memory-audience.regression.ts` (+81 -0) 📝 `scripts/regressions/advanced-memory-post-generation.regression.ts` (+31 -0) 📝 `scripts/regressions/advanced-memory-summary.regression.ts` (+3 -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 #7250 ## Why this change The builder of #7239 (the fix for #7237) found that Advanced Memory adds a bare range header for a Chat Summary that has nothing for the character replying. When every conditional section of an entry renders empty for the reader, the prompt still gets `Messages #a–#b; source timeframe (summary corrections take precedence): unknown (use message order).` with nothing under it. This happens in Individual and merged group chats and in one-character chats, in the prompt sent to the model and in Peek Prompt. The header also counts against the memory budget. This happens most to a character who joins a group later. Every summary the earlier cast wrote for themselves turns into an empty header in the newcomer's prompt. It tells the model nothing and wastes about 25 tokens per entry. Mari's design for merged chats (2026-10-07) is "things should not break; the who-remembers-what is more informative for the model". This change keeps that. Merged prompts still label private content with who knows it. The only change is that an entry with nothing for anyone replying no longer leaves a header behind. Entries that have content are byte-identical to `staging`. ## What changed - `prepareImpl` (`packages/server/src/services/advanced-memory.ts`): when `renderEntry` returns empty text for the reader, the entry is left out of the Chat Summary block, header included. Its tokens no longer count toward the budget, the receipt estimate or excerpt fitting. Peek Prompt uses the same `prepare` path (`readOnly: true`), so it matches. - **Exception for known story dates.** If the reader can read at least one of the entry's messages and those messages have a known story date (`sourceTimeline(covered)` is not null), the dated header stays exactly as before. On 2026-09-25 (fd8f408d4), Mari decided that scene dates are shared with every participant, even when some messages are hidden. `advanced-memory-summary.regression.ts` asserts that every reader's Chat Summary contains `June 12`. For the borrower, that date comes only from the header of an entry whose text is for others. Dropping every bare header would have broken that test, so a dated header stays only for a reader who saw part of that range (the borrower read message #1). A character who read none of it, such as a newcomer whose knowledge starts later, gets no header at all, dated or not. Without that limit, a newcomer in a dated chat still got `Messages #3–#4; source timeframe …: June 12.` with nothing under it for every scene before they joined. - Constant compaction (`updateConstantSummariesAfterGeneration`): an entry with no text for a view no longer adds a `\n\n` separator to that view's 70% count. Compaction never counted headers, only entry text, so it now counts exactly the entries recall shows text for. Before, every empty entry between two others added about half a token to the count. - No change to the policy revision. A swipe snapshot prepared before the update may still contain the old bare header, which is harmless and goes away on the next preparation. - CHANGELOG entry at the top of `[Unreleased]`. No docs change: `docs/` does not describe these headers, so no `[docs-i18n]` follow-up is needed. ### Prompt text, before and after Individual group chat, reading as Cara, who joined after Maukie and Pantalone wrote `CONST_SHARED` scoped to themselves: Before (staging): ```text Messages #3–#4; source timeframe (summary corrections take precedence): unknown (use message order). Messages #1–#2; source timeframe (summary corrections take precedence): unknown (use message order). CONST_PLAIN The compass promise. ``` After: ```text Messages #1–#2; source timeframe (summary corrections take precedence): unknown (use message order). CONST_PLAIN The compass promise. ``` Merged chat (Maukie, Pantalone, Narrator, Cara) with an extra entry `{{#if char == "Narrator"}}NARRATOR_ONLY_NOTE{{/if}}` on messages #5–#6. Before, the prompt ended with: ```text CONST_PLAIN The compass promise. [Known only to Maukie: CONST_MAUKIE] [Known only to Maukie: MIXED_SECRET] Messages #5–#6; source timeframe (summary corrections take precedence): unknown (use message order). ``` After, it ends at `…[Known only to Maukie: MIXED_SECRET]`. That is the same text, byte for byte, as when the narrator-only entry does not exist (estimated tokens 606 → 580). Dated partial scene (unchanged): the borrower keeps `Messages #1–#2; source timeframe (summary corrections take precedence): June 12.`. Pantalone and the narrator lose the bare `Messages #1–#1; … unknown (use message order).` header from the borrower-only entry. ### Byte-identity check against staging I dumped `chatSummary`, `recalledScenes`, the receipt's `estimatedTokensAfter`, reasons and recalled/record counts from the same fixtures, on this branch and on `origin/staging`: - With no empty entries, output is byte-identical to staging for Individual chats (Maukie, Pantalone, Narrator), merged chats (all four audiences) and the one-character chat. The one exception is Cara, whose `CONST_SHARED` entry is empty for her, which is the bug. - With an empty entry added (narrator-only, or for an absent Pantalone in the one-character chat), this branch's output for everyone else is byte-identical to staging's output **without** that entry, in Individual mode, merged mode and the one-character chat. The reader the entry is written for, the narrator, gets it exactly as on staging. - In the dated partial scene, the borrower's Chat Summary is byte-identical to staging. ### New and extended regression coverage - `advanced-memory-audience.regression.ts`: Cara's exact Individual Chat Summary has no bare header, and still none after the earlier scenes get `Date:` lines, while Pantalone, who read the narrator-only range, keeps its dated header. In Individual and merged modes, adding a narrator-only entry leaves every other reader's `chatSummary`, `recalledScenes` and estimated tokens unchanged. The narrator still gets it with its header. In a one-character chat, an entry only for an absent character changes nothing. On staging this fails at `no bare header for Cara`. With that assertion skipped, it fails at `individual maukie: an empty summary adds no header and no tokens`. - `advanced-memory-post-generation.regression.ts` (per-character constant budgets): Maukie's entries sit just under his 7k share, with 40 Pantalone-only entries between them. On staging, their separators push him over and trigger a paid compaction call. Fails on staging at `another character's entries do not push Maukie over his share`. - `advanced-memory-summary.regression.ts`: one added assertion, `Messages #1–#1;` appears only for the borrower. That is the dated header kept for the shared date, and no bare undated header for anyone else. Fails on staging. No existing assertion was changed or removed. ### Not changed here (pre-existing, for a follow-up) - In merged and one-character chats, compaction measures the `""` view with `renderEntry(ctx, content, [])`. That reads conditions as the first chat character, not the labelled any-present-reader view #7239 gave recall. Compaction can therefore under-count a merged chat's constants after a newcomer joins. This is the same as on staging. - In non-Individual chats, an entry that is empty for every current character still goes into a compaction group, and is disabled once the group is combined. Individual mode already skips such entries (`if (ctx.individual && !audience.length) continue;`). ## 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, all passing: - `pnpm check`: exit 0. - All 15 Advanced Memory regressions (`node scripts/run-regressions.mjs --filter advanced-memory`). - `memory-recall-exclusivity`, `memory-recall-revectorize` and the 3 `advanced-memory-recall*` regressions (`--filter memory-recall`). - `conversation-summary`, `semantic-summary-settings`, `semantic-summary-cancellation`, `roleplay-user-private-memory`, `native-export-memory`, `prompt-token-counters`, `capability-prompt-preview`. - `pnpm regression:prompt` (prompt, prompt-attachments, context-fit). - The three new or extended checks fail against `origin/staging`'s `advanced-memory.ts`, as described above. ### Manual verification notes - Manually verify in an **Individual** Roleplay group chat with Advanced Memory ready that a Chat Summary entry written only for another character, such as `{{#if char == "OtherName"}}secret{{/if}}` on a range outside live history, no longer shows a `Messages #…; source timeframe …: unknown (use message order).` line with nothing under it in **Peek Prompt** for the replying character, and that it still shows with its text for the character it names. - Manually verify in a **merged** group chat that a narrator-only summary entry leaves no empty `Messages #…` line in Peek Prompt, while entries known to some characters still show `[Known only to …]` marks. - Manually verify in a **one-character** chat that a summary entry only for a character who isn't in the chat leaves no empty range line in Peek Prompt. - Manually verify that an entry whose messages carry a story date (for example a message starting `Date: June 12`) still shows `Messages #…; source timeframe …: June 12.` for a character who can read some of those messages but not the entry's text. - Manually verify in an **Individual** group chat that a character added later (knowledge range starting after those messages) gets no dated `Messages #…` line with nothing under it for scenes before they joined. - Manually verify that the Peek Prompt token estimate for the Chat Summary drops by the removed lines and that generation still works. ## 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) `CHANGELOG.md` gains one entry under `[Unreleased]`. No `docs/` page changes, so no `[docs-i18n]` follow-up. ## UI evidence (if applicable) No UI change. This changes prompt text only; see the before and after above. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Chat Summaries and Peek Prompts no longer show empty message-range headers for characters with no readable summary content. * Characters who joined after a scene no longer see a date for a scene they did not witness. Characters who saw part of the scene can still see its story date, even when no summary text is available to them. * Empty entries no longer use up a character’s memory budget or trigger unnecessary summary compaction. <!-- 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:06:09 +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#7647
No description provided.