Skip to content

feat(agent): ask before the agent changes a file with unsaved changes, and stop the tool clock while the user answers - #2883

Merged
dylan-savage merged 4 commits into
feat/rocket-agent-browserfrom
feat/rocket-agent-unsaved-dialog
Oct 29, 2026
Merged

dylan-savage merged 4 commits into
feat/rocket-agent-browserfrom
feat/rocket-agent-unsaved-dialog

Conversation

@krishhgg

@krishhgg krishhgg commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #2718. Stacks on feat/rocket-agent-browser, which now holds the save-race PR (#2840) and the editor documents PR (#2882). It is the third of the four PRs split from #2840.

The problem

When the agent wanted to change a file the user had unsaved changes in, the call was refused and the model asked the user to save first. The user had to stop, save or discard by hand, and ask again. A question that did show had to beat the tool's time limit, so a call could time out while the user was deciding.

What changes

  • A change to a file with unsaved changes asks the user: Save mine first, Discard mine or Keep mine. The open editors do what the user chose (EditorControl, AgentHost.editor). One dialog shows at a time, in order; a question whose turn comes while another app dialog is on screen is not shown, and the model is told so. A dialog that is in the page but hidden does not count.
  • A delete shows its approval card first and asks about unsaved changes in its run, since Save mine first and Discard mine change files.
  • Save mine first on a delete or a rename saves the text, then refuses with a plain error, so the agent reads again and asks before it moves on. A refused write_file after Save mine first still counts as a change, so the app check runs. So does a Save mine first that landed or sent a write and then failed, since the file may have changed: its reply can fail before or after the write lands, or one editor saves and the next fails (a text tab and a canvas on one pipeline, or two files of a folder being moved). The view counts a write when it is called, so the toolkit compares the dirty paths' versions before and after the save. A save that joins a Ctrl+S already on its way moves no version, so each editor also reports when its save lands (EditorControl.save(stored)). A save the user dropped before it wrote anything is still a refusal that changed nothing.
  • A call's time limit stands still while a question is open, in the call's prepare and in its run (UserTime). A call its tool refused before changing anything (RefusedError) is unstarted, so the finish rule asks for no check.
  • Open questions close as Keep mine when the run ends or the user stops it, so an answer given later never lands after the run. After a team switch an old run finds no editor.

Tests

The manual explorations get the dialog: an answer is a step. With the runAgent variant (the clock stands still while a question is open, and a step moves it past the limit) and the editor documents, every order breaks 0 rules: manual 8,876 orders, restored start 12,014, slow first read 7,368, as runAgent runs it 13,843, text tab 54,510 and 16,223, canvas 141,527 and 47,665. With the question switched off, the manual runs never reach an answer.

Unit tests cover what the explorations don't: the queue and its end-of-run and Stop handling, a question blocked by another dialog, our own closing dialog, the clock in the prepare and in the run, runAgent's wiring of the clock (a question still open past the 300 s limit, then answered), a dirty file with no editor, the delete's card before its question, the delete and rename after Save mine first, a save that joins a Ctrl+S on its way and lands before the next editor or file fails, a save whose reply fails before or after its write lands, a save dropped before it wrote, and the finish rule after Keep mine and after Save mine first. The clock tests fake setTimeout and performance.now together, so only the test moves time and a late timer on a busy machine changes nothing.

After the restack

On the final versioned writes, the text tab exploration broke its not-stored rule in 3 of 54,510 orders, for example edit > answer discard > release 0 > type > reload > fail 0 > teammate. The agent's write fails while a Reload's read waits for it, so the view counts a version for the failure, then the read takes the teammate's copy in and counts that too. The tab shows the stored file, one version behind: the read was called before the failure, so it counted the teammate's copy but not the failure. That is the known limit for a write that failed (versioned writes PR, Known limits), which the exploration already counts apart when nothing moves the version after the failure. A second commit counts these orders under it too. The text tab exploration now breaks 0 rules, with 2,221 orders under that limit where it had 2,218, and nothing else moved. With the rule widened, the exploration still catches a clean canvas that stops following its file (11,904 orders) and unsaved text behind a moved file that never turns stale (1,750).

Since Dylan's review

