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(agent): retain AX scope across conversation clears
Emre Sokullu84ebab891af6
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 5ee574f4a..b835f8cab 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -20693,7 +20693,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis._completionSubmitStates.delete(tabId);this._recentSubmitClicks.delete(tabId);this._formValidationBlocks.delete(tabId);- this._lastAxScopes.delete(tabId);+ // A conversation clear preserves the run guard while the document is+ // unchanged: the AX scope survives alongside retained mutation debt so+ // the first exact retry keys identically and can recover immediately.+ // Stale scopes self-heal through the usual live checks on next use.+ if (!preserveRunGuard) {+ this._lastAxScopes.delete(tabId);+ }this._resetRichTextToolbarAudit(tabId);this.recentNavUrls.delete(tabId);this.completionInvariants.delete(tabId);diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex b54f2caf4..8a61ebaf8 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -19197,7 +19197,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis._completionSubmitStates.delete(tabId);this._recentSubmitClicks.delete(tabId);this._formValidationBlocks.delete(tabId);- this._lastAxScopes.delete(tabId);+ // A conversation clear preserves the run guard while the document is+ // unchanged: the AX scope survives alongside retained mutation debt so+ // the first exact retry keys identically and can recover immediately.+ // Stale scopes self-heal through the usual live checks on next use.+ if (!preserveRunGuard) {+ this._lastAxScopes.delete(tabId);+ }this._resetRichTextToolbarAudit(tabId);this.recentNavUrls.delete(tabId);this.completionInvariants.delete(tabId);diff --git a/test/run.js b/test/run.jsindex 5eb409c74..b74dc6f7c 100644--- a/test/run.js+++ b/test/run.js@@ -77808,6 +77808,55 @@ test('clearConversation preserves document-scoped mutation debt', async () => {}});+test('clearConversation retains scope for first-try debt recovery', async () => {+ const originalChrome = globalThis.chrome;+ const originalBrowser = globalThis.browser;+ try {+ const tabs = {+ async sendMessage(_tabId, message) {+ if (message.action === 'ax_verify_field_value') {+ assert.equal(message.params?.ref_id, 'ref_a');+ assert.equal(message.params?.expected, 'hello');+ return { success: true, verified: true, fieldMeta: { id: 'field-a' } };+ }+ assert.equal(message.action, 'field_value_digest');+ return { success: false, documentToken: 'doc-scope', refScopeUrl: 'https://example.test/form' };+ },+ };+ globalThis.chrome = { tabs };+ globalThis.browser = { tabs };+ for (const [label, AgentClass, tabId] of [+ ['chrome', AgentCh, 9540],+ ['firefox', AgentFx, 9541],+ ]) {+ const agent = new AgentClass({});+ agent._lastAxScopes.set(tabId, { documentToken: 'doc-scope', pageUrl: 'https://example.test/form' });+ await agent._finalizeTextMutationResult(+ tabId, 'set_field', { ref_id: 'ref_a', text: 'hello' },+ { success: false, dispatched: true, verified: false },+ );+ agent.clearConversation(tabId);+ assert.deepEqual(agent._lastAxScopes.get(tabId),+ { documentToken: 'doc-scope', pageUrl: 'https://example.test/form' },+ `${label}: conversation clear dropped the document scope`);+ // The first exact retry keys identically and recovers immediately —+ // no second call needed.+ const recovered = await agent._uncertainTextMutationBlock(+ tabId, 'set_field', { ref_id: 'ref_a', text: 'hello' },+ );+ assert.equal(recovered?.recoveredUncertainMutation, true,+ `${label}: retained debt did not recover on the first retry`);+ assert.equal(agent._uncertainTextMutations.has(tabId), false,+ `${label}: recovered debt was retained`);+ }+ } finally {+ if (originalChrome === undefined) delete globalThis.chrome;+ else globalThis.chrome = originalChrome;+ if (originalBrowser === undefined) delete globalThis.browser;+ else globalThis.browser = originalBrowser;+ }+});+test('sync SHA-256 helper matches the async subtle digest', async () => {for (const [label, AgentClass] of [['chrome', AgentCh], ['firefox', AgentFx]]) {const agent = new AgentClass({});