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
Don't ask again about a form submission the user just declined
Claudeb18b9558f61d
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 6f2a81642..a872d3386 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -6491,6 +6491,8 @@ export class Agent extends LoopDetector {this._ownedNativeChatReadRepairs.delete(tabId);// Only consume at model/tool boundaries, after all tool results are present.// Human corrections stay ordinary user messages; no page context is added.+ // A correction may change the user's mind about a declined submission.+ this.permissions?.clearDeclinedSubmissions?.(tabId);for (const item of run.messages.splice(0)) {const priorBinding = this._activeTaskBinding(messages);const parentTaskKey = this._progressTaskKeyForText(priorBinding.text);@@ -16622,6 +16624,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst canGroupSearch = submitRisk.risk === SubmitRisk.LOW_RISK_SEARCH&& ['click', 'click_ax', 'press_keys'].includes(fnName);let choice = null;+ let alreadyDeclined = false;if (canGroupSearch) {const intentKey = submitActionKey(submitConfirmation, submitConfirmation.url);choice = await this._authorizeGroupedSearch(@@ -16647,7 +16650,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dcapabilities = capabilities.filter(capability => capability !== Capability.CLICK);}} else {- choice = await this._promptSubmitConfirmation(tabId, submitConfirmation, onUpdate);+ // The user already said no to this exact submission (same form,+ // same values) in this turn: refuse it again without a new card.+ const declineKey = submitActionKey(submitConfirmation, submitConfirmation.url);+ if (this.permissions?.isSubmissionDeclined?.(declineKey, tabId) === true) {+ choice = 'deny';+ alreadyDeclined = true;+ } else {+ choice = await this._promptSubmitConfirmation(tabId, submitConfirmation, onUpdate);+ if (choice === 'deny') this.permissions?.declineSubmission?.(declineKey, tabId);+ }}if (this._hasPendingSteering(tabId) && !this._checkAbort(tabId)) return skipSteeredPermissionWait(toolIndex);if (choice === null) {@@ -16668,12 +16680,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dsuccess: false,denied: true,...(canGroupSearch ? { permissionRequired: true, groupedPermission: true } : { submitConfirmationRequired: true }),+ ...(alreadyDeclined ? { alreadyDeclined: true } : {}),error: canGroupSearch? `The user did not allow the grouped low-risk search actions on ${submitRisk.host || submitConfirmation.host || 'this site'}. Do NOT retry this unchanged search unless the user explicitly allows it.`- : `The user did not confirm submitting the form on ${submitConfirmation.host || 'this site'}. Do NOT retry this submit action unless the user explicitly confirms it.`,+ : alreadyDeclined+ ? `The user already declined this exact form submission on ${submitConfirmation.host || 'this site'} in this task, so WebBrain did not ask again and nothing was submitted. Do NOT retry it. If a value must change, ask the user what to change; otherwise report that the form was not submitted.`+ : `The user did not confirm submitting the form on ${submitConfirmation.host || 'this site'}. Do NOT retry this submit action unless the user explicitly confirms it.`,}),});- onUpdate('warning', { message: canGroupSearch ? 'Low-risk search blocked until the user allows the grouped actions.' : 'Form submission blocked until the user confirms.' });+ onUpdate('warning', { message: canGroupSearch ? 'Low-risk search blocked until the user allows the grouped actions.'+ : alreadyDeclined ? 'Not asked again: you declined this exact submission.' : 'Form submission blocked until the user confirms.' });predispatchBlocked('submitConfirmationMs');if (interruptFailedBrowserAction(toolIndex, fnName)) { navNotices.length = 0; break; }continue;@@ -21858,6 +21874,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// The time the user took to answer one of WebBrain's own cards does not// age the page observation the pending action was decided on.this._noteClarifyHeld(tabId, entry);+ // The user answering any card is the user speaking again: a submission+ // declined earlier in the turn may be asked about once more. A timeout's+ // or Instant's answer is WebBrain's, not the user's.+ if (source === 'user') this.permissions?.clearDeclinedSubmissions?.(tabId);this._settleClarification(entry, { answer, source });return true;}diff --git a/src/chrome/src/agent/permission-gate.js b/src/chrome/src/agent/permission-gate.jsindex e6b5895fe..2f831b155 100644--- a/src/chrome/src/agent/permission-gate.js+++ b/src/chrome/src/agent/permission-gate.js@@ -737,6 +737,7 @@ export class PermissionManager {this.permissions = [];this.intentGrants = [];this.intentCandidates = [];+ this.declinedSubmissions = [];this._hydrated = false;}@@ -781,6 +782,29 @@ export class PermissionManager {this.permissions = this.permissions.filter(p => p.duration === 'always' || p.tabId !== tabId);this.intentGrants = this.intentGrants.filter(grant => grant.tabId !== tabId);this.intentCandidates = this.intentCandidates.filter(candidate => candidate.tabId !== tabId);+ this.clearDeclinedSubmissions(tabId);+ }++ /**+ * A form submission the user declined on WebBrain's own submit card in+ * this turn. The key is submitActionKey(): the resolved form, its method+ * and the values that changed, hashed. WebBrain does not ask about the+ * same submission again in the turn; a changed value, a new turn, a+ * correction or the user's own answer on a later card asks again.+ */+ declineSubmission(key, tabId) {+ const normalizedKey = String(key || '');+ if (!normalizedKey || this.isSubmissionDeclined(normalizedKey, tabId)) return;+ this.declinedSubmissions.push({ key: normalizedKey, tabId, ts: Date.now() });+ }++ isSubmissionDeclined(key, tabId) {+ const normalizedKey = String(key || '');+ return !!normalizedKey && this.declinedSubmissions.some(item => item.key === normalizedKey && item.tabId === tabId);+ }++ clearDeclinedSubmissions(tabId) {+ this.declinedSubmissions = this.declinedSubmissions.filter(item => item.tabId !== tabId);}/**diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 71cbfa5be..4d892365e 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -6033,6 +6033,8 @@ export class Agent extends LoopDetector {this._ownedNativeChatReadRepairs.delete(tabId);// Only consume at model/tool boundaries, after all tool results are present.// Human corrections stay ordinary user messages; no page context is added.+ // A correction may change the user's mind about a declined submission.+ this.permissions?.clearDeclinedSubmissions?.(tabId);for (const item of run.messages.splice(0)) {const priorBinding = this._activeTaskBinding(messages);const parentTaskKey = this._progressTaskKeyForText(priorBinding.text);@@ -14798,6 +14800,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst canGroupSearch = submitRisk.risk === SubmitRisk.LOW_RISK_SEARCH&& ['click', 'click_ax', 'press_keys'].includes(fnName);let choice = null;+ let alreadyDeclined = false;if (canGroupSearch) {const intentKey = submitActionKey(submitConfirmation, submitConfirmation.url);choice = await this._authorizeGroupedSearch(@@ -14823,7 +14826,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dcapabilities = capabilities.filter(capability => capability !== Capability.CLICK);}} else {- choice = await this._promptSubmitConfirmation(tabId, submitConfirmation, onUpdate);+ // The user already said no to this exact submission (same form,+ // same values) in this turn: refuse it again without a new card.+ const declineKey = submitActionKey(submitConfirmation, submitConfirmation.url);+ if (this.permissions?.isSubmissionDeclined?.(declineKey, tabId) === true) {+ choice = 'deny';+ alreadyDeclined = true;+ } else {+ choice = await this._promptSubmitConfirmation(tabId, submitConfirmation, onUpdate);+ if (choice === 'deny') this.permissions?.declineSubmission?.(declineKey, tabId);+ }}if (this._hasPendingSteering(tabId) && !this._checkAbort(tabId)) return skipSteeredPermissionWait(toolIndex);if (choice === null) {@@ -14844,12 +14856,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dsuccess: false,denied: true,...(canGroupSearch ? { permissionRequired: true, groupedPermission: true } : { submitConfirmationRequired: true }),+ ...(alreadyDeclined ? { alreadyDeclined: true } : {}),error: canGroupSearch? `The user did not allow the grouped low-risk search actions on ${submitRisk.host || submitConfirmation.host || 'this site'}. Do NOT retry this unchanged search unless the user explicitly allows it.`- : `The user did not confirm submitting the form on ${submitConfirmation.host || 'this site'}. Do NOT retry this submit action unless the user explicitly confirms it.`,+ : alreadyDeclined+ ? `The user already declined this exact form submission on ${submitConfirmation.host || 'this site'} in this task, so WebBrain did not ask again and nothing was submitted. Do NOT retry it. If a value must change, ask the user what to change; otherwise report that the form was not submitted.`+ : `The user did not confirm submitting the form on ${submitConfirmation.host || 'this site'}. Do NOT retry this submit action unless the user explicitly confirms it.`,}),});- onUpdate('warning', { message: canGroupSearch ? 'Low-risk search blocked until the user allows the grouped actions.' : 'Form submission blocked until the user confirms.' });+ onUpdate('warning', { message: canGroupSearch ? 'Low-risk search blocked until the user allows the grouped actions.'+ : alreadyDeclined ? 'Not asked again: you declined this exact submission.' : 'Form submission blocked until the user confirms.' });predispatchBlocked('submitConfirmationMs');if (interruptFailedBrowserAction(toolIndex, fnName)) { navNotices.length = 0; break; }continue;@@ -18899,6 +18915,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// The time the user took to answer one of WebBrain's own cards does not// age the page observation the pending action was decided on.this._noteClarifyHeld(tabId, entry);+ // The user answering any card is the user speaking again: a submission+ // declined earlier in the turn may be asked about once more. A timeout's+ // or Instant's answer is WebBrain's, not the user's.+ if (source === 'user') this.permissions?.clearDeclinedSubmissions?.(tabId);this._settleClarification(entry, { answer, source });return true;}diff --git a/src/firefox/src/agent/permission-gate.js b/src/firefox/src/agent/permission-gate.jsindex c51283ac4..182fb7b41 100644--- a/src/firefox/src/agent/permission-gate.js+++ b/src/firefox/src/agent/permission-gate.js@@ -722,6 +722,7 @@ export class PermissionManager {this.permissions = [];this.intentGrants = [];this.intentCandidates = [];+ this.declinedSubmissions = [];this._hydrated = false;}@@ -766,6 +767,29 @@ export class PermissionManager {this.permissions = this.permissions.filter(p => p.duration === 'always' || p.tabId !== tabId);this.intentGrants = this.intentGrants.filter(grant => grant.tabId !== tabId);this.intentCandidates = this.intentCandidates.filter(candidate => candidate.tabId !== tabId);+ this.clearDeclinedSubmissions(tabId);+ }++ /**+ * A form submission the user declined on WebBrain's own submit card in+ * this turn. The key is submitActionKey(): the resolved form, its method+ * and the values that changed, hashed. WebBrain does not ask about the+ * same submission again in the turn; a changed value, a new turn, a+ * correction or the user's own answer on a later card asks again.+ */+ declineSubmission(key, tabId) {+ const normalizedKey = String(key || '');+ if (!normalizedKey || this.isSubmissionDeclined(normalizedKey, tabId)) return;+ this.declinedSubmissions.push({ key: normalizedKey, tabId, ts: Date.now() });+ }++ isSubmissionDeclined(key, tabId) {+ const normalizedKey = String(key || '');+ return !!normalizedKey && this.declinedSubmissions.some(item => item.key === normalizedKey && item.tabId === tabId);+ }++ clearDeclinedSubmissions(tabId) {+ this.declinedSubmissions = this.declinedSubmissions.filter(item => item.tabId !== tabId);}/**diff --git a/test/run.js b/test/run.jsindex 64e262790..ecd6f8d7a 100644--- a/test/run.js+++ b/test/run.js@@ -82577,6 +82577,92 @@ test('agent requires fresh submit confirmation across modes and prompt sources',}});+test('a declined submission is not asked again in the same turn', async () => {+ for (const AgentClass of [AgentCh, AgentFx]) {+ const agent = new AgentClass({ getVisionProvider: async () => null });+ const tabId = 5107;+ let prompts = 0;+ let executed = 0;+ let email = '[email protected]';+ const updates = [];++ agent.conversationModes.set(tabId, 'act');+ agent._ensureGateSetting = async () => { };+ agent._skipPermissionGate = false;+ agent._currentUrl = async () => 'https://host.com/newsletter';+ agent._recordProgressObservation = async () => null;+ agent._autoRecordProgressAction = () => null;+ agent._progressWarningForAction = () => '';+ agent._persist = () => { };+ agent._detectLikelySubmitAction = async (_tabId, name) => ({+ isSubmit: true,+ host: 'host.com',+ tool: name,+ method: 'GET',+ actionUrl: 'https://host.com/newsletter',+ reason: 'submit button/control activation',+ summary: `Changed/filled fields: Email: ${email}.`,+ changedFields: [{ label: 'Email', value: email, changed: true }],+ });+ agent._promptSubmitConfirmation = async () => {+ prompts += 1;+ return 'deny';+ };+ agent.executeTool = async () => {+ executed += 1;+ return { success: true };+ };+ const submit = async (id) => {+ const messages = [];+ await agent._executeToolBatch(+ tabId,+ [{ id, function: { name: 'click_ax', arguments: JSON.stringify({ ref_id: 'ref_subscribe' }) } }],+ messages,+ (type, data) => updates.push({ type, data }),+ { supportsVision: false },+ '',+ new Set(['click_ax']),+ 1,+ );+ return JSON.parse(messages[0].content);+ };++ const first = await submit('first');+ assert.equal(prompts, 1, `${AgentClass.name}: the first submission asks`);+ assert.equal(first.denied, true, `${AgentClass.name}: the first denial is reported`);+ assert.equal(first.alreadyDeclined, undefined, `${AgentClass.name}: the first denial is the user's answer`);++ const repeat = await submit('repeat');+ assert.equal(prompts, 1, `${AgentClass.name}: the same submission is not asked again`);+ assert.equal(repeat.denied, true, `${AgentClass.name}: the repeat is refused`);+ assert.equal(repeat.alreadyDeclined, true, `${AgentClass.name}: the repeat says the user already declined`);+ assert.match(repeat.error, /already declined this exact form submission/, `${AgentClass.name}: the model is told not to retry`);+ assert.ok(updates.some(update => /Not asked again/.test(update.data?.message || '')), `${AgentClass.name}: the user sees why nothing was asked`);++ const timeoutEntry = { resolve: () => { }, ts: Date.now() };+ agent._pendingClarifications.set(tabId, new Map([['timed', timeoutEntry]]));+ agent.submitClarifyResponse(tabId, 'timed', 'Yes, submit it', 'timeout');+ await submit('after-timeout');+ assert.equal(prompts, 1, `${AgentClass.name}: a timed-out answer is not the user changing their mind`);++ email = '[email protected]';+ await submit('changed');+ assert.equal(prompts, 2, `${AgentClass.name}: a changed value asks again`);++ email = '[email protected]';+ const userEntry = { resolve: () => { }, ts: Date.now() };+ agent._pendingClarifications.set(tabId, new Map([['asked', userEntry]]));+ agent.submitClarifyResponse(tabId, 'asked', 'Yes, submit it', 'user');+ await submit('after-user-answer');+ assert.equal(prompts, 3, `${AgentClass.name}: the user's own answer on a later card asks again`);++ agent.permissions.beginTurn(tabId);+ await submit('new-turn');+ assert.equal(prompts, 4, `${AgentClass.name}: a new turn asks again`);+ assert.equal(executed, 0, `${AgentClass.name}: nothing declined was submitted`);+ }+});+test('submit confirmation honors scheduled and global gate bypasses', async () => {for (const AgentClass of [AgentCh, AgentFx]) {for (const scenario of [