Skip to content

fix(engine): read waits for earlier tool calls in the same step (File not found / stale image) (#2125) - #2173

Open
jacktrnr wants to merge 2 commits into
mainfrom
fix/2125-read-not-found
Open

jacktrnr wants to merge 2 commits into
mainfrom
fix/2125-read-not-found

Conversation

@jacktrnr

Copy link
Copy Markdown
Contributor

Closes #2125

Root cause

This is a race between tool calls in one step. Path canonicalization and caching are not involved.

The AI SDK starts each tool call of an assistant step as soon as it streams in, so tool calls in one step run concurrently. When the model emits a shell write (a plotting script, cp, a > file redirect) and a read of that file in the same step, the read stats the file before the shell has written it:

  • If the file is new, the read reports "File not found" for a file that exists a moment later.
  • If the file is being overwritten, the read returns the old bytes (a stale image).

Evidence from a read-only sweep of the local session database (2026-10-26 to 2026-11-04):

  • All 268 of 268 failed reads shared their step with an earlier bash call.
  • In 266 of them, that bash call's end time was later than the read's start time.
  • Example: bash: ... > /tmp/k2.txt; wc -l /tmp/k2.txt and read /tmp/k2.txt were created 18 ms apart, and the read failed. The next step read /private/tmp/k2.txt fine. In the same session, an in-repo path (.k3.txt) failed in the same way, so /tmp is not the cause.

The /tmp vs /private/tmp pattern only reflects how agents retried: a retry in a later step succeeds under either spelling. The read path has no file or attachment cache.

Fix

SessionTools.resolve is called once per step. It now keeps track of the calls it has dispatched, and a read waits for the earlier calls in that step to settle (Promise.allSettled) before it runs. Other tools still run concurrently, and reads never block other calls, so there is no new deadlock path. The step already waits for every call to finish, so total step time does not change.

The change is in packages/app-bundle/overlay/packages/opencode/src/session/tools.ts, which is now an overlay copy of the upstream file. The manifest was regenerated with refresh_manifest.mjs, and drift_gate.mjs passes.

Tests

test/session/tools.test.ts is now an overlay copy of the upstream suite, extended with:

  • A shell call writes a file after a delay, and a read is dispatched right after it in the same step. The read sees the file under the same spelling, under /tmp → /private/tmp, and under /private/tmp → /tmp. On non-macOS hosts both spellings are the same directory.
  • An in-place overwrite followed by a read returns the new content.

RED before the fix: all 4 new tests failed with File not found: /tmp/oc-2125-…/fig.png and Received: "old figure". GREEN after the fix: 5 of 5 pass, including the existing upstream test.

Scope note: only read waits. Other tools (grep, glob, MCP tools) are out of scope for this issue.

🤖 Generated with Claude Code

Jackson Turner and others added 2 commits November 23, 2026 16:50
…p sees the file (/tmp and /private/tmp) and the overwritten content (#2125)

The AI SDK dispatches every tool call of one assistant step concurrently, so a
read that follows a shell write in the same step stats the file before the
shell has written it. Extends the upstream session tools suite (copied into the
overlay) with the write-then-read and overwrite-then-read cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t sees files a shell call just wrote (#2125)

Root cause: the AI SDK starts each tool call of an assistant step as soon as it
streams in, so when the model emits a shell write and a read of the same file
in one step, the read stats the file before the shell has written it. That
gives "File not found" for a file that exists a moment later, or the old bytes
of an image being overwritten. In the local session database, all 268 failed
reads from 2026-10-26 to 2026-11-04 shared their step with an earlier bash
call, and in 266 of them that bash call was still running when the read began.
Path spelling (/tmp vs /private/tmp) and caching are not involved: the read
path has no cache, and later reads succeed under either spelling.

Fix: SessionTools.resolve (one per step) tracks the calls it has dispatched;
a read waits for the earlier ones to settle before it runs. Other tools still
run concurrently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2dbe7199-1025-4aeb-b438-648fd0354526
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@jacktrnr
jacktrnr marked this pull request as ready for review November 23, 2026 22:02
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.

fix(engine): read reports "File not found" for files that exist, and serves stale images after an overwrite

1 participant