Skip to content

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

Closed

Description

@edenreich

Summary

When one assistant turn batches tool calls that depend on each other, an approved call can run at the same time as the calls after it. A Read of a file that an earlier Write in the same batch creates can therefore return NOT_FOUND.

Cause: ApprovingToolsState.processNextTool (internal/agent/states/approving_tools.go) asks for approvals one at a time. Once a call is approved, spawnExecution starts it in a goroutine and the loop moves straight on to the next call. A call that needs no approval (such as Read) is started at once in the same way. The two run concurrently, up to max_concurrent_tools (default 5), so the order the model chose is not kept. Results are still recorded in tool-call order, so the conversation looks ordered even though execution was not.

The concurrent execution is intentional (it lets independent calls such as parallel Reads run together). The problem is only that calls which depend on an earlier write can overlap with it.

Found while reproducing #1286. The e2e scenario approval-tail in tests/e2e/scenarios.yaml (added in #1289) hits this reliably.

Steps to Reproduce

  1. Save this as scenarios.yaml:

    fallback:
      content: "Done."
    scenarios:
      - name: write-then-read
        match: '(?i)write then read'
        turns:
          - tool_calls:
              - { name: Write, args: { file_path: "m1.txt", content: "one\n" } }
              - { name: Read, args: { file_path: "m1.txt" } }
              - { name: Write, args: { file_path: "m2.txt", content: "two\n" } }
          - content: "DONE"
  2. In an empty directory, run INFER_GATEWAY_MOCK=true INFER_GATEWAY_MOCK_SCENARIOS=scenarios.yaml infer chat and pick the mock model.

  3. Send write then read and approve both Write prompts.

Expected Behavior

Read(m1.txt) runs after Write(m1.txt) finishes and returns one.

Actual Behavior

Read(m1.txt) fails with NOT_FOUND: <cwd>/m1.txt. Both Write calls succeed, and m1.txt exists on disk afterwards. In the TUI, the Write result shows 46ms and the Read result 41ms, so the two ran at the same time.

Activity

  1. added
    bug
    on Sep 23, 2026
  2. added theissue type on Sep 23, 2026
  3. moved this to Todo in 2026on Sep 23, 2026
  4. moved this from Todo to In progress in 2026on Sep 23, 2026
  5. moved this from In progress to QA in 2026on Sep 23, 2026
  6. inference-gateway-releaser commented on Sep 23, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.207.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugreleased

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions