You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Register the complete propose_write_file replacement before awaiting its base-content read. The read still supplies that call's diff, and previousToolCallFinished still gates its result. Use satisfies to check the handler contract, matching propose_str_replace, so the regression can inject its actual dependencies without asserting incomplete handler parameters.
Why
Native tool batches can prepare successive proposals while an earlier read is pending. Previously, a following propose_str_replace missed the write's proposed content, read the old disk contents again, and reported that the replacement text was absent. The final proposal state then stayed at the first write instead of including the replacement.
How verified
One regression calls both real handlers with a deferred requestOptionalFile dependency, without sleeps or module mocks. It starts the replacement before releasing the write's read, applies both generated diffs to their expected base content, and checks the final proposal state and a single disk read.
Unchanged main 0239a27: 40 passed, 1 failed across the four affected test files; only the new regression failed.
Fixed: 41 passed, 0 failed, 162 assertions. The focused probe changed from two disk reads and a missing-text error to one read and the correct stacked proposal.
Agent-runtime and SDK typechecks, frozen-lockfile install, SDK build including declarations, Windows Freebuff binary build, version, and smoke passed with Bun 1.3.14.
A separate injected read-failure probe confirmed both dependent results reject with the original error, and run-state cleanup removes the reserved proposal.
ESLint: 0 errors, 4 local TypeScript resolver warnings. The new test is Prettier-formatted; the handler's existing formatting differences are unchanged from main.
Scope and tradeoffs
The full replacement is already known, so it can be reserved before the old contents arrive. This preserves concurrent preparation and ordered results without serializing all tools. No files are written by these proposal tools. This does not change the executor, path normalization, replacement matching, retry behavior, or the SDK's public API. Validation used injected file reads and actual handlers/diff logic on Windows; a live-model run, Linux/macOS, and the full monorepo suite were not run.
Good catch and a genuinely useful fix. In propose-write-file.ts, the old code awaited getProposedOrDiskContent()before calling setProposedContent(runId, path, ...). Because getProposedOrDiskContent only synchronously reads the current proposed-content map before yielding on the disk read, any propose_str_replace call that starts while the write's disk read is still pending would see nothing registered yet and fall back to stale disk contents — exactly the bug described. Moving setProposedContent ahead of the await closes that window without serializing unrelated tool calls, which is the right fix at the right layer (the store, not the executor).
The new test in propose-write-file.test.ts is well constructed: it uses a manually-released promise to simulate a slow disk read, starts both handlers, and verifies that the replacement correctly builds on the write's content (one disk read, correct final diff) instead of regressing to two reads and a missing-text error. That's exactly the kind of targeted regression test this repo would want for a timing bug — no sleeps, no mocked modules, just real handlers with an injected dependency.
The as → satisfies change to match propose_str_replace's handler-contract style is a nice, low-risk cleanup that makes the test's partial dependency object type-check properly.
Nothing else to flag — the diff is small, in-scope (agent-runtime), doesn't touch the executor or SDK public API, and the PR description documents verification thoroughly (typecheck, lint, cross-file test run before/after). Would want a maintainer to confirm the cleanup-on-failure path mentioned in the write-up is actually covered somewhere, since it's not visible in this diff, but that's a minor follow-up rather than a blocker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Register the complete
propose_write_filereplacement before awaiting its base-content read. The read still supplies that call's diff, andpreviousToolCallFinishedstill gates its result. Usesatisfiesto check the handler contract, matchingpropose_str_replace, so the regression can inject its actual dependencies without asserting incomplete handler parameters.Why
Native tool batches can prepare successive proposals while an earlier read is pending. Previously, a following
propose_str_replacemissed the write's proposed content, read the old disk contents again, and reported that the replacement text was absent. The final proposal state then stayed at the first write instead of including the replacement.How verified
One regression calls both real handlers with a deferred
requestOptionalFiledependency, without sleeps or module mocks. It starts the replacement before releasing the write's read, applies both generated diffs to their expected base content, and checks the final proposal state and a single disk read.0239a27: 40 passed, 1 failed across the four affected test files; only the new regression failed.Scope and tradeoffs
The full replacement is already known, so it can be reserved before the old contents arrive. This preserves concurrent preparation and ordered results without serializing all tools. No files are written by these proposal tools. This does not change the executor, path normalization, replacement matching, retry behavior, or the SDK's public API. Validation used injected file reads and actual handlers/diff logic on Windows; a live-model run, Linux/macOS, and the full monorepo suite were not run.