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(providers): address codex round 8 - instance-keyed share consent
Emre Sokulluea7e328f3ffc
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 8858ae5af..3bcdd1cf5 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -18774,6 +18774,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dmode,provider: String(provider?.config?.providerName || '').toLowerCase(),provider_name: String(provider?.config?.label || provider?.name || '').slice(0, 128),+ provider_id: String(provider?.config?._providerId || ''),});if (shareItem) await enqueueShareGeneration({ session_id: shareSessionId, ...shareItem });}@@ -18816,15 +18817,17 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d/*** Drop queued voluntary shares whose provider is no longer opted in.- * Consent is checked against live configs immediately before every flush- * (run start and run end), so entries queued while opted in are never- * delivered after the user revokes the toggle or removes the provider.+ * Consent is keyed by stable provider-config id and checked against live+ * configs immediately before every flush (run start and run end), so+ * entries queued while opted in are never delivered after the user revokes+ * the toggle or removes the provider. Entries without an id predate+ * instance-keyed consent and are dropped rather than sent unverified.*/async _purgeRevokedShareGenerations() {try {- const consented = this.providerManager?.consentedShareProviderNames?.();+ const consented = this.providerManager?.consentedShareProviderIds?.();if (!(consented instanceof Set)) return;- await purgeShareGenerations(entry => !consented.has(String(entry?.provider || '')));+ await purgeShareGenerations(entry => !consented.has(String(entry?.provider_id || '')));} catch {}}diff --git a/src/chrome/src/providers/manager.js b/src/chrome/src/providers/manager.jsindex b549e2cad..33bf390a9 100644--- a/src/chrome/src/providers/manager.js+++ b/src/chrome/src/providers/manager.js@@ -1284,20 +1284,22 @@ export class ProviderManager {}/**- * Lowercased provider names currently opted into voluntary research- * sharing. The share outbox purges queued entries for any other name- * before delivery so revoking the toggle is honored immediately.+ * Stable provider-config ids currently opted into voluntary research+ * sharing. The share outbox purges queued entries for any other id before+ * delivery so revoking the toggle is honored immediately. Keyed by config+ * id (not providerName): duplicates share one providerName, and some+ * built-ins have none at all.*/- consentedShareProviderNames() {- const names = new Set();+ consentedShareProviderIds() {+ const ids = new Set();try {- for (const provider of this.providers?.values?.() || []) {+ for (const [id, provider] of this.providers?.entries?.() || []) {if (provider?.config?.shareQueriesForResearch !== true) continue;- const name = String(provider.config.providerName || '').toLowerCase();- if (name && name !== 'webbrain-cloud') names.add(name);+ const pid = String(provider.config._providerId || id || '');+ if (pid) ids.add(pid);}} catch {}- return names;+ return ids;}async _fetchVisionCapability(providerId, provider, identity) {diff --git a/src/chrome/src/trace/webbrain-share-outbox.js b/src/chrome/src/trace/webbrain-share-outbox.jsindex bac98e96f..5f27a37a7 100644--- a/src/chrome/src/trace/webbrain-share-outbox.js+++ b/src/chrome/src/trace/webbrain-share-outbox.js@@ -284,6 +284,7 @@ export function buildShareGenerationItem({mode,provider,provider_name,+ provider_id,}) {const responseContent = String(finalContent ?? '');if (!responseContent.trim()) return null;@@ -293,6 +294,10 @@ export function buildShareGenerationItem({|| `${Date.now().toString(36)}_${(++fallbackRunCounter).toString(36)}`;return {id: String(runId || `share_${generatedId}`),+ // Stable provider-config id for consent checks (purge). provider/provider_name+ // stay human-readable attribution for the backend; the id disambiguates+ // duplicates and nameless built-ins that share one providerName.+ provider_id: String(provider_id || ''),provider: String(provider || '').slice(0, 64),provider_name: String(provider_name || '').slice(0, 128),model: String(model || '').slice(0, 255),diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 21c926b83..68c5b761f 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -16568,6 +16568,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dmode,provider: String(provider?.config?.providerName || '').toLowerCase(),provider_name: String(provider?.config?.label || provider?.name || '').slice(0, 128),+ provider_id: String(provider?.config?._providerId || ''),});if (shareItem) await enqueueShareGeneration({ session_id: shareSessionId, ...shareItem });}@@ -16610,15 +16611,17 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d/*** Drop queued voluntary shares whose provider is no longer opted in.- * Consent is checked against live configs immediately before every flush- * (run start and run end), so entries queued while opted in are never- * delivered after the user revokes the toggle or removes the provider.+ * Consent is keyed by stable provider-config id and checked against live+ * configs immediately before every flush (run start and run end), so+ * entries queued while opted in are never delivered after the user revokes+ * the toggle or removes the provider. Entries without an id predate+ * instance-keyed consent and are dropped rather than sent unverified.*/async _purgeRevokedShareGenerations() {try {- const consented = this.providerManager?.consentedShareProviderNames?.();+ const consented = this.providerManager?.consentedShareProviderIds?.();if (!(consented instanceof Set)) return;- await purgeShareGenerations(entry => !consented.has(String(entry?.provider || '')));+ await purgeShareGenerations(entry => !consented.has(String(entry?.provider_id || '')));} catch {}}diff --git a/src/firefox/src/providers/manager.js b/src/firefox/src/providers/manager.jsindex 27bbf59c3..daa07e4d9 100644--- a/src/firefox/src/providers/manager.js+++ b/src/firefox/src/providers/manager.js@@ -1168,20 +1168,22 @@ export class ProviderManager {}/**- * Lowercased provider names currently opted into voluntary research- * sharing. The share outbox purges queued entries for any other name- * before delivery so revoking the toggle is honored immediately.+ * Stable provider-config ids currently opted into voluntary research+ * sharing. The share outbox purges queued entries for any other id before+ * delivery so revoking the toggle is honored immediately. Keyed by config+ * id (not providerName): duplicates share one providerName, and some+ * built-ins have none at all.*/- consentedShareProviderNames() {- const names = new Set();+ consentedShareProviderIds() {+ const ids = new Set();try {- for (const provider of this.providers?.values?.() || []) {+ for (const [id, provider] of this.providers?.entries?.() || []) {if (provider?.config?.shareQueriesForResearch !== true) continue;- const name = String(provider.config.providerName || '').toLowerCase();- if (name && name !== 'webbrain-cloud') names.add(name);+ const pid = String(provider.config._providerId || id || '');+ if (pid) ids.add(pid);}} catch {}- return names;+ return ids;}async _fetchVisionCapability(providerId, provider, identity) {diff --git a/src/firefox/src/trace/webbrain-share-outbox.js b/src/firefox/src/trace/webbrain-share-outbox.jsindex bac98e96f..5f27a37a7 100644--- a/src/firefox/src/trace/webbrain-share-outbox.js+++ b/src/firefox/src/trace/webbrain-share-outbox.js@@ -284,6 +284,7 @@ export function buildShareGenerationItem({mode,provider,provider_name,+ provider_id,}) {const responseContent = String(finalContent ?? '');if (!responseContent.trim()) return null;@@ -293,6 +294,10 @@ export function buildShareGenerationItem({|| `${Date.now().toString(36)}_${(++fallbackRunCounter).toString(36)}`;return {id: String(runId || `share_${generatedId}`),+ // Stable provider-config id for consent checks (purge). provider/provider_name+ // stay human-readable attribution for the backend; the id disambiguates+ // duplicates and nameless built-ins that share one providerName.+ provider_id: String(provider_id || ''),provider: String(provider || '').slice(0, 64),provider_name: String(provider_name || '').slice(0, 128),model: String(model || '').slice(0, 255),diff --git a/test/run.js b/test/run.jsindex 611f04ec5..c8f491ab3 100644--- a/test/run.js+++ b/test/run.js@@ -12711,11 +12711,11 @@ test('Share-for-research outbox persists retryable failures and removes acknowleassert.deepEqual(await Promise.all([firstFlush, secondFlush]), [1, 0]);assert.equal(storage[SHARE_OUTBOX_CH.SHARE_OUTBOX_STORAGE_KEY].length, 0);// Revoked consent purges queued entries before delivery.- const revoked = { id: 'share-revoked-1', session_id: 'share_conv_1', provider: 'ollama', provider_name: 'x', model: 'm', mode: 'act', request: [{ role: 'user', content: 'hi' }], response: { role: 'assistant', content: 'yo' } };- const keptEntry = { id: 'share-kept-1', session_id: 'share_conv_1', provider: 'anthropic', provider_name: 'x', model: 'm', mode: 'act', request: [{ role: 'user', content: 'hi' }], response: { role: 'assistant', content: 'yo' } };+ const revoked = { id: 'share-revoked-1', session_id: 'share_conv_1', provider: 'ollama', provider_name: 'x', provider_id: 'ollama', model: 'm', mode: 'act', request: [{ role: 'user', content: 'hi' }], response: { role: 'assistant', content: 'yo' } };+ const keptEntry = { id: 'share-kept-1', session_id: 'share_conv_1', provider: 'anthropic', provider_name: 'x', provider_id: 'anthropic', model: 'm', mode: 'act', request: [{ role: 'user', content: 'hi' }], response: { role: 'assistant', content: 'yo' } };assert.equal(await SHARE_OUTBOX_CH.enqueueShareGeneration(revoked), true);assert.equal(await SHARE_OUTBOX_CH.enqueueShareGeneration(keptEntry), true);- assert.equal(await SHARE_OUTBOX_CH.purgeShareGenerations(e => e.provider === 'ollama'), 1, 'revoked entry not purged');+ assert.equal(await SHARE_OUTBOX_CH.purgeShareGenerations(e => e.provider_id === 'ollama'), 1, 'revoked entry not purged');assert.equal(storage[SHARE_OUTBOX_CH.SHARE_OUTBOX_STORAGE_KEY].length, 1);assert.equal(await SHARE_OUTBOX_CH.purgeShareGenerations(() => false), 0, 'purge dropped consented entries');assert.equal(storage[SHARE_OUTBOX_CH.SHARE_OUTBOX_STORAGE_KEY].length, 1);@@ -12766,6 +12766,46 @@ test('Firefox Share-for-research outbox uses the promise-based browser storage n}});+test('Share-for-research revoke purge is keyed by provider instance', async () => {+ const originalChrome = globalThis.chrome;+ const storage = {};+ globalThis.chrome = {+ storage: {+ local: {+ async get(keys) {+ const key = Array.isArray(keys) ? keys[0] : keys;+ return { [key]: storage[key] };+ },+ async set(values) { Object.assign(storage, values); },+ },+ },+ };+ try {+ for (const [label, AgentClass, outbox] of [['chrome', AgentCh, SHARE_OUTBOX_CH], ['firefox', AgentFx, SHARE_OUTBOX_FX]]) {+ for (const key of Object.keys(storage)) delete storage[key];+ // A duplicate shares its origin's providerName but has its own id; a+ // nameless built-in (anthropic-style) stores an empty provider name.+ // Only entries whose instance id is still consented may survive.+ const dupRevoked = { id: `share-dup-${label}`, session_id: 's', provider: 'openai', provider_name: 'OpenAI dup', provider_id: 'openai:duplicate:1', model: 'm', mode: 'act', request: [{ role: 'user', content: 'hi' }], response: { role: 'assistant', content: 'yo' } };+ const originKept = { id: `share-origin-${label}`, session_id: 's', provider: 'openai', provider_name: 'OpenAI', provider_id: 'openai', model: 'm', mode: 'act', request: [{ role: 'user', content: 'hi' }], response: { role: 'assistant', content: 'yo' } };+ const namelessKept = { id: `share-nameless-${label}`, session_id: 's', provider: '', provider_name: '', provider_id: 'anthropic', model: 'm', mode: 'act', request: [{ role: 'user', content: 'hi' }], response: { role: 'assistant', content: 'yo' } };+ const legacyDropped = { id: `share-legacy-${label}`, session_id: 's', provider: 'openai', provider_name: 'OpenAI', model: 'm', mode: 'act', request: [{ role: 'user', content: 'hi' }], response: { role: 'assistant', content: 'yo' } };+ assert.equal(await outbox.enqueueShareGeneration(dupRevoked), true);+ assert.equal(await outbox.enqueueShareGeneration(originKept), true);+ assert.equal(await outbox.enqueueShareGeneration(namelessKept), true);+ assert.equal(await outbox.enqueueShareGeneration(legacyDropped), true);+ const agent = new AgentClass({});+ agent.providerManager = { consentedShareProviderIds: () => new Set(['openai', 'anthropic']) };+ await agent._purgeRevokedShareGenerations();+ const remaining = (storage[outbox.SHARE_OUTBOX_STORAGE_KEY] || []).map(e => e.id).sort();+ assert.deepEqual(remaining, [`share-nameless-${label}`, `share-origin-${label}`].sort(), `${label}: instance-keyed purge kept the wrong entries`);+ }+ } finally {+ if (originalChrome === undefined) delete globalThis.chrome;+ else globalThis.chrome = originalChrome;+ }+});+test('Share-for-research delivery stays opt-in and mirrored across both builds', () => {const chromeOutbox = fs.readFileSync(path.join(ROOT, 'src/chrome/src/trace/webbrain-share-outbox.js'), 'utf8');const firefoxOutbox = fs.readFileSync(path.join(ROOT, 'src/firefox/src/trace/webbrain-share-outbox.js'), 'utf8');@@ -12791,8 +12831,9 @@ test('Share-for-research delivery stays opt-in and mirrored across both builds',assert.match(chromeOutbox, /_attachImage/, `${browser}: binary metadata attachments must be dropped`);assert.match(chromeOutbox, /scrubToolCallArguments/, `${browser}: tool-call arguments must be scrubbed`);const managerSource = fs.readFileSync(path.join(ROOT, `src/${browser}/src/providers/manager.js`), 'utf8');- assert.match(managerSource, /consentedShareProviderNames\(\)/, `${browser}: provider manager must expose share consent`);+ assert.match(managerSource, /consentedShareProviderIds\(\)/, `${browser}: provider manager must expose instance-keyed share consent`);assert.match(agent, /_purgeRevokedShareGenerations\(\)/, `${browser}: revoked shares must be purged before delivery`);+ assert.match(agent, /provider_id: String\(provider\?\.config\?\._providerId/, `${browser}: queued shares must be keyed by provider instance`);assert.match(agent, /if \(scheduledResume\) return \{ action: 'return', value: finalResponse, status: 'scheduled_resume' \}/, `${browser}: scheduler-synthesized summaries must not be shared as generations`);assert.match(settings, /shareQueriesForResearch/, `${browser}: share toggle field missing from settings`);assert.match(settings, /!input\.checked[\s\S]*?confirm\(/, `${browser}: consent confirmation must guard turning the share toggle on`);