Skip to content

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

Keep the one-click switch for the runtime's own Ask limitation

Claude06eb9a417a52
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index b6ef52324..bc7553757 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -27258,8 +27258,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// An automatically routed turn could hand itself to Act, and the user's
// next message is routed again ("yes" to an offer included), so it is
// not offered a one-click switch to a mode the user never picked.
+ // The runtime's own limitation text (a Gmail thread it could not expand)
+ // is not a conversational offer: the model cannot hand it off, and a retry
+ // in Act is the recovery, so a routed turn keeps the one-click switch for it.
+ const runtimeLimitation = typeof finalResponse === 'string' && finalResponse !== ''
+ && this._runtimeAskLimitations?.get(tabId) === finalResponse;
if (mode !== 'ask'
- || runOptions?.autoModeRouting
+ || (runOptions?.autoModeRouting && !runtimeLimitation)
|| runOptions?.cloudRun
|| this._isStandaloneChatRun(runOptions)
|| typeof finalResponse !== 'string'
@@ -55648,6 +55653,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const readFinalLimitation = this._readCompletenessLimitation(tabId);
if (readFinalLimitation && !this._guardAdvises('read-coverage-ask-limitation', { tabId, decided: false })) {
finalResponse = readFinalLimitation;
+ (this._runtimeAskLimitations ||= new Map()).set(tabId, readFinalLimitation);
_traceStatus = 'read_scope_limited';
messages.push({ role: 'assistant', content: finalResponse });
onUpdate('text', { content: finalResponse, replace: true });
@@ -57021,6 +57027,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
const readFinalLimitation = this._readCompletenessLimitation(tabId);
if (readFinalLimitation && !this._guardAdvises('read-coverage-ask-limitation', { tabId, decided: false })) {
+ (this._runtimeAskLimitations ||= new Map()).set(tabId, readFinalLimitation);
messages.push({ role: 'assistant', content: readFinalLimitation });
onUpdate('text', { content: readFinalLimitation, replace: true });
onUpdate('warning', { message: 'Ask mode could not verify that every Gmail message was expanded.' });
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 8d3ca4599..6e28c2bb6 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -24293,8 +24293,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// An automatically routed turn could hand itself to Act, and the user's
// next message is routed again ("yes" to an offer included), so it is
// not offered a one-click switch to a mode the user never picked.
+ // The runtime's own limitation text (a Gmail thread it could not expand)
+ // is not a conversational offer: the model cannot hand it off, and a retry
+ // in Act is the recovery, so a routed turn keeps the one-click switch for it.
+ const runtimeLimitation = typeof finalResponse === 'string' && finalResponse !== ''
+ && this._runtimeAskLimitations?.get(tabId) === finalResponse;
if (mode !== 'ask'
- || runOptions?.autoModeRouting
+ || (runOptions?.autoModeRouting && !runtimeLimitation)
|| runOptions?.cloudRun
|| this._isStandaloneChatRun(runOptions)
|| typeof finalResponse !== 'string'
@@ -47048,6 +47053,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const readFinalLimitation = this._readCompletenessLimitation(tabId);
if (readFinalLimitation && !this._guardAdvises('read-coverage-ask-limitation', { tabId, decided: false })) {
finalResponse = readFinalLimitation;
+ (this._runtimeAskLimitations ||= new Map()).set(tabId, readFinalLimitation);
_traceStatus = 'read_scope_limited';
messages.push({ role: 'assistant', content: finalResponse });
onUpdate('text', { content: finalResponse, replace: true });
@@ -48260,6 +48266,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
const readFinalLimitation = this._readCompletenessLimitation(tabId);
if (readFinalLimitation && !this._guardAdvises('read-coverage-ask-limitation', { tabId, decided: false })) {
+ (this._runtimeAskLimitations ||= new Map()).set(tabId, readFinalLimitation);
messages.push({ role: 'assistant', content: readFinalLimitation });
onUpdate('text', { content: readFinalLimitation, replace: true });
onUpdate('warning', { message: 'Ask mode could not verify that every Gmail message was expanded.' });
diff --git a/test/auto-mode.mjs b/test/auto-mode.mjs
index ef49b0cf4..e88e57ffe 100644
--- a/test/auto-mode.mjs
+++ b/test/auto-mode.mjs
@@ -725,6 +725,23 @@ for (const build of BUILDS) {
assert.deepEqual(chosen.updates.filter(update => update.type === 'ask_mode_handoff').map(update => update.data), [{ value: 'act' }]);
});
+ test(`${build}: a routed turn keeps the one-click switch for the runtime's own Ask limitation`, async () => {
+ // The runtime replaces the model's reply with a fixed "switch to Act" text
+ // (a Gmail thread it could not expand); the model cannot hand that off.
+ const limitation = 'I could not expand every message in this thread in Ask mode. Switch to Act mode to expand them.';
+ const settle = () => new Promise(resolve => setImmediate(resolve));
+ const f = fixture(Agent, { replies: [done('Unused.')] });
+ delete f.agent._maybeEmitAskModeHandoff;
+ f.agent._jevClassify = async () => 'act';
+ f.agent._runtimeAskLimitations = new Map([[f.tab, limitation]]);
+ const routed = { autoModeRouting: { previousMode: null } };
+ await f.agent._maybeEmitAskModeHandoff(f.tab, 'ask', 'Summarize this thread', limitation, f.onUpdate || ((type, data) => f.updates.push({ type, data })), routed);
+ await f.agent._maybeEmitAskModeHandoff(f.tab, 'ask', 'Summarize this thread', 'Would you like me to open it for you?', (type, data) => f.updates.push({ type, data }), routed);
+ await settle();
+ assert.deepEqual(f.updates.filter(update => update.type === 'ask_mode_handoff').map(update => update.data), [{ value: 'act' }],
+ 'only the runtime limitation is offered the switch');
+ });
+
test(`${build}: a slow decision model leaves the turn read-only after the grace period`, async () => {
// The decision never answers; the turn goes on without it.
const f = fixture(Agent, { decide: () => new Promise(() => {}), replies: [done('Read-only answer.')] });