Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Do not trust an action route a correction sent during it did not read

Claude2e4cd712708f
diff --git a/docs/architecture.md b/docs/architecture.md
index 2a2514a30..2adf0b816 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -75,7 +75,7 @@ Model tiering is separate from mode: `compact | mid | full` controls how many no
1. Run state decides alone when it can: a continuation keeps its run's mode; a turn for an in-browser (WebGPU) model, which runs as a tiny Ask, a selected-text scope, the standalone window, a Cloud run and a message that carries an `<untrusted_page_content>` block (a selection shortcut with page context) stay in Ask; and a video attachment, which can only be uploaded, needs Act. Context-menu and selection prompts are sent as Ask, as in Manual.
2. Otherwise the decision model answers the fixed-choice `run_mode` question (`semantic-decisions.js`) about the user's own words, the previous turn's mode and the earlier task. It never sees page text, title or address. The question starts as soon as the turn's cost state exists and is awaited after `_enrichUserMessageWithCurrentPage`, so it overlaps page capture; after capture the turn waits at most `AUTO_MODE_ROUTE_GRACE_MS` (250 ms). Only a sure `act` or `dev` answer (the choices are `authorizing`) selects an action mode; Compact maps Dev to Act. The routed mode replaces the provisional Ask setup: run mode, system prompt, the turn's trusted runtime line and dialog handling (Chrome) or the BiDi run (Firefox).
-3. Without a sure answer, or with no decision model, the turn starts in Ask at once. Its tools add `request_action_mode`, and its system prompt adds `AUTO_MODE_ASK_NOTE`. The tool is never dispatched. The loop accepts the call only when its `evidence` quotes the user's own words exactly (the request, or a correction sent during the turn) and, because the calling model has read the page, when the same `run_mode` question, about the request with its corrections and asked again without any page content (decision model, then the active model with a quoted reason; a sure routing answer is reused from the semantic-decision cache) also answers act or dev. A correction sent while that check runs supersedes the call like any pending correction: the next step applies it and the model asks again, so a correction that needs Dev gets a Dev hand-off. Corrections sent during the read-only pass, applied or still pending, go with the hand-off: they stay journaled under the same request, and the action run queues them before its first model or tool boundary, so it never acts on the uncorrected request. A correction that arrives after the check (while the hand-off is saved) marks the escalation `reroute`: the background then restarts the request in Automatic again, and that route reads the request with its carried corrections; the last of at most three restarts runs in the mode it asked for. An accepted hand-off restores the conversation and per-tab turn state captured before the turn gathered its context (approved plans, site-adapter and API notes, the follow-up allowance, the durable-turn marker) and returns; the background's `chat` handler then restarts the same request with `modeEscalation` in the requested mode, under the same request ID, so Stop still cancels it. The action run's planner gate reads the request again before any action. A refused call gets a tool result with the reason, and a second refusal withdraws the tool. Chrome drains Dev diagnostics only when a routed turn after Dev ends without handing itself to Dev.
+3. Without a sure answer, or with no decision model, the turn starts in Ask at once. So does a turn whose user sent a correction while the route ran (`route_corrected`): the route did not read it, so an action answer is not trusted. Its tools add `request_action_mode`, and its system prompt adds `AUTO_MODE_ASK_NOTE`. The tool is never dispatched. The loop accepts the call only when its `evidence` quotes the user's own words exactly (the request, or a correction sent during the turn) and, because the calling model has read the page, when the same `run_mode` question, about the request with its corrections and asked again without any page content (decision model, then the active model with a quoted reason; a sure routing answer is reused from the semantic-decision cache) also answers act or dev. A correction sent while that check runs supersedes the call like any pending correction: the next step applies it and the model asks again, so a correction that needs Dev gets a Dev hand-off. Corrections sent during the read-only pass, applied or still pending, go with the hand-off: they stay journaled under the same request, and the action run queues them before its first model or tool boundary, so it never acts on the uncorrected request. A correction that arrives after the check (while the hand-off is saved) marks the escalation `reroute`: the background then restarts the request in Automatic again, and that route reads the request with its carried corrections; the last of at most three restarts runs in the mode it asked for. An accepted hand-off restores the conversation and per-tab turn state captured before the turn gathered its context (approved plans, site-adapter and API notes, the follow-up allowance, the durable-turn marker) and returns; the background's `chat` handler then restarts the same request with `modeEscalation` in the requested mode, under the same request ID, so Stop still cancels it. The action run's planner gate reads the request again before any action. A refused call gets a tool result with the reason, and a second refusal withdraws the tool. Chrome drains Dev diagnostics only when a routed turn after Dev ends without handing itself to Dev.
The agent reports the routed mode with a `run_mode` update (`{ mode, source }`), which the run journal stores as the snapshot's mode and the panel stores on the assistant message for Retry, Continue and recovery. Traces record a `mode_route` note with the source, the decision latency and the time the turn waited. In Automatic, slash commands and the Ctrl+Shift+A/X/D shortcuts choose a mode for one message only; the shortcuts write the slash command in front of the draft.
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 728998f73..d87ceb168 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -27073,7 +27073,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// run mode, system prompt, the turn's runtime line and dialog handling.
async _settleAutoModeRun(tabId, route, enriched, onUpdate, runOptions = {}) {
const waitStartedAt = Date.now();
- const routed = await settleAutoModeRoute(route);
+ let routed = await settleAutoModeRoute(route);
+ // The route read the request and the corrections it was given. One the
+ // user sent while it ran is not covered, so an action route is not
+ // trusted: the turn starts read-only, applies the correction and can
+ // still hand itself off through request_action_mode.
+ const covered = new Set(runOptions?.autoModeRouting?.correctionIds || []);
+ if (routed.mode !== 'ask'
+ && (this._steeringRuns.get(tabId)?.messages || []).some(item => !covered.has(String(item.id)))) {
+ routed = { mode: 'ask', choice: null, source: 'route_corrected', latencyMs: routed.latencyMs };
+ }
const previousMode = runOptions?.autoModeRouting?.previousMode || null;
const mode = routed.mode;
this._autoModeRoutePendingTabs.delete(tabId);
@@ -53858,7 +53867,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
({ mode, runOptions } = this._beginAutoModeRun(tabId, userMessage, attachments, runOptions, onUpdate));
const carried = reroute ? this._takeModeEscalationSteering(tabId) : [];
if (carried.length && runOptions?.autoModeRouting) {
- runOptions = { ...runOptions, autoModeRouting: { ...runOptions.autoModeRouting, corrections: carried.map(item => item.text) } };
+ runOptions = { ...runOptions, autoModeRouting: { ...runOptions.autoModeRouting,
+ corrections: carried.map(item => item.text), correctionIds: carried.map(item => item.id) } };
}
} else if (runOptions?.modeEscalation && isRunMode(mode)) {
runOptions = { ...runOptions, modeRoute: { requested: AUTO_MODE, mode, source: 'escalation' } };
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 0eaada322..e68b8058d 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -24118,7 +24118,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// run mode, system prompt, the turn's runtime line and the BiDi run.
async _settleAutoModeRun(tabId, route, enriched, onUpdate, runOptions = {}) {
const waitStartedAt = Date.now();
- const routed = await settleAutoModeRoute(route);
+ let routed = await settleAutoModeRoute(route);
+ // The route read the request and the corrections it was given. One the
+ // user sent while it ran is not covered, so an action route is not
+ // trusted: the turn starts read-only, applies the correction and can
+ // still hand itself off through request_action_mode.
+ const covered = new Set(runOptions?.autoModeRouting?.correctionIds || []);
+ if (routed.mode !== 'ask'
+ && (this._steeringRuns.get(tabId)?.messages || []).some(item => !covered.has(String(item.id)))) {
+ routed = { mode: 'ask', choice: null, source: 'route_corrected', latencyMs: routed.latencyMs };
+ }
const mode = routed.mode;
this._autoModeRoutePendingTabs.delete(tabId);
if (mode !== 'ask') {
@@ -45434,7 +45443,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
({ mode, runOptions } = this._beginAutoModeRun(tabId, userMessage, attachments, runOptions, onUpdate));
const carried = reroute ? this._takeModeEscalationSteering(tabId) : [];
if (carried.length && runOptions?.autoModeRouting) {
- runOptions = { ...runOptions, autoModeRouting: { ...runOptions.autoModeRouting, corrections: carried.map(item => item.text) } };
+ runOptions = { ...runOptions, autoModeRouting: { ...runOptions.autoModeRouting,
+ corrections: carried.map(item => item.text), correctionIds: carried.map(item => item.id) } };
}
} else if (runOptions?.modeEscalation && isRunMode(mode)) {
runOptions = { ...runOptions, modeRoute: { requested: AUTO_MODE, mode, source: 'escalation' } };
diff --git a/test/auto-mode.mjs b/test/auto-mode.mjs
index 5f3ba2123..6fd500f7f 100644
--- a/test/auto-mode.mjs
+++ b/test/auto-mode.mjs
@@ -458,6 +458,27 @@ for (const build of BUILDS) {
assert.equal(f.agent._modeEscalationSteering.has(f.tab), false);
});
+ test(`${build}: a correction sent while the route runs keeps the turn read-only until the model reads it`, async () => {
+ const f = fixture(Agent, {
+ decide: (_q, options) => {
+ if (options.mainModel === false) {
+ // A sure Act route, but the user corrects the request meanwhile.
+ f.agent._steeringRuns.get(f.tab).messages.push({ id: 's10', text: 'first inspect the console errors' });
+ return { choice: 'act', source: 'decision_model' };
+ }
+ return { choice: 'dev', source: 'main_model' };
+ },
+ replies: [messages => {
+ assert.ok(messages.some(message => message.role === 'user' && String(message.content).startsWith('first inspect the console errors')));
+ return handoff('dev', 'first inspect the console errors');
+ }],
+ });
+ assert.equal(await f.run('Fix the login button.'), '');
+ assert.deepEqual(runModes(f.updates), [{ mode: 'ask', source: 'route_corrected' }]);
+ assert.ok(f.calls[0].tools.includes('request_action_mode'), 'the turn can still hand itself off');
+ assert.deepEqual(f.agent.takeModeEscalation(f.tab), { mode: 'dev', evidence: 'first inspect the console errors' });
+ });
+
test(`${build}: corrections checked with the hand-off do not route the restart again`, async () => {
const f = fixture(Agent, {
decide: (_q, options) => (options.mainModel === false ? { choice: null, source: 'unavailable' } : { choice: 'act', source: 'main_model' }),