-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Problem (one or two sentences)
Tool Results in wrong order, and image read content not nested in the content array key,
Date/time: 2026-02-23T18:47:53.595Z
Extension version: 3.50.3
Provider: anthropic
Model: claude-sonnet-4-6
400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.20: tool_use ids were found without tool_result blocks immediately after: toolu_012LvAhvmtDL3fCaukBiqKG2. Each tool_use block must have a corresponding tool_result block in the next message."},"request_id":"req_0"}
I think anthropic expects tool_result array entries grouped at the beginning of the user -> content array.
The fix should be in how pushToolResult handles array results. When result is a content block array (text + image), the entire array needs to go into the tool_result's content field:
json{
"type": "tool_result",
"tool_use_id": "toolu_xxx",
"content": [
{ "type": "text", "text": "File: tests/screenshots/seed-smoke-dashboard.png\nNote: Image file (15 KB)" },
{ "type": "image", "source": { "type": "base64", ... } }
]
}
log:
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "Good, I can see the login screen screenshot. Let me now view the dashboard and emails screenshots.",
"summary": []
},
{
"type": "tool_use",
"id": "toolu_01KVMKVoYinYuaZBShijKw2h",
"name": "read_file",
"input": {
"path": "tests/screenshots/seed-smoke-dashboard.png"
}
},
{
"type": "tool_use",
"id": "toolu_012LvAhvmtDL3fCaukBiqKG2",
"name": "read_file",
"input": {
"path": "tests/screenshots/seed-smoke-emails.png"
}
}
],
"ts": 1771713465053
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "toolu_01KVMKVoYinYuaZBShijKw2h",
"content": "File: tests/screenshots/seed-smoke-dashboard.png\nNote: Image file (15 KB)"
},
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": "iVBORw0"
}
},
{
"type": "tool_result",
"tool_use_id": "toolu_012LvAhvmtDL3fCaukBiqKG2",
"content": "File: tests/screenshots/seed-smoke-emails.png\nNote: Image file (359 KB)"
},
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": "iVBORw0KGgoAAAA",
}
},
Context (who is affected and when)
multiple read file tool calls of images in parallel.
Reproduction steps
did a new session with the prompt: "im testing something - was getting api errors when in a previous task i asked you to read multiple images at once. can you retry that - find the screenshots and attempt to read 3 images in one read file tool call"
This immediately failed with the same error
Expected result
reading of two or more image files at once works.
Actual result
400 error from API
Variations tried (optional)
No response
App Version
3.50.3
API Provider (optional)
Anthropic
Model Used (optional)
Sonnet 4.6
Roo Code Task Links (optional)
No response
Relevant logs or errors (optional)
[
{
"role": "user",
"content": [
{
"type": "text",
"text": "<user_message>\nim testing something - was getting api errors when in a previous task i asked you to read multiple images at once. can you retry that - find the screenshots and attemtp to read 3 images in one read file tool call\n</user_message>"
},
{
"type": "text",
"text": "<environment_details>\n# VSCode Visible Files"
}
],
"ts": 1771873240271
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "The user wants me to find screenshots in the workspace and attempt to read 3 images in one read_file tool call (as parallel calls). Let me first find where the screenshots are stored.",
"summary": []
},
{
"type": "text",
"text": "\nLet me find the screenshots first."
},
{
"type": "tool_use",
"id": "toolu_01G6SxhtwAPtbwDLVfzhc9ze",
"name": "execute_command",
"input": {
"command": "find /home/administrator/pulse/Pulse-DSL -name \"*.png\" -o -name \"*.jpg\" -o -name \"*.jpeg\" 2>/dev/null | head -20",
"cwd": "/home/administrator/pulse/Pulse-DSL",
"timeout": 10
}
}
],
"ts": 1771873244680
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "toolu_01G6SxhtwAPtbwDLVfzhc9ze",
"content": "Command executed in terminal within working directory '/home/administrator/pulse/Pulse-DSL'. Exit code: 0\nOutput:\n/home/administrator/pulse/Pulse-DSL/tests/screenshots/seed-smoke-dashboard.png\r\n/home/administrator/pulse/Pulse-DSL/tests/screenshots/seed-smoke-home.png\r\n/home/administrator/pulse/Pulse-DSL/tests/screenshots/seed-smoke-emails.png\r\n/home/administrator/pulse/Pulse-DSL/apps/example/tests/screenshots/deals.png"
},
{
"type": "text",
"text": "<environment_details>\n# VSCode Visible Files"
}
],
"ts": 1771873245431
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "The user wants me to read 3 images at once in a single read_file tool call. However, the read_file tool only reads exactly one file per call. The instructions say \"IMPORTANT: This tool reads exactly one file per call. If you need multiple files, issue multiple parallel read_file calls.\"\n\nSo I need to issue 3 parallel read_file calls simultaneously. Let me pick 3 screenshots and read them all at once.",
"summary": []
},
{
"type": "text",
"text": "\nThe [`read_file`](packages/parser/src/lexer.ts) tool reads **one file per call**, but the instructions explicitly say to issue **multiple parallel calls** for multiple files. I'll fire all 3 simultaneously now:"
},
{
"type": "tool_use",
"id": "toolu_0133TC2SNR1wkGpjqQh7z4av",
"name": "read_file",
"input": {
"path": "apps/example/tests/screenshots/dashboard.png"
}
},
{
"type": "tool_use",
"id": "toolu_01M8GVA46BwaGNeDKRQ3sT3e",
"name": "read_file",
"input": {
"path": "apps/example/tests/screenshots/contacts.png"
}
},
{
"type": "tool_use",
"id": "toolu_01ALGnpNKo7xtWptMYEGrRr7",
"name": "read_file",
"input": {
"path": "apps/example/tests/screenshots/deals.png"
}
}
],
"ts": 1771873251098
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "toolu_0133TC2SNR1wkGpjqQh7z4av",
"content": "File: apps/example/tests/screenshots/dashboard.png\nNote: Image file (17 KB)"
},
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": "iVBORw0KGgoAAAA"
}
},
{
"type": "tool_result",
"tool_use_id": "toolu_01M8GVA46BwaGNeDKRQ3sT3e",
"content": "File: apps/example/tests/screenshots/contacts.png\nNote: Image file (17 KB)"
},
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": "iVBORw0KGgoAAAANS"
}
},
{
"type": "tool_result",
"tool_use_id": "toolu_01ALGnpNKo7xtWptMYEGrRr7",
"content": "File: apps/example/tests/screenshots/deals.png\nNote: Image file (17 KB)"
},
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": "iVBORw0KGgoAAAANS"
}
},
{
"type": "text",
"text": "<environment_details>\n# VSCode Visible Files"
}
],
"ts": 1771873251364
}
]