fix(opencode): never place cache_control on message object in hybrid mode#50
Merged
ualtinok merged 2 commits intoJun 1, 2026
Merged
Conversation
698b198 to
4de4be8
Compare
…mode setMessageCacheAnchor() fell back to setWireCacheControl(message, true) when a message had empty content or only thinking/redacted_thinking blocks. That attaches cache_control to the message object, which Anthropic rejects with "messages.N.cache_control: Extra inputs are not permitted" (HTTP 400) when resuming sessions in hybrid cache mode. Skip the anchor entirely when no cacheable content block exists: return false for empty content, exclude redacted_thinking alongside thinking when finding the last cacheable block, and only materialize the normalized content array once an anchor target is confirmed. Adds 2 regression tests.
4de4be8 to
273dce1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In hybrid cache mode,
setMessageCacheAnchor()fell back tosetWireCacheControl(message, true)when a message had empty content or onlythinking/redacted_thinkingblocks. That attachescache_controlto the message object, which Anthropic only permits on content blocks.When resuming a session whose moving anchor (
messages[n-2]) landed on such a message, the API rejected the request:Fix
Never anchor on the message object. In
setMessageCacheAnchor():falsewhen content is empty (instead of setting cache_control on the message).redacted_thinkingalongsidethinkingwhen finding the last cacheable block.falsewhen no cacheable block exists.Tests
Adds 2 regression tests:
cache_controlon the message object when the n-2 anchor has no cacheable blockAll opencode tests pass (261), typecheck clean, biome clean.
Need help on this PR? Tag
@codesmithwith what you need. Autofix is disabled.Summary by cubic
Prevents 400s in hybrid cache mode by never setting
cache_controlon message objects. Anchors only on valid content blocks to avoid “messages.N.cache_control: Extra inputs are not permitted”.cache_controlto the message.thinking/redacted_thinkingblock; skip when none exists.Written for commit 1ba42c1. Summary will update on new commits.