Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix extended thinking bug by reordering tool messages#1798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

habema
Copy link
Contributor

Resolves#1797

This fixes the issue where conversation histories with extended thinking could have tool_result messages appearing before their corresponding tool_use messages, causing Anthropic API rejections.

What was happening:

  • Reasoning blocks between tool calls caused the converter to create malformed message sequences
  • Multiple consecutive assistant messages with tool calls weren't getting paired with their results properly
  • Anthropic API requires strict tool_use → tool_result ordering

The fix:

  • Added_fix_tool_message_ordering() method that only activates whenpreserve_thinking_blocks=True
  • Analyzes the entire conversation to identify tool call/result pairs
  • Reconstructs messages ensuring proper tool_use → tool_result sequencing
  • Handles edge cases like consecutive tool calls and misplaced results
  • Non-breaking - only affects extended thinking scenarios

Repro script available in the original issue.

Copy link

@chatgpt-codex-connectorchatgpt-codex-connectorbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Comment on lines 482 to 485
elifrole=="tool":
# Skip - these will be handled as part of tool pairs above
used_indices.add(i)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

P1 Badge Preserve unmatched tool_result messages

In_fix_tool_message_ordering() therole == "tool" branch simply marks the index as used and skips emitting the message. When a tool message has no matchingtool_call_id or the corresponding tool call is absent from the trimmed history, this logic drops the tool result entirely. Previously those messages were forwarded to the provider; now they silently disappear, which removes tool outputs from the conversation and can change agent behaviour. Consider emitting unmatched tool messages (or raising) rather than discarding them.

Useful? React with 👍 / 👎.

habema reacted with thumbs up emoji
Copy link
Member

@seratchseratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks!

@seratchseratch merged commit46d0d2f intoopenai:mainSep 24, 2025
5 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@chatgpt-codex-connectorchatgpt-codex-connector[bot]chatgpt-codex-connector[bot] left review comments

@seratchseratchseratch approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Anthropic Extended Thinking bug: tool_result blocks appear before corresponding tool_use blocks
2 participants
@habema@seratch

[8]ページ先頭

©2009-2025 Movatter.jp