[PR #8841] [MERGED] fix(server): hold summarized Roleplay history to the recent message tail #8838

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

📋 Pull Request Information

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

Base: staging ← Head: fix/recent-tail-strict


📝 Commits (2)

  • 6cfa789 fix(server): hold summarized Roleplay history to the recent message tail
  • ee4b5f2 fix(server): keep messages whose summary the prompt leaves out

📊 Changes

14 files changed (+730 additions, -23 deletions)

View changed files

📝 docs/agents/memory.md (+2 -0)
📝 docs/chats/peek-prompt.md (+2 -0)
➕ e2e/peek-prompt-current-context.e2e.ts (+81 -0)
📝 e2e/summary-controls.e2e.ts (+125 -0)
📝 packages/client/src/components/chat/ChatSummaryPanel.tsx (+17 -1)
📝 packages/client/src/components/chat/PeekPromptModal.tsx (+49 -2)
📝 packages/client/src/hooks/use-chats.ts (+21 -2)
📝 packages/client/src/localization/locales/en.json (+6 -0)
📝 packages/server/src/routes/chats.routes.ts (+33 -12)
📝 packages/server/src/routes/generate.routes.ts (+6 -0)
📝 packages/server/src/routes/generate/dry-run-route.ts (+6 -0)
📝 packages/server/src/routes/generate/generate-route-utils.ts (+36 -0)
📝 packages/server/src/services/generation/roleplay-summary-retrieval.ts (+29 -6)
➕ scripts/regressions/summary-recent-tail.regression.ts (+317 -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 #8831

Why this change

With Automatic Summaries and Hide summarised messages on, users set Recent message tail to 10 but Peek Prompt showed 12 to 24 history messages, and the count changed from turn to turn (#8831). Prompts got bigger and cost more than the setting suggests, and nothing said why. After this change the tail is a real cap on summarized messages. The prompt holds at most the tail plus any older messages no summary covers yet. Chat Summary counts those messages instead of letting them exceed the tail silently. Peek Prompt now says that a saved request comes from before that turn's summary, and can show the context as it is now.

What changed

  • Server: new pure helper capSummarizedHistory in packages/server/src/routes/generate/generate-route-utils.ts. When Hide summarised messages is on, it drops any message an enabled summary entry covers once that message is older than the newest summaryTailMessages messages. It keeps a covered message the user un-hid by hand (visibilityManual). It keeps older messages no entry covers and returns how many there are as backlog. A message covered only by a turned-off entry is kept but not counted, which matches what Backfill Summary skips.
  • Server: Roleplay generation (generate.routes.ts, only without Advanced Memory), the dry-run preview (dry-run-route.ts) and Peek Prompt's live assembly (chats.routes.ts) now pass history through capSummarizedHistory, after hidden-message filtering and before the context message limit. Summary selection still reads all stored messages, so it is unaffected.
  • Server: new GET /api/chats/:id/summary-backlog. It returns the backlog count for the history the next Roleplay prompt would start from, and 0 for other modes or when Advanced Memory is on.
  • Server: POST /api/chats/:id/peek-prompt accepts { current: true }. This skips the saved request and builds the live preview now. In that case the four live-preview return paths no longer claim that "No saved model request was available" (they share one livePreviewNote).
  • Client: Chat Summary shows a localized status line under Recent message tail when the backlog is above 0 (ui.chat.summarypopover.summaryBacklog). It comes from a new useSummaryBacklog query under chatKeys.summaryBacklog (nested under the messages key, so transcript refreshes update it), keyed by the tail and each entry's id, enabled state and message count.
  • Client: on an Exact Text Model Request, Peek Prompt shows a localized hint that the request is the one sent for that reply, captured before any later summary or hiding. A Show current context / Show sent request button switches to a live preview fetched once with current: true and back. Reply checkup is hidden in the current view, and running a Decision test goes back to the sent request.
  • Docs: one paragraph each in docs/agents/memory.md (how the tail caps summarized messages, the backlog note, Backfill Summary) and docs/chats/peek-prompt.md (sent request vs current context). Translation follow-up is the existing issue #8835 [docs-i18n] docs/agents/memory.md, docs/chats/peek-prompt.md, opened by the earlier attempt with this same content, so I reused it instead of opening a duplicate.
  • Tests: new scripts/regressions/summary-recent-tail.regression.ts drives real generations against a fake provider through the issue's scenario. It checks the history counts sent per turn ([65, 26, 26, 26, 10, 10]), the backlog after each turn ([16, 16, 16, 0, 0, 0]), the saved vs current Peek Prompt and the dry-run preview, plus unit cases for the helper (hiding off, disabled entry, tail 0, manual un-hide, disabled-entry backlog). New e2e/peek-prompt-current-context.e2e.ts and a new backlog test in e2e/summary-controls.e2e.ts.
  • A swipe or regeneration with Hide summarised messages on now sends, word for word, the messages covered by the summary of the reply it replaces. Before, they were dropped from history while that summary was also left out.
  • With Semantic Summary Retrieval on, messages covered only by an older summary that retrieval may skip stay in the prompt as written, instead of being dropped by the recent message tail.
  • The Chat Summary backlog note now updates once turning on Hide summarised messages, changing the tail or editing summaries is saved, instead of keeping a count taken before the save.

Validation

  • pnpm check passes locally
  • Ran the app, clicked through the changes manually

Manual verification notes

  • Manually verify in a browser: in a Roleplay chat with more than 50 messages, turn on Automatic Summaries and Hide summarised messages, set Recent message tail to 10, generate until an automatic summary runs, and confirm that the next reply's Peek Prompt shows at most 10 history messages plus the number Chat Summary reports under Recent message tail.
  • Manually verify that Chat Summary shows the line 'Older messages still sent past this tail because no summary covers them yet: N. Backfill Summary can summarize them.' after the first automatic summary, and that it disappears after clicking Backfill Summary and the backfill finishes.
  • Manually verify that opening Peek prompt from the newest AI message shows the 'This is the request as sent for this reply…' hint, that Show current context switches the badge to Live Preview and shows the smaller current history, and that Show sent request returns to the Exact Text Model Request without another network request.
  • Manually verify that running a Decision test inside Peek Prompt while the current context is shown, then clicking Show original prompt, returns to the sent request.
  • Manually verify on a phone-width window that the new hint, button and backlog line wrap without horizontal scroll, in light and dark themes.
  • Manually verify that with Hide summarised messages off, or with Advanced Memory on, prompts and Chat Summary behave as before (no backlog line, no history cap).

Agent-run checks (for reference):

  • node ./scripts/run-regressions.mjs --filter scripts/regressions/summary-recent-tail.regression.ts (new swipe case, HEAD code): FAILED as expected: 'a swipe sends what its left-out summary covers' 4 !== 15
  • node ./scripts/run-regressions.mjs --filter scripts/regressions/summary-recent-tail.regression.ts (final, after prettier --write): PASSED, 1/1
  • node ./scripts/run-regressions.mjs --filter for each of: summary-recent-tail, regeneration-context, prompt, advanced-memory-generation, summary-write-: all 9 PASSED
  • throwaway tsx probe of capSummarizedHistory with semantic retrieval (HEAD helper vs fixed helper; probe deleted afterwards): HEAD [m1,m2,m6,m7,m8], fix [m1,m2,m3,m4,m6,m7,m8]
  • npx playwright test e2e/summary-controls.e2e.ts --project=desktop-chromium -g backlog (new save-race test, before the client fix): 1 failed: switch checked, early backlog {backlog:0}, the note with count 3 never appeared
  • npx playwright test e2e/summary-controls.e2e.ts e2e/peek-prompt-current-context.e2e.ts --project=desktop-chromium (final): 9 passed, 2 skipped (the phone-keyboard tests skip on non-mobile projects by design); mobile projects not run
  • pnpm check (final tree): exit 0; client lint 0 errors, 12 warnings, all in ChatArea.tsx, HomeProfessorMariChat.tsx and ConnectionSwitcherBody.tsx, none of which this commit touches
  • pnpm localization:check: exit 0, newEnglishKeys 0, changedFiles []
  • npx prettier --check on the 7 changed files; git diff --check: the regression file needed formatting, fixed with prettier --write and rerun (PASSED); diff check clean

Independent review of 6cfa78983a: 3 findings. Two fixed in ee4b5f2239 (a swipe or retrieval could drop messages whose summary the prompt leaves out; the backlog note could show a stale 0 right after turning hiding on). One not changed at the maintainer's direction (the backlog note does not apply the removed context message limit). Dottore Review: Viable, With Notes, no defects.

Known limits and risks:

  • Automatic summaries still pick the newest summaryContextSize messages on a first run (selectRollingSummaryMessages is unchanged). A large uncovered backlog is not summarized oldest-first automatically. It shrinks over later runs or through Backfill Summary, and the new note in Chat Summary shows its size until then.
  • The tail counts every visible message, including narrator/system ones, the same way summary hiding always has. Users who count only user/assistant messages may see fewer of those than the tail number.
  • The current-context view is Peek Prompt's existing best-effort live preview. It leaves out runtime-only parts such as cached game state, scene context and semantic memory, and it drops a trailing assistant reply. Right after a reply it can therefore show tail-1 history messages and one older message than the next request will. The hint says it is best-effort.
  • The backlog note counts messages only while Hide summarised messages is on, in Roleplay chats without Advanced Memory. Unsummarized messages newer than the last summary but older than the tail (for example when Every is larger than the tail) also count until the next automatic summary covers them.
  • A covered message the user un-hid by hand stays in the prompt past the tail. As before, a later summary that re-covers it can hide it again.
  • The hint and current-context toggle appear only on a saved exact request. {{prompt}} after a summary already fell back to a live preview through the summary fingerprint check.
  • Local CodeRabbit review was not run in this step. Mobile e2e projects were not run (task asked for desktop only).

🤖 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/8841 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/4/2026 **Status:** ✅ Merged **Merged:** 11/4/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/recent-tail-strict` --- ### 📝 Commits (2) - [`6cfa789`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6cfa78983ab7c7d4ea280509630154427332a33e) fix(server): hold summarized Roleplay history to the recent message tail - [`ee4b5f2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ee4b5f223905334841b99973388692b081347e7a) fix(server): keep messages whose summary the prompt leaves out ### 📊 Changes **14 files changed** (+730 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `docs/agents/memory.md` (+2 -0) 📝 `docs/chats/peek-prompt.md` (+2 -0) ➕ `e2e/peek-prompt-current-context.e2e.ts` (+81 -0) 📝 `e2e/summary-controls.e2e.ts` (+125 -0) 📝 `packages/client/src/components/chat/ChatSummaryPanel.tsx` (+17 -1) 📝 `packages/client/src/components/chat/PeekPromptModal.tsx` (+49 -2) 📝 `packages/client/src/hooks/use-chats.ts` (+21 -2) 📝 `packages/client/src/localization/locales/en.json` (+6 -0) 📝 `packages/server/src/routes/chats.routes.ts` (+33 -12) 📝 `packages/server/src/routes/generate.routes.ts` (+6 -0) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+6 -0) 📝 `packages/server/src/routes/generate/generate-route-utils.ts` (+36 -0) 📝 `packages/server/src/services/generation/roleplay-summary-retrieval.ts` (+29 -6) ➕ `scripts/regressions/summary-recent-tail.regression.ts` (+317 -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 #8831 ## Why this change With Automatic Summaries and Hide summarised messages on, users set Recent message tail to 10 but Peek Prompt showed 12 to 24 history messages, and the count changed from turn to turn (#8831). Prompts got bigger and cost more than the setting suggests, and nothing said why. After this change the tail is a real cap on summarized messages. The prompt holds at most the tail plus any older messages no summary covers yet. Chat Summary counts those messages instead of letting them exceed the tail silently. Peek Prompt now says that a saved request comes from before that turn's summary, and can show the context as it is now. ## What changed - Server: new pure helper `capSummarizedHistory` in `packages/server/src/routes/generate/generate-route-utils.ts`. When Hide summarised messages is on, it drops any message an enabled summary entry covers once that message is older than the newest `summaryTailMessages` messages. It keeps a covered message the user un-hid by hand (`visibilityManual`). It keeps older messages no entry covers and returns how many there are as `backlog`. A message covered only by a turned-off entry is kept but not counted, which matches what Backfill Summary skips. - Server: Roleplay generation (`generate.routes.ts`, only without Advanced Memory), the dry-run preview (`dry-run-route.ts`) and Peek Prompt's live assembly (`chats.routes.ts`) now pass history through `capSummarizedHistory`, after hidden-message filtering and before the context message limit. Summary selection still reads all stored messages, so it is unaffected. - Server: new `GET /api/chats/:id/summary-backlog`. It returns the backlog count for the history the next Roleplay prompt would start from, and 0 for other modes or when Advanced Memory is on. - Server: `POST /api/chats/:id/peek-prompt` accepts `{ current: true }`. This skips the saved request and builds the live preview now. In that case the four live-preview return paths no longer claim that "No saved model request was available" (they share one `livePreviewNote`). - Client: Chat Summary shows a localized status line under **Recent message tail** when the backlog is above 0 (`ui.chat.summarypopover.summaryBacklog`). It comes from a new `useSummaryBacklog` query under `chatKeys.summaryBacklog` (nested under the messages key, so transcript refreshes update it), keyed by the tail and each entry's id, enabled state and message count. - Client: on an **Exact Text Model Request**, Peek Prompt shows a localized hint that the request is the one sent for that reply, captured before any later summary or hiding. A **Show current context** / **Show sent request** button switches to a live preview fetched once with `current: true` and back. Reply checkup is hidden in the current view, and running a Decision test goes back to the sent request. - Docs: one paragraph each in `docs/agents/memory.md` (how the tail caps summarized messages, the backlog note, Backfill Summary) and `docs/chats/peek-prompt.md` (sent request vs current context). Translation follow-up is the existing issue #8835 `[docs-i18n] docs/agents/memory.md, docs/chats/peek-prompt.md`, opened by the earlier attempt with this same content, so I reused it instead of opening a duplicate. - Tests: new `scripts/regressions/summary-recent-tail.regression.ts` drives real generations against a fake provider through the issue's scenario. It checks the history counts sent per turn ([65, 26, 26, 26, 10, 10]), the backlog after each turn ([16, 16, 16, 0, 0, 0]), the saved vs current Peek Prompt and the dry-run preview, plus unit cases for the helper (hiding off, disabled entry, tail 0, manual un-hide, disabled-entry backlog). New `e2e/peek-prompt-current-context.e2e.ts` and a new backlog test in `e2e/summary-controls.e2e.ts`. - A swipe or regeneration with Hide summarised messages on now sends, word for word, the messages covered by the summary of the reply it replaces. Before, they were dropped from history while that summary was also left out. - With Semantic Summary Retrieval on, messages covered only by an older summary that retrieval may skip stay in the prompt as written, instead of being dropped by the recent message tail. - The Chat Summary backlog note now updates once turning on Hide summarised messages, changing the tail or editing summaries is saved, instead of keeping a count taken before the save. ## Validation <!-- These are human tasks. Never tick a box for a check that was not actually performed. --> - [ ] `pnpm check` passes locally - [ ] Ran the app, clicked through the changes manually ### Manual verification notes - Manually verify in a browser: in a Roleplay chat with more than 50 messages, turn on Automatic Summaries and Hide summarised messages, set Recent message tail to 10, generate until an automatic summary runs, and confirm that the next reply's Peek Prompt shows at most 10 history messages plus the number Chat Summary reports under Recent message tail. - Manually verify that Chat Summary shows the line 'Older messages still sent past this tail because no summary covers them yet: N. Backfill Summary can summarize them.' after the first automatic summary, and that it disappears after clicking Backfill Summary and the backfill finishes. - Manually verify that opening Peek prompt from the newest AI message shows the 'This is the request as sent for this reply…' hint, that Show current context switches the badge to Live Preview and shows the smaller current history, and that Show sent request returns to the Exact Text Model Request without another network request. - Manually verify that running a Decision test inside Peek Prompt while the current context is shown, then clicking Show original prompt, returns to the sent request. - Manually verify on a phone-width window that the new hint, button and backlog line wrap without horizontal scroll, in light and dark themes. - Manually verify that with Hide summarised messages off, or with Advanced Memory on, prompts and Chat Summary behave as before (no backlog line, no history cap). Agent-run checks (for reference): - node ./scripts/run-regressions.mjs --filter scripts/regressions/summary-recent-tail.regression.ts (new swipe case, HEAD code): FAILED as expected: 'a swipe sends what its left-out summary covers' 4 !== 15 - node ./scripts/run-regressions.mjs --filter scripts/regressions/summary-recent-tail.regression.ts (final, after prettier --write): PASSED, 1/1 - node ./scripts/run-regressions.mjs --filter for each of: summary-recent-tail, regeneration-context, prompt, advanced-memory-generation, summary-write-: all 9 PASSED - throwaway tsx probe of capSummarizedHistory with semantic retrieval (HEAD helper vs fixed helper; probe deleted afterwards): HEAD [m1,m2,m6,m7,m8], fix [m1,m2,m3,m4,m6,m7,m8] - npx playwright test e2e/summary-controls.e2e.ts --project=desktop-chromium -g backlog (new save-race test, before the client fix): 1 failed: switch checked, early backlog {backlog:0}, the note with count 3 never appeared - npx playwright test e2e/summary-controls.e2e.ts e2e/peek-prompt-current-context.e2e.ts --project=desktop-chromium (final): 9 passed, 2 skipped (the phone-keyboard tests skip on non-mobile projects by design); mobile projects not run - pnpm check (final tree): exit 0; client lint 0 errors, 12 warnings, all in ChatArea.tsx, HomeProfessorMariChat.tsx and ConnectionSwitcherBody.tsx, none of which this commit touches - pnpm localization:check: exit 0, newEnglishKeys 0, changedFiles [] - npx prettier --check on the 7 changed files; git diff --check: the regression file needed formatting, fixed with prettier --write and rerun (PASSED); diff check clean Independent review of 6cfa78983a: 3 findings. Two fixed in ee4b5f2239 (a swipe or retrieval could drop messages whose summary the prompt leaves out; the backlog note could show a stale 0 right after turning hiding on). One not changed at the maintainer's direction (the backlog note does not apply the removed context message limit). Dottore Review: Viable, With Notes, no defects. Known limits and risks: - Automatic summaries still pick the newest `summaryContextSize` messages on a first run (`selectRollingSummaryMessages` is unchanged). A large uncovered backlog is not summarized oldest-first automatically. It shrinks over later runs or through Backfill Summary, and the new note in Chat Summary shows its size until then. - The tail counts every visible message, including narrator/system ones, the same way summary hiding always has. Users who count only user/assistant messages may see fewer of those than the tail number. - The current-context view is Peek Prompt's existing best-effort live preview. It leaves out runtime-only parts such as cached game state, scene context and semantic memory, and it drops a trailing assistant reply. Right after a reply it can therefore show tail-1 history messages and one older message than the next request will. The hint says it is best-effort. - The backlog note counts messages only while Hide summarised messages is on, in Roleplay chats without Advanced Memory. Unsummarized messages newer than the last summary but older than the tail (for example when Every is larger than the tail) also count until the next automatic summary covers them. - A covered message the user un-hid by hand stays in the prompt past the tail. As before, a later summary that re-covers it can hide it again. - The hint and current-context toggle appear only on a saved exact request. `{{prompt}}` after a summary already fell back to a live preview through the summary fingerprint check. - Local CodeRabbit review was not run in this step. Mobile e2e projects were not run (task asked for desktop only). 🤖 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:40:05 +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#8838
No description provided.