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 retest regressions: Gmail send gate, declined-card recovery, stale tests
Barack Sokulluacf019e939ce
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex be1b8a2d6..18660a632 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -73,7 +73,7 @@ import {shouldInvalidateFormInventoryAfterAction,workflowRequiredRowsAreProcessed,} from './adapter-workflow-evidence.js';-import { messageTargetMatchesObservedIdentities, messageRecipientUploadSourceKey, normalizeMessageTarget, normalizeRecipientIdentity } from './message-recipient-guard.js';+import { messageTargetMatchesObservedIdentities, messageRecipientUploadSourceKey, normalizeMessageTarget, normalizeRecipientAnswer, normalizeRecipientIdentity } from './message-recipient-guard.js';import { advanceChatSession, chatRunEndedNotice, createOwnedNativeChatReadRepair, createChatSession, decideChatSend, markChatSendPending, normalizeChatSession, normalizeChatSnapshot, normalizeNativeOpaqueBaseline, serializeChatSession } from './chat-workflow.js';import {fetchUrl,diff --git a/src/chrome/src/agent/incomplete-completion.js b/src/chrome/src/agent/incomplete-completion.jsindex 1b1b6fd78..f8877fbe9 100644--- a/src/chrome/src/agent/incomplete-completion.js+++ b/src/chrome/src/agent/incomplete-completion.js@@ -34,7 +34,8 @@ function recordedResults(agent, tabId, run) {if (!result || typeof result !== 'object' || Array.isArray(result)) return { tool };const entry = { tool };for (const key of ['success', 'dispatched', 'noDispatch', 'denied', 'cancelled', 'outcomeUnknown',- 'verified', 'remoteStateVerified', 'stable']) if (typeof result[key] === 'boolean') entry[key] = result[key];+ 'verified', 'remoteStateVerified', 'stable', 'deletionDeclined', 'submitConfirmationRequired',+ 'permissionRequired']) if (typeof result[key] === 'boolean') entry[key] = result[key];for (const key of ['error', 'attachmentState', 'previousUrl', 'currentUrl']) {if (typeof result[key] === 'string') entry[key] = text(result[key]);}@@ -42,6 +43,11 @@ function recordedResults(agent, tabId, run) {}).filter(Boolean);}+function userDeclined(entry) {+ return entry.deletionDeclined === true+ || (entry.denied === true && (entry.submitConfirmationRequired === true || entry.permissionRequired === true));+}+export async function incompleteCompletionBlock(agent, tabId, { outcome, summary, pageState, pageUrl = '', terminalOnly = false }) {const guard = agent._planExecutionGuards.get(tabId);const run = agent.completionInvariants.get(tabId);@@ -69,6 +75,11 @@ export async function incompleteCompletionBlock(agent, tabId, { outcome, summarylet parentIdentity = identity;try { const composed = JSON.parse(identity); if (Array.isArray(composed)) parentIdentity = composed[0]; } catch {}if (pageState.documentIdentity && pageState.documentIdentity !== parentIdentity) return changed();+ const results = recordedResults(agent, tabId, run);+ // The user's own refusal on a WebBrain card (a deletion, a submit or a+ // permission) is the reason this run is incomplete. Reporting that is the+ // honest end; recovery must not push the model to try again.+ if (results.some(userDeclined)) return null;const request = agent._progressTaskAnchorText(tabId) || agent._latestTaskText(tabId) || '';const reading = await agent._semanticDecision(tabId, 'incomplete_task', { request, page: {candidate_summary_not_proof: text(summary),@@ -82,7 +93,7 @@ export async function incompleteCompletionBlock(agent, tabId, { outcome, summarylabel: text(control?.label), disabled: control?.disabled === true,busy: control?.busy === true, progress: text(control?.progress),})),- recorded_current_results: recordedResults(agent, tabId, run),+ recorded_current_results: results,recorded_task_progress: { successfulTools: Number(guard.successfulTaskToolCalls || 0),consequentialTools: Number(guard.successfulConsequentialToolCalls || 0),verifiedSubmission: guard.verifiedSubmissionEvidence === true },diff --git a/src/chrome/src/agent/message-recipient-guard.js b/src/chrome/src/agent/message-recipient-guard.jsindex 740612820..a388f6a24 100644--- a/src/chrome/src/agent/message-recipient-guard.js+++ b/src/chrome/src/agent/message-recipient-guard.js@@ -81,6 +81,22 @@ export function normalizeRecipientIdentity(value) {}}+// Free text (a user's task or answer) normalized the same way as identities,+// so an identity can be found inside it with indexOf.+export function normalizeRecipientAnswer(value) {+ const text = String(value ?? '')+ .replace(/[\u0000-\u001f\u007f]/g, ' ')+ .replace(/[\u200b-\u200d\ufeff]/g, '')+ .replace(/\s+/g, ' ')+ .trim();+ if (!text) return '';+ try {+ return text.normalize('NFKC').toLocaleLowerCase();+ } catch {+ return text.toLowerCase();+ }+}+export function recipientMatchesObservedIdentity(recipient, observedIdentity) {const expected = normalizeRecipientIdentity(recipient);const observed = normalizeRecipientIdentity(observedIdentity);diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 5b2d86d26..d07a237e1 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -71,7 +71,7 @@ import {shouldInvalidateFormInventoryAfterAction,workflowRequiredRowsAreProcessed,} from './adapter-workflow-evidence.js';-import { messageTargetMatchesObservedIdentities, messageRecipientUploadSourceKey, normalizeMessageTarget, normalizeRecipientIdentity } from './message-recipient-guard.js';+import { messageTargetMatchesObservedIdentities, messageRecipientUploadSourceKey, normalizeMessageTarget, normalizeRecipientAnswer, normalizeRecipientIdentity } from './message-recipient-guard.js';import { advanceChatSession, chatRunEndedNotice, createOwnedNativeChatReadRepair, createChatSession, decideChatSend, markChatSendPending, normalizeChatSession, normalizeChatSnapshot, normalizeNativeOpaqueBaseline, serializeChatSession } from './chat-workflow.js';import {fetchUrl,diff --git a/src/firefox/src/agent/incomplete-completion.js b/src/firefox/src/agent/incomplete-completion.jsindex 1b1b6fd78..f8877fbe9 100644--- a/src/firefox/src/agent/incomplete-completion.js+++ b/src/firefox/src/agent/incomplete-completion.js@@ -34,7 +34,8 @@ function recordedResults(agent, tabId, run) {if (!result || typeof result !== 'object' || Array.isArray(result)) return { tool };const entry = { tool };for (const key of ['success', 'dispatched', 'noDispatch', 'denied', 'cancelled', 'outcomeUnknown',- 'verified', 'remoteStateVerified', 'stable']) if (typeof result[key] === 'boolean') entry[key] = result[key];+ 'verified', 'remoteStateVerified', 'stable', 'deletionDeclined', 'submitConfirmationRequired',+ 'permissionRequired']) if (typeof result[key] === 'boolean') entry[key] = result[key];for (const key of ['error', 'attachmentState', 'previousUrl', 'currentUrl']) {if (typeof result[key] === 'string') entry[key] = text(result[key]);}@@ -42,6 +43,11 @@ function recordedResults(agent, tabId, run) {}).filter(Boolean);}+function userDeclined(entry) {+ return entry.deletionDeclined === true+ || (entry.denied === true && (entry.submitConfirmationRequired === true || entry.permissionRequired === true));+}+export async function incompleteCompletionBlock(agent, tabId, { outcome, summary, pageState, pageUrl = '', terminalOnly = false }) {const guard = agent._planExecutionGuards.get(tabId);const run = agent.completionInvariants.get(tabId);@@ -69,6 +75,11 @@ export async function incompleteCompletionBlock(agent, tabId, { outcome, summarylet parentIdentity = identity;try { const composed = JSON.parse(identity); if (Array.isArray(composed)) parentIdentity = composed[0]; } catch {}if (pageState.documentIdentity && pageState.documentIdentity !== parentIdentity) return changed();+ const results = recordedResults(agent, tabId, run);+ // The user's own refusal on a WebBrain card (a deletion, a submit or a+ // permission) is the reason this run is incomplete. Reporting that is the+ // honest end; recovery must not push the model to try again.+ if (results.some(userDeclined)) return null;const request = agent._progressTaskAnchorText(tabId) || agent._latestTaskText(tabId) || '';const reading = await agent._semanticDecision(tabId, 'incomplete_task', { request, page: {candidate_summary_not_proof: text(summary),@@ -82,7 +93,7 @@ export async function incompleteCompletionBlock(agent, tabId, { outcome, summarylabel: text(control?.label), disabled: control?.disabled === true,busy: control?.busy === true, progress: text(control?.progress),})),- recorded_current_results: recordedResults(agent, tabId, run),+ recorded_current_results: results,recorded_task_progress: { successfulTools: Number(guard.successfulTaskToolCalls || 0),consequentialTools: Number(guard.successfulConsequentialToolCalls || 0),verifiedSubmission: guard.verifiedSubmissionEvidence === true },diff --git a/src/firefox/src/agent/message-recipient-guard.js b/src/firefox/src/agent/message-recipient-guard.jsindex 740612820..a388f6a24 100644--- a/src/firefox/src/agent/message-recipient-guard.js+++ b/src/firefox/src/agent/message-recipient-guard.js@@ -81,6 +81,22 @@ export function normalizeRecipientIdentity(value) {}}+// Free text (a user's task or answer) normalized the same way as identities,+// so an identity can be found inside it with indexOf.+export function normalizeRecipientAnswer(value) {+ const text = String(value ?? '')+ .replace(/[\u0000-\u001f\u007f]/g, ' ')+ .replace(/[\u200b-\u200d\ufeff]/g, '')+ .replace(/\s+/g, ' ')+ .trim();+ if (!text) return '';+ try {+ return text.normalize('NFKC').toLocaleLowerCase();+ } catch {+ return text.toLowerCase();+ }+}+export function recipientMatchesObservedIdentity(recipient, observedIdentity) {const expected = normalizeRecipientIdentity(recipient);const observed = normalizeRecipientIdentity(observedIdentity);diff --git a/test/generative-media.mjs b/test/generative-media.mjsindex eebc14cb6..c3260310c 100644--- a/test/generative-media.mjs+++ b/test/generative-media.mjs@@ -15,13 +15,16 @@ for (const build of ['chrome', 'firefox']) {test(`${build}: generated assets survive the actual background broadcast and bounded replay`, async () => {const source = await readFile(`src/${build}/src/background.js`, 'utf8');const start = source.indexOf('function sendAgentUpdate(');- const sendSource = source.slice(start, source.indexOf('\nfunction ', start + 1));+ // End at the function's own closing brace; top-level declarations may follow it.+ const sendSource = source.slice(start, source.indexOf('\n}\n', start) + 2);const runJournal = new journal.RunUiJournal();runJournal.begin(11, 'media-run');const delivered = [];const api = { runtime: { sendMessage: async message => { delivered.push(message); } } };- const send = new Function('recordRunUiEvent', 'agent', 'chrome', 'browser', `return (${sendSource});`)(+ const send = new Function('recordRunUiEvent', 'agent', 'chrome', 'browser', 'notifyPlanReview',+ 'clearPlanReviewAttention', 'planReviewAttentionByTab', `return (${sendSource});`)((...args) => runJournal.record(...args), { currentRunId: new Map() }, api, api,+ () => {}, () => {}, new Map(),);const results = [{ success: true, provider: 'fal', model: 'fal-ai/flux/schnell', url: 'https://cdn.example/image.png' },diff --git a/test/quality/shared-action-guards-mv3.mjs b/test/quality/shared-action-guards-mv3.mjsindex 272ce92d6..e5464b1f4 100644--- a/test/quality/shared-action-guards-mv3.mjs+++ b/test/quality/shared-action-guards-mv3.mjs@@ -320,6 +320,13 @@ const server = http.createServer(async (request, response) => {// reports the outcome.current.summaryReadings = (current.summaryReadings || 0) + 1;completion = { role: 'assistant', content: JSON.stringify({ choice: 'result', evidence: '' }) };+ } else if (system.startsWith("Answer one fixed-choice question for a browser agent's safety check.")+ && /^- "continue_now":/m.test(system)) {+ // A partial or failed end is checked once for a remaining step. Its+ // request is the app-assembled task anchor, not the latest correction;+ // these cases end on a guard's refusal, so nothing should resume.+ current.incompleteReadings = (current.incompleteReadings || 0) + 1;+ completion = { role: 'assistant', content: JSON.stringify({ choice: 'stop_required', evidence: '' }) };} else if (system.startsWith("Answer one fixed-choice question for a browser agent's safety check.")) {// The model's reading of the latest request, in any language: whether it// asks to delete this exact item, or the earlier post first.diff --git a/test/quality/steering-worker-restart-mv3.mjs b/test/quality/steering-worker-restart-mv3.mjsindex 1df9255d9..faaa9640d 100644--- a/test/quality/steering-worker-restart-mv3.mjs+++ b/test/quality/steering-worker-restart-mv3.mjs@@ -47,7 +47,10 @@ const server = http.createServer(async (request, response) => {try {let raw = ''; for await (const chunk of request) raw += chunk;const input = JSON.parse(raw);- const users = input.messages.filter(message => message.role === 'user').map(message => text(message.content));+ // The latest user turn may carry the app-projected task authority after its+ // authored text; a correction is counted by the words the user wrote.+ const users = input.messages.filter(message => message.role === 'user')+ .map(message => text(message.content).split('\n\n[APP-OWNED CURRENT USER TASK')[0]);const evaluator = text(input.messages[0]?.content).startsWith('Evaluate only the observable requirements of the genuine user task');const action = Array.isArray(input.tools) && input.tools.length > 0;const record = { worker, stage: evaluator ? 'completion' : action ? 'action' : 'planner',diff --git a/test/run.js b/test/run.jsindex d3919999b..c7cc79f77 100644--- a/test/run.js+++ b/test/run.js@@ -112663,7 +112663,7 @@ test('content-script actions have a bounded unknown-outcome timeout', async () =assert.ok(fallbackScrollStart >= 0 && fallbackScrollEnd > fallbackScrollStart, `${label}: fallback scroll deadline boundary missing`);assert.match(fallbackScroll,- /if \(actionDeadlineExpired\(\)\) return deadlineFailure\(\);\s*window\.__wbPageMonitor\?\.beforeLocalDispatch\(\);\s*dispatched = true;\s*scrollElementInstant/,+ /if \(actionDeadlineExpired\(\)\) return deadlineFailure\(\);\s*window\.__wbPageMonitor\?\.beforeLocalDispatch\([^)]*\);\s*dispatched = true;\s*scrollElementInstant/,`${label}: fallback container scrolling can start after its deadline`,);assert.match(@@ -116323,8 +116323,12 @@ test('run UI journal: streamed deltas coalesce durable snapshots without delayinconst background = fs.readFileSync(path.join(ROOT, backgroundRel), 'utf8');assert.match(background, /change\?\.eventType === 'text_delta'[\s\S]*?runUiSnapshotPersistence\.defer\(tabId, snapshot\)/, `${label}: background should defer only text deltas`);assert.match(background, /runUiSnapshotPersistence\.flush\(tabId\) \|\| runUiPersistenceQueues\.get\(tabId\)/, `${label}: durability checkpoints should flush deferred deltas`);- assert.match(background, /function clearRunUiSnapshot\(tabId\) \{\s*(?:runUiSnapshotReads\.delete\(tabId\);\s*)?runUiSnapshotPersistence\.cancel\(tabId\)/, `${label}: clearing a run should synchronously cancel deferred persistence`);- assert.match(background, /function sendAgentUpdate\([\s\S]{0,700}?runtime\.sendMessage\(/, `${label}: live event broadcast should remain immediate`);+ assert.match(background, /function clearRunUiSnapshot\(tabId\) \{\s*(?:clearPlanReviewAttention\(tabId\);\s*)?(?:runUiSnapshotReads\.delete\(tabId\);\s*)?runUiSnapshotPersistence\.cancel\(tabId\)/, `${label}: clearing a run should synchronously cancel deferred persistence`);+ const sendStart = background.indexOf('function sendAgentUpdate(');+ const sendBody = background.slice(sendStart, background.indexOf('\n}\n', sendStart));+ const beforeBroadcast = sendBody.slice(0, sendBody.indexOf('runtime.sendMessage('));+ assert.ok(sendStart >= 0 && sendBody.includes('runtime.sendMessage('), `${label}: live event broadcast should remain immediate`);+ assert.doesNotMatch(beforeBroadcast, /\bawait\b|setTimeout|queueMicrotask|\.then\(|runUiSnapshotPersistence|runUiPersistenceQueues/, `${label}: live event broadcast should remain immediate`);}});