Skip to content

fix(providers): send parallel Anthropic tool results in one user message - #107

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-e2ab
Closed

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-e2ab

Conversation

@cursor

@cursor cursor Bot commented Oct 1, 2026

Copy link
Copy Markdown

Bug and impact

When Claude returns two or more tool_use blocks in one assistant turn (normal parallel tool use), the agent executes every tool and then sends each result as its own user message. The Messages API accepts those tool_result blocks only inside the single following user message. The follow-up request is rejected (roles must alternate / missing tool_result for the other ids), so the model never sees the tool output. The tools have already run, and the turn ends in an API error.

Root cause

build_and_send in src/providers/anthropic.c mapped each tool_use_id message to a separate user message. The agent loop in agent.c stores one message per tool result.

Fix

Consecutive tool-result messages are coalesced into one user message whose content array holds a tool_result block per call. A single tool result is unchanged.

Validation

make test_anthropic passed, including test_parallel_tool_results_share_one_user_message (two tool results become one user message with both tool_use_ids, and the assistant message still carries both tool_use blocks). src/providers/anthropic.c also compiles without SHELLCLAW_TEST.

Open in Web聽View Automation聽

Claude often returns several tool_use blocks in one assistant turn. Each
result was posted as its own user message, which the Messages API rejects,
so the model never saw the tool output after the tools had already run.

Co-authored-by: esadrianno <esadrianno@gmail.com>
@adriannoes

Copy link
Copy Markdown
Collaborator

Superseded by #124: consolidated into the operator-authored branch fix/providers-anthropic-local (same fixes, re-validated with make test_reload, make test_anthropic, make test_local_provider, CI=true make test, make static). Closing in favor of the consolidation.

@adriannoes adriannoes closed this Oct 16, 2026
@adriannoes
adriannoes deleted the cursor/high-severity-issues-e2ab branch October 16, 2026 03:12
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.

2 participants