Skip to content

fix(opencode): drop empty text separators between signed reasoning blocks - #42296

Open
vladislav-miroshnikov wants to merge 1 commit into
anomalyco:devfrom
vladislav-miroshnikov:compaction-thinking
Open

fix(opencode): drop empty text separators between signed reasoning blocks#42296
vladislav-miroshnikov wants to merge 1 commit into
anomalyco:devfrom
vladislav-miroshnikov:compaction-thinking

Conversation

@vladislav-miroshnikov

@vladislav-miroshnikov vladislav-miroshnikov commented Aug 13, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #41738

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Anthropic signs thinking/redacted_thinking reasoning blocks and rejects any modification to the assistant message that contains them. Empty text parts ("") can appear as structural separators between reasoning groups (e.g. step-start, reasoning(sig), text(""), step-start, reasoning(sig)). Previously these were rewritten to a single space (" ") to survive AI SDK filtering, but that mutation itself causes Anthropic to reject the signed reasoning blocks as "modified" — breaking compaction for any session using extended thinking.

This drops empty text parts entirely when signed reasoning is present. Step-start parts already delimit reasoning groups, so the separator is not needed. The signed blocks remain byte-for-byte identical to the original response.

How did you verify your code works?

  • cd packages/opencode && bun test test/session/message-v2.test.ts — 37 pass, 0 fail
  • cd packages/opencode && bun test test/session/compaction.test.ts — 52 pass, 1 skip, 0 fail
  • cd packages/opencode && bun typecheck — clean
  • Changed-file Prettier and git diff --check

Two new tests verify that signed reasoning and redacted thinking blocks survive toModelMessages with their signatures intact and no mutated text separator.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Aug 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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: thinking/redacted_thinking blocks in latest assistant message cannot be modified

1 participant