Skip to content

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

Merged
dylan-savage merged 4 commits into
feat/rocket-agent-commit-checkfrom
feat/rocket-agent-turn-contract
Oct 29, 2026
Merged

dylan-savage merged 4 commits into
feat/rocket-agent-commit-checkfrom
feat/rocket-agent-turn-contract

Conversation

@krishhgg

@krishhgg krishhgg commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Before this, a turn ended with only its reply text. Nothing recorded what it changed or checked, so the chat couldn't show it and the next turn couldn't build on it. The agent had no way to stop and ask the user for something it needed, such as a missing Variable. A turn stopped by a team switch lost its transcript. And terminate was a free call: in any mode the agent could stop a run it didn't start, including a team's deployed run.

Now every turn ends with a TurnResult and a card on its last reply: what it changed, what it checked, and what it needs. The agent can end a turn by asking the user (ask_user), and the next message answers it. Terminate and restart ask in Ask mode. In Auto they act only on a run this conversation started, after a live check right before the call.

Part of #2718: layer 8 of 11, on the commit check PR's branch feat/rocket-agent-commit-check, the last of the four PRs split from #2840. Merge the stack top-down: each PR into the branch below it, down to #2835 into feat/rocket-agent-browser. A bottom-up squash conflicts unless each next branch is rebased onto the squashed base first. The next layer, limits and Undo, builds on the result and the card added here.

How a turn ends

runAgent, agent() and AgentSession.execute now return a TurnResult (turn.ts). Before, runAgent resolved with nothing, and the only record of a turn was its reply text.

Field What it holds
turnId, messageId, scopeKey The turn, the chat row that closes it once the session links it, and the team it ran in.
outcome, reason done (the finish rule took the answer), needs_input (ask_user), stopped (Stop, or unmounted), failed (the model failed, or refused for a message the session would not run), incomplete (replies stayed unusable).
finalText, error The answer with its checks line, and the error of a turn that threw.
files Each changed path with added, modified, deleted or renamed, and a rename's source. From the file tracker #2840 added, which also hears the files create_app's scaffold wrote.
checks The newest result per target and step: pass, fail or not run. A step that did not run never counts as a pass. An app changed and never checked is listed as not run.
usage Waves, model requests (each chat request sent, so a pipeline retry and the best-effort answer count) and tool calls. cost stays empty: the stand-in model call returns no token counts (known bug 15), and the next layer adds the estimate.
request, runsStarted, undoAvailable The needs-you request, the runs this turn started, and a slot for Undo.

Every turn ends once, in execute: a refused message, a model error, Stop and an unmount all leave a result. A model that fails before the turn gathered anything still throws, so the chat shows its error row, but the error carries the result.

Session file version 2

The session file gains turns, each linked to the id of the row that closes it, and runsStarted. A turn is linked by position: its opening user row sits at the index of its history length, and its closing row is the first bot row after that which is not a thinking row. A version 1 file loads with no turns and no runs, so it owns no run. Rows, cards, turns and run records all pass through redactText on save. Run tokens stay readable, as #2836 keeps them for the model.

The card

This is the one shell change. ChatMessage gains an optional card (tone, title, lines, files, actions), and ChatView gains onCardAction(messageId, action). MessageList draws the card under its row with #2853's "Needs your OK" card styles. With no handler, its links and buttons are disabled. Approval cards are unchanged and stay on the turn, unsaved. ROCKETRIDE_UI_COMPONENTS.md and the ChatView gallery entry document card and onCardAction.

The Agent tab puts each turn's card on its row (AgentSession.decorate), and saves it with the row:

  • done: "Done", the changed files as links, every check.
  • failed and incomplete: "Not finished", the error and the failing checks.
  • needs_input: "Needs you", with a button per choice, Open Variables, or Continue.
  • stopped: "Stopped", the files changed so far.

A file link opens the file the way the Explorer does (AgentHost.openFile). Open Variables emits shell:openOverlay with environment. A choice or Continue sends its text as the user's reply. An error row shows its own banner, so it gets no card.

Needs you

ask_user (toolkits/askUser.ts) ends the turn after its wave. The question is the turn's answer, and the outcome is needs_input. The answer gets "Not checked" only when something the turn changed is still unchecked; a pipeline that validated on save needs nothing more.

  • question, with up to 4 choices, each a button.
  • variable, with a ROCKETRIDE_ name. The tool reads account.getEnvironmentKeys (names only), so the card says whether the name is set. It never says whether a key works.
  • continue is defined for the next layer's limits, with a Continue button. The model cannot ask with it.

Each request has an 8-character id. Only the user's next message answers it, typed or pressed, and the model reads "(answering request )" under it. A second press, a press after the reply, and a press after a typed reply do nothing, and the card shows its answers disabled.

