Repository navigation
fix(agent): give every file a version, so the agent and an editor cannot write over each other - #2840
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review: 2
Please check the settings in the CodeRabbit UI or the
|
🤖 Internal: Discord sync markerAuto-managed by the Discord notification workflow. Stores the linked Discord message ID and forum thread ID. Do not edit or delete. |
afa656a to
72c1e51
Compare
f17ce08 to
85a4e05
Compare
dylan-savage
left a comment
There was a problem hiding this comment.
Requesting changes on two things.
-
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. -
In manual mode a rename can stage unsaved typing.
rename()checks for unsaved changes only when it's called (stagedFileSystem.ts:1267), butrenameNowreadsreadNow(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 withstoredand recheckdirtyPaths()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.
72c1e51 to
6dfcb2c
Compare
85a4e05 to
d07faa8
Compare
|
Split into four PRs, in this order:
FileTracker's Rename, fixed in #2882. A queued rename now rechecks unsaved changes in its own turn and reads One queue, tried and not kept. It cut Reviewing the split also turned up these, now fixed:
|
dylan-savage
left a comment
There was a problem hiding this comment.
Approving. Versioned writes close the agent-over-editor race, and the reread of an overtaken read closes #2839's stale-read gap.
6dfcb2c to
651bef5
Compare
d07faa8 to
de54720
Compare
…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.
…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>
651bef5 to
91b5fb4
Compare
3bd9822 to
c6a99f0
Compare
…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>
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
write(path, content, origin, expect)is refused withStaleVersionError(aStaleWriteError) when the path moved pastexpect.readVersionednever returns content older than its version. A wait gives up after 60 s with an error that says what it waits for.write_filerefuses a file that changed since the agent read it.edit_fileon 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.Since Dylan's review
changes()and its change kinds moved to feat(agent): end each turn with a result card, let the agent ask the user, and stop only its own runs in Auto #2869, which is their only reader.After the restack
a tab's save on its way when the cached copy is dropped counts once, so the tab's next save landsandCommit 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.FakeStorenow, which gainsholdsPersistsfor 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:
stagedFileSystem.ts.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.tsholds the actors the ordering explorations share: rocket-ui's real workspace over #2839's in-memoryFakeStorethat 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:write, reads waiting for writes, a copy taken in after a Reload counting no version (21 of 871 orders erase a write)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
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.