Skip to content

fix(ai): strip reasoning blocks before sending history to LLM#282

Open
sk5268 wants to merge 1 commit into
crynta:mainfrom
sk5268:fix_unsupported_reasoning_content
Open

fix(ai): strip reasoning blocks before sending history to LLM#282
sk5268 wants to merge 1 commit into
crynta:mainfrom
sk5268:fix_unsupported_reasoning_content

Conversation

@sk5268
Copy link
Copy Markdown

@sk5268 sk5268 commented May 16, 2026

What

Strips reasoning blocks from the message history before sending it back to the LLM, and moves this filter to run prior to message compaction.

Why

Echoing reasoning/thinking blocks back in the history was causing API failures, particularly with Cerebras models, as most providers do not accept reasoning blocks in inbound requests. Furthermore, because these blocks were previously filtered after compaction, reasoning tokens were unnecessarily eating up the context budget and causing older, valid messages to be dropped prematurely.

How

  • Added a .map() + .filter() pass over the converted history that removes all content parts with type: "reasoning" from assistant messages before they reach the LLM.
  • Moved this filter to execute before compactModelMessagesDetailed so compaction only counts the actual tokens being sent.
  • Added a short-circuit to return the original message object when no reasoning blocks are found, avoiding unnecessary object allocations.

Testing

  • pnpm exec tsc --noEmit clean
  • Manual smoke-test of the affected feature
  • (If you touched src-tauri/) cargo check clean
  • (If UI) tested in pnpm tauri dev

Screenshots / GIFs

  • Before:
before
  • After:
after

Sending reasoning/thinking blocks back in the message history was
causing API failures, particularly noticeable with all Cerebras models.
It's generally not standard practice to send reasoning blocks back
anyway, since most providers expect them to be omitted from subsequent
turns.

Also moved the filter to run *before* the message compaction step.
Previously, reasoning tokens were eating up the context budget and
causing older messages to drop prematurely, only for the reasoning
blocks to get stripped out right after.
@sk5268 sk5268 requested a review from crynta as a code owner May 16, 2026 06:25
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.

1 participant