A message the user sent before the question showed never answers it. If the user writes during the wave that called ask_user, the loop takes the message before it ends the turn, drops the question, and the model reads the message and may ask again. Only a needs_input turn keeps its request, so a turn the user stopped in that wave, whose card says only "Stopped", has nothing to answer.

Terminate and restart

terminate and restart were free. They are now ask rows in approval.ts, with a rule for the run they name.

  • Ask mode asks for both, whoever started the run. The card says "This conversation started it." only after the same status read the Auto run step makes. When the run's token now holds another run, or its status can't be read, the card says "Not confirmed as this conversation's run" and why. For a run the conversation has no record of, it says "This conversation did not start it."
  • Auto runs one only on a run this conversation started. On any other run it refuses with no card. The message names the run and tells the model to call ask_user, so the turn ends as needs-you.
  • Which runs are the conversation's (toolkits/runs.ts). A use that the engine answers with reused: false is followed at once by getTaskStatus(token), since use returns no start time. The record keeps the token, project_id, source and startTime from that read, the scope and the conversation. It lives in the session file. A reused run, a run whose status could not be read, and every deploy.run start are never recorded.
  • The live check. An Auto terminate or restart reads the run's status again in the call's run step, after approval and right before the client call. The start time, project_id and source must match the record, and the host's scope must still be the recorded one. Otherwise the call is refused. A restart refreshes the record from a status read afterwards.
  • Switching to Auto while a card waits approves it only for the conversation's own run, and then the live check runs. A card about another run keeps waiting for the user.

Known bugs folded in

  • Bug 5: a turn's transcript was lost when the Agent tab unmounted, for example on a team switch. The tab now hands the session the rows it showed last (detach). The session saves them at once, in the conversation's own team. When the stopped turn ends, the session adds a closing row ("Stopped by you: the Agent tab closed.", with the progress rows the chat showed), links the turn to it and saves again. React's dev double mount runs that cleanup once at start, so the tab's effect calls attach first.
  • Bug 14: rerunning an edited pipeline failed with "Pipeline is already running". A use refused that way now adds one line: the edits are not in the running task, so terminate it (getTaskToken gives the token) and call use again, and ask the user first if this conversation did not start it.