Below 1024 px the question never showed. There the shell's sidebar is a drawer, and it stays in the page as a modal dialog (role="dialog", aria-modal="true") with visibility: hidden while it is closed. otherDialogOpen() counted it, so every question resolved unasked, and the agent asked the user to close a dialog they could not see. A new commit counts only the dialogs that checkVisibility({ visibilityProperty: true, checkVisibilityCSS: true }) reports visible.

  • Reproduced at 900 px on the previous head (c81691a). The unsaved-edits journey showed no dialog, and the agent replied "Could you close whatever dialog/prompt is currently open in the editor". In that page the closed drawer answers checkVisibility() with true and checkVisibility({ visibilityProperty: true }) with false, so the option is needed.
  • An open drawer still blocks the question. With the drawer opened right after the message was sent, no dialog showed, the agent was told the user was not asked, and the file stayed as it was.
  • A browser without checkVisibility counts every dialog, as before, so a question never opens over another dialog. Chrome has the method from 105 and visibilityProperty from 121. Chrome 105 to 120 know the option only by its old name, checkVisibilityCSS, so the call passes both.
  • Tests. "A dialog in the page but hidden, as the closed navigation drawer is below 1024 px, does not block the question" fails on the previous head, and when visibilityProperty is dropped. "The closed drawer does not block the question in Chrome 105 to 120, which know the option only as checkVisibilityCSS" fails when checkVisibilityCSS is dropped. Both fail when the visibility check is removed. "A visible dialog still blocks the question, as does one in a browser without checkVisibility" fails when a missing method counts as hidden. Each revert of one option, or of the fallback, fails only its own test. The visible-dialog test passes on the previous head, which counted every dialog.
  • Journeys: unsaved-edits with keep, save and discard pass at 900 px and at the default 1440 px.

The stack

Eleven PRs, each on the one below it. #2835, #2836, #2839, #2840 and #2882 are merged, and this PR now sits directly on feat/rocket-agent-browser. The rest merge top-down: each PR squashes into the branch below it, starting with #2885.

  1. fix(agent): let Wave read plan replies itself #2835 plan replies (merged)
  2. fix(agent): keep secrets out of the model in the browser agent #2836 secrets (merged)
  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 (merged)
  4. fix(agent): give every file a version, so the agent and an editor cannot write over each other #2840 versioned writes (merged)
  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 (merged)
  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 (this PR)
  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 28, 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 github-actions Bot added module:ui Chat UI and Dropper UI tests labels Oct 28, 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 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 one thing.

Below 1024 px the question never shows. The shell's compact sidebar is always in the page with role="dialog" aria-modal="true", drawer open or closed (Sidebar.tsx:759-760), so otherDialogOpen() (choice.tsx:104) matches it and every question resolves unasked. The agent is then told to "try again after they close it" for a dialog the user can't see. Count only visible dialogs, for example by skipping any where checkVisibility({ visibilityProperty: true }) is false.

Base automatically changed from feat/rocket-agent-documents to feat/rocket-agent-save-race October 28, 2026 20:26
@krishhgg
krishhgg force-pushed the feat/rocket-agent-save-race branch from 3bd9822 to c6a99f0 Compare October 28, 2026 20:29
Base automatically changed from feat/rocket-agent-save-race to feat/rocket-agent-team-timeout October 28, 2026 20:37
@github-actions github-actions Bot added the builder Node builder tooling and ./builder workflows label Oct 28, 2026
Base automatically changed from feat/rocket-agent-team-timeout to feat/rocket-agent-browser October 28, 2026 20:38
Krish Garg added 3 commits October 28, 2026 20:50
…, and stop the tool clock while the user answers

When the agent wanted to change a file the user had unsaved changes in,
the call was refused and the model told the user to save first.

Now the user is asked: Save mine first, Discard mine or Keep mine, one
dialog at a time. The open editors do what the user chose. A call's time
limit stands still while the question is open, in its prepare and in its
run. A call its tool refused before changing anything is unstarted, so the
finish rule asks for no check. One in which the user's save landed or
sent a write still counts as a change, even when that save or another
editor's save then failed, since the file may have changed. A save that
joins a Ctrl+S already on its way counts once it lands. Open questions
close as Keep mine when the run ends or the user stops it.
…imit, also after a later read

