Skip to content

fix(agent): give every file a version, so the agent and an editor cannot write over each other - #2840

Merged
dylan-savage merged 3 commits into
feat/rocket-agent-team-timeoutfrom
feat/rocket-agent-save-race
Oct 28, 2026
Merged

dylan-savage merged 3 commits into
feat/rocket-agent-team-timeoutfrom
feat/rocket-agent-save-race

Conversation

@krishhgg

@krishhgg krishhgg commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #2718. Stacks on #2839 (feat/rocket-agent-team-timeout). This is the first of four PRs split from the #2840 Dylan reviewed: versioned writes (this one), the editor documents, the unsaved-changes dialog with the tool clock, and the manual-mode commit check. Each one stacks on the one before.

The problem

The agent reads a file, the user saves it, and the agent's edit then lands on the text it read, so the user's save is gone. Nothing in the workspace view said a write was computed from an older copy. In manual mode Commit all, Discard all, the per-file discard, a rollback and Undo also raced the writes called just before them: a save could be swept without being committed, or survive a discard that should have dropped it.

What changes

  • Every path in the staged view has a version. A write, delete, rename or mkdir counts when it is called, then waits behind the path's earlier mutations. A delete or rename also counts every path under it, at both ends of a rename, so a write that found a path empty is refused once a folder moves onto it. write(path, content, origin, expect) is refused with StaleVersionError (a StaleWriteError) when the path moved past expect.
  • A read waits for the writes called before it, so readVersioned never returns content older than its version. A wait gives up after 60 s with an error that says what it waits for.
  • Commit all, Undo, Discard all, the per-file discard and a rollback run in call order, each after the mutations called before it. A commit carries what was staged before it was called; a write while it runs lands above the layers it replays and is not swept. A commit counts no version, so an editor's save after it is not refused. Undo counts and holds its paths from its call, so a save called after it lands after it, and one computed before it is refused. That includes the paths a commit called before the Undo retains only once it runs.
  • A server read that one of the view's own changes overtook (a commit's replay, an invalidate) is read again, so the cache never serves the older file under the newer version.
  • A checkpoint runs after the writes called before it, and the writes called after it wait for it, so a rollback to it keeps the first and drops the second.
  • Switching to auto mode is refused while a staged save is on its way, as it is while changes are staged. Before, the save landed staged after the switch, and auto mode never committed it.
  • A staged write to a folder, or a rename onto one, is refused before it stages anything, as a file system refuses them. Before, the write hid the folder's files.
  • A staged rename stages its delete and its write together and saves them with one store write. Before, it saved the delete first, so a store write that failed in between could leave only the delete, and Commit all then deleted the file's only copy.
  • When the cached copy is dropped (a Reload, a team switch away and back), the view keeps it. A read that then takes in a different server copy counts a version, so an editor that loaded the old copy cannot save over a teammate's change; each read reports that version with the copy, also a read that finds the copy a batch read cached and has not counted yet. Until a read takes the server's copy in, the dropped copy guards the next save, so a teammate's delete is not undone and an unchanged file saves at once. A save, or a file Commit all writes, that lands after the copy was dropped becomes the dropped copy, so taking it back in counts nothing.
  • The agent's file tools read and write at a version. write_file refuses a file that changed since the agent read it. edit_file on a changed file applies only when its anchor still matches exactly once, and says so. When the server refuses a write for a teammate's change, the cached copy is dropped, so the agent's next read gets the server's copy.
  • At the top of each wave the model hears which files someone else changed since it read them.

Since Dylan's review

After the restack

  • A save or Commit all's write on its way when the cached copy was dropped counted twice. Going back to a team, or the agent's refused write, drops the cached copy. When an editor's save was still on its way, the read after it took the save's own content in as a changed copy and counted a second version, so the editor's next save was refused as changed on the server. The editor documents PR's canvas test of a Reload during a save caught it. Commit all's writes had the same gap: a file staged at version 1 read as version 2 after the commit, and the editor's next save at version 1 was refused. The dropped copy now becomes the written content once the write lands, for a write-through save and for each file Commit all writes. Tests: a tab's save on its way when the cached copy is dropped counts once, so the tab's next save lands and Commit all's write on its way when the cached copy is dropped counts once, so the tab's next save is staged (workspace). Each fails without its half of the fix and passes without the other's.
  • One fake store. The explorations' store is fix(agent): keep a run in its team, start nothing over a timed-out call, and ignore markers of deleted files #2839's shared FakeStore now, which gains holdsPersists for the restored start. On this PR's code the six explorations try the same orders with it as with the old one (865, 57, 104, 6,592, 11,370, 5,945), and the 259 and 25 above still break without their fixes.

