[PR #8794] [MERGED] fix(memory): bound Advanced Memory's parsed-extras cache; keep manual hides when a summary that hid nothing is deleted #8807

Closed
opened 2026-11-07 17:39:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8794
Author: @SpicyMarinara
Created: 11/3/2026
Status: ✅ Merged
Merged: 11/3/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/memory-summary-hides-cache


📝 Commits (2)

  • 1dc3533 fix(memory): keep parsed message extras for only the last few chats
  • 4c7fad2 fix(summary): deleting a summary that hid nothing keeps manual hides

📊 Changes

5 files changed (+128 additions, -25 deletions)

View changed files

📝 packages/server/src/routes/chats.routes.ts (+3 -1)
📝 packages/server/src/services/advanced-memory.ts (+12 -3)
📝 packages/shared/src/utils/chat-summary-entries.ts (+7 -2)
📝 scripts/regressions/advanced-memory-prepare-scale.regression.ts (+40 -19)
➕ scripts/regressions/summary-delete-manual-hide.regression.ts (+66 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.

Linked issue

Closes #8793

Why this change

Two problems found in release-prep auditing, both re-checked on staging aed5e3578d.

(1) The two Advanced Memory route services live for the whole server process. Each kept a parsed copy of every message extra for every Roleplay/Game chat it ever read, with no limit. Opening Chat Settings on a Roleplay or Game chat is enough to fill it, even with Advanced Memory off. A deleted chat stayed cached until restart. On SteamOS and Termux the cache also kept chats that the MARINARA_MAX_RESIDENT_CHATS cap had already evicted.

(2) A summary saved with "Hide summarised messages" off records which messages it covers, but no list of messages it hid. Deleting it fell back to the covered list and showed every covered message to the model again. That includes messages the user later hid by hand with the eye toggle or /hide. Branching inside such a summary did the same to the copied messages. Turning the hide setting off already showed only what the summary hid, so delete and branch were the odd ones out.

No linked issue exists. One should be opened before the PR is submitted.

What changed

  • Behaviour change for legacy summaries only: deleting a summary saved before per-entry hidden lists were recorded (pre-2026-06-23 / pre-v2.0.3) no longer unhides the messages it covered. Those messages stay hidden, as they did before v2.0.3, and can be unhidden by hand. Current summaries that hid messages still unhide exactly those messages.
  • Deleting a summary that hid nothing, for example one written with "Hide summarised messages" off, no longer shows messages you hid yourself to the model again.
  • Branching a chat inside such a summary's range keeps your own hides on the copied messages.
  • Advanced Memory now keeps cached message details for only the four chats read most recently, instead of every chat opened since the server started, deleted chats included. This lowers memory use on long sessions, mostly on SteamOS and Termux.

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

Manual verification notes

  • Manually verify in the browser: in a Roleplay chat with "Hide summarised messages" off, summarise messages 1-3, hide message 2 with the eye toggle, delete the summary, and confirm message 2 still shows as hidden from AI.
  • Manually verify in the browser: with "Hide summarised messages" on, summarise a range so messages get hidden, delete the summary, and confirm those messages become visible to the AI again.
  • Manually verify branching: hide a covered message by hand, branch from a message inside the summary's range, and confirm the copied message is still hidden in the new branch.
  • Manually verify that opening Chat Settings and the Advanced Memory inspector across more than four Roleplay/Game chats in one session still loads normally.
  • Not done in this worktree: the relayed user request to make showing off an outfit to a love interest in Otome Hearth give +5 affection instead of +20. Otome Hearth (otome-forge) is a downloadable package; under AGENTS.md its code belongs in Pasta-Devs/Marinara-Agents, outside this worktree. That change still needs to be made there.

Agent-run checks (for reference; each regression was shown to fail without its fix):

  • node ./scripts/pnpm-runner.mjs build:shared: succeeded; rebuilt again after every stash/pop so shared dist matches the fixed source
  • node ./scripts/run-regressions.mjs --filter summary-delete-manual-hide (fixed / both stashed / each half stashed): PASSED with fix; FAILED with each revert, each on its own assertion
  • node ./scripts/run-regressions.mjs --filter advanced-memory-prepare-scale (fixed / stashed / FIFO variant): PASSED with fix; FAILED on the eviction assertion without the fix; FAILED on the re-read assertion with FIFO
  • node ./scripts/run-regressions.mjs --filter advanced-memory: 23/23 passed
  • node ./scripts/run-regressions.mjs --filter summary: 10/10 passed (includes the new regression)
  • node ./scripts/run-regressions.mjs --filter issue-sweep-5391: 1/1 passed
  • node ./scripts/run-regressions.mjs --filter chat-branch: 4/4 passed
  • node ./scripts/run-regressions.mjs --filter profile-apply-hide-summarised / roleplay-commands / data-integrity-bulk-hidden / merged-chat-summary / roleplay-user: 1/1 passed each
  • node ./scripts/run-regressions.mjs --filter memory-recall: 7/7 passed
  • node ./scripts/pnpm-runner.mjs --filter @marinara-engine/shared lint (generate-feature-registries + tsc --noEmit): exit 0
  • node ./scripts/pnpm-runner.mjs --filter @marinara-engine/server lint (tsc -b ../shared && tsc --noEmit && regressions character-activity tsconfig): exit 0
  • npx prettier --write, then npx prettier --check on all 5 changed files: All matched files use Prettier code style

Independent adversarial review: approve.

Known limits and risks:

Low. (1) Cache: a miss only costs a JSON re-parse, so a working set of more than 4 chats per service, for example generating in more than 4 Advanced Memory chats at once, just re-parses more often. Correctness is unchanged. A deleted chat's entry stays until 4 other chats are read on that service; this is marked with a ponytail: comment. (2) Summary: legacy entries saved before hiddenMessageIds existed, which hid all their messageIds client-side, no longer unhide on delete or branch drop, so those messages stay hidden until unhidden by hand. That is the conservative failure direction: nothing hidden is exposed. Retained entries still use the messageIds fallback to protect coverage. Not done here: the relayed user request about Otome Hearth outfit affection (+20 to +5). It is outside this worktree and, under AGENTS.md routing, belongs in the Marinara-Agents package repo, so it still needs separate handling. Nothing was pushed and no PR was opened, per the task rules.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

🤖 Generated with Claude Code


🔄 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/8794 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/3/2026 **Status:** ✅ Merged **Merged:** 11/3/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/memory-summary-hides-cache` --- ### 📝 Commits (2) - [`1dc3533`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1dc35337954bf63563298810179b5e4dd5e7cddb) fix(memory): keep parsed message extras for only the last few chats - [`4c7fad2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4c7fad24126f1ca9c9eb1b1ec67ef20a65636416) fix(summary): deleting a summary that hid nothing keeps manual hides ### 📊 Changes **5 files changed** (+128 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/chats.routes.ts` (+3 -1) 📝 `packages/server/src/services/advanced-memory.ts` (+12 -3) 📝 `packages/shared/src/utils/chat-summary-entries.ts` (+7 -2) 📝 `scripts/regressions/advanced-memory-prepare-scale.regression.ts` (+40 -19) ➕ `scripts/regressions/summary-delete-manual-hide.regression.ts` (+66 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. ## Linked issue Closes #8793 ## Why this change Two problems found in release-prep auditing, both re-checked on staging aed5e3578d. (1) The two Advanced Memory route services live for the whole server process. Each kept a parsed copy of every message extra for every Roleplay/Game chat it ever read, with no limit. Opening Chat Settings on a Roleplay or Game chat is enough to fill it, even with Advanced Memory off. A deleted chat stayed cached until restart. On SteamOS and Termux the cache also kept chats that the MARINARA_MAX_RESIDENT_CHATS cap had already evicted. (2) A summary saved with "Hide summarised messages" off records which messages it covers, but no list of messages it hid. Deleting it fell back to the covered list and showed every covered message to the model again. That includes messages the user later hid by hand with the eye toggle or /hide. Branching inside such a summary did the same to the copied messages. Turning the hide setting off already showed only what the summary hid, so delete and branch were the odd ones out. No linked issue exists. One should be opened before the PR is submitted. ## What changed - Behaviour change for legacy summaries only: deleting a summary saved before per-entry hidden lists were recorded (pre-2026-06-23 / pre-v2.0.3) no longer unhides the messages it covered. Those messages stay hidden, as they did before v2.0.3, and can be unhidden by hand. Current summaries that hid messages still unhide exactly those messages. - Deleting a summary that hid nothing, for example one written with "Hide summarised messages" off, no longer shows messages you hid yourself to the model again. - Branching a chat inside such a summary's range keeps your own hides on the copied messages. - Advanced Memory now keeps cached message details for only the four chats read most recently, instead of every chat opened since the server started, deleted chats included. This lowers memory use on long sessions, mostly on SteamOS and Termux. ## Validation <!-- These are human tasks. Never tick a box for a check that was not actually performed. --> - [ ] `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` ### Manual verification notes - Manually verify in the browser: in a Roleplay chat with "Hide summarised messages" off, summarise messages 1-3, hide message 2 with the eye toggle, delete the summary, and confirm message 2 still shows as hidden from AI. - Manually verify in the browser: with "Hide summarised messages" on, summarise a range so messages get hidden, delete the summary, and confirm those messages become visible to the AI again. - Manually verify branching: hide a covered message by hand, branch from a message inside the summary's range, and confirm the copied message is still hidden in the new branch. - Manually verify that opening Chat Settings and the Advanced Memory inspector across more than four Roleplay/Game chats in one session still loads normally. - Not done in this worktree: the relayed user request to make showing off an outfit to a love interest in Otome Hearth give +5 affection instead of +20. Otome Hearth (otome-forge) is a downloadable package; under AGENTS.md its code belongs in Pasta-Devs/Marinara-Agents, outside this worktree. That change still needs to be made there. Agent-run checks (for reference; each regression was shown to fail without its fix): - `node ./scripts/pnpm-runner.mjs build:shared`: succeeded; rebuilt again after every stash/pop so shared dist matches the fixed source - `node ./scripts/run-regressions.mjs --filter summary-delete-manual-hide (fixed / both stashed / each half stashed)`: PASSED with fix; FAILED with each revert, each on its own assertion - `node ./scripts/run-regressions.mjs --filter advanced-memory-prepare-scale (fixed / stashed / FIFO variant)`: PASSED with fix; FAILED on the eviction assertion without the fix; FAILED on the re-read assertion with FIFO - `node ./scripts/run-regressions.mjs --filter advanced-memory`: 23/23 passed - `node ./scripts/run-regressions.mjs --filter summary`: 10/10 passed (includes the new regression) - `node ./scripts/run-regressions.mjs --filter issue-sweep-5391`: 1/1 passed - `node ./scripts/run-regressions.mjs --filter chat-branch`: 4/4 passed - `node ./scripts/run-regressions.mjs --filter profile-apply-hide-summarised / roleplay-commands / data-integrity-bulk-hidden / merged-chat-summary / roleplay-user`: 1/1 passed each - `node ./scripts/run-regressions.mjs --filter memory-recall`: 7/7 passed - `node ./scripts/pnpm-runner.mjs --filter @marinara-engine/shared lint (generate-feature-registries + tsc --noEmit)`: exit 0 - `node ./scripts/pnpm-runner.mjs --filter @marinara-engine/server lint (tsc -b ../shared && tsc --noEmit && regressions character-activity tsconfig)`: exit 0 - `npx prettier --write, then npx prettier --check on all 5 changed files`: All matched files use Prettier code style Independent adversarial review: approve. Known limits and risks: Low. (1) Cache: a miss only costs a JSON re-parse, so a working set of more than 4 chats per service, for example generating in more than 4 Advanced Memory chats at once, just re-parses more often. Correctness is unchanged. A deleted chat's entry stays until 4 other chats are read on that service; this is marked with a ponytail: comment. (2) Summary: legacy entries saved before hiddenMessageIds existed, which hid all their messageIds client-side, no longer unhide on delete or branch drop, so those messages stay hidden until unhidden by hand. That is the conservative failure direction: nothing hidden is exposed. Retained entries still use the messageIds fallback to protect coverage. Not done here: the relayed user request about Otome Hearth outfit affection (+20 to +5). It is outside this worktree and, under AGENTS.md routing, belongs in the Marinara-Agents package repo, so it still needs separate handling. Nothing was pushed and no PR was opened, per the task rules. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:39:51 +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#8807
No description provided.