With versioned writes, a read that takes a teammate's copy in counts it for
the editor too. When that read waited for a write that then failed, the
failure's count lands before the read and the editor misses only that one,
while the file moves past the failure's version. The text tab exploration
broke its not-stored rule in 3 such orders, where the tab shows the stored
file. They now count under the known limit for a failed write, as the same
order without the teammate's change already does.
…e closed drawer is a hidden dialog

Below 1024 px the shell's sidebar is a drawer. It stays in the page as a
modal dialog, with `visibility: hidden` while it is closed. otherDialogOpen()
counted it, so every question resolved unasked, and the agent was told to try
again after the user closed a dialog they could not see.

otherDialogOpen() now counts only dialogs that
checkVisibility({ visibilityProperty: true }) reports visible. The call also
passes the option's old name, checkVisibilityCSS, which Chrome 105 to 120
know instead. An open drawer still blocks the question. A browser without
checkVisibility counts every dialog, as before, so a question never opens
over another dialog.
@krishhgg
krishhgg force-pushed the feat/rocket-agent-unsaved-dialog branch from c81691a to 95b719b Compare October 28, 2026 20:52
@github-actions github-actions Bot removed the builder Node builder tooling and ./builder workflows label Oct 28, 2026
@krishhgg

Copy link
Copy Markdown
Collaborator Author

Fixed in the top commit. otherDialogOpen() now counts a dialog only when checkVisibility({ visibilityProperty: true, checkVisibilityCSS: true }) doesn't return false. The old option name covers Chrome 105 to 120, which have checkVisibility but not visibilityProperty. If the method is missing, the dialog counts as visible, so the question still never opens over a real dialog on those browsers.

I reproduced the bug at 900 px on the old head: no question showed, and the model was told the user had another dialog open. With the fix, the unsaved-edits journey passes at 900 px and at 1440 px. With the drawer actually open at 900 px, the question still waits. The tests cover a hidden dialog, a visible one, and a hidden drawer that answers only to checkVisibilityCSS.

The branch now sits directly on feat/rocket-agent-browser, after your merges. The trees above it are unchanged apart from this fix.

…mmit all meets a teammate's change (#2884)

* fix(agent): check a staged file against the copy the page read, so Commit all meets a teammate's change

In manual mode a staged file's conflict anchor was a fresh server read
taken when it was first staged. A teammate's change from before then became
the anchor, so Commit all wrote over it.

The anchor is now the copy the page read, so the commit meets a conflict.
The view's prime records the path only: the dev preview primed what its
batch read returned, unsaved typing included, and the cache then served it
as the server's copy. The preview and teammate exploration covers both.

Going back to a team drops the page's cached copies, so a delete the agent
decided on before a switch away and back anchored on the server's copy
after it, and Commit all deleted a teammate's change. The view's delete
now takes an anchor, the hash of the stored copy the delete is based on.
delete_file passes the copy the agent last read or wrote. Under unsaved
typing that is the stored copy below the typing, which Discard mine brings
back. The view checks the anchor in the delete's turn, against the same
capture its tombstone records, so no copy read later can become the
delete's anchor. In write-through mode it checks the server's copy.

* feat(agent): end each turn with a result card, let the agent ask the user, and stop only its own runs in Auto (#2869)

* refactor(agent): move FileTracker changes() here from the save-race PR

The turn's result card lists what the run changed, so FileTracker records
each file's change (added, modified, deleted or renamed, and where a
renamed file came from) and changes() lists them. A file the run created
and then deleted is no change. A deleted file keeps its version, so a
file the run only deleted is not read back as seen. The stored copy a
delete is checked against stays with each read, write and rename.

* feat(agent): end each turn with a result card, let the agent ask the user, and stop only its own runs in Auto

- runAgent, agent() and AgentSession.execute return a TurnResult: the
  outcome (done, needs_input, stopped, failed, incomplete), the files and
  checks, the usage and any needs-you request. Every turn ends once through
  execute, including a refused message, an error, Stop and an unmount.
- The session file is version 2. It keeps the turns, linked to the rows that
  close them, and the runs the conversation started. A version 1 file loads
  with neither. Every saved field passes through redactText.
- The shell's ChatMessage gains an optional `card`, and ChatView gains
  `onCardAction`. The Agent tab puts each turn's card under its row: links to
  the changed files, Open Variables, a button per choice, and Continue.
