Skip to content

fix(opencode): strip thinking blocks from compaction, guard orphaned boundaries - #268

Merged
jeonghun-jj-lee merged 1 commit into
local/amicodefrom
fix/267-compaction-thinking-blocks
Aug 28, 2026
Merged

jeonghun-jj-lee merged 1 commit into
local/amicodefrom
fix/267-compaction-thinking-blocks

Conversation

@jeonghun-jj-lee

Copy link
Copy Markdown
Contributor

Closes #267

Summary

Compaction fails with an API error on Bedrock Claude Opus 4.6 when extended thinking is enabled: the Anthropic API rejects requests where thinking/redacted_thinking blocks in the latest assistant message are modified. The failure path then incorrectly treats the errored compaction as a valid boundary, truncating the user's conversation history.

Changes

Part A — Strip thinking blocks from compaction input

  • Added forCompaction option to toModelMessagesEffect (consistent with existing stripMedia/toolOutputMaxChars options)
  • When forCompaction: true, reasoning blocks are unconditionally downgraded to plain text regardless of model match
  • Wired this option in the compaction caller (processCompaction)
  • Enforces the specs/v2/session.md invariant: reasoning does not survive compaction boundaries

Part B — Guard orphaned compaction boundaries

  • Added !msg.info.error check to filterCompacted's second-phase summary lookup
  • An errored summary-assistant is no longer treated as a valid compaction boundary
  • Pre-tail history is preserved when compaction fails

Testing

  • New test: strips reasoning blocks when forCompaction is true, even for same model
  • New test: errored summary does not truncate pre-tail history
  • New test: missing summary does not truncate pre-tail history
  • Full session test suite passes (395 tests, 0 failures)

…haned boundaries

Fixes #267 — compaction fails with API error on Bedrock Claude models
using extended thinking because reasoning blocks in the latest assistant
message cannot be modified.

Two independent fixes:

1. Add forCompaction option to toModelMessagesEffect that unconditionally
   downgrades reasoning blocks to plain text (regardless of model match),
   enforcing the spec invariant that reasoning does not survive compaction.
   Wire this option in the compaction caller.

2. Guard filterCompacted's second-phase reorder to require !msg.info.error
   on the summary-assistant, preventing an errored compaction from
   truncating pre-tail history (the 'context cleared' symptom).
@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 42c49bf4-8148-4d7e-a1f7-bae97265561c


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jeonghun-jj-lee
jeonghun-jj-lee marked this pull request as ready for review August 28, 2026 17:16
@jeonghun-jj-lee
jeonghun-jj-lee merged commit 2cda289 into local/amicode Aug 28, 2026
1 of 3 checks passed
@jeonghun-jj-lee
jeonghun-jj-lee deleted the fix/267-compaction-thinking-blocks branch August 28, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compaction fails with thinking-block API error on Bedrock, clears context on failure

1 participant