Bug: compaction sends mutated thinking block, causes permanent retry loop (400 invalid_request_error)
opencode version: 1.16.2
Provider: anthropic, model claude-sonnet-5, extended thinking enabled (budget_tokens 8000)
Agent: compaction
What happened
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.
Bug: compaction sends mutated
thinkingblock, causes permanent retry loop (400 invalid_request_error)opencode version: 1.16.2
Provider: anthropic, model
claude-sonnet-5, extended thinking enabled (budget_tokens 8000)Agent:
compactionWhat happened
During context compaction, opencode rebuilds the request history and reuses a prior assistant
turn's
thinkingblock, but the block'sthinkingtext field comes back empty ("thinking":"")while the
signatureis preserved from the original. Anthropic's API rejects this because thinkingblocks 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)
Nvaried across retries (7, 1, 5, 3, ...) — consistent with the mutated block shifting positionas compaction repeatedly re-summarizes a growing/changing history.
Repro conditions
thinkingblock whosethinkingtextis
""butsignatureis 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
thinkingtype block with empty text + stale signature) whenbuilding the summarization request.
Additional observation
Traffic in the failing session routed through
http://127.0.0.1:4097/v1/messages— a local proxyin 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.