[PR #2821] [MERGED] feat(summary): compress roleplay rolling summaries by auto-hiding summarized messages #5752

Closed
opened 2026-10-22 04:19:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2821
Author: @Romuromylus
Created: 6/23/2026
Status: ✅ Merged
Merged: 6/23/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/2820-roleplay-summary-token-compression


📝 Commits (10+)

  • b1d258d feat(summary): compress roleplay rolling summaries by auto-hiding summarized messages
  • 12d5d83 fix(summary): restore legacy hide fallback and stop chat pref leaking globally
  • 7084608 fix(summary): make unhide-on-delete atomic and drop the shared hide fallback
  • 6463dfa fix(summary): own hide pref per-chat, compensate failed delete, scope refetch
  • ed26140 fix(summary): compensate against the exact unhidden set on failed delete
  • 6709302 chore(summary): return the updated message IDs from the bulk-hidden route
  • 65066da chore(summary): keep the bulk-hidden response a count
  • 2eabcb1 fix(summary): descope approval-path hide, simplify delete, harden tail bounds
  • 488e17b fix(summary): apply the recent-message tail to manual hiding too
  • 82a7dec fix(summary): hide the tail-excluded subset on manual last-N, persist hidden set

📊 Changes

10 files changed (+372 additions, -70 deletions)

View changed files

📝 packages/client/src/components/chat/ChatRoleplaySurface.tsx (+18 -0)
📝 packages/client/src/components/chat/SummaryPopover.tsx (+54 -18)
📝 packages/client/src/hooks/use-chats.ts (+12 -0)
📝 packages/client/src/hooks/use-generate.ts (+6 -0)
📝 packages/server/src/routes/chats.routes.ts (+112 -33)
📝 packages/server/src/routes/generate.routes.ts (+29 -2)
📝 packages/server/src/routes/generate/generate-route-utils.ts (+40 -0)
📝 packages/server/src/services/storage/chats.storage.ts (+69 -14)
📝 packages/shared/src/types/chat.ts (+30 -3)
📝 packages/shared/src/utils/chat-summary-entries.ts (+2 -0)

📄 Description

Linked issue

Closes #2820

Why this change

In roleplay / visual-novel mode the rolling summary runs automatically every N user messages and injects a recap into the prompt, but it never hides the messages it just summarized. The originals stay in context, so each summary is a net token increase layered on top of the history it was meant to compress — the opposite of what a rolling summary is for. The only ways to save tokens today are to manually cap context in Advanced Parameters or to manually summarize with "Hide summarised messages" ticked, and even that hides everything with no tail (so the most recent turns can vanish) and never reaches the automatic path.

The primitives already existed — hiddenFromAI, per-entry messageIds, the bulkSetHiddenFromAI storage method, the collapsible hidden-message UI. This change wires them into the automatic summary path so the summary becomes a real token reduction, behind an opt-in toggle.

What changed

  • Opt-in metadata flag. Added ChatMetadata.hideSummarisedMessages (default off — existing chats are untouched). The server auto-summary reads it; the Summary-popover toggle now writes it per-chat instead of only the browser-local UI store (legacy pref is used as the initial display value for back-compat).
  • Auto-hide with a tail. When the flag is on, runAutomaticRoleplaySummary hides the messages a summary covered, except the most-recent summaryTailMessages (reused from the conversation-mode field; default 10, 0 hides the whole batch). The set math lives in two pure, unit-tested helpers — computeSummaryHideIds and resolveRoleplaySummaryTail — and the same helpers run on the approval-gated commit path so behavior is consistent whether or not agent-write approval is required.
  • Tail slider in the Summary popover. A "Recent message tail" control appears under the toggle (roleplay), mirroring the conversation-mode slider.
  • Unhide on delete. Deleting a summary entry now unhides the messages it covered, except any still referenced by another enabled entry — no orphaned permanently-hidden messages.
  • UI freshness. The chat_summary SSE event carries hiddenMessageIds; the client invalidates the message-list query so server-driven hides show immediately.

Scope notes: the manual "Hide summarised messages" popover path is intentionally left as hide-everything (no behavior change for existing manual use). Conversation-mode day/week summaries are untouched — roleplay and conversation summary paths are mutually exclusive by chat mode.

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 a roleplay chat: enable automatic summaries, turn on "Hide summarised messages", set a low interval, send enough messages to trigger a summary, and confirm the older summarized messages become hidden-from-AI while the last summaryTailMessages stay visible.
  • Manually verify the tail slider: set the tail to 0 (whole batch hidden) and to a larger value (more recent messages preserved).
  • Manually verify unhide-on-delete: delete a summary entry and confirm its messages reappear, except any covered by another still-enabled entry.
  • Manually verify opt-out: with the toggle off, a summary run hides nothing (existing-chat behavior).
  • Manually verify the manual Summary-popover "hide" path still works as before.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

To follow once verified on a live build.


🔄 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/2821 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/23/2026 **Status:** ✅ Merged **Merged:** 6/23/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/2820-roleplay-summary-token-compression` --- ### 📝 Commits (10+) - [`b1d258d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b1d258d0134f1e4d034785f356b72d271026b46b) feat(summary): compress roleplay rolling summaries by auto-hiding summarized messages - [`12d5d83`](https://github.com/Pasta-Devs/Marinara-Engine/commit/12d5d838539a583c60b56ccbee41026572f66fa1) fix(summary): restore legacy hide fallback and stop chat pref leaking globally - [`7084608`](https://github.com/Pasta-Devs/Marinara-Engine/commit/70846084d1f0040465acd44ee688113822ec237f) fix(summary): make unhide-on-delete atomic and drop the shared hide fallback - [`6463dfa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6463dfabb970d538921686673dbdb9aab81ed6bf) fix(summary): own hide pref per-chat, compensate failed delete, scope refetch - [`ed26140`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ed2614030f27bd2740df766d51267d372a857265) fix(summary): compensate against the exact unhidden set on failed delete - [`6709302`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6709302bdec8d2fc6effd67f6379ffa2a577f08b) chore(summary): return the updated message IDs from the bulk-hidden route - [`65066da`](https://github.com/Pasta-Devs/Marinara-Engine/commit/65066daed2abc93ed14f8f0c7f5fb1fd6e20b055) chore(summary): keep the bulk-hidden response a count - [`2eabcb1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2eabcb158cb0b09805f1a0ddccbb0b68ef00efe1) fix(summary): descope approval-path hide, simplify delete, harden tail bounds - [`488e17b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/488e17b479558469ce6977a13923286ef4376c80) fix(summary): apply the recent-message tail to manual hiding too - [`82a7dec`](https://github.com/Pasta-Devs/Marinara-Engine/commit/82a7dec5eeadc337ee5bbac551d01b10a4d136f2) fix(summary): hide the tail-excluded subset on manual last-N, persist hidden set ### 📊 Changes **10 files changed** (+372 additions, -70 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatRoleplaySurface.tsx` (+18 -0) 📝 `packages/client/src/components/chat/SummaryPopover.tsx` (+54 -18) 📝 `packages/client/src/hooks/use-chats.ts` (+12 -0) 📝 `packages/client/src/hooks/use-generate.ts` (+6 -0) 📝 `packages/server/src/routes/chats.routes.ts` (+112 -33) 📝 `packages/server/src/routes/generate.routes.ts` (+29 -2) 📝 `packages/server/src/routes/generate/generate-route-utils.ts` (+40 -0) 📝 `packages/server/src/services/storage/chats.storage.ts` (+69 -14) 📝 `packages/shared/src/types/chat.ts` (+30 -3) 📝 `packages/shared/src/utils/chat-summary-entries.ts` (+2 -0) </details> ### 📄 Description ## Linked issue Closes #2820 ## Why this change In roleplay / visual-novel mode the rolling summary runs automatically every N user messages and injects a recap into the prompt, but it never hides the messages it just summarized. The originals stay in context, so each summary is a net token **increase** layered on top of the history it was meant to compress — the opposite of what a rolling summary is for. The only ways to save tokens today are to manually cap context in Advanced Parameters or to manually summarize with "Hide summarised messages" ticked, and even that hides everything with no tail (so the most recent turns can vanish) and never reaches the automatic path. The primitives already existed — `hiddenFromAI`, per-entry `messageIds`, the `bulkSetHiddenFromAI` storage method, the collapsible hidden-message UI. This change wires them into the automatic summary path so the summary becomes a real token reduction, behind an opt-in toggle. ## What changed - **Opt-in metadata flag.** Added `ChatMetadata.hideSummarisedMessages` (default off — existing chats are untouched). The server auto-summary reads it; the Summary-popover toggle now writes it per-chat instead of only the browser-local UI store (legacy pref is used as the initial display value for back-compat). - **Auto-hide with a tail.** When the flag is on, `runAutomaticRoleplaySummary` hides the messages a summary covered, except the most-recent `summaryTailMessages` (reused from the conversation-mode field; default 10, `0` hides the whole batch). The set math lives in two pure, unit-tested helpers — `computeSummaryHideIds` and `resolveRoleplaySummaryTail` — and the same helpers run on the approval-gated commit path so behavior is consistent whether or not agent-write approval is required. - **Tail slider in the Summary popover.** A "Recent message tail" control appears under the toggle (roleplay), mirroring the conversation-mode slider. - **Unhide on delete.** Deleting a summary entry now unhides the messages it covered, except any still referenced by another *enabled* entry — no orphaned permanently-hidden messages. - **UI freshness.** The `chat_summary` SSE event carries `hiddenMessageIds`; the client invalidates the message-list query so server-driven hides show immediately. Scope notes: the manual "Hide summarised messages" popover path is intentionally left as hide-everything (no behavior change for existing manual use). Conversation-mode day/week summaries are untouched — roleplay and conversation summary paths are mutually exclusive by chat mode. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Manually verify in a roleplay chat: enable automatic summaries, turn on "Hide summarised messages", set a low interval, send enough messages to trigger a summary, and confirm the older summarized messages become hidden-from-AI while the last `summaryTailMessages` stay visible. - Manually verify the tail slider: set the tail to `0` (whole batch hidden) and to a larger value (more recent messages preserved). - Manually verify unhide-on-delete: delete a summary entry and confirm its messages reappear, except any covered by another still-enabled entry. - Manually verify opt-out: with the toggle off, a summary run hides nothing (existing-chat behavior). - Manually verify the manual Summary-popover "hide" path still works as before. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) To follow once verified on a live build. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:19:12 +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#5752
No description provided.