You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During context compaction, opencode rebuilds the request history and reuses a prior assistant
turn's thinking block, but the block's thinking text field comes back empty ("thinking":"")
while the signature is preserved from the original. Anthropic's API rejects this because thinking
blocks in the last assistant message must be sent back byte-identical to how they were returned.
Because compaction retries automatically and rebuilds the same mutated payload every time, the
session gets stuck in a permanent retry loop — same 400 error, dozens of times over roughly an
hour, never recovering. Only a fresh session avoids it.
Error (from Anthropic API, relayed by opencode)
AI_APICallError
messages.N.content.1: `thinking` or `redacted_thinking` blocks in the latest assistant message
cannot be modified. These blocks must remain as they were in the original response.
N varied across retries (7, 1, 5, 3, ...) — consistent with the mutated block shifting position
as compaction repeatedly re-summarizes a growing/changing history.
Repro conditions
Long-running session that triggers auto-compaction with extended thinking enabled.
Compaction request's latest assistant message contains a thinking block whose thinking text
is "" but signature is non-empty (from the original response) — i.e. the block was stripped/
edited before resending.
Expected
Compaction should either preserve thinking blocks completely unmodified when replaying them, or
strip them entirely (not send thinking type block with empty text + stale signature) when
building the summarization request.
Additional observation
Traffic in the failing session routed through http://127.0.0.1:4097/v1/messages — a local proxy
in front of the Anthropic API — worth checking whether the proxy or opencode itself is the one
truncating the thinking block content before the request leaves the client.
Session type: long-running investigation of legacy codebase
Empirical data from the affected session
Session: ses_064f372afffeAfS6ezjKK9RT5v
Title: SIPD Convocatorias y Participaciones
Status: STUCK in compaction loop (process still running, no progress)
Total messages: 6,483
Total parts (DB rows): 22,837
Total parts size (serialized): 28 MB
Manual compactions performed: 6 (all "auto": false)
Auto compactions triggered: 0
Or use a non-thinking variant (variant: none or default) for long sessions.
Confirmation
This is the same bug as #39291 — auto-compaction with extended thinking enabled produces a request that the API rejects, and opencode retries it forever with the same corrupted payload. The cache_read explosion is the downstream effect of dozens of failed retries per minute over roughly an hour.
Activity
github-actions commentedon Jul 28, 2026
This issue might be a duplicate of existing issues. Please check:
thinkingblocks (Anthropic extended thinking) #31188: Same root cause — compaction with extended thinking enabled sends invalidthinkingblocks, triggering the samethinkingorredacted_thinkingblocks in the latest assistant message cannot be modified Anthropic 400 error. That issue also includes a proposed fix (stripReasoningoption intoModelMessagesEffect).iamjalberto commentedon Aug 6, 2026
Confirming this bug affects opencode 1.18.10 with MiniMax-M3 (Anthropic-compatible endpoint), and providing empirical data.
Environment
minimax-coding-plan(useshttps://api.minimax.io/anthropic/v1)MiniMax-M3withvariant: thinkingbuildEmpirical data from the affected session
Token breakdown (lifetime totals)
Behavior timeline (last 10 messages, seconds apart)
cache_readis monotonically growing — each turn re-reads the same context.Part distribution (proves the model is in a loop)
Observations consistent with #39291
auto: truein compaction config but zero auto-compactions ever firedcache_readkeeps growing — same byte-identical context being re-sent with mutated thinking blocksCompaction config (for reference)
{ "compaction": { "auto": true, "prune": true, "tail_turns": 2, "preserve_recent_tokens": 50000, "reserved": 500000 } }Workaround applied
kill -9 <pid>to stop the looping processSuggested mitigation for users
Until fixed, disable auto-compaction for sessions using thinking-enabled models:
{ "compaction": { "auto": false // disable auto-compaction } }Or use a non-thinking variant (
variant: noneordefault) for long sessions.Confirmation
This is the same bug as #39291 — auto-compaction with extended thinking enabled produces a request that the API rejects, and opencode retries it forever with the same corrupted payload. The cache_read explosion is the downstream effect of dozens of failed retries per minute over roughly an hour.
github-actions commentedon Oct 6, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.