Why not one queue for the whole view

Dylan suggested one view-wide queue in place of the per-path chains. It was built and measured on this code (kept on a local branch), and not kept:

  • It removed 6 of the 16 new fields and 144 code lines from stagedFileSystem.ts.
  • It serializes writes to different files. With a fake store at 20 ms latency, a 50-file edit wave in auto mode went from 46 ms to 2.0 s; at 80 ms, from 167 ms to 8.0 s. A save or a tab opening during the wave waited for all of it.
  • One write that never answers then stops every later save, read and commit in the view, each for the full 60 s, instead of only its own file.
  • The restored-start exploration broke 8 orders: a save waiting behind a per-file discard of another file made the next save stale.

In manual mode the staging store already persists one change at a time, so a save already waits behind an agent wave's persists there. That cost is the staging store's, and worth its own fix.

Tests

ordering.harness.ts holds the actors the ordering explorations share: rocket-ui's real workspace over #2839's in-memory FakeStore that holds each read and write until a step releases it, the agent's file tools in the real Wave loop, and an editor that saves at the version it loaded. #2839's team-switch runs move into it unchanged. Each run tries every order of up to 6 steps and breaks 0 rules:

Exploration Orders Breaks without
Auto, one file: two agent edits, an editor save, a teammate's change and a second tab's Reload 865 the version check on write, reads waiting for writes, a copy taken in after a Reload counting no version (21 of 871 orders erase a write)
Team switch, and with approvals (#2839's) 57, 104 #2839's fixes
Manual, two files with unsaved typing: saves, typing, Commit all, Discard all, a per-file discard, a rollback 6,592 a write during a commit landing in the swept layers (259), a commit counting versions (927), a discard not waiting (2,441)
The same, from a working layer the page restored 11,370 a commit carrying what was staged after it (18), a discard counting what a waiting commit carries (633)
The same, with an editor's first read slow 5,945 an overtaken read not read again (25)

The unit tests cover what no exploration reaches: the time limits, a server that stops answering, a save after a failed Commit all, folder deletes and renames (a write that found the destination empty, a folder delete staged while Commit all waits), Undo's paths held from its call (also for a turn a commit called before it retains), a checkpoint between writes, a switch to auto mode with a save on its way, a write or a rename onto a folder, a folder that appears at a rename's destination while the rename is saved, a failed write, a reread after a refused write, the batch reread, two reads that take a changed copy in at once, a read that finds a batch read's copy before the batch counts it, a team switch away and back (an unchanged file, a teammate's change, a teammate's delete), the changed-files note, and the tracker. Commit and discard unit tests whose fixes an exploration also catches were cut.

Known limits

  • A write that fails, from the network for instance, still counts a version, so a writer that read the file before it is told to read again. Nothing is lost.
  • A teammate's change that lands between Commit all's check and its write is lost. The store has no conditional write.
  • Until the editor documents PR, no editor registers its unsaved typing with the view, so the agent's dirty-file guard sees what it saw before this PR. The editors also save with no version until then, so once a read takes a teammate's change in (the agent's read after its refused write, or the first read after a team switch away and back), their next save is no longer refused for it.

Notes

Land with the documents PR: until it is in, editor saves carry no version.

The stack

Eleven PRs, each on the one below it. Merge top-down: each PR squashes into the branch below it, starting with #2885 and ending with #2835 into feat/rocket-agent-browser. A top-down rehearsal in a scratch clone was clean at every step and ended on #2885's tree. Bottom-up also works if each next branch is first rebased onto the squashed base.

  1. fix(agent): let Wave read plan replies itself #2835 plan replies
  2. fix(agent): keep secrets out of the model in the browser agent #2836 secrets
  3. fix(agent): keep a run in its team, start nothing over a timed-out call, and ignore markers of deleted files #2839 team, timeouts and deleted files
  4. fix(agent): give every file a version, so the agent and an editor cannot write over each other #2840 versioned writes (this PR)
  5. fix(agent): keep one document per open file and pipeline, so splits, closed tabs and saves stay in step #2882 editor documents and the rename fix
  6. feat(agent): ask before the agent changes a file with unsaved changes, and stop the tool clock while the user answers #2883 unsaved-changes dialog and tool clock
  7. fix(agent): check a staged file against the copy the page read, so Commit all meets a teammate's change #2884 manual-mode commit check
  8. feat(agent): end each turn with a result card, let the agent ask the user, and stop only its own runs in Auto #2869 turn result, needs you and run ownership
  9. feat(agent): pause a turn at its step or cost limit, show its estimated cost, and undo its file changes #2873 step and cost limits, cost estimate, Undo
  10. feat(agent): check the browser agent end to end in a real browser, with a verify skill for each layer of the stack #2874 verify skill
  11. feat(agent): replay the browser agent's smoke scenarios in CI, from fresh recordings #2885 eval runner

@coderabbitai

coderabbitai Bot commented Oct 26, 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

Comment @coderabbitai help to get the list of available commands.

@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 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes on two things.

  1. The PR is 9.7k lines and only about 1.7k of them are code. Source comments (1.6k) are about as long as the code, and tests are 6.2k. Please split it (versioned writes; the unsaved-changes dialog and tool clock; FileDocument/CanvasDocument plus the Documents.tsx changes; the manual-mode commit check; FileTracker's changes() belongs in #2869), cut comments to the why, and keep one test per user-visible flow plus the exploration. Aim for under about 2k lines per PR.

  2. In manual mode a rename can stage unsaved typing. rename() checks for unsaved changes only when it's called (stagedFileSystem.ts:1267), but renameNow reads readNow(from) (:1282), which returns the dirty buffer. So a rename queued behind a pending write or Commit all stores the typing as the new file and tombstones the old one. Read with stored and recheck dirtyPaths() in the rename's turn.

While splitting, consider one view-wide queue in place of the per-path chains. It would remove most of the new StagedFileSystem state.

@krishhgg

Copy link
Copy Markdown
Collaborator Author

Split into four PRs, in this order:

  1. fix(agent): give every file a version, so the agent and an editor cannot write over each other #2840 (this PR): versioned writes.
  2. fix(agent): keep one document per open file and pipeline, so splits, closed tabs and saves stay in step #2882: FileDocument, CanvasDocument, the Documents.tsx changes and the rename fix.
  3. feat(agent): ask before the agent changes a file with unsaved changes, and stop the tool clock while the user answers #2883: the unsaved-changes dialog and the tool clock. It sits above the documents PR because the dialog has nothing to show until editors register their unsaved typing.
  4. fix(agent): check a staged file against the copy the page read, so Commit all meets a teammate's change #2884: the manual-mode commit check.

FileTracker's changes() moved to #2869. Across the four, source comments went from 1,627 lines to about 850, and test lines from 6,231 to about 4,200. This PR and #2882 are still over 2k. #2882 has no clean seam: one harness checks both text and canvas documents, and they share the registry, the stored read and the save queue. Every kept test fails on a revert that no other test or exploration catches.

Rename, fixed in #2882. A queued rename now rechecks unsaved changes in its own turn and reads stored. A rename from the sidebar or the explorer is refused while the file has unsaved changes, or any file under a renamed folder does. Clean tabs move to the new path.

One queue, tried and not kept. It cut stagedFileSystem.ts by 270 lines. But a 50-file wave went from 46 ms to 2.0 s at 20 ms store latency (167 ms to 8.0 s at 80 ms), and a save or tab open during a wave waited for all of it. One write that never answered stalled every save in the view for 60 s. The numbers are in the PR body.

Reviewing the split also turned up these, now fixed:

  • a folder rename that left the versions of files under the destination unchanged
  • a cache refresh that took in a teammate's change without moving the version
  • a checkpoint and an undo racing saves still in flight
  • a staged save left behind when switching to Auto
  • a rename staged in two persists, which is now one
  • a save or Commit all that landed after the cached copy was dropped counting twice, which falsely refused the next save

@dylan-savage dylan-savage left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Versioned writes close the agent-over-editor race, and the reread of an overtaken read closes #2839's stale-read gap.

@krishhgg
krishhgg force-pushed the feat/rocket-agent-team-timeout branch from 6dfcb2c to 651bef5 Compare October 28, 2026 19:22
@krishhgg
krishhgg force-pushed the feat/rocket-agent-save-race branch from d07faa8 to de54720 Compare October 28, 2026 19:22
@dylan-savage
dylan-savage self-requested a review October 28, 2026 20:05
…not write over each other

The agent read a file, the user saved it, and the agent's edit then landed
on the text it had read, so the save was gone. In manual mode Commit all,
the discards, a rollback and Undo also raced the writes called just before
them.

Every path in the staged view now has a version. A mutation counts when it
is called and then waits behind the path's earlier ones; a read waits for
them too, up to 60 s. A delete or rename also counts every path under it,
at both ends of a rename. A write that names an older version is refused
with StaleVersionError. Commit all, Undo, the discards and a rollback run
in call order, and a commit carries only what was staged before it was
called. Undo counts and holds its paths from its call, also those a commit
called before it retains only once it runs. A checkpoint runs after the
writes called before it and holds the ones called after it. A server read
that one of the view's own changes overtook is read again.

A switch to auto mode is refused while a staged save is on its way, as it
is while changes are staged. A staged write to a folder, or a rename onto
one, is refused before it stages anything. A staged rename stages its delete
and its write together and saves them in one store write, so the view never
keeps the delete without the write.

An invalidate keeps the cached copy it drops. A read that then takes in a
different server copy, or finds one a batch read cached, counts a version,
so an editor that loaded the old copy cannot save over a teammate's
change, and until a read does, the dropped copy guards the next save.

The agent's tools read and write at a version: write_file refuses a file
that changed since the read, edit_file applies to a changed file only when
its anchor still matches once, and each wave tells the model which files
someone else changed. The ordering harness gets the auto run with an
editor save, a teammate's change and a Reload, and three manual runs
without the dialog.
Krish Garg and others added 2 commits October 28, 2026 20:28
…ropped while its write is on its way

Going back to a team, or the agent's refused write, drops the cached copy.
When an editor's save or Commit all's write was still on its way, the read
after it took the write's own content in as a changed copy and counted a
second version. The editor's next save was then refused as changed on the
server, and a canvas save after a Reload was too. The dropped copy now
becomes the written content once the write lands, for a write-through save
and for each file Commit all writes.
…closed tabs and saves stay in step (#2882)

Two splits of one file kept their own text and version, so a save from one
left the other behind and its next save was refused or wrote over the
first. A closed tab's unsaved text came back stale, and Ctrl+S and the close
dialog's Save skipped the version check.

A text file's text, version and save state now belong to a FileDocument
that every tab of the path shares and that outlives its last tab while the
text is unsaved. A pipeline's belong to a CanvasDocument that lives while
Documents holds it. Each document queues its saves; Reload, Overwrite and
closing the last tab drop the saves still waiting, which reject with
SaveDroppedError, so Save & Run and a publish stop. A refused save offers
Reload or Overwrite. The editors register their unsaved typing with the
view, so the agent's dirty guard and a rename see it: a rename over
unsaved changes is refused, also when it waited its turn behind a save or
Commit all, and it reads what the view stores. A rename from the sidebar
or the explorer closes the tabs of the file, or of the files under a folder,
while it runs and opens them on the new paths, so no typing lands on an old
path. Documents keeps typing that lands during a read or a write.

Co-authored-by: Krish Garg <krish.garg@rocketride.ai>
@krishhgg
krishhgg force-pushed the feat/rocket-agent-team-timeout branch from 651bef5 to 91b5fb4 Compare October 28, 2026 20:29
@krishhgg
krishhgg force-pushed the feat/rocket-agent-save-race branch from 3bd9822 to c6a99f0 Compare October 28, 2026 20:29
@dylan-savage
dylan-savage merged commit 42aef3f into feat/rocket-agent-team-timeout Oct 28, 2026
4 checks passed
@dylan-savage
dylan-savage deleted the feat/rocket-agent-save-race branch October 28, 2026 20:37
dylan-savage pushed a commit that referenced this pull request Oct 28, 2026
…ll, and ignore markers of deleted files (#2839)

* fix(agent): keep a run in its team, start nothing over a timed-out call, and ignore markers of deleted files

A tool call still running when the team changes lands in the team it started in.
A turn in another team's conversation is refused before anything runs.
A call on the same files as a timed-out call that still runs is not started, and the model hears when that call ends.
A late result is stored under its memory key redacted, as the model reads it.
check_app ignores type errors of TypeScript files that no longer exist, matching files by Monaco's own model uri.
Going back to a team reuses its workspace only if no other tab changed its staged state, and an old read cannot refill its cache.
A listing save reads and writes the app's package in the workspace it started in.
The dev session disposes a deleted file's model once the view confirms the deletion, and keeps it when a read only failed.

* fix(agent): refuse done until every late result is read, keep one test per behaviour, and cut comments to the why

The ordering explorations cover the orders of team switches, timeouts and
approvals. Each hand-written test left guards a fix line no other kept test
or exploration fails on when that line is reverted. Cut: the in-flight write
at a switch, the timed-out edit in the real workspace, the loop tests that
pair an approval with a timeout, and tests that pass on the base.

ordering.test.ts and workspace.test.ts now share FakeStore
(fakeStore.harness.ts). One cache test covers every change fill() checks.

unfinished() counts every call in late again, as on the base. A timed-out
call that ended while endWave ran, after lateReturns() took the calls that
had ended, let a done stand before the model read how it ended.

Where a revert passed every kept test, a test now fails on it: a deleted
file's markers let check_app pass, a done with calls waits for a late
result, going back to a team reads its files and file list again, and a
dev session reads its package, lock and icons and writes its lock in the
team it opened in after a switch.

A reopened workspace is no longer written back to builtByScope. The next
reopen gets the same workspace from the first entry.

* fix(agent): hide the values the file tools hid in a late result too

A call that timed out reaches the model as a late entry once it ends. Its
result and error went through redactText only, so a value a read had hidden
showed in full there, while every other tool result shows its marker. Late
returns now go through the same hiding as an outcome, values first, then key
shapes.

* fix(agent): give every file a version, so the agent and an editor cannot write over each other (#2840)

* fix(agent): give every file a version, so the agent and an editor cannot write over each other

The agent read a file, the user saved it, and the agent's edit then landed
on the text it had read, so the save was gone. In manual mode Commit all,
the discards, a rollback and Undo also raced the writes called just before
them.

Every path in the staged view now has a version. A mutation counts when it
is called and then waits behind the path's earlier ones; a read waits for
them too, up to 60 s. A delete or rename also counts every path under it,
at both ends of a rename. A write that names an older version is refused
with StaleVersionError. Commit all, Undo, the discards and a rollback run
in call order, and a commit carries only what was staged before it was
called. Undo counts and holds its paths from its call, also those a commit
called before it retains only once it runs. A checkpoint runs after the
writes called before it and holds the ones called after it. A server read
that one of the view's own changes overtook is read again.

A switch to auto mode is refused while a staged save is on its way, as it
is while changes are staged. A staged write to a folder, or a rename onto
one, is refused before it stages anything. A staged rename stages its delete
and its write together and saves them in one store write, so the view never
keeps the delete without the write.

An invalidate keeps the cached copy it drops. A read that then takes in a
different server copy, or finds one a batch read cached, counts a version,
so an editor that loaded the old copy cannot save over a teammate's
change, and until a read does, the dropped copy guards the next save.

The agent's tools read and write at a version: write_file refuses a file
that changed since the read, edit_file applies to a changed file only when
its anchor still matches once, and each wave tells the model which files
someone else changed. The ordering harness gets the auto run with an
editor save, a teammate's change and a Reload, and three manual runs
without the dialog.

* fix(agent): count a save or Commit all once when the cached copy is dropped while its write is on its way

Going back to a team, or the agent's refused write, drops the cached copy.
When an editor's save or Commit all's write was still on its way, the read
after it took the write's own content in as a changed copy and counted a
second version. The editor's next save was then refused as changed on the
server, and a canvas save after a Reload was too. The dropped copy now
becomes the written content once the write lands, for a write-through save
and for each file Commit all writes.

* fix(agent): keep one document per open file and pipeline, so splits, closed tabs and saves stay in step (#2882)

Two splits of one file kept their own text and version, so a save from one
left the other behind and its next save was refused or wrote over the
first. A closed tab's unsaved text came back stale, and Ctrl+S and the close
dialog's Save skipped the version check.

A text file's text, version and save state now belong to a FileDocument
that every tab of the path shares and that outlives its last tab while the
text is unsaved. A pipeline's belong to a CanvasDocument that lives while
Documents holds it. Each document queues its saves; Reload, Overwrite and
closing the last tab drop the saves still waiting, which reject with
SaveDroppedError, so Save & Run and a publish stop. A refused save offers
Reload or Overwrite. The editors register their unsaved typing with the
view, so the agent's dirty guard and a rename see it: a rename over
unsaved changes is refused, also when it waited its turn behind a save or
Commit all, and it reads what the view stores. A rename from the sidebar
or the explorer closes the tabs of the file, or of the files under a folder,
while it runs and opens them on the new paths, so no typing lands on an old
path. Documents keeps typing that lands during a read or a write.

Co-authored-by: Krish Garg <krish.garg@rocketride.ai>

---------

Co-authored-by: Krish Garg <kg@g14-node1.tailb99b1b.ts.net>
Co-authored-by: Krish Garg <krish.garg@rocketride.ai>

---------

Co-authored-by: Krish Garg <kg@g14-node1.tailb99b1b.ts.net>
Co-authored-by: Krish Garg <krish.garg@rocketride.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:ui Chat UI and Dropper UI tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants