mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3041] [Issue]: Anthropic cache breakpoint silently dropped when the cache-depth message has no text content (image/file-only turn) #1609
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#1609
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 @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3041
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
With prompt caching enabled on an Anthropic connection, the cache breakpoint can be silently lost when the message chosen for the breakpoint is an image-only or PDF-only turn (empty text content). The ephemeral
cache_controlmarker is attached only insideif (m.content), i.e. only when a text block is created. The cache-depth message is selected purely by position, without checking whether it has text. When a content-less attachment turn lands at that position, no text block is created,cache_controlis never attached, and the intended cache breakpoint vanishes — degrading prompt-cache hit rate (cost/latency) with no error or warning.How to reproduce (try it yourself)
enableCaching=trueand acachingAtDepththat resolves to a message which is image-only or PDF-only (empty content) — e.g. an older user turn that contained only an image.chat()path.You'll see: the content array for that turn contains only image/document blocks and no
cache_controlanywhere; the request goes out with no cache breakpoint at the configured depth, so caching does not apply where expected.Expected: the breakpoint is carried by the trailing image/document block, so caching still lands at the configured depth.
Where it is
packages/server/src/services/llm/providers/anthropic.provider.ts: the streamingchat()body buildermessages.mapat lines 426-439 (theif (m.content)guard at 428-432 is the only placecache_controlis attached).resolveCacheControlMessageIndexpicks by position only (lines 25-28). The message filter that keeps content-less attachment turns is at lines 391-393.What's happening
cache_controlplacement is coupled to the existence of a text block, butresolveCacheControlMessageIndexdoes not account for content-less messages, so the breakpoint can be assigned to a turn that produces no text block to carry it. The filter keeps a turn when it has images or files even if its content string is empty, so such a turn can sit atcacheControlMessageIndex.Suggested fix
When the turn is the cache breakpoint but has no text content, attach
cache_controlto the trailing attachment block instead of dropping it — with an empty-array guard. Replace the map body (lines 426-439):Anthropic accepts
cache_controlon image/document blocks, so the breakpoint lands at the configured depth. Regression avoided: theparts.length > 0guard is essential — the message filter keeps a turn whose only attachments are unparseable (imageContentBlockssilently drops non-data-URL images;fileContentBlocksskips non-PDF files), which can yield an emptypartsarray. Without the guard,parts[parts.length-1].cache_control = ...dereferencesundefinedand throws, crashing the generation request. With it, that corner falls back to the pre-existingcontent: []behavior.resolveCacheControlMessageIndexis left unchanged (the alternative — skipping content-less messages there — would forfeit the breakpoint at the intended depth). The happy text-turn path runs exactly as before.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Claiming this for the current staging sweep in draft PR #3053 (branch
codex/issue-sweep-3033-3052).@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in PR #3053 on branch
codex/issue-sweep-3033-3052(commitbfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.