[GH-ISSUE #7455] [Issue]: Roll and function-call follow-ups trigger Advanced Memory cutoffs and fail near the limit #4153

Closed
opened 2026-10-21 06:11:50 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @SpicyMarinara on GitHub (Oct 11, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7455

Originally assigned to: @SpicyMarinara on GitHub.

Summary

With Advanced Memory, a dice roll or function-call round can cut the context (archive older scenes) even though the prompt that was sent fit the limit. A follow-up near the limit can also fail the whole reply.

Expected behavior

The automatic cutoff fires only when the input actually sent for the narrator or a character reaches or passes "Maximum allowed context before compression". Function-call rounds and roll follow-ups never cause a cutoff, and they never fail because of that limit.

Actual behavior

  • The cutoff compares the largest request of the turn with the limit. A roll or tool follow-up resends the prompt plus the model's own output, including thinking, the tool call and the result. It is therefore always the largest request, and it triggers the cut while the outgoing prompt itself was under the limit.
  • The check uses >, so an input exactly at the limit does not count.
  • A follow-up that grows past the limit throws "Advanced Memory: this tool follow-up or continuation exceeds the context cap" and the reply fails.

Steps to reproduce

  1. Roleplay with Advanced Memory, Claude Opus, rolls enabled.
  2. Let the prompt grow close to the limit, then get a reply that rolls dice.
  3. The context start jumps to the newest closed scene after that reply, although the first request was within the limit. Reproduced with a route-level regression: the first request was 64,000 under a 65,000 cap and the follow-up 66,600, and a cutoff was saved.

Environment

  • Marinara Engine version: 2.5.0 (staging 3066f0c72)
  • Install type: docker
  • OS + version: n/a (server-side)
  • Browser or app shell: n/a

Logs, screenshots, or video

recordRequestUsage in packages/server/src/routes/generate.routes.ts keeps Math.max over every main request, including tool rounds and follow-ups. resetContextForActualInput in packages/server/src/services/advanced-memory.ts uses <= maxContextTokens as its no-op guard. fitPromptForSend holds follow-ups to the Advanced Memory cap.

Additional context

Follows #6550/#6551, which added the check on actual input.

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 @SpicyMarinara on GitHub (Oct 11, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7455 Originally assigned to: @SpicyMarinara on GitHub. ## Summary With Advanced Memory, a dice roll or function-call round can cut the context (archive older scenes) even though the prompt that was sent fit the limit. A follow-up near the limit can also fail the whole reply. ## Expected behavior The automatic cutoff fires only when the input actually sent for the narrator or a character reaches or passes "Maximum allowed context before compression". Function-call rounds and roll follow-ups never cause a cutoff, and they never fail because of that limit. ## Actual behavior - The cutoff compares the largest request of the turn with the limit. A roll or tool follow-up resends the prompt plus the model's own output, including thinking, the tool call and the result. It is therefore always the largest request, and it triggers the cut while the outgoing prompt itself was under the limit. - The check uses `>`, so an input exactly at the limit does not count. - A follow-up that grows past the limit throws "Advanced Memory: this tool follow-up or continuation exceeds the context cap" and the reply fails. ## Steps to reproduce 1. Roleplay with Advanced Memory, Claude Opus, rolls enabled. 2. Let the prompt grow close to the limit, then get a reply that rolls dice. 3. The context start jumps to the newest closed scene after that reply, although the first request was within the limit. Reproduced with a route-level regression: the first request was 64,000 under a 65,000 cap and the follow-up 66,600, and a cutoff was saved. ## Environment - Marinara Engine version: 2.5.0 (staging 3066f0c72) - Install type: docker - OS + version: n/a (server-side) - Browser or app shell: n/a ## Logs, screenshots, or video `recordRequestUsage` in `packages/server/src/routes/generate.routes.ts` keeps `Math.max` over every main request, including tool rounds and follow-ups. `resetContextForActualInput` in `packages/server/src/services/advanced-memory.ts` uses `<= maxContextTokens` as its no-op guard. `fitPromptForSend` holds follow-ups to the Advanced Memory cap. ## Additional context Follows #6550/#6551, which added the check on actual input. ## 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-10-21 06:11:50 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Oct 11, 2026):

Working on this: Claude Code on behalf of @SpicyMarinara. A PR against staging will follow shortly.

<!-- gh-comment-id:6115201760 --> @SpicyMarinara commented on GitHub (Oct 11, 2026): Working on this: Claude Code on behalf of @SpicyMarinara. A PR against `staging` will follow shortly.
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#4153
No description provided.