Skip to content

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

Recheck page feedback after the hand-off verdict

Claude24d5acc7e638
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index c406807fa..b3f8890b0 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -55358,6 +55358,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
continue;
}
const escalation = handoff.accepted;
+ // The check above awaited a model decision. Input or a main-frame
+ // navigation that arrived meanwhile is queued, and a hand-off that did
+ // not see it is not accepted; page churn alone does not count.
+ if (escalation && this._pageFeedbackSupersedesHandoff?.(tabId)) {
+ onUpdate('text', { content: '', replace: true });
+ continue;
+ }
if (escalation) {
// The caller restarts this turn in the requested mode, from the
// state the turn started with, so the request is recorded once.
diff --git a/src/chrome/src/agent/page-feedback.js b/src/chrome/src/agent/page-feedback.js
index 34acda548..fa82bde0f 100644
--- a/src/chrome/src/agent/page-feedback.js
+++ b/src/chrome/src/agent/page-feedback.js
@@ -915,6 +915,13 @@ export const pageFeedbackMethods = {
return observation ? `${prompt}\n\n${observation}` : prompt;
},
+ // Whether feedback queued since a hand-off's model check began is one the
+ // person caused or a navigation, not page churn the hand-off ignores.
+ _pageFeedbackSupersedesHandoff(tabId) {
+ const events = [...(this._pageFeedbackRuns?.get(tabId)?.events?.values() || [])];
+ return events.length > 0 && !isAutomaticPageFeedback(events);
+ },
+
_hasPendingPageFeedback(tabId) {
return !!this._pageFeedbackRuns?.get(tabId)?.events.size;
},
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 88e9fa925..1fad8f5e7 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -46766,6 +46766,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
continue;
}
const escalation = handoff.accepted;
+ // The check above awaited a model decision. Input or a main-frame
+ // navigation that arrived meanwhile is queued, and a hand-off that did
+ // not see it is not accepted; page churn alone does not count.
+ if (escalation && this._pageFeedbackSupersedesHandoff?.(tabId)) {
+ onUpdate('text', { content: '', replace: true });
+ continue;
+ }
if (escalation) {
// The caller restarts this turn in the requested mode, from the
// state the turn started with, so the request is recorded once.
diff --git a/src/firefox/src/agent/page-feedback.js b/src/firefox/src/agent/page-feedback.js
index 34acda548..fa82bde0f 100644
--- a/src/firefox/src/agent/page-feedback.js
+++ b/src/firefox/src/agent/page-feedback.js
@@ -915,6 +915,13 @@ export const pageFeedbackMethods = {
return observation ? `${prompt}\n\n${observation}` : prompt;
},
+ // Whether feedback queued since a hand-off's model check began is one the
+ // person caused or a navigation, not page churn the hand-off ignores.
+ _pageFeedbackSupersedesHandoff(tabId) {
+ const events = [...(this._pageFeedbackRuns?.get(tabId)?.events?.values() || [])];
+ return events.length > 0 && !isAutomaticPageFeedback(events);
+ },
+
_hasPendingPageFeedback(tabId) {
return !!this._pageFeedbackRuns?.get(tabId)?.events.size;
},
diff --git a/test/auto-mode.mjs b/test/auto-mode.mjs
index a37ac5c11..16dd85b08 100644
--- a/test/auto-mode.mjs
+++ b/test/auto-mode.mjs
@@ -357,6 +357,21 @@ for (const build of BUILDS) {
assert.deepEqual(f.agent.takeModeEscalation(f.tab), { mode: 'act', evidence: request });
});
+ test(`${build}: input that arrives while the hand-off is being confirmed makes the model decide again`, async () => {
+ const request = 'Post on Mastodon: WebBrain QA test, please ignore';
+ let typed = false, emit = null;
+ const f = fixture(Agent, { decide: (question, options) => {
+ // The person types while routing confirms the first hand-off.
+ if (!typed && options.mainModel !== false) { typed = true; emit({ kind: 'input', source: 'user', target: 'textarea#compose' }); }
+ return decidesAct(question, options);
+ } });
+ emit = watchedPage(f);
+ fixtureReplies(f, [handoff('act', request), handoff('act', request)]);
+ assert.equal(await f.run(request), '');
+ assert.equal(f.calls.length, 2, 'the stale hand-off was not accepted');
+ assert.deepEqual(f.agent.takeModeEscalation(f.tab), { mode: 'act', evidence: request });
+ });
+
test(`${build}: a hand-off quoting anything but the user's words is refused`, async () => {
const f = fixture(Agent, {
replies: [