[PR #6490] [MERGED] fix: prioritize memory budgets and archive exact scene endings #7200

Closed
opened 2026-10-23 04:17:27 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6490
Author: @SpicyMarinara
Created: 9/21/2026
Status: ✅ Merged
Merged: 9/21/2026
Merged by: @SpicyMarinara

Base: staging ← Head: codex/sept21-memory-constants-scenes


📝 Commits (9)

  • 96dbe41 docs: track Advanced Memory constant and scene follow-up
  • 3493c74 fix: retain constants and archive numbered scene endings after replies
  • d84328e test: align interrupt fixture with numbered scene-check decisions
  • 422054c fix: tell the summary helper about the soft token target
  • f4fc936 Merge branch 'staging' into codex/sept21-memory-constants-scenes
  • 0feb91b fix: reserve per-character constant share and unify recall markers
  • 7167804 fix: preserve scoped summary macros during compaction
  • e771565 Merge remote-tracking branch 'origin/staging' into codex/sept21-memory-constants-scenes
  • 95f6009 Merge remote-tracking branch 'origin/codex/sept21-memory-constants-scenes' into codex/sept21-memory-constants-scenes

📊 Changes

18 files changed (+936 additions, -246 deletions)

View changed files

📝 CHANGELOG.md (+5 -0)
📝 docs/agents/memory.md (+5 -6)
📝 e2e/advanced-memory-wizard.e2e.ts (+1 -1)
📝 e2e/advanced-memory.e2e.ts (+67 -1)
📝 packages/client/src/components/chat/AdvancedMemorySettings.tsx (+6 -3)
📝 packages/client/src/components/presets/PresetEditor.tsx (+15 -15)
📝 packages/client/src/localization/locales/en.json (+3 -2)
📝 packages/server/src/routes/generate.routes.ts (+36 -1)
📝 packages/server/src/services/advanced-memory.ts (+256 -161)
📝 packages/server/src/services/agents/agent-progress.ts (+8 -8)
📝 scripts/regressions/advanced-memory-core.regression.ts (+25 -17)
📝 scripts/regressions/advanced-memory-generation.regression.ts (+3 -1)
📝 scripts/regressions/advanced-memory-history-start.regression.ts (+9 -4)
📝 scripts/regressions/advanced-memory-post-generation.regression.ts (+321 -11)
📝 scripts/regressions/advanced-memory-recall.regression.ts (+153 -3)
📝 scripts/regressions/advanced-memory-summary.regression.ts (+5 -1)
📝 scripts/regressions/agent-scene-check.regression.ts (+13 -10)
📝 scripts/regressions/roleplay-interrupt-generation.regression.ts (+5 -1)

📄 Description

Linked issue

Follow-up to #6474 and #6471, based on SpicyMarinara's post-update testing. Implementation owner: SpicyMarinara / Codex.

Why this change

Enabled Chat Summaries disappeared until their entire ranges fell behind the live cutoff. Constants now remain included across archived, overlapping and live ranges, with character access and historical-source restrictions preserved. The configured memory budget now prioritizes constants, then scene summaries, then excerpts, while keeping compaction after the main reply.

What changed

  • Allocate each character's summary and recall budget in this order: enabled constants, all selected scene summaries, then excerpts. Constants target at most 70% of the configured budget; the combined memory block may use up to 2,000 additional tokens.
  • Compact over-budget constants only after the main reply, with no wait before generation. Reuse ranged and legacy Chat Summaries, the helper connection, and Chat Summary's Maximum output size. Separate private audiences do not add together for compaction.
  • Count expanded macro text for compaction. Shared templates whose text differs by character remain intact; their size is reserved while other constants combine. If those templates alone exceed the target, they need a manual edit.
  • Show one Recalled Scenes option in preset marker selection; existing recalled_messages markers remain compatible aliases.
  • Omit illustration attachments and captions from recalled message text and new summary inputs; retain readable text attachments.
  • Send canonical message numbers to post-generation checks and request exact scene endings. Consecutive archived ranges begin after the previous ending and include the reported end, including the latest reply. Live scenes stay excluded from recall.
  • Reuse the existing tracker-batching hook when source visibility and context capacity permit, with standalone helper fallback. Archive preparation remains after the main reply.
  • Keep existing archives and completed summaries. Incompatible cached prompts refresh once; no memory reset is needed.

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 evidence:

  • pnpm check and pnpm regression:prompt passed. One existing client hook-dependency lint warning remains outside this patch.
  • All 8 Advanced Memory regression suites and the agent scene-check suite passed. Cases cover multiple constants, priority over recall, disabled/future exclusions, dynamic per-user and per-character 70% shares, the total 2,000-token allowance, preserved maximum output size, attachment filtering, numbered endings, stale/invalid decisions, and no pre-generation preparation.
  • pnpm exec playwright test e2e/advanced-memory.e2e.ts e2e/advanced-memory-wizard.e2e.ts --workers=1: all 24 cases passed across desktop Chromium, mobile Chromium and mobile WebKit, including streaming with the OpenAI Responses fixture, idle behavior and post-generation progress.
  • Actual HTTP fixtures verify one tracker call supplies the scene decision, only the newly closed range is summarized/indexed, and consecutive endings produce #1–#5 then #6–#10. Fully live scenes are not recalled.
  • The 1,000-message performance fixture retained approximately 0.2–0.3-second preparation and 0.4-second Peek Prompt, with responsive concurrent character/preset requests.
  • ARM64 full Docker image built and ran; API, frontend, native bindings and persistence passed using an isolated disposable volume.
  • Local CodeRabbit review covered the implementation and follow-ups. Fixed per-audience budget calculation, expanded macro counting, shared-template preservation, and fixture cleanup. The archive-rebuild suggestion was declined: record fingerprints intentionally exclude recall size settings, and the passing regressions verify reuse without paid archive regeneration. The requested budget percentages and priority rules remain in the user-facing release notes. #6491 tracks translated docs.

Manual verification notes

Manually verify the original long iPhone chat: all applicable enabled constants in Peek Prompt, illustration-free recalled excerpts, and exact closed-scene ranges with and without tracker agents. Automated fixtures do not establish live-model scene judgment or physical-iPhone behavior.

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
  • Version/release files updated (only if this PR includes a version bump)

Updated CHANGELOG.md and docs/agents/memory.md; #6491 tracks all ten documentation language packs. No storage migration or version bump.

UI evidence

Settings describe the combined memory budget and its allocation. Presets offer one combined recall marker. Browser coverage includes the legacy alias, the single marker picker, budget autosave, archive editing/deletion, idle behavior, streaming and background progress. Before/after desktop and iPhone screenshots were captured locally; browser test artifacts include current light/dark marker-picker screenshots. The original physical-iPhone chat remains a manual check.

Summary by CodeRabbit

  • New Features

    • Advanced Memory now identifies and archives completed scenes using exact message boundaries.
    • Summary and recall budgets prioritize enabled constants, with up to 2,000 additional tokens available when needed.
    • Enabled summaries remain available alongside overlapping live history and take priority over optional recalled scenes.
    • Recalled context excludes images and image captions while retaining readable text attachments.
    • Presets now use a unified Recalled Scenes marker, while existing message markers remain compatible aliases.
  • Documentation

    • Updated Advanced Memory guidance for scene tracking, budget allocation, marker usage, and attachment handling.

🔄 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/6490 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 9/21/2026 **Status:** ✅ Merged **Merged:** 9/21/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `codex/sept21-memory-constants-scenes` --- ### 📝 Commits (9) - [`96dbe41`](https://github.com/Pasta-Devs/Marinara-Engine/commit/96dbe41a2401a0a8a586664692eec9c9780aac1c) docs: track Advanced Memory constant and scene follow-up - [`3493c74`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3493c745e8faa0a146b3954b6eee9aec72aa36bf) fix: retain constants and archive numbered scene endings after replies - [`d84328e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d84328ee6efe4f7cb6563c4bd5a5e81ebd0e2457) test: align interrupt fixture with numbered scene-check decisions - [`422054c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/422054cecbb8a322791ea91967ae812c344f9392) fix: tell the summary helper about the soft token target - [`f4fc936`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f4fc9369683e0039cd762eec96d19def39b32bbe) Merge branch 'staging' into codex/sept21-memory-constants-scenes - [`0feb91b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0feb91bb96251e07dbccf6db99e7d1d52a178ef8) fix: reserve per-character constant share and unify recall markers - [`7167804`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7167804dc00b04c79f0ef8e9c581690f6086b6c1) fix: preserve scoped summary macros during compaction - [`e771565`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e77156598887e86d6f17b4b31d82cf10f4c39b98) Merge remote-tracking branch 'origin/staging' into codex/sept21-memory-constants-scenes - [`95f6009`](https://github.com/Pasta-Devs/Marinara-Engine/commit/95f6009187d22b8a009e873e21767cdcfc7ecca9) Merge remote-tracking branch 'origin/codex/sept21-memory-constants-scenes' into codex/sept21-memory-constants-scenes ### 📊 Changes **18 files changed** (+936 additions, -246 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+5 -0) 📝 `docs/agents/memory.md` (+5 -6) 📝 `e2e/advanced-memory-wizard.e2e.ts` (+1 -1) 📝 `e2e/advanced-memory.e2e.ts` (+67 -1) 📝 `packages/client/src/components/chat/AdvancedMemorySettings.tsx` (+6 -3) 📝 `packages/client/src/components/presets/PresetEditor.tsx` (+15 -15) 📝 `packages/client/src/localization/locales/en.json` (+3 -2) 📝 `packages/server/src/routes/generate.routes.ts` (+36 -1) 📝 `packages/server/src/services/advanced-memory.ts` (+256 -161) 📝 `packages/server/src/services/agents/agent-progress.ts` (+8 -8) 📝 `scripts/regressions/advanced-memory-core.regression.ts` (+25 -17) 📝 `scripts/regressions/advanced-memory-generation.regression.ts` (+3 -1) 📝 `scripts/regressions/advanced-memory-history-start.regression.ts` (+9 -4) 📝 `scripts/regressions/advanced-memory-post-generation.regression.ts` (+321 -11) 📝 `scripts/regressions/advanced-memory-recall.regression.ts` (+153 -3) 📝 `scripts/regressions/advanced-memory-summary.regression.ts` (+5 -1) 📝 `scripts/regressions/agent-scene-check.regression.ts` (+13 -10) 📝 `scripts/regressions/roleplay-interrupt-generation.regression.ts` (+5 -1) </details> ### 📄 Description ## Linked issue Follow-up to #6474 and #6471, based on SpicyMarinara's post-update testing. Implementation owner: SpicyMarinara / Codex. ## Why this change Enabled Chat Summaries disappeared until their entire ranges fell behind the live cutoff. Constants now remain included across archived, overlapping and live ranges, with character access and historical-source restrictions preserved. The configured memory budget now prioritizes constants, then scene summaries, then excerpts, while keeping compaction after the main reply. ## What changed - Allocate each character's summary and recall budget in this order: enabled constants, all selected scene summaries, then excerpts. Constants target at most 70% of the configured budget; the combined memory block may use up to 2,000 additional tokens. - Compact over-budget constants only after the main reply, with no wait before generation. Reuse ranged and legacy Chat Summaries, the helper connection, and Chat Summary's Maximum output size. Separate private audiences do not add together for compaction. - Count expanded macro text for compaction. Shared templates whose text differs by character remain intact; their size is reserved while other constants combine. If those templates alone exceed the target, they need a manual edit. - Show one Recalled Scenes option in preset marker selection; existing recalled_messages markers remain compatible aliases. - Omit illustration attachments and captions from recalled message text and new summary inputs; retain readable text attachments. - Send canonical message numbers to post-generation checks and request exact scene endings. Consecutive archived ranges begin after the previous ending and include the reported end, including the latest reply. Live scenes stay excluded from recall. - Reuse the existing tracker-batching hook when source visibility and context capacity permit, with standalone helper fallback. Archive preparation remains after the main reply. - Keep existing archives and completed summaries. Incompatible cached prompts refresh once; no memory reset is needed. ## 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 evidence: - `pnpm check` and `pnpm regression:prompt` passed. One existing client hook-dependency lint warning remains outside this patch. - All 8 Advanced Memory regression suites and the agent scene-check suite passed. Cases cover multiple constants, priority over recall, disabled/future exclusions, dynamic per-user and per-character 70% shares, the total 2,000-token allowance, preserved maximum output size, attachment filtering, numbered endings, stale/invalid decisions, and no pre-generation preparation. - `pnpm exec playwright test e2e/advanced-memory.e2e.ts e2e/advanced-memory-wizard.e2e.ts --workers=1`: all 24 cases passed across desktop Chromium, mobile Chromium and mobile WebKit, including streaming with the OpenAI Responses fixture, idle behavior and post-generation progress. - Actual HTTP fixtures verify one tracker call supplies the scene decision, only the newly closed range is summarized/indexed, and consecutive endings produce #1–#5 then #6–#10. Fully live scenes are not recalled. - The 1,000-message performance fixture retained approximately 0.2–0.3-second preparation and 0.4-second Peek Prompt, with responsive concurrent character/preset requests. - ARM64 full Docker image built and ran; API, frontend, native bindings and persistence passed using an isolated disposable volume. - Local CodeRabbit review covered the implementation and follow-ups. Fixed per-audience budget calculation, expanded macro counting, shared-template preservation, and fixture cleanup. The archive-rebuild suggestion was declined: record fingerprints intentionally exclude recall size settings, and the passing regressions verify reuse without paid archive regeneration. The requested budget percentages and priority rules remain in the user-facing release notes. #6491 tracks translated docs. ### Manual verification notes Manually verify the original long iPhone chat: all applicable enabled constants in Peek Prompt, illustration-free recalled excerpts, and exact closed-scene ranges with and without tracker agents. Automated fixtures do not establish live-model scene judgment or physical-iPhone behavior. ## 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 - [ ] Version/release files updated (only if this PR includes a version bump) Updated `CHANGELOG.md` and `docs/agents/memory.md`; #6491 tracks all ten documentation language packs. No storage migration or version bump. ## UI evidence Settings describe the combined memory budget and its allocation. Presets offer one combined recall marker. Browser coverage includes the legacy alias, the single marker picker, budget autosave, archive editing/deletion, idle behavior, streaming and background progress. Before/after desktop and iPhone screenshots were captured locally; browser test artifacts include current light/dark marker-picker screenshots. The original physical-iPhone chat remains a manual check. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Advanced Memory now identifies and archives completed scenes using exact message boundaries. - Summary and recall budgets prioritize enabled constants, with up to 2,000 additional tokens available when needed. - Enabled summaries remain available alongside overlapping live history and take priority over optional recalled scenes. - Recalled context excludes images and image captions while retaining readable text attachments. - Presets now use a unified **Recalled Scenes** marker, while existing message markers remain compatible aliases. - **Documentation** - Updated Advanced Memory guidance for scene tracking, budget allocation, marker usage, and attachment handling. <!-- 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-23 04:17:27 +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#7200
No description provided.