[PR #7285] [MERGED] fix(memory): keep combined summaries' ranges and private sentences with their readers #7664

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

📋 Pull Request Information

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

Base: staging ← Head: fix/combine-privacy-code-followup


📝 Commits (10+)

  • 4ed53f8 fix(memory): keep combined summaries' ranges and private sentences with their readers
  • 0557f44 Merge origin/staging into fix/combine-privacy-code-followup
  • 77c5ac8 Merge origin/staging into fix/combine-privacy-code-followup
  • 40a4da3 fix(memory): check private sentences whole across decimals and abbreviations
  • f9d6cc1 Merge origin/staging into fix/combine-privacy-code-followup
  • 7e885f5 Merge origin/staging into fix/combine-privacy-code-followup
  • d48504b fix(memory): catch copied private lines and keep the copy check fast
  • 66f801e Merge origin/fix/combine-privacy-code-followup into fix/combine-privacy-code-followup
  • 37bc43c Merge origin/staging into fix/combine-privacy-code-followup
  • 0b719f9 test(memory): pin matching normalization in the combine leak check

📊 Changes

3 files changed (+236 additions, -16 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/services/advanced-memory.ts (+51 -16)
📝 scripts/regressions/advanced-memory-post-generation.regression.ts (+184 -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

Follow-up to #7275. Refs #7270 (#7275 already closed it).

Why this change

#7275 lets the Helper combine summaries that have private {{#if char == "Name"}} sections, as long as each section keeps its condition. A privacy review of the merged code found three ways private content could still reach the wrong character:

  • Merged group chats combined summaries read by different characters. One-by-one chats only combine summaries the same characters read. In merged chats, every summary went into one group, so a summary only Maukie reads was combined with one Pantalone also reads. The conditions survived, but a summary has a single message range. The prompt shows that range, and the story dates taken from its messages, to everyone who reads any part of it. Pantalone then got the date of a message hidden from him (Messages #1–#2; … timeframe: NIGHT_OF_THE_HEIST → MORNING_AFTER). This also contradicted #7275's own design note: "Summaries read by different characters are still not merged into one entry."
  • The copied-sentence check didn't work in Chinese or Japanese. It split sentences on .!? and counted words by spaces, so a private sentence like 毛奇把钥匙藏在了钟楼里。 counted as one word. A Helper reply that copied it word for word into text everyone reads was saved.
  • Text next to another macro was never checked. If a plain summary in the group contained an unknown macro such as {{foo}}, a private sentence placed beside that macro in the result was skipped by the check. Pantalone could then read it.

What changed

  • packages/server/src/services/advanced-memory.ts:
    • Merged chats now group summaries by the characters who read them, the same way one-by-one chats do. In one-by-one chats the grouping is unchanged. A side effect: in merged chats, a summary no current character can read is no longer turned off by being combined into another.
    • The private-sentence check splits on every sentence mark (\p{Sentence_Terminal}). It counts words with Intl.Segmenter, the same way roleplay-interrupt.ts already does.
    • The check treats text next to another macro as readable by everyone.
  • scripts/regressions/advanced-memory-post-generation.regression.ts: three new blocks, one per problem. Each one fails without its fix and passes with it. No existing assertion was changed.
  • CHANGELOG.md: a new entry at the top of [Unreleased].

No docs change: docs/agents/memory.md already says private summaries are combined "with the other summaries the same characters read", and that is now true in merged chats too. No UI copy and no model prompt changed. Debug prompt logging is untouched.

Overlap: #7284 (fix/combine-behaviour-followup) edits the same leaks lines and the top of CHANGELOG.md. Whichever PR merges second will need a small manual merge. The two changes are compatible: #7284 ignores sentences the wider section already had, and this PR changes how sentences are split and words counted, and which sections count as wider.

Still open, not changed here (same as #7275): the check only catches private sentences copied word for word, not reworded ones. That is the open CodeRabbit thread on #7275, and it is Mari's decision.

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

Agent-run checks (please re-run; do not take this as proof):

  • Each new regression block was run against the merged #7275 code and failed there: the Chinese copy was saved, the copy next to {{foo}} was saved, and Pantalone's prompt contained NIGHT_OF_THE_HEIST.
  • With the fix, these all passed: every advanced-memory-*, memory-recall-* and *summary* regression, roleplay-regeneration-context, roleplay-interrupt-generation, pnpm regression:prompt and pnpm check.

Manual verification notes

  • Manually verify in a merged Roleplay group chat with two characters (A and B), with Advanced Memory on and a Helper connection set:
    1. Hide an early message from B, and give it a Date: … line.
    2. Let Advanced Memory write a Chat Summary that only A can read for that message. Let it also write shared summaries for later messages that both A and B read.
    3. Lower Summary and recall budget until compaction runs after a reply.
    4. Open Chat Summaries. Check that A's private summary was not combined into a summary that B also reads.
    5. Open Peek Prompt for a reply from B alone. Check that it shows no message range or date from the hidden message.
  • Manually verify in a one-by-one group chat that compaction still combines a summary with a private section together with the shared summaries both characters read, as in #7275.
  • Manually verify that a chat written in Chinese or Japanese still combines and shortens summaries normally, so the stricter check does not block ordinary results.

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)

UI evidence (if applicable)

Not applicable: server-only change.

Summary by CodeRabbit

  • Bug Fixes
    • Private sentences in Advanced Memory summaries are protected from appearing in content shared with other characters, including in languages that do not use spaces. Checks account for variations in punctuation, quotation marks, line breaks, and formatting.
    • When chats are merged, summaries are combined only for characters who can read the same content. Story dates and visible message ranges remain specific to each summary, keeping hidden details out of other characters’ recall.

🔄 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/7285 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/7/2026 **Status:** ✅ Merged **Merged:** 10/8/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/combine-privacy-code-followup` --- ### 📝 Commits (10+) - [`4ed53f8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4ed53f83c1ba69e94aa75d432bf4c7d951e82af6) fix(memory): keep combined summaries' ranges and private sentences with their readers - [`0557f44`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0557f44e8b2373bc4108d56e59c95338cdef560a) Merge origin/staging into fix/combine-privacy-code-followup - [`77c5ac8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/77c5ac84d9e3ef3e7486d37ca15e3310fd308482) Merge origin/staging into fix/combine-privacy-code-followup - [`40a4da3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/40a4da3e9774a8e30f20906d8b793aa1834003e4) fix(memory): check private sentences whole across decimals and abbreviations - [`f9d6cc1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f9d6cc1319884df50a867994d94e063940040f4f) Merge origin/staging into fix/combine-privacy-code-followup - [`7e885f5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7e885f5d3d9b154a0b0e7a423433f074d229a356) Merge origin/staging into fix/combine-privacy-code-followup - [`d48504b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d48504b47dd00db8b08ca74ce412490a28112c89) fix(memory): catch copied private lines and keep the copy check fast - [`66f801e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/66f801ee66ee2dcbcdf778e44f0bf22404a75cfd) Merge origin/fix/combine-privacy-code-followup into fix/combine-privacy-code-followup - [`37bc43c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/37bc43c232425f4a81e176cd96891fedff3fea70) Merge origin/staging into fix/combine-privacy-code-followup - [`0b719f9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0b719f9a8792c34a8212dca7e756add5699e12f3) test(memory): pin matching normalization in the combine leak check ### 📊 Changes **3 files changed** (+236 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/services/advanced-memory.ts` (+51 -16) 📝 `scripts/regressions/advanced-memory-post-generation.regression.ts` (+184 -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 Follow-up to #7275. Refs #7270 (#7275 already closed it). ## Why this change #7275 lets the Helper combine summaries that have private `{{#if char == "Name"}}` sections, as long as each section keeps its condition. A privacy review of the merged code found three ways private content could still reach the wrong character: - **Merged group chats combined summaries read by different characters.** One-by-one chats only combine summaries the same characters read. In merged chats, every summary went into one group, so a summary only Maukie reads was combined with one Pantalone also reads. The conditions survived, but a summary has a single message range. The prompt shows that range, and the story dates taken from its messages, to everyone who reads any part of it. Pantalone then got the date of a message hidden from him (`Messages #1–#2; … timeframe: NIGHT_OF_THE_HEIST → MORNING_AFTER`). This also contradicted #7275's own design note: "Summaries read by different characters are still not merged into one entry." - **The copied-sentence check didn't work in Chinese or Japanese.** It split sentences on `.!?` and counted words by spaces, so a private sentence like `毛奇把钥匙藏在了钟楼里。` counted as one word. A Helper reply that copied it word for word into text everyone reads was saved. - **Text next to another macro was never checked.** If a plain summary in the group contained an unknown macro such as `{{foo}}`, a private sentence placed beside that macro in the result was skipped by the check. Pantalone could then read it. ## What changed - `packages/server/src/services/advanced-memory.ts`: - Merged chats now group summaries by the characters who read them, the same way one-by-one chats do. In one-by-one chats the grouping is unchanged. A side effect: in merged chats, a summary no current character can read is no longer turned off by being combined into another. - The private-sentence check splits on every sentence mark (`\p{Sentence_Terminal}`). It counts words with `Intl.Segmenter`, the same way `roleplay-interrupt.ts` already does. - The check treats text next to another macro as readable by everyone. - `scripts/regressions/advanced-memory-post-generation.regression.ts`: three new blocks, one per problem. Each one fails without its fix and passes with it. No existing assertion was changed. - `CHANGELOG.md`: a new entry at the top of `[Unreleased]`. No docs change: `docs/agents/memory.md` already says private summaries are combined "with the other summaries the same characters read", and that is now true in merged chats too. No UI copy and no model prompt changed. Debug prompt logging is untouched. **Overlap:** #7284 (`fix/combine-behaviour-followup`) edits the same `leaks` lines and the top of `CHANGELOG.md`. Whichever PR merges second will need a small manual merge. The two changes are compatible: #7284 ignores sentences the wider section already had, and this PR changes how sentences are split and words counted, and which sections count as wider. **Still open, not changed here (same as #7275):** the check only catches private sentences copied word for word, not reworded ones. That is the open CodeRabbit thread on #7275, and it is Mari's decision. ## 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` Agent-run checks (please re-run; do not take this as proof): - Each new regression block was run against the merged #7275 code and failed there: the Chinese copy was saved, the copy next to `{{foo}}` was saved, and Pantalone's prompt contained `NIGHT_OF_THE_HEIST`. - With the fix, these all passed: every `advanced-memory-*`, `memory-recall-*` and `*summary*` regression, `roleplay-regeneration-context`, `roleplay-interrupt-generation`, `pnpm regression:prompt` and `pnpm check`. ### Manual verification notes - Manually verify in a **merged** Roleplay group chat with two characters (A and B), with Advanced Memory on and a Helper connection set: 1. Hide an early message from B, and give it a `Date: …` line. 2. Let Advanced Memory write a Chat Summary that only A can read for that message. Let it also write shared summaries for later messages that both A and B read. 3. Lower **Summary and recall budget** until compaction runs after a reply. 4. Open **Chat Summaries**. Check that A's private summary was not combined into a summary that B also reads. 5. Open **Peek Prompt** for a reply from B alone. Check that it shows no message range or date from the hidden message. - Manually verify in a **one-by-one** group chat that compaction still combines a summary with a private section together with the shared summaries both characters read, as in #7275. - Manually verify that a chat written in Chinese or Japanese still combines and shortens summaries normally, so the stricter check does not block ordinary results. ## 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) ## UI evidence (if applicable) Not applicable: server-only change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Private sentences in Advanced Memory summaries are protected from appearing in content shared with other characters, including in languages that do not use spaces. Checks account for variations in punctuation, quotation marks, line breaks, and formatting. * When chats are merged, summaries are combined only for characters who can read the same content. Story dates and visible message ranges remain specific to each summary, keeping hidden details out of other characters’ recall. <!-- 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:18 +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#7664
No description provided.