fix: ensure thinking blocks in assistant messages for extended thinking#38
Merged
bigboateng merged 1 commit intomainfrom Dec 15, 2025
Merged
fix: ensure thinking blocks in assistant messages for extended thinking#38bigboateng merged 1 commit intomainfrom
bigboateng merged 1 commit intomainfrom
Conversation
…nking enabled This fixes the 400 error "Expected thinking or redacted_thinking, but found text" that occurs when thinkingBudget is enabled. The API requires that every assistant message must start with a thinking or redacted_thinking block when extended thinking is enabled. Changes: - Add ensureThinkingBlocksForExtendedThinking() function to filter out assistant messages without thinking blocks when thinking is enabled - Call this function in samplingLoop before API requests - Add comprehensive documentation for the new function Tested with examples/test-extended-thinking.ts - test passes successfully.
There was a problem hiding this comment.
Caution
Changes requested ❌
Reviewed everything up to d1e5842 in 2 minutes and 18 seconds. Click for details.
- Reviewed
89lines of code in3files - Skipped
0files when reviewing. - Skipped posting
3draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. loop.ts:223
- Draft comment:
Confirm that using!!thinkingBudget(which treats 0 as false) is the intended behavior for enabling extended thinking. - Reason this comment was not posted:
Comment looked like it was already resolved.
2. utils/message-processing.ts:279
- Draft comment:
Dropping entire assistant messages that lack a thinking block may cause loss of context. Consider prepending a default thinking block instead if preserving history is important. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =40%<= threshold50%The comment suggests a change in behavior regarding how assistant messages are handled. It doesn't ask for confirmation or testing, but rather suggests an alternative approach. This aligns with the rules for making code suggestions. However, it does not directly address a specific code issue or provide a clear suggestion for improvement, which makes it more of a general advice rather than a specific actionable comment.
3. utils/message-processing.ts:280
- Draft comment:
For better traceability, consider logging which assistant messages are removed due to missing thinking blocks. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% This comment suggests adding logging, which is a code quality suggestion. However, I need to consider if this violates the rules. The comment says "consider logging" which is a suggestion, not a clear requirement. It's about "traceability" which could be seen as speculative - we don't know if traceability is actually needed here. The function is silently removing messages, but that might be intentional. The comment doesn't point to a clear bug or issue, just suggests that logging "might be nice to have." This feels like it's asking the author to consider something rather than pointing out a clear problem. According to the rules, comments should only be made if there is "clearly a code change required" and should not be "speculative." The function is dealing with message processing to prevent API errors, and silently removing messages could make debugging difficult if something goes wrong. Adding logging could be a legitimate code quality improvement that makes the system more maintainable. This might be an actionable suggestion rather than just speculation. While logging could be helpful, the comment uses "consider" which makes it a suggestion rather than a clear requirement. The rules state comments should only be made when there is "clearly a code change required." This is more of a "nice to have" suggestion about traceability rather than identifying a clear problem. Without evidence that lack of logging is causing issues, this is speculative. This comment should be deleted. It's a speculative suggestion about adding logging for "better traceability" rather than identifying a clear bug or required change. The use of "consider" indicates it's optional, which violates the rule that comments should only be made when a code change is clearly required.
Workflow ID: wflow_ye6WCKycRHkN8Ord
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
| // Remove messages in reverse order to maintain correct indices | ||
| for (let i = indicesToRemove.length - 1; i >= 0; i--) { | ||
| const index = indicesToRemove[i]; | ||
| if (index !== undefined) { |
There was a problem hiding this comment.
Consider using Array.filter to remove messages instead of collecting indices and splicing in reverse; also, the check for index !== undefined is redundant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Important
Fixes 400 error by ensuring assistant messages start with thinking blocks when extended thinking is enabled.
thinkingBudgetis enabled insamplingLoop()inloop.ts.ensureThinkingBlocksForExtendedThinking()tomessage-processing.tsto filter out non-compliant messages.ensureThinkingBlocksForExtendedThinking()intosamplingLoop()inloop.tsto enforce message compliance.fix-extended-thinking-blocks.mdto document the patch.This description was created by
for d1e5842. You can customize this summary. It will automatically update as commits are pushed.