Skip to content

fix(vfs): save through fs_put_if_unchanged so another connection's save is not overwritten - #3218

Merged
dylan-savage merged 3 commits into
feat/rocket-agent-browserfrom
fix/3215-store-conditional-write
Nov 12, 2026
Merged

dylan-savage merged 3 commits into
feat/rocket-agent-browserfrom
fix/3215-store-conditional-write

Conversation

@dylan-savage

Copy link
Copy Markdown
Collaborator

Summary

  • An auto-mode save read the server copy, compared hashes, then wrote with no condition. A save from another tab, device or teammate that landed between the two was overwritten, and nobody was told. Browser-agent evals hit this in edit-05 in both rounds of batch 1.
  • New rrext_store subcommand fs_put_if_unchanged, modeled on fs_put_json. One message carries path, text and base_hash, the SHA-256 of the text the writer read (null when it saw no file). The engine reads the file and its version, compares the hash, then calls the backend's write_file_atomic with that version. On a mismatch it writes nothing and answers written: false. The clients get fsWriteStringIfUnchanged and fs_write_string_if_unchanged.
  • The view's writeNow now sends the hash of the copy it read with the write, in place of the separate check. Commit all sends the hash its own check saw. A refusal is the existing StaleWriteError, which the agent already reports as "changed on the server since you read it". IVirtualFileSystem gets an optional writeIfUnchanged, which CachedVfs forwards to the workspace backend.
  • Two filesystem-store changes keep workspace files as they were. write_file_atomic writes with newline='', so Windows doesn't turn \n into \r\n. Lock files move to a .locks folder under the store root. Without that move, every file this write saved got a .name.lock file next to it in the user's file tree.

Deletes and Undo in auto mode still check, then act. This PR leaves them as they are. A create has no store-level condition, so two engine processes that share one store can still race on one. The engine half, the feat(store) commit, could go to develop on its own later, minus its one-line entry in the agent's client policy. Against an older engine the view fails every auto-mode save with "Unknown subcommand", so the engine has to ship first.

Type

Fix

Testing

  • Tests added or updated
  • Tested locally
  • ./builder test passes

The first commit adds the tests and fails against the current code. In stagedFileSystem.test.ts, a write-through save and a Commit all each meet another connection's save just before the write. Both failed with "Missing expected rejection", because the other save was overwritten. The three TestPutTextIfUnchanged cases in test_file_store.py failed because the store had no conditional write.

With the fix, all five pass. packages/ai/tests passes in full (4260 passed, 128 skipped). The shared vfs, agent and toolkit suites pass (75 tests). apps/rocket-ui typechecks clean. apps/shared has one type error that is already on this branch (eval/trial.ts:331, missing leasePreview). With that line patched locally, shell:check reports "Up to date with v9".

Two clients against a real local engine built from this branch, with a filesystem store. Client B saves between client A's read and A's write:

  • Before: A's write replaced B's save. The view in auto mode (StagedFileSystem over CachedVfs, on a backend that does what the workspace backend does) replaced it too.
  • After: fsWriteStringIfUnchanged returns false and B's save stays. A retry after a re-read lands. A create with no hash lands once, then refuses. The view throws StaleWriteError and B's save stays. The Python client gives the same result.

I did not run ./builder test, the builder in a real browser, the S3 and Azure stores, or Windows. The edit-05 runner holds fs_open in mode w, so it needs to hold fs_put_if_unchanged before it can test this.

Checklist

  • Commit messages follow conventional commits
  • No secrets or credentials included
  • Wiki updated (if applicable)
  • Breaking changes documented (if applicable)

Linked Issue

Closes #3215

🤖 Generated with Claude Code

dylan-savage and others added 3 commits November 11, 2026 15:51
The view checks the server copy, then writes without a condition. A save
from another connection between the two is overwritten. The view tests
fail with "Missing expected rejection". The store tests fail because the
store has no conditional write yet.

Refs #3215

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The writer sends the SHA-256 of the text it read, or null when it saw no
file. The engine reads the file and its version, compares the hash, then
calls the backend's write_file_atomic with that version, so a save from
another connection can't land in between. On a mismatch it writes
nothing and answers written: false.

The TypeScript and Python clients get fsWriteStringIfUnchanged and
fs_write_string_if_unchanged.

Two filesystem-store changes keep workspace files as they were:
- write_file_atomic writes with newline='', so Windows no longer turns
  '\n' into '\r\n' and the hash of what was written still matches.
- Lock files move from next to each file to a .locks folder under the
  store root. Next to the file they showed up in the user's file tree.

Refs #3215

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An auto-mode save read the server copy, compared hashes, then wrote with
no condition. A save from another tab, device or teammate between the
two was overwritten. writeNow now sends the hash of the copy the view
read with the write, and the store refuses if the file moved. Commit
all does the same with the hash its check saw. A refusal is the existing
StaleWriteError, which the agent reports as "changed on the server since
you read it".

IVirtualFileSystem gets an optional writeIfUnchanged, which CachedVfs
forwards and the workspace backend sends as fs_put_if_unchanged.

Closes #3215

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

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review: 2

  • develop
  • release/.*

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

@github-actions github-actions Bot added module:client-python Python SDK and MCP client module:ai AI/ML modules module:ui Chat UI and Dropper UI module:client-typescript TypeScript client SDK tests labels Nov 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor
🤖 Internal: Discord sync marker

Auto-managed by the Discord notification workflow. Stores the linked Discord message ID and forum thread ID. Do not edit or delete.

@dylan-savage
dylan-savage merged commit 5df7ef4 into feat/rocket-agent-browser Nov 12, 2026
@dylan-savage
dylan-savage deleted the fix/3215-store-conditional-write branch November 12, 2026 01:22
dylan-savage added a commit that referenced this pull request Nov 18, 2026
This reverts 5df7ef4. An auto-mode save checks the server copy, then
writes, as it did before #3218. A save from another connection that
lands between the check and the write is overwritten again. We accept
that rare race.

Why:
- #3218 added fsWriteStringIfUnchanged and fs_write_string_if_unchanged
  to both SDK clients' public API, which broke the shell's frozen API
  contract.
- Saves needed the new fs_put_if_unchanged engine subcommand, so the
  engine had to deploy before the UI, with no fallback.
- Deletes and Undo still checked, then acted, so they stayed racy anyway.

The filesystem store's newline='' write and its .locks folder go too.
Lock files sit next to each file again, as before #3218. Workspace
saves don't take those locks once the conditional write is gone, so
they stay out of the user's file tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:ai AI/ML modules module:client-python Python SDK and MCP client module:client-typescript TypeScript client SDK module:ui Chat UI and Dropper UI tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant