[GH-ISSUE #8831] [Issue]: Recent message tail is not a strict limit and Peek Prompt shows pre-summary counts #8516

Closed
opened 2026-11-07 16:43:28 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @qvazzar on GitHub (Nov 4, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8831

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Recent message tail is configured to 10, but Peek Prompt often shows 12–24 history messages. The value is not enforced as a hard cap on the model-visible history. In addition, Peek Prompt normally shows the cached prompt from the last generation, which was captured before the post-generation summary ran.

Expected behavior

If Recent message tail is 10, then after summary processing completes, the prompt should contain at most the 10 protected recent messages plus any explicitly reported unsummarized backlog. If the backlog cannot be closed, the UI should say so instead of presenting the setting as a strict limit.

Peek Prompt should distinguish:

  • the exact cached request used for a turn;
  • the current model context assembled now.

Actual behavior

The observed number of history messages in Peek Prompt varies between roughly 12 and 24 even when the setting is 10. It changes from turn to turn and does not match the configured tail.

Steps to reproduce

  1. Open a long Roleplay chat with more visible messages than summaryContextSize (default is 50).
  2. Enable Automatic Summaries.
  3. Enable Hide summarised messages.
  4. Set Recent message tail to 10.
  5. Generate several replies.
  6. Open Peek Prompt and count the user/assistant history messages.
  7. Compare the count with the current number of model-visible messages and with the configured tail.

Environment

  • Marinara Engine version: v2.5.1
  • Install type: git clone
  • OS + version: Windows 10 x64
  • Browser or app shell: Browser

Logs, screenshots, or video

Image Image

Additional context

Why this happens

There are several contributing causes.

1. The tail is applied only when messages are hidden, not when the prompt is assembled

summaryTailMessages is used by computeSummaryHideIds in:

  • packages/server/src/routes/generate/generate-route-utils.ts (around lines 840–855)

That helper hides only messages covered by the current summary entry, minus the last tail visible messages. It is not consulted during prompt assembly.

As a result, the model-visible history is closer to:

visible_model_history = tail
                     + messages_arrived_since_last_successful_hide
                     + uncovered_old_prefix

New messages that arrive between successful summary runs are not hidden until the next run. Because automatic summarization runs after the assistant reply, the cached prompt for that reply necessarily contains the pre-summary state.

2. The first automatic batch only covers the last contextSize visible messages

The automatic summary path calls selectRollingSummaryMessages from:

  • packages/server/src/routes/generate.routes.ts (around lines 11717–11721);
  • packages/server/src/routes/generate/generate-route-utils.ts (around lines 981–1020).

When there is no summary-owned hidden boundary yet, that helper returns:

visible.slice(-size);

So on a chat with more than summaryContextSize visible messages, the first automatic summary covers only the newest contextSize messages. Older visible messages are not included in the summary entry and therefore are not hidden by computeSummaryHideIds.

Example:

64 visible messages
summaryContextSize = 50
summaryTailMessages = 10

64 - 50 = 14 older messages remain visible
14 + 10 protected tail = 24 messages in the prompt

Subsequent runs may reduce the old prefix when the visible count drops to contextSize or below, but with a large backlog, a small context window, or summary failures, the prefix can remain for many turns.

3. summaryContextSize can be smaller than the backlog

If summaryContextSize is smaller than the total visible history, one automatic batch cannot cover everything. The engine needs an explicit catch-up/backfill path that starts from the oldest uncovered messages. Otherwise the oldest visible prefix is never summarized and never hidden.

4. summaryContextSize < summaryTailMessages makes hiding a no-op

If the summarizer window is smaller than the protected tail, every selected message falls inside the tail and computeSummaryHideIds hides nothing. The UI currently does not warn about this combination.

5. Peek Prompt prefers the cached prompt from the last generation

The cached prompt is saved in:

  • packages/server/src/routes/generate.routes.ts (around lines 10870–10879).

The automatic summary runs later:

  • packages/server/src/routes/generate.routes.ts (around lines 14358+).

POST /chats/:id/peek-prompt returns the cached prompt first:

  • packages/server/src/routes/chats.routes.ts (around lines 3475–3519).

That cached prompt describes the request that produced the reply, before the post-reply summary and hiding ran. It is expected to contain more messages than the current context. The UI currently presents it as the prompt without making that temporal difference obvious.

6. Other independent limits can change the observed count

  • ChatMetadata.contextMessageLimit in Advanced Parameters applies a separate history limit.
  • Pinned messages and conversation-start markers can change the final history set.
  • computeSummaryHideIds treats all visible roles as tail candidates, including narrator/system, while users often count only user/assistant messages.

Suggested fixes

  1. Make automatic summarization select the oldest uncovered visible messages, not the newest contextSize messages.
  2. After each successful batch, hide everything covered except the protected tail.
  3. Continue catch-up until the model-visible history is within the tail, or show an explicit unsummarized-backlog warning.
  4. Treat Recent message tail as a strict cap for covered messages, or rename and document it as a minimum protected tail.
  5. Warn when summaryContextSize < summaryTailMessages.
  6. Add diagnostics to Chat Summary:
    • excluded from model context;
    • still in model context;
    • unsummarized backlog.
  7. Make Peek Prompt distinguish the cached request from a current live preview, and explain that later summaries are not reflected in the cached request.
  8. Add a regression test covering:
    • 64 visible messages, contextSize=50, tail=10 → after catch-up, 10 messages remain, not 24;
    • a large backlog;
    • contextSize < tail;
    • cached prompt versus current preview.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @qvazzar on GitHub (Nov 4, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8831 Originally assigned to: @SpicyMarinara on GitHub. ## Summary `Recent message tail` is configured to 10, but `Peek Prompt` often shows 12–24 history messages. The value is not enforced as a hard cap on the model-visible history. In addition, `Peek Prompt` normally shows the cached prompt from the last generation, which was captured before the post-generation summary ran. ## Expected behavior If `Recent message tail` is 10, then after summary processing completes, the prompt should contain at most the 10 protected recent messages plus any explicitly reported unsummarized backlog. If the backlog cannot be closed, the UI should say so instead of presenting the setting as a strict limit. `Peek Prompt` should distinguish: - the exact cached request used for a turn; - the current model context assembled now. ## Actual behavior The observed number of history messages in `Peek Prompt` varies between roughly 12 and 24 even when the setting is 10. It changes from turn to turn and does not match the configured tail. ## Steps to reproduce 1. Open a long Roleplay chat with more visible messages than `summaryContextSize` (default is 50). 2. Enable **Automatic Summaries**. 3. Enable **Hide summarised messages**. 4. Set **Recent message tail** to 10. 5. Generate several replies. 6. Open **Peek Prompt** and count the user/assistant history messages. 7. Compare the count with the current number of model-visible messages and with the configured tail. ## Environment - Marinara Engine version: v2.5.1 - Install type: git clone - OS + version: Windows 10 x64 - Browser or app shell: Browser ## Logs, screenshots, or video <img width="986" height="675" alt="Image" src="https://github.com/user-attachments/assets/e956f011-0b31-4b0c-be59-3203e54c7560" /> <img width="390" height="243" alt="Image" src="https://github.com/user-attachments/assets/c5685f0f-c417-491f-852e-3f9d19095fbc" /> ## Additional context ### Why this happens There are several contributing causes. #### 1. The tail is applied only when messages are hidden, not when the prompt is assembled `summaryTailMessages` is used by `computeSummaryHideIds` in: - `packages/server/src/routes/generate/generate-route-utils.ts` (around lines 840–855) That helper hides only messages covered by the current summary entry, minus the last `tail` visible messages. It is not consulted during prompt assembly. As a result, the model-visible history is closer to: ```text visible_model_history = tail + messages_arrived_since_last_successful_hide + uncovered_old_prefix ``` New messages that arrive between successful summary runs are not hidden until the next run. Because automatic summarization runs after the assistant reply, the cached prompt for that reply necessarily contains the pre-summary state. #### 2. The first automatic batch only covers the last `contextSize` visible messages The automatic summary path calls `selectRollingSummaryMessages` from: - `packages/server/src/routes/generate.routes.ts` (around lines 11717–11721); - `packages/server/src/routes/generate/generate-route-utils.ts` (around lines 981–1020). When there is no summary-owned hidden boundary yet, that helper returns: ```ts visible.slice(-size); ``` So on a chat with more than `summaryContextSize` visible messages, the first automatic summary covers only the newest `contextSize` messages. Older visible messages are not included in the summary entry and therefore are not hidden by `computeSummaryHideIds`. Example: ```text 64 visible messages summaryContextSize = 50 summaryTailMessages = 10 64 - 50 = 14 older messages remain visible 14 + 10 protected tail = 24 messages in the prompt ``` Subsequent runs may reduce the old prefix when the visible count drops to `contextSize` or below, but with a large backlog, a small context window, or summary failures, the prefix can remain for many turns. #### 3. `summaryContextSize` can be smaller than the backlog If `summaryContextSize` is smaller than the total visible history, one automatic batch cannot cover everything. The engine needs an explicit catch-up/backfill path that starts from the oldest uncovered messages. Otherwise the oldest visible prefix is never summarized and never hidden. #### 4. `summaryContextSize < summaryTailMessages` makes hiding a no-op If the summarizer window is smaller than the protected tail, every selected message falls inside the tail and `computeSummaryHideIds` hides nothing. The UI currently does not warn about this combination. #### 5. `Peek Prompt` prefers the cached prompt from the last generation The cached prompt is saved in: - `packages/server/src/routes/generate.routes.ts` (around lines 10870–10879). The automatic summary runs later: - `packages/server/src/routes/generate.routes.ts` (around lines 14358+). `POST /chats/:id/peek-prompt` returns the cached prompt first: - `packages/server/src/routes/chats.routes.ts` (around lines 3475–3519). That cached prompt describes the request that produced the reply, before the post-reply summary and hiding ran. It is expected to contain more messages than the current context. The UI currently presents it as the prompt without making that temporal difference obvious. #### 6. Other independent limits can change the observed count - `ChatMetadata.contextMessageLimit` in Advanced Parameters applies a separate history limit. - Pinned messages and conversation-start markers can change the final history set. - `computeSummaryHideIds` treats all visible roles as tail candidates, including narrator/system, while users often count only user/assistant messages. ### Suggested fixes 1. Make automatic summarization select the **oldest uncovered visible messages**, not the newest `contextSize` messages. 2. After each successful batch, hide everything covered except the protected tail. 3. Continue catch-up until the model-visible history is within the tail, or show an explicit unsummarized-backlog warning. 4. Treat `Recent message tail` as a strict cap for covered messages, or rename and document it as a minimum protected tail. 5. Warn when `summaryContextSize < summaryTailMessages`. 6. Add diagnostics to Chat Summary: - excluded from model context; - still in model context; - unsummarized backlog. 7. Make `Peek Prompt` distinguish the cached request from a current live preview, and explain that later summaries are not reflected in the cached request. 8. Add a regression test covering: - 64 visible messages, `contextSize=50`, `tail=10` → after catch-up, 10 messages remain, not 24; - a large backlog; - `contextSize < tail`; - cached prompt versus current preview. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-11-07 16:43:28 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Nov 4, 2026):

Taking this (SpicyMarinara, via Claude Code), branch fix/recent-tail-strict.

<!-- gh-comment-id:6636935366 --> @SpicyMarinara commented on GitHub (Nov 4, 2026): Taking this (SpicyMarinara, via Claude Code), branch `fix/recent-tail-strict`.
Author
Owner

@SpicyMarinara commented on GitHub (Nov 4, 2026):

Fixed by #8841, merged into staging in 06f93787ba.

<!-- gh-comment-id:6644563268 --> @SpicyMarinara commented on GitHub (Nov 4, 2026): Fixed by #8841, merged into staging in 06f93787ba.
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#8516
No description provided.