A turn that the chat closes before it ends (Stop's 3-second grace runs out, for example behind a slow store) now links itself to the chat's stop row and saves when it ends. Before, nothing saved it.

Tests

Each new behavior has a test that fails without it.

  • turn.test.ts: each loop stop maps to its outcome; the card for each outcome; the needs-you cards and their disabled state; redactDeep keeps the run token.
  • wave/loop.test.ts: a call that asks the user ends the turn as needs_input even in a reply that says done; the tool-call count.
  • toolkits.test.ts, one per outcome through runAgent: done (files with a rename source, checks, usage), the files create_app scaffolds, needs_input (variable and question, a bad name refused, "Not checked" only when something is unchecked), stopped (with the unchecked app), failed (best effort, and a thrown TurnError), incomplete. Also: a key in a result is redacted; the rerun guidance; ownership (a fresh start then reuse, Ask for owned and foreign runs, Auto owned and foreign, a token holding another run, in Auto and on the Ask card, a vanished run, a scope change, a deploy.run start, a switch to Auto with a waiting owned and foreign card, the refresh after restart, and runs handed through runAgent).
  • agent.test.ts, through AgentSession and the shell's TurnController: version 1 to 2; a chat request retried after a pipeline restart counts twice; a refused message's turn; a reloaded version 2 conversation that still owns its run while a version 1 file owns none; an unmount mid-turn; a turn the chat closed before it ended; late and duplicate answers; a turn stopped in the wave that asked, whose request the next message does not answer; a message sent while the model asks, read in the same turn; each card action; no key in the saved file, including a key already in a stored turn; the dev double mount.

Each of 33 mutations, one per new behavior, fails at least one of these tests.

Fixes from review

  • Scaffolded files were missing from the result. create_app writes through the host's scaffold, not the file toolkit, so a turn that created an app returned files: [], and its card listed nothing. After the scaffold, the toolkit now lists the new app's folder and records each file as added (FileTracker.created). The model still reads a scaffolded file before it edits one.
  • A retried model request counted once. modelRequests counted calls to the model function, so the request createChatModel sends again after a pipeline restart was not counted. createChatModel now reports each chat request it sends (onRequest), the retry included. A model a test passes in still counts once per call, so nothing counts twice.

Each fix has a test that fails on the commit before it and passes with it: "the files create_app scaffolds are in the turn result as added, though the scaffold writes past the file toolkit" (it got files: []), and "a chat request the stand-in pipeline retries after a restart counts as two model requests in the turn's usage" (it got modelRequests: 1).

Later review rounds found five more ways the file list could misreport a turn, all fixed, each with a test that fails without its fix:

  • A scaffold that failed part way lost its files. create_app now records the new folder's files in a finally, so files a failed scaffold wrote are listed as added.
  • A file deleted with its folder and made again by a scaffold stayed deleted. FileTracker.created now turns a deleted file into a modified one, as a write does.
  • A recreated folder kept its deleted row. The card said "Deleted apps/daybook-ui" next to a link to a file inside it. A write, create or rename under a folder the run deleted now brings the folder back.
  • An unread file a deleted folder held vanished from the list. Clearing the folder row hid it. delete_file now lists a folder's files before deleting it, and each gets a deleted row of its own.
  • A file renamed into a deleted and recreated folder left the folder deleted. A rename now brings the folder back too.

Fixes from Dylan's review

  • A message the user sent before seeing the question closed the needs-you request. Two paths led there. A turn the user stopped in the wave that called ask_user showed only "Stopped" but kept its request. And a message sent during that wave stayed queued, so it ran as its own turn. Either way the next message reached the model with "(answering request …)", and the card's buttons went dead. Only a needs_input turn keeps its request now. Before it ends on ask_user, the loop takes queued messages. When there are any, it drops the question and goes on, as a done does with a message the model has not read. Tests: "a turn stopped in the wave that asked the user answers nothing: the next message is not a reply to the question" and "a message sent while the model asks the user is read in the same turn, and the model can ask again" (agent.test.ts). Each fails on the commit before.
  • The step-limit and cost-limit pauses (feat(agent): pause a turn at its step or cost limit, show its estimated cost, and undo its file changes #2873) already take queued messages before and after their best-effort answer, and feat(agent): pause a turn at its step or cost limit, show its estimated cost, and undo its file changes #2873's test "a message sent in the last step or during the summary is heard by the paused turn" covers it. Their Continue request comes only on a turn that paused, never on a stopped one.
  • ChatMessage.card and onCardAction had no doc. They are now in docs/agents/context/ROCKETRIDE_UI_COMPONENTS.md and the ChatView gallery entry.
  • The Ask card claimed a run from its record alone. The engine gives a later run on the same project and source the same token, so after the conversation's run ended the card could say "This conversation started it." about the user's run. The label now reads the run's status first, as the Auto run step does. Test: "an Ask card says the conversation started the run only after a fresh status read, so a token that now holds a later run is not claimed" (toolkits.test.ts).

After the restack

  • FileTracker's changes() is here now, as its own first commit ("move FileTracker changes() here from the save-race PR"). It moved out of fix(agent): give every file a version, so the agent and an editor cannot write over each other #2840's split, since this PR is its only reader. It records each file's change kind and where a renamed file came from, and keeps the commit check's stored-copy hash with each read, write and rename.
  • The card hides what the file tools hid. Since fix(agent): keep secrets out of the model in the browser agent #2836's review, the answer and the approval cards show a value the file tools hid as its marker. The TurnResult, which the card and the saved session show, quotes the model's ask_user question and choices, so those two now pass through the run's hiding too. Only those two: a hidden value with a character that is not a letter can be a word the card acts on, such as needs_input, and the card acts on the request's kind and id and on the turn's outcome and reason. Test: a value a read hid shows as its marker in the turn's question and choices, and the card keeps its outcome, kind and buttons (toolkits), with a .env that holds PASSWORD=needs_input. It fails when the question and choices are not hidden, and when every string of the turn is.

Proof

On this commit, with the fixes from Dylan's review:

On the commit before the review, which the review did not change outside the files above:

  • The shell's dirtyClose 14 of 14, and its chat tests (turnController, statusRows) 8 of 8. The review changed no shell code.
  • The shell contract check says "Up to date with v6 (no actionable change)".

Browser journeys, on an engine built from this branch (server-v3.5.0 binary, the branch's engine Python), with Claude through the stand-in. On this commit every journey passed every check in one full run. An earlier full run failed one needs-you check on a counting flaw in the check itself, explained below.

Journey Checks
unsaved-edits, Keep mine, Save mine first, Discard mine 5, 5 and 5
steps closed-dirty-tab, split-save 3 and 7
build-pipeline 4
secrets 14
needs-you (new) 7
foreign-terminate (new) 8
  • needs-you. The first turn ended with a "Needs you" card: "ROCKETRIDE_VERIFY_MISSING_KEY is not set in Variables", a link to the pipeline it built, and Open Variables, which opened Variables. The reply answered the request ("(answering request 27edc590)" in the next question, and answeredBy in the file). After a reload the card came back from the session file, and its link opened the pipeline.
  • The needs-you check that failed. The card's link opened the pipeline's tab in the full run too (its screenshot shows the tab and the canvas). The check counts visible text that reads just verify-search before and after the click. That run's second answer showed the name in a code span, so the count was 1 before the click, and 1 after it once the chat was hidden. The rerun's answer had no such span, and the count went from 0 to 1.
  • foreign-terminate. A run started outside the agent. In Ask mode the card said "This conversation did not start it.", and after Deny the run still ran. In Auto, in a new session, there was no card, the call was refused, and the run still ran. Both turns ended as needs-you.

The first full run found two problems in this PR's own behavior, both fixed above with tests: a needs-you answer said "Not checked" under "Checked: validate OK", and in Auto the model answered the refusal in prose, so the turn ended "Done" with an empty card.

Known limits

  • Check, then act. Between the live status read and the terminate, the run could still change. The engine has no conditional terminate, as the store has no conditional write (known bug 3).
  • A card on a turn the chat stopped as it finished. If the user presses Stop just as a turn ends with done, the chat writes its stop row and the card on it says Done.
  • The error row has no card. Its banner already shows the error.
  • Usage has no cost until the next layer, and no token counts until the model call reports them (known bug 15).

Proved with: 481 of 483 shared tests (2 todo for #2836's limits), all twelve ordering explorations with 0 broken rules, dirtyClose and the shell chat tests, the type-checks and test-file check, the rocket-ui build, and nine browser journeys passing every check on an engine built from this branch, two of them new (needs-you, foreign-terminate).

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
  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 (this PR)
  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 27, 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 27, 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.

  1. A message the user sent before seeing the question closes the needs-you request. If the user stops during the ask_user wave, the turn shows only "Stopped" but keeps request (run.ts:811). If they type during the last wave, the needs_input exit (loop.ts:1160) skips the run.hear() that done does. Either way the next message reaches the model with (answering request …), and the card's buttons are disabled. Keep request only on needs_input turns, and hear queued messages before ending on ask_user, continuing as done does with READ_THE_USER.
  2. ChatMessage.card and onCardAction on ChatView/MessageList are new public shell props with no doc. Per AGENTS.md, add them to docs/agents/context/ROCKETRIDE_UI_COMPONENTS.md and chat-view.entry.tsx in this PR.

Not blocking, but worth fixing too. The Ask card's "This conversation started it." skips the status read, so after token reuse it labels the user's run as the agent's.

@krishhgg

Copy link
Copy Markdown
Collaborator Author

Both fixed.

  1. Only a needs_input turn keeps request now, so a turn stopped during the ask_user wave leaves nothing for the next message to answer. The loop also hears queued messages before it ends on ask_user. If any arrived, it withdraws the question and carries on the way done does. I gave that refusal its own text (ASKED_UNSEEN), because READ_THE_USER says "before done=true", which doesn't fit an ask_user call. Each path has a test that fails on the old head.
  2. ChatMessage.card and onCardAction are documented in ROCKETRIDE_UI_COMPONENTS.md and chat-view.entry.tsx.

The Ask card label now uses the same status read as the Auto run step, so after token reuse it reads "Not confirmed as this conversation's run". The card's question and choices hide values the file tools hid, as the answer already does; its kind, outcome and ids are left alone. FileTracker's changes() moved here from #2840 as its own commit.

@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.

Both fixes, the docs and the Ask label look good. Approving.

@krishhgg
krishhgg force-pushed the feat/rocket-agent-commit-check branch from 8e6f799 to de7ca6e Compare October 28, 2026 19:22
@krishhgg
krishhgg force-pushed the feat/rocket-agent-turn-contract branch from 8074fb3 to 791c40f Compare October 28, 2026 19:22
Krish Garg added 3 commits October 28, 2026 20:50
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.
…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).
… 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.
@krishhgg
krishhgg force-pushed the feat/rocket-agent-commit-check branch from de7ca6e to ad93fd3 Compare October 28, 2026 20:52
@krishhgg
krishhgg force-pushed the feat/rocket-agent-turn-contract branch from 791c40f to 4df0253 Compare October 28, 2026 20:52
…ed 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>
@dylan-savage
dylan-savage merged commit 45b6098 into feat/rocket-agent-commit-check Oct 29, 2026
4 checks passed
@dylan-savage
dylan-savage deleted the feat/rocket-agent-turn-contract branch October 29, 2026 00:03
dylan-savage pushed a commit that referenced this pull request Oct 29, 2026
…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>
dylan-savage pushed a commit that referenced this pull request Oct 29, 2026
…, and stop the tool clock while the user answers (#2883)

* feat(agent): ask before the agent changes a file with unsaved changes, 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.

* test(agent): count a tab behind only by a failed write as the known limit, 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.

* fix(agent): show the unsaved-changes question below 1024 px, where the 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.

* fix(agent): check a staged file against the copy the page read, so Commit 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>

---------

Co-authored-by: Krish Garg <kg@g14-node1.tailb99b1b.ts.net>
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