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 10 - per-send consent, canonical URIs, done rawSummary
Emre Sokullue0beb87c6662
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 3bd531a31..1875d6e1e 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -12729,7 +12729,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// auto-progress resume paths) so voluntary research sharing and workflow// drafts treat it as a pause, never as an ordinary model generation.if (scheduledResume) return { action: 'return', value: finalResponse, status: 'scheduled_resume' };- return { action: 'return', value: finalResponse };+ // rawSummary is the model-authored done text before the progress+ // ledger is appended for display; research sharing stores it as the+ // response instead of mislabeling local presentation as provider output.+ return { action: 'return', value: finalResponse, rawSummary: repairedDoneSummary };}// Loop detection — exact calls, semantic AX reads, and coordinates run@@ -18785,7 +18788,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// mirroring the Compass runtime outbox pattern. Revoked entries are// purged first so opt-out is honored immediately before delivery.try { await this._purgeRevokedShareGenerations(); } catch {}- void flushShareOutbox(shareTransport);+ void flushShareOutbox(shareTransport, (entry) => this._shareEntryConsented(entry));if (runId) {await this._flushAdapterMatchTraceRun(runId);try {@@ -18832,6 +18835,20 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d} catch {}}+ /**+ * Live per-entry consent check for an in-flight flush. Re-reads configs on+ * every send (not once per flush) so revocation mid-flush drops the+ * remaining snapshot entries instead of delivering them.+ */+ _shareEntryConsented(entry) {+ try {+ const consented = this.providerManager?.consentedShareProviderIds?.();+ return consented instanceof Set && consented.has(String(entry?.provider_id || ''));+ } catch {+ return false;+ }+ }+/*** Build a compact, single-line-per-turn digest of recent conversation so the* planner can resolve follow-up references ("continue", "open the first@@ -40516,7 +40533,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dvoid flushCloudRuntimeOutbox(provider);// Purge shares revoked since they were queued before retrying delivery.void this._purgeRevokedShareGenerations();- void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'));+ void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'), (entry) => this._shareEntryConsented(entry));if (typeof runOptions?.isDetachedStartCancelled === 'function'&& runOptions.isDetachedStartCancelled()) {@@ -41292,6 +41309,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d);if (batchResult.action === 'return') {finalResponse = batchResult.value;+ if (typeof batchResult.rawSummary === 'string' && batchResult.rawSummary.trim()) {+ shareRawResponse = batchResult.rawSummary;+ }if (batchResult.status) {_traceStatus = batchResult.status;onUpdate('run_status', { status: batchResult.status, message: batchResult.value });@@ -41887,7 +41907,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dvoid flushCloudRuntimeOutbox(provider);// Purge shares revoked since they were queued before retrying delivery.void this._purgeRevokedShareGenerations();- void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'));+ void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'), (entry) => this._shareEntryConsented(entry));// The run claim owns cancellation reset. Stop during setup must survive.this._throwIfAborted(this._runAbortSignal(tabId));@@ -42367,6 +42387,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dtabId, toolCalls, messages, onUpdate, provider, fullText, allowedToolNames, steps, runOptions, toolSchemas);if (batchResult.action === 'return') {+ if (typeof batchResult.rawSummary === 'string' && batchResult.rawSummary.trim()) {+ shareRawResponse = batchResult.rawSummary;+ }if (batchResult.status) {onUpdate('run_status', { status: batchResult.status, message: batchResult.value });}diff --git a/src/chrome/src/trace/webbrain-share-outbox.js b/src/chrome/src/trace/webbrain-share-outbox.jsindex 5ac54c332..b3c89a0f9 100644--- a/src/chrome/src/trace/webbrain-share-outbox.js+++ b/src/chrome/src/trace/webbrain-share-outbox.js@@ -34,13 +34,15 @@ function clampText(value, limit = MAX_MESSAGE_CHARS) {function scrubText(value, limit = MAX_MESSAGE_CHARS) {if (typeof value !== 'string') return value;let text = value;- if (text.includes('data:')) {+ // Non-canonical forms count too: uppercase scheme (DATA:...), extra+ // media-type parameters (...;charset=utf-8;base64,...). Case-insensitive.+ if (/data:/i.test(text)) {// Detect data URIs regardless of surrounding string or payload length:// even a 1x1 canvas/QR thumbnail is image bytes the UI promises to strip.// Newlines (but not spaces/words) are allowed inside the payload so// wrapped base64 is still removed while surrounding prose survives.text = text.replace(- /data:(image|audio|video|application|font|model)\/[a-zA-Z0-9+.-]+;base64,[A-Za-z0-9+/=\r\n]+/g,+ /data:(image|audio|video|application|font|model)\/[a-zA-Z0-9+.-]+(?:;[a-zA-Z0-9!#$&^_.+-]+(?:=[a-zA-Z0-9!#$&^_.+-]+)?)*;base64,[A-Za-z0-9+/=\r\n]+/gi,'[embedded base64 data omitted]',);}@@ -61,8 +63,9 @@ function containsBinaryBlock(value) {// screenshot bytes echoed into a tool result). Check anywhere in the// string, at any length: even tiny thumbnails are image bytes.if (typeof value === 'string') {- return value.includes('data:')- && /data:(image|audio|video|application)\/[^;]+;base64,/i.test(value);+ // Case-insensitive with optional media-type parameters, matching scrubText.+ return /data:/i.test(value)+ && /data:(image|audio|video|application)\/[^,]+;base64,/i.test(value);}if (!value || typeof value !== 'object') return false;const type = typeof value.type === 'string' ? value.type.toLowerCase() : '';@@ -369,7 +372,7 @@ export async function purgeShareGenerations(shouldDrop) {return removed;}-async function flushShareOutboxNow(transportProvider) {+async function flushShareOutboxNow(transportProvider, shouldSend) {if (typeof transportProvider?.sendShareGeneration !== 'function') return 0;await storageQueue.catch(() => {});let snapshot;@@ -377,6 +380,18 @@ async function flushShareOutboxNow(transportProvider) {if (!snapshot.length) return 0;const removeIds = new Set();for (const entry of snapshot) {+ // Revalidate consent immediately before each delivery: a pre-flush purge+ // cannot cover revocation that lands mid-flush, and this loop otherwise+ // holds a stale snapshot. Revoked entries are dropped, never sent.+ // Fail-closed: a throwing predicate drops the entry.+ if (typeof shouldSend === 'function') {+ let allowed = false;+ try { allowed = shouldSend(entry) !== false; } catch { allowed = false; }+ if (!allowed) {+ removeIds.add(entry.id);+ continue;+ }+ }let result;try {result = await transportProvider.sendShareGeneration(entry.session_id, {@@ -399,8 +414,8 @@ async function flushShareOutboxNow(transportProvider) {return removeIds.size;}-export function flushShareOutbox(transportProvider) {- const next = flushQueue.catch(() => {}).then(() => flushShareOutboxNow(transportProvider));+export function flushShareOutbox(transportProvider, shouldSend) {+ const next = flushQueue.catch(() => {}).then(() => flushShareOutboxNow(transportProvider, shouldSend));flushQueue = next;return next;}diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 7d5ab0be2..5c82c4793 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -11242,7 +11242,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// auto-progress resume paths) so voluntary research sharing and workflow// drafts treat it as a pause, never as an ordinary model generation.if (scheduledResume) return { action: 'return', value: finalResponse, status: 'scheduled_resume' };- return { action: 'return', value: finalResponse };+ // rawSummary is the model-authored done text before the progress+ // ledger is appended for display; research sharing stores it as the+ // response instead of mislabeling local presentation as provider output.+ return { action: 'return', value: finalResponse, rawSummary: repairedDoneSummary };}// Loop detection — exact calls, semantic AX reads, and coordinates run@@ -16579,7 +16582,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// mirroring the Compass runtime outbox pattern. Revoked entries are// purged first so opt-out is honored immediately before delivery.try { await this._purgeRevokedShareGenerations(); } catch {}- void flushShareOutbox(shareTransport);+ void flushShareOutbox(shareTransport, (entry) => this._shareEntryConsented(entry));if (runId) {await this._flushAdapterMatchTraceRun(runId);try {@@ -16626,6 +16629,20 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d} catch {}}+ /**+ * Live per-entry consent check for an in-flight flush. Re-reads configs on+ * every send (not once per flush) so revocation mid-flush drops the+ * remaining snapshot entries instead of delivering them.+ */+ _shareEntryConsented(entry) {+ try {+ const consented = this.providerManager?.consentedShareProviderIds?.();+ return consented instanceof Set && consented.has(String(entry?.provider_id || ''));+ } catch {+ return false;+ }+ }+/*** Build a compact, single-line-per-turn digest of recent conversation so the* planner can resolve follow-up references ("continue", "open the first@@ -33662,7 +33679,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dvoid flushCloudRuntimeOutbox(provider);// Purge shares revoked since they were queued before retrying delivery.void this._purgeRevokedShareGenerations();- void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'));+ void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'), (entry) => this._shareEntryConsented(entry));if (typeof runOptions?.isDetachedStartCancelled === 'function'&& runOptions.isDetachedStartCancelled()) {@@ -34348,6 +34365,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d);if (batchResult.action === 'return') {finalResponse = batchResult.value;+ if (typeof batchResult.rawSummary === 'string' && batchResult.rawSummary.trim()) {+ shareRawResponse = batchResult.rawSummary;+ }if (batchResult.status) {_traceStatus = batchResult.status;onUpdate('run_status', { status: batchResult.status, message: batchResult.value });@@ -34871,7 +34891,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dvoid flushCloudRuntimeOutbox(provider);// Purge shares revoked since they were queued before retrying delivery.void this._purgeRevokedShareGenerations();- void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'));+ void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'), (entry) => this._shareEntryConsented(entry));// The run claim owns cancellation reset. Stop during setup must survive.this._throwIfAborted(this._runAbortSignal(tabId));@@ -35283,6 +35303,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dtabId, toolCalls, messages, onUpdate, provider, fullText, allowedToolNames, steps, runOptions, toolSchemas);if (batchResult.action === 'return') {+ if (typeof batchResult.rawSummary === 'string' && batchResult.rawSummary.trim()) {+ shareRawResponse = batchResult.rawSummary;+ }if (batchResult.status) {onUpdate('run_status', { status: batchResult.status, message: batchResult.value });}diff --git a/src/firefox/src/trace/webbrain-share-outbox.js b/src/firefox/src/trace/webbrain-share-outbox.jsindex 5ac54c332..b3c89a0f9 100644--- a/src/firefox/src/trace/webbrain-share-outbox.js+++ b/src/firefox/src/trace/webbrain-share-outbox.js@@ -34,13 +34,15 @@ function clampText(value, limit = MAX_MESSAGE_CHARS) {function scrubText(value, limit = MAX_MESSAGE_CHARS) {if (typeof value !== 'string') return value;let text = value;- if (text.includes('data:')) {+ // Non-canonical forms count too: uppercase scheme (DATA:...), extra+ // media-type parameters (...;charset=utf-8;base64,...). Case-insensitive.+ if (/data:/i.test(text)) {// Detect data URIs regardless of surrounding string or payload length:// even a 1x1 canvas/QR thumbnail is image bytes the UI promises to strip.// Newlines (but not spaces/words) are allowed inside the payload so// wrapped base64 is still removed while surrounding prose survives.text = text.replace(- /data:(image|audio|video|application|font|model)\/[a-zA-Z0-9+.-]+;base64,[A-Za-z0-9+/=\r\n]+/g,+ /data:(image|audio|video|application|font|model)\/[a-zA-Z0-9+.-]+(?:;[a-zA-Z0-9!#$&^_.+-]+(?:=[a-zA-Z0-9!#$&^_.+-]+)?)*;base64,[A-Za-z0-9+/=\r\n]+/gi,'[embedded base64 data omitted]',);}@@ -61,8 +63,9 @@ function containsBinaryBlock(value) {// screenshot bytes echoed into a tool result). Check anywhere in the// string, at any length: even tiny thumbnails are image bytes.if (typeof value === 'string') {- return value.includes('data:')- && /data:(image|audio|video|application)\/[^;]+;base64,/i.test(value);+ // Case-insensitive with optional media-type parameters, matching scrubText.+ return /data:/i.test(value)+ && /data:(image|audio|video|application)\/[^,]+;base64,/i.test(value);}if (!value || typeof value !== 'object') return false;const type = typeof value.type === 'string' ? value.type.toLowerCase() : '';@@ -369,7 +372,7 @@ export async function purgeShareGenerations(shouldDrop) {return removed;}-async function flushShareOutboxNow(transportProvider) {+async function flushShareOutboxNow(transportProvider, shouldSend) {if (typeof transportProvider?.sendShareGeneration !== 'function') return 0;await storageQueue.catch(() => {});let snapshot;@@ -377,6 +380,18 @@ async function flushShareOutboxNow(transportProvider) {if (!snapshot.length) return 0;const removeIds = new Set();for (const entry of snapshot) {+ // Revalidate consent immediately before each delivery: a pre-flush purge+ // cannot cover revocation that lands mid-flush, and this loop otherwise+ // holds a stale snapshot. Revoked entries are dropped, never sent.+ // Fail-closed: a throwing predicate drops the entry.+ if (typeof shouldSend === 'function') {+ let allowed = false;+ try { allowed = shouldSend(entry) !== false; } catch { allowed = false; }+ if (!allowed) {+ removeIds.add(entry.id);+ continue;+ }+ }let result;try {result = await transportProvider.sendShareGeneration(entry.session_id, {@@ -399,8 +414,8 @@ async function flushShareOutboxNow(transportProvider) {return removeIds.size;}-export function flushShareOutbox(transportProvider) {- const next = flushQueue.catch(() => {}).then(() => flushShareOutboxNow(transportProvider));+export function flushShareOutbox(transportProvider, shouldSend) {+ const next = flushQueue.catch(() => {}).then(() => flushShareOutboxNow(transportProvider, shouldSend));flushQueue = next;return next;}diff --git a/test/run.js b/test/run.jsindex c112d584b..b043519d7 100644--- a/test/run.js+++ b/test/run.js@@ -12587,6 +12587,15 @@ test('Share-for-research scrub removes embedded data URIs and keeps repeated-ansmodel: 'some-model', mode: 'act', provider: 'anthropic', provider_name: 'Anthropic Claude',});assert.equal(JSON.stringify(tiny).includes('iVBOR'), false, `${label}: short data URI escaped the scrub`);+ // Non-canonical forms: uppercase scheme and media-type parameters.+ const odd = outbox.buildShareGenerationItem({+ runId: `run-share-odduri-${label}`,+ finalContent: 'ok',+ messages: [{ role: 'tool', content: 'a DATA:image/png;base64,QUJDRA b data:image/png;charset=utf-8;base64,REVGRA c' }],+ model: 'some-model', mode: 'act', provider: 'anthropic', provider_name: 'Anthropic Claude',+ });+ assert.equal(JSON.stringify(odd).includes('QUJDRA'), false, `${label}: uppercase data URI escaped the scrub`);+ assert.equal(JSON.stringify(odd).includes('REVGRA'), false, `${label}: parameterized data URI escaped the scrub`);// Pre-response snapshots must not lose earlier history that repeats the answer.const repeat = outbox.buildShareGenerationItem({runId: `run-share-repeat-${label}`,@@ -12732,6 +12741,21 @@ test('Share-for-research outbox persists retryable failures and removes acknowleassert.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);+ // Mid-flush revocation drops the remaining snapshot without sending.+ assert.equal(await SHARE_OUTBOX_CH.enqueueShareGeneration({ id: 'share-mid-1', session_id: 's', provider: 'p', provider_name: 'x', model: 'm', mode: 'act', request: [{ role: 'user', content: 'one' }], response: { role: 'assistant', content: '1' } }), true);+ assert.equal(await SHARE_OUTBOX_CH.enqueueShareGeneration({ id: 'share-mid-2', session_id: 's', provider: 'p', provider_name: 'x', model: 'm', mode: 'act', request: [{ role: 'user', content: 'two' }], response: { role: 'assistant', content: '2' } }), true);+ const sentIds = [];+ let consentRevoked = false;+ const revokingProvider = {+ async sendShareGeneration(sessionId, payload) {+ sentIds.push(payload.client_share_id);+ if (payload.client_share_id === 'share-kept-1') consentRevoked = true;+ return { ok: true, retryable: false, status: 202 };+ },+ };+ assert.equal(await SHARE_OUTBOX_CH.flushShareOutbox(revokingProvider, () => !consentRevoked), 3, 'mid-flush revoke miscounted');+ assert.deepEqual(sentIds, ['share-kept-1'], 'revoked snapshot entries were delivered');+ assert.equal(storage[SHARE_OUTBOX_CH.SHARE_OUTBOX_STORAGE_KEY].length, 0, 'revoked entries not dropped from storage');} finally {if (originalChrome === undefined) delete globalThis.chrome;else globalThis.chrome = originalChrome;@@ -12830,12 +12854,14 @@ test('Share-for-research delivery stays opt-in and mirrored across both builds',assert.match(agent, /status === 'done'[\s\S]*hadProviderCompletion === true[\s\S]*shareQueriesForResearch === true[\s\S]*enqueueShareGeneration/, `${browser}: capture must require a provider completion and the per-provider toggle`);assert.match(agent, /shareRequest/, `${browser}: capture must prefer the model-facing source-grounded request`);assert.match(agent, /shareRawResponse/, `${browser}: shared response must be the raw provider completion`);+ assert.match(agent, /rawSummary/, `${browser}: done-tool summaries must exclude appended presentation`);+ assert.match(agent, /_shareEntryConsented/, `${browser}: in-flight flushes must recheck consent per send`);assert.match(agent, /currentNonStreamRequestMessages/, `${browser}: non-streaming turns must retain the exact pruned request`);assert.match(agent, /currentStreamRequestMessages/, `${browser}: streaming turns must retain the exact pruned request`);assert.match(agent, /shareCapture/, `${browser}: response-only turns must keep their context-only request`);assert.match(agent, /shareHadProviderCompletion/, `${browser}: local-only fast paths must not be shareable`);assert.match(agent, /'webbrain-cloud'/, `${browser}: Compass provider must not route through the share path`);- assert.match(agent, /void flushShareOutbox\(shareTransport\)/, `${browser}: run-end share flush missing`);+ assert.match(agent, /void flushShareOutbox\(shareTransport[^)]*\)/, `${browser}: run-end share flush missing`);assert.match(agent, /_shareSessionId\(/, `${browser}: share session id sanitizer missing`);assert.match(chromeOutbox, /client_share_id/, `${browser}: outbox flush must send an idempotency key`);assert.match(chromeOutbox, /input_file/, `${browser}: binary scrub must cover file/input_file blocks`);@@ -27069,7 +27095,7 @@ test('completion recovery keeps scoped observations read-only and target-specifi);assert.deepEqual(honestUnavailablePartial,- { action: 'return', value: 'Download verification is unavailable.' },+ { action: 'return', value: 'Download verification is unavailable.', rawSummary: 'Download verification is unavailable.' },`${label}: unavailable verification could not return an honest partial`,);assert.deepEqual(executedUnavailableDone, ['partial'], `${label}: unavailable verification executed the wrong terminal outcome`);