fix: require reasoning block before injecting context for Claude models #257
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
hasReasoningInCurrentAssistantTurnto verify Claude has emitted its required thinking block before injecting context infoisIgnoredUserMessageutility to identify UI-only messages that aren't sent to the LLMgetLastUserMessageto skip ignored messages for accurate model detectionProblem
Claude models with extended thinking require every assistant turn to start with a thinking block. Our context injection was sometimes happening before Claude emitted its thinking block, which would break the conversation.
Solution
For Anthropic models, we now walk backwards through messages to verify there's a reasoning block in the current assistant turn before injecting. This ensures we only inject after Claude has properly started its response.