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 7 - schedule_resume status, revoke-purge before flush
Emre Sokullu586e5ef8c5c5
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 3d8dd5797..8858ae5af 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -77,7 +77,7 @@ import { isPdfHandlerTabUrl, pdfUrlFromTabUrl } from './pdf-extraction.js';import { normalizePdfOcrResult, PDF_OCR_SYSTEM_PROMPT } from './pdf-ocr.js';import * as trace from '../trace/recorder.js';import { buildTerminalRuntimeEvent, enqueueCloudRuntimeEvent, flushCloudRuntimeOutbox } from '../trace/cloud-runtime-outbox.js';-import { buildShareGenerationItem, enqueueShareGeneration, flushShareOutbox } from '../trace/webbrain-share-outbox.js';+import { buildShareGenerationItem, enqueueShareGeneration, flushShareOutbox, purgeShareGenerations } from '../trace/webbrain-share-outbox.js';import { normalizeRuntimeTraceConfig } from '../trace/runtime-config.js';import { tracesToMarkdown } from './trace-export.js';import { solveCaptcha, detectCaptcha, injectToken, captchaParamError, captchaTypesMatch, captchaWebsiteUrl } from './captcha-solver.js';@@ -12724,6 +12724,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// Without this, the child alarm exists but the parent needs reconciliation.await settleConsequentialTool();this._persist(tabId);+ // A scheduled resume's summary is synthesized locally by createResumeJob,+ // not authored by the provider. Report it as scheduled_resume (like the+ // 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 };}@@ -18775,7 +18780,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d} catch {}}// Retry delivery of previously queued voluntary shares on every run end,- // mirroring the Compass runtime outbox pattern.+ // 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);if (runId) {await this._flushAdapterMatchTraceRun(runId);@@ -18807,6 +18814,20 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn safe ? `share_${safe}` : '';}+ /**+ * 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.+ */+ async _purgeRevokedShareGenerations() {+ try {+ const consented = this.providerManager?.consentedShareProviderNames?.();+ if (!(consented instanceof Set)) return;+ await purgeShareGenerations(entry => !consented.has(String(entry?.provider || '')));+ } catch {}+ }+/*** Build a compact, single-line-per-turn digest of recent conversation so the* planner can resolve follow-up references ("continue", "open the first@@ -40489,6 +40510,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// to upload; the current run is enqueued at finalization and may complete// in the background or on the next Compass run.void flushCloudRuntimeOutbox(provider);+ // Purge shares revoked since they were queued before retrying delivery.+ void this._purgeRevokedShareGenerations();void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'));if (typeof runOptions?.isDetachedStartCancelled === 'function'@@ -41847,6 +41870,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst provider = this._activeProvider(tabId);void flushCloudRuntimeOutbox(provider);+ // Purge shares revoked since they were queued before retrying delivery.+ void this._purgeRevokedShareGenerations();void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'));// The run claim owns cancellation reset. Stop during setup must survive.diff --git a/src/chrome/src/providers/manager.js b/src/chrome/src/providers/manager.jsindex 88519a641..b549e2cad 100644--- a/src/chrome/src/providers/manager.js+++ b/src/chrome/src/providers/manager.js@@ -1283,6 +1283,23 @@ export class ProviderManager {return provider;}+ /**+ * 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.+ */+ consentedShareProviderNames() {+ const names = new Set();+ try {+ for (const provider of this.providers?.values?.() || []) {+ if (provider?.config?.shareQueriesForResearch !== true) continue;+ const name = String(provider.config.providerName || '').toLowerCase();+ if (name && name !== 'webbrain-cloud') names.add(name);+ }+ } catch {}+ return names;+ }+async _fetchVisionCapability(providerId, provider, identity) {const root = identity.baseUrl.replace(/\/v1$/i, '');const headers = this._modelListHeaders(provider);diff --git a/src/chrome/src/trace/webbrain-share-outbox.js b/src/chrome/src/trace/webbrain-share-outbox.jsindex 33e457e26..bac98e96f 100644--- a/src/chrome/src/trace/webbrain-share-outbox.js+++ b/src/chrome/src/trace/webbrain-share-outbox.js@@ -337,6 +337,26 @@ export async function enqueueShareGeneration(item) {return true;}+// Drop queued entries the predicate no longer consents to (e.g. the user+// revoked "share queries for research" after an offline/failed run queued an+// entry). Run before every flush so revocation is honored immediately before+// delivery, not just at enqueue time. Returns the dropped count.+export async function purgeShareGenerations(shouldDrop) {+ if (typeof shouldDrop !== 'function') return 0;+ let removed = 0;+ await updateOutbox(current => {+ const kept = [];+ for (const entry of current) {+ let drop = false;+ try { drop = shouldDrop(entry) === true; } catch { drop = false; }+ if (drop) removed++;+ else kept.push(entry);+ }+ return removed ? kept : current;+ });+ return removed;+}+async function flushShareOutboxNow(transportProvider) {if (typeof transportProvider?.sendShareGeneration !== 'function') return 0;await storageQueue.catch(() => {});diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 2e19a9d55..21c926b83 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -71,7 +71,7 @@ import {import { normalizePdfOcrResult, PDF_OCR_SYSTEM_PROMPT } from './pdf-ocr.js';import * as trace from '../trace/recorder.js';import { buildTerminalRuntimeEvent, enqueueCloudRuntimeEvent, flushCloudRuntimeOutbox } from '../trace/cloud-runtime-outbox.js';-import { buildShareGenerationItem, enqueueShareGeneration, flushShareOutbox } from '../trace/webbrain-share-outbox.js';+import { buildShareGenerationItem, enqueueShareGeneration, flushShareOutbox, purgeShareGenerations } from '../trace/webbrain-share-outbox.js';import { normalizeRuntimeTraceConfig } from '../trace/runtime-config.js';import { tracesToMarkdown } from './trace-export.js';import { solveCaptcha, detectCaptcha, injectToken, captchaParamError, captchaTypesMatch, captchaWebsiteUrl } from './captcha-solver.js';@@ -11237,6 +11237,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// Without this, the child alarm exists but the parent needs reconciliation.await settleConsequentialTool();this._persist(tabId);+ // A scheduled resume's summary is synthesized locally by createResumeJob,+ // not authored by the provider. Report it as scheduled_resume (like the+ // 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 };}@@ -16569,7 +16574,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d} catch {}}// Retry delivery of previously queued voluntary shares on every run end,- // mirroring the Compass runtime outbox pattern.+ // 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);if (runId) {await this._flushAdapterMatchTraceRun(runId);@@ -16601,6 +16608,20 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn safe ? `share_${safe}` : '';}+ /**+ * 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.+ */+ async _purgeRevokedShareGenerations() {+ try {+ const consented = this.providerManager?.consentedShareProviderNames?.();+ if (!(consented instanceof Set)) return;+ await purgeShareGenerations(entry => !consented.has(String(entry?.provider || '')));+ } catch {}+ }+/*** Build a compact, single-line-per-turn digest of recent conversation so the* planner can resolve follow-up references ("continue", "open the first@@ -33635,6 +33656,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// to upload; the current run is enqueued at finalization and may complete// in the background or on the next Compass run.void flushCloudRuntimeOutbox(provider);+ // Purge shares revoked since they were queued before retrying delivery.+ void this._purgeRevokedShareGenerations();void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'));if (typeof runOptions?.isDetachedStartCancelled === 'function'@@ -34830,6 +34853,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst provider = this.providerManager.getActive();void flushCloudRuntimeOutbox(provider);+ // Purge shares revoked since they were queued before retrying delivery.+ void this._purgeRevokedShareGenerations();void flushShareOutbox(this.providerManager?.getProvider?.('webbrain_cloud'));// The run claim owns cancellation reset. Stop during setup must survive.diff --git a/src/firefox/src/providers/manager.js b/src/firefox/src/providers/manager.jsindex 36074aec4..27bbf59c3 100644--- a/src/firefox/src/providers/manager.js+++ b/src/firefox/src/providers/manager.js@@ -1167,6 +1167,23 @@ export class ProviderManager {return provider;}+ /**+ * 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.+ */+ consentedShareProviderNames() {+ const names = new Set();+ try {+ for (const provider of this.providers?.values?.() || []) {+ if (provider?.config?.shareQueriesForResearch !== true) continue;+ const name = String(provider.config.providerName || '').toLowerCase();+ if (name && name !== 'webbrain-cloud') names.add(name);+ }+ } catch {}+ return names;+ }+async _fetchVisionCapability(providerId, provider, identity) {const root = identity.baseUrl.replace(/\/v1$/i, '');const headers = this._modelListHeaders(provider);diff --git a/src/firefox/src/trace/webbrain-share-outbox.js b/src/firefox/src/trace/webbrain-share-outbox.jsindex 33e457e26..bac98e96f 100644--- a/src/firefox/src/trace/webbrain-share-outbox.js+++ b/src/firefox/src/trace/webbrain-share-outbox.js@@ -337,6 +337,26 @@ export async function enqueueShareGeneration(item) {return true;}+// Drop queued entries the predicate no longer consents to (e.g. the user+// revoked "share queries for research" after an offline/failed run queued an+// entry). Run before every flush so revocation is honored immediately before+// delivery, not just at enqueue time. Returns the dropped count.+export async function purgeShareGenerations(shouldDrop) {+ if (typeof shouldDrop !== 'function') return 0;+ let removed = 0;+ await updateOutbox(current => {+ const kept = [];+ for (const entry of current) {+ let drop = false;+ try { drop = shouldDrop(entry) === true; } catch { drop = false; }+ if (drop) removed++;+ else kept.push(entry);+ }+ return removed ? kept : current;+ });+ return removed;+}+async function flushShareOutboxNow(transportProvider) {if (typeof transportProvider?.sendShareGeneration !== 'function') return 0;await storageQueue.catch(() => {});diff --git a/test/run.js b/test/run.jsindex d5a5d9909..611f04ec5 100644--- a/test/run.js+++ b/test/run.js@@ -12710,6 +12710,15 @@ test('Share-for-research outbox persists retryable failures and removes acknowlereleaseSend();assert.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' } };+ 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(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);} finally {if (originalChrome === undefined) delete globalThis.chrome;else globalThis.chrome = originalChrome;@@ -12781,6 +12790,10 @@ test('Share-for-research delivery stays opt-in and mirrored across both builds',assert.match(chromeOutbox, /scrubText\(responseContent/, `${browser}: shared responses must get the binary scrub`);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(agent, /_purgeRevokedShareGenerations\(\)/, `${browser}: revoked shares must be purged before delivery`);+ 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`);assert.match(provider, /\/improvement\/generations/, `${browser}: share endpoint missing from the Compass provider transport`);