Skip to content

fix(databricks): ensure parallel tool image responses don't interleave tool results#9241

Merged
DOsinga merged 3 commits into
aaif-goose:mainfrom
msteve123:fix/databricks-image-tool-response-ordering
May 20, 2026
Merged

fix(databricks): ensure parallel tool image responses don't interleave tool results#9241
DOsinga merged 3 commits into
aaif-goose:mainfrom
msteve123:fix/databricks-image-tool-response-ordering

Conversation

@msteve123
Copy link
Copy Markdown
Contributor

@msteve123 msteve123 commented May 15, 2026

Fixes #7449

Collects all tool-role messages first and appends user-role image messages after, so the API sees consecutive tool results followed by user image messages. This prevents Claude's API from rejecting requests when multiple parallel tool calls return images.

…e tool results

  When multiple parallel tool calls each return images, format_tool_response
  was emitting user-role image messages between tool-role result messages.
  Claude's API requires all tool_result blocks to be consecutive after
  tool_use blocks.

  Fix by deferring image user-messages until all tool result messages for
  a given goose Message have been emitted.

  Fixes aaif-goose#7449

Signed-off-by: Steve Marshall <steve.marshall@fasthosts.com>
Douwe Osinga added 2 commits May 18, 2026 10:40
- Merge with latest main (formatting updates from edition bump)
- Trim redundant comments in code and tests to one-liners

Signed-off-by: Douwe Osinga <douwe@squareup.com>
Copy link
Copy Markdown
Collaborator

@DOsinga DOsinga left a comment

Choose a reason for hiding this comment

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

Clean fix for #7449. The deferred-image-messages approach is correct and minimal. I merged main, ran cargo fmt (Rust edition bump changed import ordering), and trimmed the verbose comments down to one-liners. Tests pass, clippy clean.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

Reviewed commit: 874a70b880

ℹ️ 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +194 to +195
if msg.role == "user" {
pending_image_messages.push(msg);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve image-to-tool association when reordering responses

Deferring every user image message until after all tool responses breaks the implicit pairing between a tool result and its image payload. In mixed parallel results (e.g., tool A has an image, tool B is text-only), the image from A is emitted after B, and these image messages carry no tool_call_id, so the model can misattribute which tool produced which image. This is a behavior regression from the prior adjacent ordering and can lead to incorrect reasoning about tool outputs.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've prepared a pull request into this branch so the approach I took can be reviewed first msteve123#1

@DOsinga Did you want to take a look?

@DOsinga DOsinga added this pull request to the merge queue May 20, 2026
Merged via the queue into aaif-goose:main with commit 955288d May 20, 2026
22 checks passed
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.

Bug: Image tool responses break Claude API tool_result ordering

2 participants