mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #7865] [Issue]: Claude (Subscription) re-caches the whole chat history every turn #4327
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#4327
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?
Originally created by @stonebystone on GitHub (Oct 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7865
Originally assigned to: @SpicyMarinara on GitHub.
Summary
On the Claude (Subscription) connection, prompt caching only ever reuses the system prompt. Every turn writes the full chat history to the cache again and never reads it back. The cost per turn is the whole history in the prompt, which can reach Claude's context limit (up to a million tokens) on a long chat, or less where a chat summary replaces older messages. It burns subscription usage and adds latency.
Expected behavior
Each turn reads the previous turn's history from the cache and writes only the new messages and the per-turn blocks.
Actual behavior
Measured on a 300-message roleplay chat (Opus 5.5, 1-hour cache on). For this test the preset was arranged so nothing before the chat history changes between turns: its lorebook and depth blocks were moved to depth 0. Presets that place World Info or depth injections earlier break the cache sooner, but even this best case reuses only the system prompt.
The 8,508 tokens are the system prompt. The two stored prompts (
extra.cachedPrompt) are identical through every history message except the last two.Cause: Claude Code places its message cache marker on the current turn only. Marinara's current turn carries per-turn blocks: tracker
<context>, the<last_message>wrapper, and depth-0 sections such as post-history instructions (and World Info, when a preset places it there). A turn later that message comes back as plain history, so the saved prefix never matches again. The resumed JSONL history has no marker of its own, so nothing between the system prompt and the current turn is reusable.A second, smaller break: with xml wrapping,
</chat_history>is appended to the last history message (marker-expander.ts), so that message also changes every turn.Steps to reproduce
generationInfo.tokensCachedPrompt/tokensCacheWritePrompton the two replies: the read stays at the system-prompt size, and the write is roughly the whole prompt.Environment
e1e28a367)Additional context
cache_controlon the newest assistant reply in the resumed JSONL that isn't the last history entry. Claude Code passes it through. Live test on the subscription with the 1-hour cache on: turn 2 read 24,963 of 26k tokens (without the marker: 2,398). With the 1-hour cache off, Claude Code's own TTL is account-dependent and an extra marker exceeds the four-marker limit, so that mode stays a known gap.cachingAtDepthmessages back.Template check
cc @SpicyMarinara
@SpicyMarinara commented on GitHub (Oct 20, 2026):
Fixed on staging by #7866. Thank you @stonebystone!