Skip to content

fix(agent): keep batched tool calls in order around non-read-only calls - #1291

Merged
edenreich merged 1 commit into
mainfrom
fix/tool-call-ordering
Sep 23, 2026
Merged

edenreich merged 1 commit into
mainfrom
fix/tool-call-ordering

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Fixes #1290.

Root cause

Tool calls from one assistant turn ran fully concurrently in both schedulers: ApprovingToolsState.spawnExecution (approval path, including auto-accept) and Agent.executeToolCallsParallel (no-approval path, e.g. --mode auto). A Read issued after a Write in the same batch could run before the Write finished and return NOT_FOUND.

Fix

New states.CallOrder (internal/agent/states/call_order.go), used by both schedulers:

The read-only set is the existing ReadOnly subagent toolset, moved to agentdomain.ReadOnlyTools and reused by ListToolsForMode.

Trade-off: separate Bash or Agent calls in one batch now run in sequence. Parallel subagents still run together via the Agent tool's tasks array.

Tests

  • Unit: TestApprovingToolsState_ReadWaitsForEarlierWrite, an approved Write followed by an ungated Read.
  • E2E: TestAgentReadAfterWriteInSameBatchSeesWrite, headless --mode auto against the tokenless mock; the Read result must contain what the Write wrote.
  • Both fail on main (the e2e test failed 3 out of 3 runs) and pass with the fix. internal/agent/... passes under -race, the full e2e suite passes, and lint reports 0 issues.

Batched tool calls ran fully concurrently, so a Read issued after a Write in
the same turn could run before the Write finished and return NOT_FOUND. Both
schedulers (ApprovingTools and executeToolCallsParallel) now share CallOrder:
read-only calls still run together, but any other call waits for every
earlier call, and later calls wait for it. Approval prompts still overlap
execution (#609); only execution is ordered.

The read-only set is the existing ReadOnly subagent toolset, hoisted to
agentdomain.ReadOnlyTools.

Fixes #1290
@edenreich
edenreich requested a review from a team as a code owner September 23, 2026 23:05
@edenreich
edenreich merged commit 48067e3 into main Sep 23, 2026
1 check passed
@edenreich
edenreich deleted the fix/tool-call-ordering branch September 23, 2026 23:15
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.207.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Approved tool calls run concurrently with later calls in the same batch, so a Read can race the Write it depends on

1 participant