Skip to content

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

fix(agent): live scope on minted proofs, canonical URL on token agreement

Emre Sokullue5f4ad80d6ed
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index e4d791962..47f472ef0 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -20333,6 +20333,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
stableSelector: typeof response.stableSelector === 'string' && response.stableSelector.trim()
? response.stableSelector.trim()
: null,
+ // Live scope the probe answered from (attached by the dispatcher on
+ // every return path): selector/focused writes need no AX read, so the
+ // caller may hold empty/stale scope while this is current.
+ documentToken: String(response.documentToken || ''),
+ pageUrl: String(response.refScopeUrl || ''),
};
} catch {
return null;
@@ -20438,6 +20443,23 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
};
}
+ // Rebuild a mutation target's key for a fresher scope, keeping the locator
+ // identical. Used when the write-time digest answers from the live
+ // document while the target still carries empty/stale scope.
+ _rekeyTextMutationTarget(target, documentToken, pageUrl) {
+ const doc = documentToken || pageUrl || 'document';
+ if (target?.locatorType === 'ax' && typeof target.refId === 'string') {
+ return `ax:${doc}:${target.refId}`;
+ }
+ if (target?.locatorType === 'selector' && typeof target.selector === 'string') {
+ return `selector:${doc}:${target.selector}`;
+ }
+ if (target?.locatorType === 'focused') {
+ return target.focusedKind ? `focused:${doc}:${target.focusedKind}` : `focused:${doc}`;
+ }
+ return target?.key;
+ }
+
async _verifiedTextReplacementRecord(tabId, target, text, fieldMeta = null) {
const workflow = this._planExecutionGuards.get(tabId)?.siteWorkflow;
const needsCommitProof = workflow?.adapterName === 'github'
@@ -20446,8 +20468,27 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
? await this._textMutationValueDigest(tabId, target, text)
: null;
const readback = candidateReadback?.verified === true ? candidateReadback : null;
+ // Live scope propagation: selector/focused writes need no AX read, so
+ // the target can carry empty/stale scope while the digest answered from
+ // the live document. Stamp the record (fields + key) with the live scope
+ // so the binding's exact-URL checks don't reject an otherwise valid
+ // proof. When both tokens agree the document is proven identical, the
+ // agent-canonical URL spelling wins (the gate compares paths
+ // case-sensitively); otherwise the live probe is authoritative.
+ // Deliberately no global adoption here — adopting would clear the maps
+ // this caller's set() still targets.
+ const tokensAgree = !!readback?.documentToken && !!target.documentToken
+ && readback.documentToken === target.documentToken;
+ const liveDocumentToken = readback?.documentToken || target.documentToken;
+ const livePageUrl = tokensAgree ? target.pageUrl : (readback?.pageUrl || target.pageUrl);
+ const liveScope = readback && (readback.documentToken || readback.pageUrl);
return {
...target,
+ documentToken: liveDocumentToken,
+ pageUrl: livePageUrl,
+ key: liveScope
+ ? this._rekeyTextMutationTarget(target, liveDocumentToken, livePageUrl)
+ : target.key,
expectedLength: text.length,
expectedSha256: await this._sha256Text(text),
expectedFp: this._workflowInventoryFingerprint(text),
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index dc31ea183..ea3a90653 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -17904,6 +17904,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
stableSelector: typeof response.stableSelector === 'string' && response.stableSelector.trim()
? response.stableSelector.trim()
: null,
+ // Live scope the probe answered from (attached by the dispatcher on
+ // every return path): selector/focused writes need no AX read, so the
+ // caller may hold empty/stale scope while this is current.
+ documentToken: String(response.documentToken || ''),
+ pageUrl: String(response.refScopeUrl || ''),
};
} catch {
return null;
@@ -18009,6 +18014,23 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
};
}
+ // Rebuild a mutation target's key for a fresher scope, keeping the locator
+ // identical. Used when the write-time digest answers from the live
+ // document while the target still carries empty/stale scope.
+ _rekeyTextMutationTarget(target, documentToken, pageUrl) {
+ const doc = documentToken || pageUrl || 'document';
+ if (target?.locatorType === 'ax' && typeof target.refId === 'string') {
+ return `ax:${doc}:${target.refId}`;
+ }
+ if (target?.locatorType === 'selector' && typeof target.selector === 'string') {
+ return `selector:${doc}:${target.selector}`;
+ }
+ if (target?.locatorType === 'focused') {
+ return target.focusedKind ? `focused:${doc}:${target.focusedKind}` : `focused:${doc}`;
+ }
+ return target?.key;
+ }
+
async _verifiedTextReplacementRecord(tabId, target, text, fieldMeta = null) {
const workflow = this._planExecutionGuards.get(tabId)?.siteWorkflow;
const needsCommitProof = workflow?.adapterName === 'github'
@@ -18017,8 +18039,27 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
? await this._textMutationValueDigest(tabId, target, text)
: null;
const readback = candidateReadback?.verified === true ? candidateReadback : null;
+ // Live scope propagation: selector/focused writes need no AX read, so
+ // the target can carry empty/stale scope while the digest answered from
+ // the live document. Stamp the record (fields + key) with the live scope
+ // so the binding's exact-URL checks don't reject an otherwise valid
+ // proof. When both tokens agree the document is proven identical, the
+ // agent-canonical URL spelling wins (the gate compares paths
+ // case-sensitively); otherwise the live probe is authoritative.
+ // Deliberately no global adoption here — adopting would clear the maps
+ // this caller's set() still targets.
+ const tokensAgree = !!readback?.documentToken && !!target.documentToken
+ && readback.documentToken === target.documentToken;
+ const liveDocumentToken = readback?.documentToken || target.documentToken;
+ const livePageUrl = tokensAgree ? target.pageUrl : (readback?.pageUrl || target.pageUrl);
+ const liveScope = readback && (readback.documentToken || readback.pageUrl);
return {
...target,
+ documentToken: liveDocumentToken,
+ pageUrl: livePageUrl,
+ key: liveScope
+ ? this._rekeyTextMutationTarget(target, liveDocumentToken, livePageUrl)
+ : target.key,
expectedLength: text.length,
expectedSha256: await this._sha256Text(text),
expectedFp: this._workflowInventoryFingerprint(text),
diff --git a/test/run.js b/test/run.js
index f4c9004f5..92b8d6cd9 100644
--- a/test/run.js
+++ b/test/run.js
@@ -75731,6 +75731,72 @@ test('refresh revalidates label-identified editor proofs', async () => {
}
});
+test('minted proofs carry the live digest scope', async () => {
+ const originalChrome = globalThis.chrome;
+ const originalBrowser = globalThis.browser;
+ try {
+ const pageUrl = 'https://github.com/Example/Repo/edit/main/docs/plan.md';
+ const body = '# Live scope document\n\nOne complete copy.\n';
+ for (const [label, AgentClass, resolveJob, tabId, controlTabId] of [
+ ['chrome', AgentCh, resolveAdapterWorkflowJob, 9508, 9510],
+ ['firefox', AgentFx, resolveAdapterWorkflowJobFx, 9509, 9511],
+ ]) {
+ const agent = new AgentClass({});
+ agent._planExecutionGuards.set(tabId, {
+ enabled: true,
+ siteWorkflow: resolveJob(pageUrl, 'edit-file-and-commit'),
+ workflowMetadataRequirements: [],
+ workflowMetadataRequirementsResolved: true,
+ });
+ // No AX-tree read ever happened: the target carries empty scope, but
+ // the digest answers from the live document.
+ const tabs = {
+ async sendMessage(_tabId, message) {
+ assert.equal(message.action, 'field_value_digest');
+ return { success: true, verified: true,
+ valueLength: body.length, valueSha256: await agent._sha256Text(body),
+ fieldMeta: { contentEditable: true, ariaLabelledByText: 'Editing file contents' },
+ documentToken: 'doc-live', refScopeUrl: pageUrl };
+ },
+ };
+ globalThis.chrome = { tabs };
+ globalThis.browser = { tabs };
+ const record = await agent._verifiedTextReplacementRecord(
+ tabId, agent._textMutationTarget(tabId, 'type_text', { selector: '#ed' }), body, null,
+ );
+ assert.equal(record.documentToken, 'doc-live',
+ `${label}: proof kept the empty scope instead of the live token`);
+ assert.equal(record.pageUrl, pageUrl,
+ `${label}: proof kept the empty scope instead of the live URL`);
+ assert.ok(String(record.key).includes('doc-live'),
+ `${label}: proof key was not rebuilt for the live scope (key: ${record.key})`);
+ assert.ok(record.readbackSha256,
+ `${label}: scoped proof lost its readback`);
+ // Stale cache variant: same treatment, never the cached token.
+ const stale = new AgentClass({});
+ stale._planExecutionGuards.set(controlTabId, {
+ enabled: true,
+ siteWorkflow: resolveJob(pageUrl, 'edit-file-and-commit'),
+ workflowMetadataRequirements: [],
+ workflowMetadataRequirementsResolved: true,
+ });
+ stale._lastAxScopes.set(controlTabId, { documentToken: 'doc-stale', pageUrl });
+ const staleRecord = await stale._verifiedTextReplacementRecord(
+ controlTabId, stale._textMutationTarget(controlTabId, 'type_text', { selector: '#ed' }), body, null,
+ );
+ assert.equal(staleRecord.documentToken, 'doc-live',
+ `${label}: proof kept the stale token instead of the live one`);
+ assert.ok(!String(staleRecord.key).includes('doc-stale'),
+ `${label}: proof key kept the stale scope (key: ${staleRecord.key})`);
+ }
+ } finally {
+ if (originalChrome === undefined) delete globalThis.chrome;
+ else globalThis.chrome = originalChrome;
+ if (originalBrowser === undefined) delete globalThis.browser;
+ else globalThis.browser = originalBrowser;
+ }
+});
+
test('selector writes to proven-distinct fields bypass unrelated debt', async () => {
const originalChrome = globalThis.chrome;
const originalBrowser = globalThis.browser;