[PR #7275] [MERGED] feat(memory): let the Helper combine related summaries when compacting #7658

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/7275
Author: @SpicyMarinara
Created: 10/7/2026
Status: ✅ Merged
Merged: 10/7/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/compaction-combine-summaries


📝 Commits (7)

  • b887aff feat(memory): let the Helper combine summaries with private sections when compacting
  • ec9044d Merge remote-tracking branch 'origin/staging' into feat/compaction-combine-summaries
  • d49b6e0 Merge origin/staging into feat/compaction-combine-summaries
  • 813b2bf fix(memory): reject a combined summary that copies a private sentence into shared text
  • 0aaa4cd Merge remote-tracking branch 'origin/feat/compaction-combine-summaries' into feat/compaction-combine-summaries
  • 11a0693 Merge origin/staging into feat/compaction-combine-summaries
  • 892ef8d Merge origin/staging into feat/compaction-combine-summaries

📊 Changes

4 files changed (+232 additions, -14 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/agents/memory.md (+1 -1)
📝 packages/server/src/services/advanced-memory.ts (+72 -12)
📝 scripts/regressions/advanced-memory-post-generation.regression.ts (+158 -1)

📄 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 #7270

Why this change

  • Mari: "When it's time to compact constant summaries, I noticed we never use the combine summaries option. Wish the helper model had that tool at hand to combine memories in order to shorten them, aside from standard compacting."
  • Compaction already sends the Combine prompt and already merges each group into one entry. But it skipped every summary whose text differs by character: anything with a private {{#if char == "Name"}}…{{/if}} section. Advanced Memory's own scene recaps put private facts in exactly those sections, so in group chats most constants were never combined or shortened. In merged group chats every summary with a character condition was skipped. A character could stay over the 70% share while later replies kept paying to shorten the plain summaries again.
  • Parts of a summary not meant for a character are still never shown to that character: the Helper gets the conditions and must keep them, and a result that changes who can read a section is thrown away.

What changed

  • packages/server/src/services/advanced-memory.ts (updateConstantSummariesAfterGeneration):
    • A summary whose text differs by character now joins the group of summaries the same characters read, if Advanced Memory wrote it (origin: "automated"), nobody changed it since (createdAt === updatedAt), and its sections differ only by character conditions. That group is sent with its conditions kept. The group's plain summaries are wrapped in the group's own reader condition. Summaries you wrote or edited, legacy summaries, and templates with other macros stay skipped, as before.
    • summarize() gets keepConditions: one sentence added after the existing Combine prompt. Debug prompt logging (logDebugOverride, debugMode / DEBUG_AGENTS) is unchanged and shows it.
    • Before saving, the result's sections are compared with the inputs' (via scopeCharacterSummary's reader callback): the same groups of readers, none dropped, none added, no other macros, and no private sentence of four or more words copied into a section more characters read. If any check fails, nothing is saved, a Pino warning is logged, the paid result stays cached (no repeat for the same summaries), and the group's plain summaries are shortened on their own exactly as before. A reworded private fact moved into a wider section cannot be caught this way (ponytail: note in the code).
    • Saving reuses the existing path: stale-entry and policy checks, union of message IDs and range title, sources disabled by combineChatSummaryEntryHistory, cache cleared.
    • Groups without such a summary send exactly today's prompt.
  • Summaries read by different characters are still not merged into one entry. It would not shorten anyone's memory, because each character only reads their own sections. And every character's entry would then claim message ranges they never saw, which also stops Advanced Memory from writing their own summary of those messages later (the existing "another character's summary cannot suppress uncovered history" check).
  • docs/agents/memory.md, CHANGELOG.md. Translation follow-up: #7274.

Before / after (regression fixture: Maukie + Pantalone, budget 1000 → 700 share)

Entries: {{#if char == "Maukie" || "Pantalone"}}SHARED_WALK… {{#if char == "Maukie"}}MAUKIE_SECRET hid the key.{{/if}}{{/if}} (#1) and {{#if char == "Maukie" || "Pantalone"}}SHARED_TWO…{{/if}} (#2), both automated.

Before (origin/staging): one call. The user message is only SHARED_TWO …, the target is 333 tokens, and the #1 recap is never sent or shortened.

After: one call. The system prompt ends:

Condense the ordered summaries below into one summary. Preserve durable facts, relationships, decisions, and chronological order. Return the same summary format requested by the system prompt.

Some summaries contain {{#if char == "Name"}}...{{/if}} sections. Keep each fact inside a section with exactly its original condition; combine and shorten shared text freely, but never move a fact from a section into text more characters can read.

Summarize only the supplied eligible source material. … Aim for approximately … tokens. …

User message:

{{#if char == "Pantalone" || "Maukie"}}SHARED_WALK … {{/if}}{{#if char == "Maukie"}}MAUKIE_SECRET hid the key.{{/if}}

{{#if char == "Pantalone" || "Maukie"}}SHARED_TWO … {{/if}}

Saved as one automated entry, Messages #1–#2, with both sources inactive:

{{#if char == "Pantalone" || "Maukie"}}COMBINED_WALK. {{/if}}{{#if char == "Maukie"}}MAUKIE_SECRET hid the key.{{/if}}

Maukie's prepared memory includes the secret; Pantalone's does not.

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 (for the reviewer to confirm, not proof):

  • New block in scripts/regressions/advanced-memory-post-generation.regression.ts (fake Helper that records prompts) fails on origin/staging and passes here. It covers: one combine call with the raw condition and Combine prompt; combined entry IDs, range and title; per-character recall; no further calls once within budget; a result that copies the private sentence into shared text rejected, with the template unchanged while the plain summary is still shortened; a result that drops the private section rejected and not paid for again; a hand-edited summary left alone; merged group chats.
  • Passed: all advanced-memory-*, memory-recall-*, conversation-summary, merged-chat-summary, semantic-summary-*, roleplay-regeneration-context, roleplay-interrupt-generation regressions; pnpm regression:prompt; pnpm check.
  • No existing test was changed. The fixture's fake provider gained an optional per-prompt reply hook.

Local CodeRabbit (coderabbit review --agent --committed): 1 finding (major), asking for a fact-level guard so a private sentence copied into shared text is rejected. Valid. Fixed in 813b2bff0, with a regression case that fails without the guard. GitHub CodeRabbit re-reviewed the fixed code and asked for reworded private facts to be caught too. I didn't change that: it needs a second paid model call, and the Helper already gets the same trust, unchecked, when it writes scene recaps. Reasoning is in the thread, which is left open for the maintainer's call.

Manual verification notes

  • Manually verify in a Roleplay group chat where characters reply one by one, with Advanced Memory on and a Helper model: create enough closed scenes, some with a private {{#if char == "Name"}} section in their Chat Summary, so the constants pass 70% of Summary and recall budget. After the next reply, check that Chat Summaries shows one new Messages #a–#b entry replacing the summaries the same characters read, with every private section still under its original character condition.
  • Manually verify with Peek Prompt for each character that a private section only appears for the characters named in its condition.
  • Manually verify that a Chat Summary you edited by hand (or wrote yourself) with a private section is left unchanged after compaction.
  • Manually verify with debug mode (or DEBUG_AGENTS=true) that the server log shows the compaction prompt with the Combine prompt and the "Keep each fact inside a section with exactly its original condition" sentence.
  • Manually verify a merged group chat the same way: summaries with character conditions are now combined, and Peek Prompt still marks private parts with who knows them.

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 and CHANGELOG.md updated; translation follow-up #7274.

UI evidence (if applicable)

No UI change.

Summary by CodeRabbit

  • New Features
    • Advanced Memory can now combine and shorten eligible automated chat summaries while preserving which characters can read private sections.
    • If a combined summary would change access to private content, it is not saved; other eligible summaries can still be shortened.
    • User-written and edited summaries remain unchanged.

🔄 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/7275 **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:** `feat/compaction-combine-summaries` --- ### 📝 Commits (7) - [`b887aff`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b887aff4f9330c3bbd57858dd5ceb70be78d4b1e) feat(memory): let the Helper combine summaries with private sections when compacting - [`ec9044d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ec9044d3bb2ba3d9b7d3c1567719d65fb11f4cda) Merge remote-tracking branch 'origin/staging' into feat/compaction-combine-summaries - [`d49b6e0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d49b6e0112f7934220c82923dc746df9bdbea4bc) Merge origin/staging into feat/compaction-combine-summaries - [`813b2bf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/813b2bff0f95954b691a501d4adc573a25a00cf7) fix(memory): reject a combined summary that copies a private sentence into shared text - [`0aaa4cd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0aaa4cd26cd724bf3323e4ba88395680da6171cd) Merge remote-tracking branch 'origin/feat/compaction-combine-summaries' into feat/compaction-combine-summaries - [`11a0693`](https://github.com/Pasta-Devs/Marinara-Engine/commit/11a0693e1ae9bf40a15a98128677953a490b5f46) Merge origin/staging into feat/compaction-combine-summaries - [`892ef8d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/892ef8d3b459012fc789fc366276cd5593a9e4b2) Merge origin/staging into feat/compaction-combine-summaries ### 📊 Changes **4 files changed** (+232 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/agents/memory.md` (+1 -1) 📝 `packages/server/src/services/advanced-memory.ts` (+72 -12) 📝 `scripts/regressions/advanced-memory-post-generation.regression.ts` (+158 -1) </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 #7270 ## Why this change - Mari: *"When it's time to compact constant summaries, I noticed we never use the combine summaries option. Wish the helper model had that tool at hand to combine memories in order to shorten them, aside from standard compacting."* - Compaction already sends the **Combine prompt** and already merges each group into one entry. But it skipped **every** summary whose text differs by character: anything with a private `{{#if char == "Name"}}…{{/if}}` section. Advanced Memory's own scene recaps put private facts in exactly those sections, so in group chats most constants were never combined or shortened. In merged group chats every summary with a character condition was skipped. A character could stay over the 70% share while later replies kept paying to shorten the plain summaries again. - Parts of a summary not meant for a character are still never shown to that character: the Helper gets the conditions and must keep them, and a result that changes who can read a section is thrown away. ## What changed - `packages/server/src/services/advanced-memory.ts` (`updateConstantSummariesAfterGeneration`): - A summary whose text differs by character now joins the group of summaries the same characters read, if Advanced Memory wrote it (`origin: "automated"`), nobody changed it since (`createdAt === updatedAt`), and its sections differ only by character conditions. That group is sent with its conditions kept. The group's plain summaries are wrapped in the group's own reader condition. Summaries you wrote or edited, legacy summaries, and templates with other macros stay skipped, as before. - `summarize()` gets `keepConditions`: one sentence added after the existing Combine prompt. Debug prompt logging (`logDebugOverride`, `debugMode` / `DEBUG_AGENTS`) is unchanged and shows it. - Before saving, the result's sections are compared with the inputs' (via `scopeCharacterSummary`'s reader callback): the same groups of readers, none dropped, none added, no other macros, and no private sentence of four or more words copied into a section more characters read. If any check fails, nothing is saved, a Pino warning is logged, the paid result stays cached (no repeat for the same summaries), and the group's plain summaries are shortened on their own exactly as before. A reworded private fact moved into a wider section cannot be caught this way (`ponytail:` note in the code). - Saving reuses the existing path: stale-entry and policy checks, union of message IDs and range title, sources disabled by `combineChatSummaryEntryHistory`, cache cleared. - Groups without such a summary send exactly today's prompt. - Summaries read by **different** characters are still not merged into one entry. It would not shorten anyone's memory, because each character only reads their own sections. And every character's entry would then claim message ranges they never saw, which also stops Advanced Memory from writing their own summary of those messages later (the existing "another character's summary cannot suppress uncovered history" check). - `docs/agents/memory.md`, `CHANGELOG.md`. Translation follow-up: #7274. ### Before / after (regression fixture: Maukie + Pantalone, budget 1000 → 700 share) Entries: `{{#if char == "Maukie" || "Pantalone"}}SHARED_WALK… {{#if char == "Maukie"}}MAUKIE_SECRET hid the key.{{/if}}{{/if}}` (#1) and `{{#if char == "Maukie" || "Pantalone"}}SHARED_TWO…{{/if}}` (#2), both automated. Before (`origin/staging`): one call. The user message is only `SHARED_TWO …`, the target is 333 tokens, and the #1 recap is never sent or shortened. After: one call. The system prompt ends: ``` Condense the ordered summaries below into one summary. Preserve durable facts, relationships, decisions, and chronological order. Return the same summary format requested by the system prompt. Some summaries contain {{#if char == "Name"}}...{{/if}} sections. Keep each fact inside a section with exactly its original condition; combine and shorten shared text freely, but never move a fact from a section into text more characters can read. Summarize only the supplied eligible source material. … Aim for approximately … tokens. … ``` User message: ``` {{#if char == "Pantalone" || "Maukie"}}SHARED_WALK … {{/if}}{{#if char == "Maukie"}}MAUKIE_SECRET hid the key.{{/if}} {{#if char == "Pantalone" || "Maukie"}}SHARED_TWO … {{/if}} ``` Saved as one automated entry, **Messages #1–#2**, with both sources inactive: ``` {{#if char == "Pantalone" || "Maukie"}}COMBINED_WALK. {{/if}}{{#if char == "Maukie"}}MAUKIE_SECRET hid the key.{{/if}} ``` Maukie's prepared memory includes the secret; Pantalone's does not. ## 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 (for the reviewer to confirm, not proof): - New block in `scripts/regressions/advanced-memory-post-generation.regression.ts` (fake Helper that records prompts) fails on `origin/staging` and passes here. It covers: one combine call with the raw condition and Combine prompt; combined entry IDs, range and title; per-character recall; no further calls once within budget; a result that copies the private sentence into shared text rejected, with the template unchanged while the plain summary is still shortened; a result that drops the private section rejected and not paid for again; a hand-edited summary left alone; merged group chats. - Passed: all `advanced-memory-*`, `memory-recall-*`, `conversation-summary`, `merged-chat-summary`, `semantic-summary-*`, `roleplay-regeneration-context`, `roleplay-interrupt-generation` regressions; `pnpm regression:prompt`; `pnpm check`. - No existing test was changed. The fixture's fake provider gained an optional per-prompt reply hook. Local CodeRabbit (`coderabbit review --agent --committed`): 1 finding (major), asking for a fact-level guard so a private sentence copied into shared text is rejected. Valid. Fixed in 813b2bff0, with a regression case that fails without the guard. GitHub CodeRabbit re-reviewed the fixed code and asked for reworded private facts to be caught too. I didn't change that: it needs a second paid model call, and the Helper already gets the same trust, unchecked, when it writes scene recaps. Reasoning is in the thread, which is left open for the maintainer's call. ### Manual verification notes - Manually verify in a Roleplay group chat where characters reply one by one, with Advanced Memory on and a Helper model: create enough closed scenes, some with a private `{{#if char == "Name"}}` section in their Chat Summary, so the constants pass 70% of **Summary and recall budget**. After the next reply, check that **Chat Summaries** shows one new **Messages #a–#b** entry replacing the summaries the same characters read, with every private section still under its original character condition. - Manually verify with **Peek Prompt** for each character that a private section only appears for the characters named in its condition. - Manually verify that a Chat Summary you edited by hand (or wrote yourself) with a private section is left unchanged after compaction. - Manually verify with debug mode (or `DEBUG_AGENTS=true`) that the server log shows the compaction prompt with the Combine prompt and the "Keep each fact inside a section with exactly its original condition" sentence. - Manually verify a merged group chat the same way: summaries with character conditions are now combined, and **Peek Prompt** still marks private parts with who knows them. ## 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` and `CHANGELOG.md` updated; translation follow-up #7274. ## UI evidence (if applicable) No UI change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Advanced Memory can now combine and shorten eligible automated chat summaries while preserving which characters can read private sections. * If a combined summary would change access to private content, it is not saved; other eligible summaries can still be shortened. * User-written and edited summaries remain unchanged. <!-- 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: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#7658
No description provided.