- ask_user ends the turn as needs_input, as a question or a missing
  Variable. Only the user's next message answers the request.
- terminate and restart ask first in Ask mode. In Auto they run only on a run
  this conversation started with use, after a fresh getTaskStatus matches the
  record and the scope. Any other run is refused, and the model is told to
  ask the user.
- A turn running when the Agent tab unmounts is saved with its rows and a
  closing row (known bug 5).
- A use refused because the pipeline is already running says how to run the
  edited version (known bug 14).

* fix(agent): answer a needs-you request only after it showed, document the row card, and check the run on the Ask card

A turn the user stopped in the wave that called ask_user kept its request.
Its card said only "Stopped", yet the next message answered the question and
disabled its buttons. Only a needs_input turn keeps its request now.

A message the user sent during the wave that called ask_user stayed queued,
then ran as its own turn and answered the question the user had not seen.
The loop now takes such a message before it ends the turn. It drops the
question, and the model reads the message and may ask again.

ChatMessage.card and the onCardAction prop of ChatView and MessageList are
documented in ROCKETRIDE_UI_COMPONENTS.md and the ChatView gallery entry.

The Ask card for terminate and restart said "This conversation started it."
from the run record alone. The engine gives a later run on the same project
and source the same token, so the card could claim the user's run. It now
reads the run's status first, as the Auto run step does.

* feat(agent): pause a turn at its step or cost limit, show its estimated cost, and undo its file changes (#2873)

* feat(agent): pause a turn at its step or cost limit, show its estimated cost, and undo its file changes

- A turn takes at most 60 steps (waves) by default. At the limit the loop
  plans no more, answers with the best-effort summary, and the turn ends as
  needs_input with a continue request: the card says "Paused after 60 steps"
  and Continue starts a new turn with a fresh budget. Messages sent during
  the turn do not reset the count. Agent Step Limit in Settings changes it,
  and 0 turns it off.
- A UsageMeter estimates each model request from characters, 4 to a token,
  priced from a dated table with one row for the stand-in's model
  (claude-sonnet-5, Anthropic's price page, read 2026-10-27). The prompt
  start is priced at the cache-write rate on a turn's first request, at the
  cache-read rate after, and as a write again after a gap over five minutes,
  only for a provider that caches it and a question that asks.
- Before every model request, the retry after a pipeline restart and the
  best-effort summary included, the meter reserves the input estimate and
  an output allowance. A request that could pass the turn's cost limit is
  not sent, and the turn pauses with Continue. A failed request keeps its
  reservation. The limit is $2 per turn by default (Agent Cost Limit, 0
  turns it off); a model with no price shows tokens and has no limit.
- The bot row's meta line shows the estimate ("~$0.42 est."), and
  TurnResult.usage carries the tokens and the cost, marked estimated.
- The latest turn's card has Undo for that turn's file changes. The file
  toolkit records, in memory only, each path's content at its first touch
  and the version and hash each agent change left. Undo checks every path
  first: no editor holds unsaved changes, the version is the agent's, no one
  else changed it between agent changes, and the stored content matches what
  the agent left (the server's copy afresh, or the staged content for a path
  still staged). Then every inverse starts in one block, through the
  versioned write. In manual mode a file the agent created and never
  committed has its staged entry dropped, so nothing stays pending. A note
  row says what Undo did, and the model reads it in the next turn.

* fix(agent): say that the cost estimate and the cost limit leave out thinking

The stand-in model request sends no thinking param, so Sonnet 5 thinks by
default and bills it as output the browser never sees. The estimate counts
only the reply text, so "~$X est." and the cost limit are lower bounds. The
row's meta line now reads "~$X est., not counting thinking", and the cost
limit setting says a turn can cost more than the limit.

---------

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

---------

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

---------

Co-authored-by: Krish Garg <kg@g14-node1.tailb99b1b.ts.net>
@github-actions github-actions Bot added the docs Documentation label Oct 29, 2026
@dylan-savage
dylan-savage merged commit 7e1537b into feat/rocket-agent-browser Oct 29, 2026
4 checks passed
@dylan-savage
dylan-savage deleted the feat/rocket-agent-unsaved-dialog branch October 29, 2026 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation module:ui Chat UI and Dropper UI tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants