mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7456] [MERGED] fix(memory): cut context only when the outgoing prompt reaches the cap, never on roll or tool follow-ups #7743
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#7743
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7456
Author: @SpicyMarinara
Created: 10/12/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/advanced-memory-cutoff-outgoing-input📝 Commits (5)
28d1796fix(memory): cut context only when the outgoing prompt reaches the cap97fd698fix(memory): count a streamed roll's outgoing prompt when its usage is lost60c962adocs(changelog): say when a streamed roll moves the context start latera7666a3fix(memory): still cut when a streamed reply rolls more than onceae4e34afix(memory): fit each follow-up against the tools it actually sends📊 Changes
5 files changed (+396 additions, -45 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
docs/agents/memory.md(+1 -1)📝
packages/server/src/routes/generate.routes.ts(+81 -31)📝
packages/server/src/services/advanced-memory.ts(+6 -2)📝
scripts/regressions/advanced-memory-post-generation.regression.ts(+307 -11)📄 Description
Linked issue
Closes #7455
Why this change
With Advanced Memory on, a reply that rolls dice or calls a function could move the context start to the latest scene even though the prompt sent for the narrator or character fit under Maximum allowed context before compression. The cutoff compared the largest main-model request of the turn with the cap. A roll or tool follow-up resends the outgoing prompt plus the model's own output (replayed thinking, the tool call) and the result, so it is always the largest request. The check also used
>, so a prompt that exactly reached the cap did not count. A follow-up that grew past the cap also failed the whole reply with "Advanced Memory: this tool follow-up or continuation exceeds the context cap".Mari's decision (2026-10-12): cut only when the input actually sent as the outgoing prompt for the narrator or one character reaches or passes the cap (
>=). Function-call/tool rounds and roll follow-ups never trigger a cutoff, and output tokens never count.What changed
[roll: …]tag before that chunk arrives. Then the first later request that reports usage, minus the UTF-8 bytes of everything added since the outgoing prompt (the partial replies and roll results), counts for the outgoing prompt. This also covers a reply that rolls more than once, where each round is cut at its roll before usage arrives. Every token covers at least one byte, so this floor never cuts early; a prompt only just past the cap can cut a reply or two late. Anthropic keeps the outgoing prompt's usage when its stream is cut, so it is unaffected. A first request that reports no usage for any other reason still counts nothing.>=), not only when it passes it.docs/agents/memory.md: one sentence in the cutoff paragraph says function-call and roll follow-ups don't count toward the cap or trigger a reset.advanced-memory-post-generation.regression.ts: a textual roll follow-up and a native tool round reporting 66,600 after a 64,000 first request (cap 65,000) save no cutoff and don't error; a first request without usage is not replaced by its follow-up; a follow-up past a 1,500 cap but inside the 16,384 window is sent; one past the window fails clearly and is never sent; a first request of exactly 65,000 cuts; with streaming on and usage sent only on the last chunk, a reply cut at its roll with an outgoing prompt of 64,999 and a 65,099 follow-up does not cut, and one with 66,000 and a 66,100 follow-up resets everyone to the latest scene; a reply cut at two rolls does not cut at 64,999 (follow-ups 65,099 and 65,199) and resets everyone at 66,000; a final follow-up placed halfway into the room the tool definitions take is sent (it sends no tools), while a tool round of the same size, which sends them, fails before it is sent. The follow-up chat setup moved into acreateFollowupChathelper so the streamed case gets a fresh chat; no assertion changed.Validation
pnpm checkpasses locallyCONTRIBUTING.mdNotes from the agent runs (commands run locally on this branch).
Review-thread fixes, at
ae4e34a2c:ae4e34a2c; with the route restored froma7666a3dathe new regression fails at "a final follow-up that sends no tools reserves no room for them".pnpm check: exit 0.node ./scripts/run-regressions.mjs --filter advanced-memory: 16/16 passed.--filter context-fit: 2/2 passed.--filter, all passed: game-text-dice, game-mode-dice-tool, roleplay-function-calling, roleplay-streaming, roleplay-commands, roleplay-interrupt-generation, one-request-dice (6 files), game-tool-outcomes, game-tool-controls, gm-skill-check-resolution, provider-compat, regeneration-context (2 files), generate-agent-abort.coderabbit review --agent --committed --base-commit 3066f0c72): completed, 0 findings.Final verification, at
a7666a3da:a7666a3da; the new two-roll assertion fails at60c962adaand passes now.pnpm check: exit 0.node ./scripts/run-regressions.mjs --filter advanced-memory: 16/16 passed. Each with--filter: roleplay-commands, roleplay-streaming, roleplay-function-calling, roleplay-interrupt-generation, game-text-dice, game-mode-dice-tool, provider-compat, generate-agent-abort (1/1 each), one-request-dice 6/6, context-fit 2/2, regeneration-context 2/2.coderabbit review --agent --committed --base-commit 60c962ada): completed, 0 findings.Review fixes, at
60c962ada:pnpm check: exit 0.node ./scripts/run-regressions.mjs --filter advanced-memory: 16/16 passed.--filter context-fit: 2/2.--filter regeneration-context: 2/2.--filter merged-chat-summary: 1/1.--filter memory-recall: 5/5.--filter prompt: 16/16.--filter, all passed: roleplay-commands, roleplay-streaming, roleplay-function-calling, roleplay-interrupt-generation, game-dice-commands, game-mode-dice-tool, game-text-dice, one-request-dice (6 files), game-tool-controls, game-tool-outcomes, gm-skill-check-resolution, provider-compat, past-reasoning-history, generate-agent-abort.28d17968fthe new streamed-roll regression fails at "a streamed roll whose outgoing prompt passed the cap still resets everyone to the latest scene". Letting the raw follow-up input stand in (no byte subtraction) fails at "a streamed roll follow-up past the cap does not cut when what it added explains the difference".coderabbit review --agent --committed --base-commit 3066f0c72): 2 findings. The docs-i18n one is handled by #7461. The other (byte floor vs token estimate) recommends keeping the byte floor, which the code does; no change.First push, at
28d17968f:pnpm check: exit 0.node ./scripts/run-regressions.mjs --filter advanced-memory: 16/16 passed.--filter context-fit: 2/2 passed.--filter regeneration-context: 2/2 passed.--filter: agent-activation-questions, agent-connection-parameters, capability-gm-verb-runtime, chat-variable-history, conversation-summary, decision-reachable-statements, experience-lore-entries, game-dice-commands, game-inventory-turn, game-mode-dice-tool, game-text-dice, game-tool-controls, game-tool-outcomes, generate-agent-abort, gm-skill-check-resolution, lorebook-decision-activation, multiplayer-game-runtime, one-request-dice (6 files), open-issues, prompt (7 files), provider-compat, roleplay-function-calling, roleplay-interrupt-generation, roleplay-streaming, roleplay-commands, past-reasoning-history: all passed.<=guard it fails at the exact-cap assertion. With follow-ups still held to the cap it fails at "a follow-up past the cap but inside the model's window is sent".--committedagainst the staging merge base): completed, 0 findings at that head.Manual verification needed
Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)docs/agents/memory.mdchanged (one sentence in the cutoff paragraph) andCHANGELOG.mdhas an[Unreleased]entry. Translation follow-up: #7461 ([docs-i18n] docs/agents/memory.md).Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.