[PR #6513] [MERGED] fix: preserve memory summaries and make context cutoffs shared and reversible #7208

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

📋 Pull Request Information

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

Base: staging ← Head: codex/sept22-memory-summary-budgets


📝 Commits (6)

  • fe9f0f8 docs: track advanced memory summary budget fix
  • 1de29c6 fix: preserve archived summaries and remove tiny compaction limits
  • 5b34570 fix: make memory cutoffs shared, reversible, and prompt-budgeted
  • 0bfb737 fix: reuse message-extra parser for memory flags
  • 43b52fb fix: save memory context flags and swipe mirrors atomically
  • aceeb07 fix: keep personal start flag saves atomic without clearing shared cutoffs

📊 Changes

23 files changed (+744 additions, -249 deletions)

View changed files

📝 CHANGELOG.md (+6 -0)
📝 docs/agents/memory.md (+7 -7)
📝 e2e/advanced-memory.e2e.ts (+29 -12)
📝 e2e/issue-sweep-chat.e2e.ts (+3 -0)
📝 packages/client/src/components/chat/ChatMessage.tsx (+1 -1)
📝 packages/client/src/components/chat/ChatRoleplaySurface.tsx (+3 -6)
📝 packages/client/src/hooks/use-chats.ts (+4 -1)
📝 packages/client/src/localization/locales/en.json (+2 -2)
📝 packages/server/src/routes/chats.routes.ts (+30 -21)
📝 packages/server/src/routes/generate.routes.ts (+1 -0)
📝 packages/server/src/services/advanced-memory.ts (+160 -110)
📝 packages/server/src/services/agents/agent-progress.ts (+14 -2)
📝 packages/server/src/services/generation/advanced-memory-context.ts (+10 -2)
📝 packages/server/src/services/llm/base-provider.ts (+9 -0)
📝 packages/server/src/services/storage/chats.storage.ts (+76 -0)
📝 packages/shared/src/types/advanced-memory.ts (+3 -1)
📝 scripts/regressions/advanced-memory-context.regression.ts (+6 -0)
📝 scripts/regressions/advanced-memory-core.regression.ts (+20 -16)
📝 scripts/regressions/advanced-memory-generation.regression.ts (+22 -5)
📝 scripts/regressions/advanced-memory-history-start.regression.ts (+148 -36)

...and 3 more files

📄 Description

Linked issue

Closes #6512

Why this change

Advanced Memory could fail repeatedly on a 196-token constant-compaction target, duplicate live messages in summaries, and reset context near 30k despite a 65k setting because reply tokens were subtracted from that allowance. Automatic cutoffs also targeted individual characters and could not be removed through the flag menu.

The context setting now limits the estimated outgoing prompt. Automatic scene resets apply to everyone and can be undone through the existing All flag. Saved summaries survive failed helper calls and resume without reprocessing completed work.

What changed

  • Keep reply tokens separate from the configured prompt threshold while respecting the model's total context capacity. A 65,000-token prompt allowance stays 65,000 with a 32,768-token reply allowance when the model has room.
  • Persist one shared cutoff at the latest scene boundary. Show All selected in the existing New Start menu and clear the automatic cutoff through that control. Personal flags remain independent. Ignore legacy per-character automatic cutoffs; temporary trimming inside an oversized open scene does not create a persistent flag. Shared and personal flag changes save with all swipe copies in one transaction; only shared edits change automatic cutoff metadata; failed saves leave all previous values intact. No archive reset is required.
  • Request 2–3 paragraphs for scene recaps, with at least 8,196 output tokens or the larger Chat Summary Maximum output size. Proportional compaction targets guide length rather than causing hard retry failures.
  • Reject unfinished helper output before saving. Only replace constants when the result is shorter, adding the replacement and deactivating originals together. Use message-range titles.
  • Omit ranged constants overlapping live messages from the prompt, archived constant budget, and compaction. Preserve their saved enabled state and character conditions; legacy unranged entries remain compatible.
  • Show standalone and shared tracker scene checks in Advanced Recall call activity, preserving the interval across reindexing.
  • Give the existing history-navigation browser scenario 90 seconds for its three jumps and three refetches. This addresses the observed staging timeout; individual assertion limits are unchanged. The failed staging lane also passed on rerun.

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 local verification:

  • pnpm check passed after the shared and personal flag-save fixes, including localization, formatting, TypeScript, ESLint and production builds. The existing metadata-namespace guard and regeneration/swipe regression also pass.
  • All eight Advanced Memory regression suites passed. Cases cover the tiny-target failure, output settings, unfinished output, Resume, atomic replacement, range titles, live-range exclusion, reindex cadence, two-character shared cutoffs, clearing All while preserving a personal flag, legacy automatic cutoffs, prompt-only token budgets, missing swipes, and rollback of message/swipe/metadata changes after forced metadata and swipe failures. Successful personal edits retain the shared automatic cutoff. The rollback regression failed before the transaction fix and passes afterward.
  • Prompt, prompt-attachment, context-fit and agent-progress regressions passed.
  • Shared flag removal and streaming/post-generation activity passed across desktop Chromium, mobile Chromium and iPhone WebKit. Flag removal passed again after the atomic storage change. The earlier nine browser checks also covered Conversation and Roleplay history navigation. Light/dark iPhone screenshots were inspected. Browser evidence.
  • Local CodeRabbit review of the atomic storage change completed with zero findings. GitHub review findings about atomic shared/personal flag saves are addressed with transactions and forced-failure regressions; personal edits preserve the shared cutoff. Translation follow-up #6491 covers the documentation finding. Local and GitHub reviews of the final personal-flag correction completed with zero actionable findings. All 40 GitHub checks passed on the final commit, including 346/346 Node regressions, the full desktop/mobile browser matrix, and platform checks. Regression run. Merged to staging as d7c58fa700.

Manual verification notes

Manually verify Resume and post-generation consolidation on the affected chat with the selected helper model. Confirm past constants remain included, live-range constants are absent, due scene checks appear after the reply, and unchecking All restores the shared window without clearing personal flags. Fixtures exercise real routes with deterministic provider responses; live GPT-6-Astra output quality and the exact personal archive have not been reprocessed. iPhone coverage uses WebKit emulation rather than a physical device.

Docs and release impact

Updated CHANGELOG.md and docs/agents/memory.md. Translation follow-up #6491 covers all current language packs and the final behavior. No release version change.

Review follow-up

No inline findings have appeared on merged #6510; its review status remains pending. Any valid late findings will be addressed separately if posted after this follow-up lands.


🔄 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/6513 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 9/21/2026 **Status:** ✅ Merged **Merged:** 9/22/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `codex/sept22-memory-summary-budgets` --- ### 📝 Commits (6) - [`fe9f0f8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fe9f0f8d6bcd017ef67f52df97d2abfa3b0fb2b0) docs: track advanced memory summary budget fix - [`1de29c6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1de29c6c2228357b9f5588acfd9a751dcfc90d45) fix: preserve archived summaries and remove tiny compaction limits - [`5b34570`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5b345701f998aeff8c9bf2accb796d25ff6d12cf) fix: make memory cutoffs shared, reversible, and prompt-budgeted - [`0bfb737`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0bfb73792e97262febe37ee7c12cf0530073ca37) fix: reuse message-extra parser for memory flags - [`43b52fb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/43b52fb4bde7dc92dc81ea349a9536861b1aee77) fix: save memory context flags and swipe mirrors atomically - [`aceeb07`](https://github.com/Pasta-Devs/Marinara-Engine/commit/aceeb0746cc22b44d041ff2832e9db2c945d3f61) fix: keep personal start flag saves atomic without clearing shared cutoffs ### 📊 Changes **23 files changed** (+744 additions, -249 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+6 -0) 📝 `docs/agents/memory.md` (+7 -7) 📝 `e2e/advanced-memory.e2e.ts` (+29 -12) 📝 `e2e/issue-sweep-chat.e2e.ts` (+3 -0) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+1 -1) 📝 `packages/client/src/components/chat/ChatRoleplaySurface.tsx` (+3 -6) 📝 `packages/client/src/hooks/use-chats.ts` (+4 -1) 📝 `packages/client/src/localization/locales/en.json` (+2 -2) 📝 `packages/server/src/routes/chats.routes.ts` (+30 -21) 📝 `packages/server/src/routes/generate.routes.ts` (+1 -0) 📝 `packages/server/src/services/advanced-memory.ts` (+160 -110) 📝 `packages/server/src/services/agents/agent-progress.ts` (+14 -2) 📝 `packages/server/src/services/generation/advanced-memory-context.ts` (+10 -2) 📝 `packages/server/src/services/llm/base-provider.ts` (+9 -0) 📝 `packages/server/src/services/storage/chats.storage.ts` (+76 -0) 📝 `packages/shared/src/types/advanced-memory.ts` (+3 -1) 📝 `scripts/regressions/advanced-memory-context.regression.ts` (+6 -0) 📝 `scripts/regressions/advanced-memory-core.regression.ts` (+20 -16) 📝 `scripts/regressions/advanced-memory-generation.regression.ts` (+22 -5) 📝 `scripts/regressions/advanced-memory-history-start.regression.ts` (+148 -36) _...and 3 more files_ </details> ### 📄 Description ## Linked issue Closes #6512 ## Why this change Advanced Memory could fail repeatedly on a 196-token constant-compaction target, duplicate live messages in summaries, and reset context near 30k despite a 65k setting because reply tokens were subtracted from that allowance. Automatic cutoffs also targeted individual characters and could not be removed through the flag menu. The context setting now limits the estimated outgoing prompt. Automatic scene resets apply to everyone and can be undone through the existing All flag. Saved summaries survive failed helper calls and resume without reprocessing completed work. ## What changed - Keep reply tokens separate from the configured prompt threshold while respecting the model's total context capacity. A 65,000-token prompt allowance stays 65,000 with a 32,768-token reply allowance when the model has room. - Persist one shared cutoff at the latest scene boundary. Show All selected in the existing New Start menu and clear the automatic cutoff through that control. Personal flags remain independent. Ignore legacy per-character automatic cutoffs; temporary trimming inside an oversized open scene does not create a persistent flag. Shared and personal flag changes save with all swipe copies in one transaction; only shared edits change automatic cutoff metadata; failed saves leave all previous values intact. No archive reset is required. - Request 2–3 paragraphs for scene recaps, with at least 8,196 output tokens or the larger Chat Summary Maximum output size. Proportional compaction targets guide length rather than causing hard retry failures. - Reject unfinished helper output before saving. Only replace constants when the result is shorter, adding the replacement and deactivating originals together. Use message-range titles. - Omit ranged constants overlapping live messages from the prompt, archived constant budget, and compaction. Preserve their saved enabled state and character conditions; legacy unranged entries remain compatible. - Show standalone and shared tracker scene checks in Advanced Recall call activity, preserving the interval across reindexing. - Give the existing history-navigation browser scenario 90 seconds for its three jumps and three refetches. This addresses the observed staging timeout; individual assertion limits are unchanged. The failed staging lane also passed on rerun. ## 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 local verification: - `pnpm check` passed after the shared and personal flag-save fixes, including localization, formatting, TypeScript, ESLint and production builds. The existing metadata-namespace guard and regeneration/swipe regression also pass. - All eight Advanced Memory regression suites passed. Cases cover the tiny-target failure, output settings, unfinished output, Resume, atomic replacement, range titles, live-range exclusion, reindex cadence, two-character shared cutoffs, clearing All while preserving a personal flag, legacy automatic cutoffs, prompt-only token budgets, missing swipes, and rollback of message/swipe/metadata changes after forced metadata and swipe failures. Successful personal edits retain the shared automatic cutoff. The rollback regression failed before the transaction fix and passes afterward. - Prompt, prompt-attachment, context-fit and agent-progress regressions passed. - Shared flag removal and streaming/post-generation activity passed across desktop Chromium, mobile Chromium and iPhone WebKit. Flag removal passed again after the atomic storage change. The earlier nine browser checks also covered Conversation and Roleplay history navigation. Light/dark iPhone screenshots were inspected. [Browser evidence](https://gist.github.com/SpicyMarinara/4d2f82ff85a2b27ddb19f77ddca258b8). - Local CodeRabbit review of the atomic storage change completed with zero findings. GitHub review findings about atomic shared/personal flag saves are addressed with transactions and forced-failure regressions; personal edits preserve the shared cutoff. Translation follow-up #6491 covers the documentation finding. Local and GitHub reviews of the final personal-flag correction completed with zero actionable findings. All 40 GitHub checks passed on the final commit, including 346/346 Node regressions, the full desktop/mobile browser matrix, and platform checks. [Regression run](https://github.com/Pasta-Devs/Marinara-Engine/actions/runs/35668628628). Merged to staging as d7c58fa700387a265b2fdf5160ef760729479f7e. ### Manual verification notes Manually verify Resume and post-generation consolidation on the affected chat with the selected helper model. Confirm past constants remain included, live-range constants are absent, due scene checks appear after the reply, and unchecking All restores the shared window without clearing personal flags. Fixtures exercise real routes with deterministic provider responses; live GPT-6-Astra output quality and the exact personal archive have not been reprocessed. iPhone coverage uses WebKit emulation rather than a physical device. ## Docs and release impact Updated `CHANGELOG.md` and `docs/agents/memory.md`. Translation follow-up #6491 covers all current language packs and the final behavior. No release version change. ## Review follow-up No inline findings have appeared on merged #6510; its review status remains pending. Any valid late findings will be addressed separately if posted after this follow-up lands. --- <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:31 +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#7208
No description provided.