Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Fix completion retries during passive page updates
Emre Sokullu0d9771937f33
diff --git a/docs/page-feedback-monitor.md b/docs/page-feedback-monitor.mdindex dbc9af13e..d3b389bbf 100644--- a/docs/page-feedback-monitor.md+++ b/docs/page-feedback-monitor.md@@ -83,6 +83,11 @@ Steer or grant authorization. Enter and Alt+Enter retain their existing behavior- Runtime observations use nonce-delimited `page_feedback` untrusted data. Theydo not enter the trusted text-steering authorization path. Screenshots followthe current capture, vision-routing and budget policies.+- Passive main-frame DOM updates on the same URL preserve a single explicit+ `done` success candidate after refreshing the page observation. The completion+ verifier still checks fresh evidence; the summary does not establish success.+ User activity, navigation, unknown sources and mixed action batches still+ require a new model decision.## Workflow and notificationsdiff --git a/src/chrome/src/agent/page-feedback.js b/src/chrome/src/agent/page-feedback.jsindex 40f86a045..78b99a4c8 100644--- a/src/chrome/src/agent/page-feedback.js+++ b/src/chrome/src/agent/page-feedback.js@@ -46,6 +46,12 @@ function canKeepPageResponse(previous, current, events, toolCalls) {const name = call.function?.name;// These tools will observe the refreshed page when actually dispatched.if (['get_accessibility_tree', 'get_interactive_elements', 'read_page', 'inspect_viewport'].includes(name)) return true;+ // Success is only a candidate: done captures and verifies fresh evidence.+ // Let that verifier assess passive page churn instead of retrying the model.+ // Other outcomes skip verification, and mixed batches may still act on stale targets.+ if (name === 'done' && toolCalls.length === 1 && current.success !== false) {+ try { return JSON.parse(call.function.arguments)?.outcome === 'success'; } catch { return false; }+ }if (name !== 'click_ax') return false;let args;try { args = JSON.parse(call.function.arguments); } catch { return false; }@@ -508,9 +514,9 @@ export const pageFeedbackMethods = {}}this._persist(tabId);- // Refresh observations without paying for the same navigation decision- // again on a live feed. The ordinary preparation/dispatch fences still- // run, and any user activity or target change supersedes the response.+ // Refresh observations without repeating reads, unchanged navigation or+ // a success candidate on a live feed. Completion still needs fresh proof;+ // ordinary preparation/dispatch fences and user feedback remain authoritative.if (run.latestPage && this._pageFeedbackRuns.get(tabId) === run && !this._hasPendingPageFeedback(tabId)&& canKeepPageResponse(previousPage, run.latestPage, events, responseToolCalls)) return false;return true;diff --git a/src/firefox/src/agent/page-feedback.js b/src/firefox/src/agent/page-feedback.jsindex 40f86a045..78b99a4c8 100644--- a/src/firefox/src/agent/page-feedback.js+++ b/src/firefox/src/agent/page-feedback.js@@ -46,6 +46,12 @@ function canKeepPageResponse(previous, current, events, toolCalls) {const name = call.function?.name;// These tools will observe the refreshed page when actually dispatched.if (['get_accessibility_tree', 'get_interactive_elements', 'read_page', 'inspect_viewport'].includes(name)) return true;+ // Success is only a candidate: done captures and verifies fresh evidence.+ // Let that verifier assess passive page churn instead of retrying the model.+ // Other outcomes skip verification, and mixed batches may still act on stale targets.+ if (name === 'done' && toolCalls.length === 1 && current.success !== false) {+ try { return JSON.parse(call.function.arguments)?.outcome === 'success'; } catch { return false; }+ }if (name !== 'click_ax') return false;let args;try { args = JSON.parse(call.function.arguments); } catch { return false; }@@ -508,9 +514,9 @@ export const pageFeedbackMethods = {}}this._persist(tabId);- // Refresh observations without paying for the same navigation decision- // again on a live feed. The ordinary preparation/dispatch fences still- // run, and any user activity or target change supersedes the response.+ // Refresh observations without repeating reads, unchanged navigation or+ // a success candidate on a live feed. Completion still needs fresh proof;+ // ordinary preparation/dispatch fences and user feedback remain authoritative.if (run.latestPage && this._pageFeedbackRuns.get(tabId) === run && !this._hasPendingPageFeedback(tabId)&& canKeepPageResponse(previousPage, run.latestPage, events, responseToolCalls)) return false;return true;diff --git a/test/chat-steering.mjs b/test/chat-steering.mjsindex 8ae0ed937..463d3ce9a 100644--- a/test/chat-steering.mjs+++ b/test/chat-steering.mjs@@ -163,7 +163,9 @@ for (const build of ['chrome', 'firefox']) {return call('click_ax', { ref_id: 'ref_5' });case 6: return call('type_ax', { ref_id: 'ref_8', text: 'WebBrain helps with browser tasks.' });case 7: return call('click_ax', { ref_id: 'ref_9' });- case 8: return call('done', { summary: 'Revised posting task completed', outcome: 'success' });+ case 8:+ news++; feedback();+ return call('done', { summary: 'Revised posting task completed', outcome: 'success' });default: assert.fail('A passive feed update caused another model retry');}};@@ -188,6 +190,7 @@ for (const build of ['chrome', 'firefox']) {if (name === 'navigate') feedback();if (args.ref_id === 'ref_3') { url = 'https://mastoturk.org/home'; feedback(); }if (args.ref_id === 'ref_5') url = 'https://mastoturk.org/publish';+ if (args.ref_id === 'ref_9') { url = 'https://mastoturk.org/public/local'; feedback(); }return { success: true, dispatched: true, verified: true };};const getTab = api.tabs.get;diff --git a/test/page-feedback.mjs b/test/page-feedback.mjsindex fb29a4175..5275ada21 100644--- a/test/page-feedback.mjs+++ b/test/page-feedback.mjs@@ -89,6 +89,78 @@ function allowBatchPreparation(agent) {for (const build of ['chrome', 'firefox']) {const { Agent } = await import(`../src/${build}/src/agent/agent.js`);const { beforePageAgentDispatch } = await import(`../src/${build}/src/agent/page-feedback.js`);+ const { verifyBrowserCompletion } = await import(`../src/${build}/src/agent/completion-runtime.js`);++ for (const outcome of ['succeeded', 'failed']) {+ test(`${build}: retained success candidate verifies fresh ${outcome} evidence`, async () => {+ const agent = setup(Agent, { chat: async () => assert.fail('Completion should use the bounded judge request') });+ const tab = nextTab++;+ let page = { success: true, pageContent: 'article "Old timeline" [ref_1]' }, requests = 0;+ agent.executeTool = async (_tab, name) => {+ assert.equal(name, 'get_accessibility_tree');+ return page;+ };+ agent._completionDocumentStamp = async () => 'same-document';+ agent._progressTaskKeyHash = () => 'publish-task';+ agent._progressTaskAnchorText = () => 'Publish a WebBrain post';+ agent._chatWithCostAllowance = async (_provider, messages, options) => {+ requests++;+ assert.equal(options.tools, undefined);+ assert.match(JSON.stringify(messages), /Fresh result/);+ assert.doesNotMatch(JSON.stringify(messages), /Old timeline/);+ return { content: JSON.stringify({ outcome, reason: 'Fresh result establishes the outcome.' }) };+ };+ await agent._claimRunEntry(tab, 'interactive');+ try {+ const binding = bind(agent, tab), messages = [{ role: 'system', content: '' }, { role: 'user', content: 'Publish a WebBrain post' }];+ agent.conversations.set(tab, messages);+ binding.send({ kind: 'dom', source: 'page', target: 'time' });+ await agent._applyPendingPageFeedback(tab, messages);+ page = { success: true, pageContent: `article "Fresh result: ${outcome}" [ref_1]` };+ binding.send({ kind: 'dom', source: 'page', target: 'time' });+ const args = { summary: 'Published successfully', outcome: 'success' };+ assert.equal(await agent._applyPendingPageFeedback(tab, messages, () => {}, {+ responseToolCalls: [{ function: { name: 'done', arguments: JSON.stringify(args) } }],+ }), false);+ const verdict = await verifyBrowserCompletion(agent, tab, { pageUrl: 'https://example.com/new', summary: args.summary });+ assert.equal(verdict.outcome, outcome, 'Retaining a success candidate must not override fresh negative evidence');+ assert.equal(verdict.engine, 'llm');+ assert.equal(requests, 1);+ } finally { agent._releaseRunEntry(tab); }+ });+ }++ for (const change of ['feed', 'user', 'unknown', 'iframe', 'navigation', 'viewport', 'style', 'failed_read',+ 'partial', 'missing_outcome', 'malformed', 'mixed', 'duplicate', 'pending']) {+ test(`${build}: success completion ${change === 'feed' ? 'survives' : 'rejects'} ${change} feedback`, async () => {+ const agent = setup(Agent), tab = nextTab++;+ let page = { success: true, pageContent: 'article "Published WebBrain post" [ref_1]' };+ agent.executeTool = async () => page;+ await agent._claimRunEntry(tab, 'interactive');+ try {+ const binding = bind(agent, tab), messages = [{ role: 'system', content: '' }, { role: 'user', content: 'Publish a WebBrain post' }];+ binding.send({ kind: 'dom', source: 'page', target: 'time' });+ await agent._applyPendingPageFeedback(tab, messages);+ page = { success: change !== 'failed_read', pageContent: 'article "Updated timeline" [ref_1]' };+ binding.send({ kind: change === 'viewport' ? 'resize' : 'dom',+ source: change === 'user' ? 'user' : change === 'unknown' ? 'unknown' : 'page',+ target: change === 'style' ? 'style' : 'time' });+ if (change === 'iframe') agent._queuePageFeedback(tab, { kind: 'dom', source: 'page', frameId: 1, target: 'time' });+ if (change === 'navigation') agent._queuePageFeedback(tab, { kind: 'navigation', source: 'page', frameId: 0 });+ if (change === 'pending') agent.executeTool = async () => {+ binding.send({ kind: 'input', source: 'user' });+ return page;+ };+ const args = { summary: 'Published', outcome: change === 'partial' ? 'partial' : 'success' };+ if (change === 'missing_outcome') delete args.outcome;+ const call = { function: { name: 'done', arguments: change === 'malformed' ? '{' : JSON.stringify(args) } };+ const calls = change === 'duplicate' ? [call, call] : change === 'mixed'+ ? [call, { function: { name: 'click_ax', arguments: '{"ref_id":"ref_1"}' } }] : [call];+ assert.equal(await agent._applyPendingPageFeedback(tab, messages, () => {}, { responseToolCalls: calls }), change !== 'feed');+ assert.equal(agent._activeTaskBinding(messages).text, 'Publish a WebBrain post');+ } finally { agent._releaseRunEntry(tab); }+ });+ }for (const change of ['feed', 'label', 'href', 'ancestor', 'user', 'unknown', 'iframe', 'base', 'truncated', 'missing', 'submit', 'coordinates']) {test(`${build}: response navigation ${change === 'feed' ? 'survives' : 'rejects'} ${change} feedback`, async () => {