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(decisions): keep Auto's checks off Compass VLD Tiny v5 while another in-browser model serves the task
Claude6c7c73ad4882
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b49bf64ab..9709201a8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,7 +10,7 @@ This changelog was generated from the repository Git history and release tags. V- Compass VLD Tiny v5, a new in-browser model for Chrome: one 2.2 GB WebGPU download that chats, reads screenshots and answers WebBrain's quick decision questions on your device, with no network once it is downloaded. It is WebBrain's fine-tune of MiniCPM-V-4.7-1B and the new default local model: the first-install guide's **Download local models** button downloads it, instead of D1 and Ternary Bonsai 2 2B Vision, and Apocalypse Mode's Text Model card and Providers → WebGPU list it first. Once, on the first start after the update, a WebGPU provider that was never set up moves to it when Compass Tiny v2.1, the previous default, was never downloaded on that device. Its files are fetched at a fixed revision and each is checked against a pinned size and SHA-256 before it is used; a dropped connection retries that file. Compass Tiny v2.1 and Ternary Bonsai 2 2B Vision stay available.### Changed-- Decision models, Auto (Chrome): once Compass VLD Tiny v5 is downloaded, it checks whether tasks and scheduled runs are finished, before a downloaded D1 and in place of WebBrain Cloud's decision model, which still answers what a request asks for. As with D1, a "finished" from it is confirmed by the chat model. On d1's synthetic test, through the extension, it answered 120 of 126 questions correctly and called none of the 48 unfinished views finished; D1 answered 92 and called one finished. **In-browser chat model** under On can be chosen again and uses it. Ternary Bonsai 2 2B Vision no longer answers decisions, and a saved selection of it now uses Compass VLD Tiny v5. Firefox is unchanged.+- Decision models, Auto (Chrome): once Compass VLD Tiny v5 is downloaded, it checks whether tasks and scheduled runs are finished, before a downloaded D1 and in place of WebBrain Cloud's decision model, which still answers what a request asks for. While you chat with another in-browser model, or another in-browser model reads screenshots for a chat model that cannot see them, it leaves those checks to a downloaded D1, or else to your chat model, because loading it would unload the model you are using. As with D1, a "finished" from it is confirmed by the chat model. On d1's synthetic test, through the extension, it answered 120 of 126 questions correctly and called none of the 48 unfinished views finished; D1 answered 92 and called one finished. **In-browser chat model** under On can be chosen again and uses it. Ternary Bonsai 2 2B Vision no longer answers decisions, and a saved selection of it now uses Compass VLD Tiny v5. Firefox is unchanged.- In-browser vision (Chrome): Auto now uses Compass VLD Tiny v5 once it is downloaded, and Ternary Bonsai 2 2B Vision when only that one is. Providers → Vision and Apocalypse Mode's Vision Model card offer Compass VLD Tiny v5 as a choice.- Ask with Compass VLD Tiny v5 looks at a screenshot of the page when its own trained readout says the question needs one, in any language, as it did with Ternary Bonsai 2 2B Vision. Short follow-ups such as "And the button?" after an answer from a screenshot look again too.- The spinning ring next to "Thinking…" in the side panel is now a small WebBrain brain drawn as a neural circuit: a signal keeps tracing the W, and the brain's outline lights up as it passes. It moves only while WebBrain is working and the panel is visible, follows the light and dark themes, and holds still when your system asks to reduce motion.diff --git a/docs/providers-and-models.md b/docs/providers-and-models.mdindex 739cf6d70..37e4dd20c 100644--- a/docs/providers-and-models.md+++ b/docs/providers-and-models.md@@ -74,16 +74,23 @@ page asks one question first:- **Auto** (default) needs no setup. In Chrome, once Compass VLD Tiny v5 (thein-browser chat model, below) is downloaded on this device, it is Auto'sdecision model for completion checks and scheduled watch and completion- checks, whatever the chat provider. The Chrome install guide's **Download+ checks, whatever the chat provider, except while the task keeps another+ in-browser model loaded: a WebGPU chat model other than v5, or the+ in-browser model that reads screenshots for a provider that cannot see+ them. The WebGPU worker holds one model at a time, so a check would unload+ that model and the task's next turn or screenshot would load it again+ (`agent._inBrowserModels`). The Chrome install guide's **Downloadlocal models** button downloads it, and so does Providers → WebGPU or- Apocalypse Mode. Without it, a downloaded D1 (below) takes the same checks:+ Apocalypse Mode. Without it, or while it would unload another model, a+ downloaded D1 (below), which runs in its own worker, takes the same checks:**Download and load** under On → D1 downloads it, in both browsers, and D1serves Auto while that Download or Load stands: **Unload**, **Remove cachedmodel** and Off end it. While Compass is the chat provider, Compass'smanaged decision model keeps semantic decisions, and answers completionchecks too until one of these is downloaded. Otherwise no decision model isused. Readiness (`agent/decision-availability.js`) is the chat model's- ready marker in Cache Storage, then D1's experimental-model consent, the+ ready marker in Cache Storage and the task's in-browser models (read only+ when the chat model could answer), then D1's experimental-model consent, thestored Load request and the package's ready marker in its OPFS directory(`providers/d1-cache.js`), all read without starting the offscreen document,the Worker or the GPU. Other downloaded chat or vision models, Ternary@@ -222,8 +229,8 @@ existing checks. Strict Secret Mode disables these additional calls.| WebBrain Compass (default), no on-device decision model downloaded | Managed decision model | Active LLM, then existing checks || Explicitly selected in-browser chat model (Chrome), including with Compass | Compass VLD Tiny v5; no sole success authority | Active LLM, then existing checks || Explicitly enabled and consented D1, including with Compass | Experimental local D1; no sole success authority | Active LLM, then existing checks |-| Auto, Compass VLD Tiny v5 downloaded (Chrome; Compass included) | Compass VLD Tiny v5; no sole success authority | Active LLM, then existing checks |-| Auto, D1 downloaded and the chat model not (Compass included) | Experimental local D1; no sole success authority | Active LLM, then existing checks |+| Auto, Compass VLD Tiny v5 downloaded and no other in-browser model serving the task (Chrome; Compass included) | Compass VLD Tiny v5; no sole success authority | Active LLM, then existing checks |+| Auto, D1 downloaded and the chat model not, or serving the task would unload another in-browser model (Compass included) | Experimental local D1; no sole success authority | Active LLM, then existing checks || Other provider, completion outsourcing enabled | Selected decision model | Active LLM, then existing checks || Other provider, outsourcing disabled or unconfigured | Active LLM | Existing checks |diff --git a/docs/webgpu-models.md b/docs/webgpu-models.mdindex 05177f052..e7fcb340e 100644--- a/docs/webgpu-models.md+++ b/docs/webgpu-models.md@@ -429,7 +429,12 @@ The labelled set is d1's balanced-V3 held-out test (72 synthetic screenshots,small, so the score is close to the scaled Yes margin. In Chrome, Autouses it once it is downloaded, before a downloaded D1, for completion andscheduled checks, in place of Compass's managed route too; a saved On- selection of the in-browser chat model uses it for every decision. A+ selection of the in-browser chat model uses it for every decision. Auto+ skips it while the task keeps another model in this worker (a WebGPU chat+ model other than v5, or the in-browser screenshot reader of a provider+ that cannot see images): the worker holds one model at a time, so each+ check would unload that model and the next turn would load it again. D1,+ in its own worker, answers those checks instead. Apositive completion still needs independent proof, and the first decisionafter a browser restart, which loads the model, can exceed the judge's15-second deadline and fall back to the existing chain.diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex bc2ab4a79..683a036ac 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -9155,12 +9155,27 @@ export class Agent extends LoopDetector {return image;}+ // The in-browser models a task on `provider` keeps in the offscreen WebGPU+ // worker: its chat model, and the model reading its screenshots when it+ // cannot see them (Providers → Vision). Auto's decisions stay off that+ // worker while one of them is another model (decision-availability.js+ // chatDecisionModelFree). Storage and Cache Storage lookups only.+ async _inBrowserModels(provider) {+ if (!provider) return [];+ const models = this._isInBrowserProvider(provider) && provider.model ? [provider.model] : [];+ if (!provider.supportsVision) {+ const route = await this._resolveVisionRoute(null, provider);+ if (route?.route === 'local_fallback' && route.provider?.model) models.push(route.provider.model);+ }+ return models;+ }+// The decision settings when the decision model answers `feature`// (decision-config.js DECISION_FEATURES), otherwise null.async _jevSettings(tabId, provider = this._activeProvider(tabId), feature = 'semantic') {const stored = await chrome.storage.local.get([...JEV_FAST_KEYS, ...DECISION_SETTINGS_KEYS]);const compass = provider?.config?.providerName === 'webbrain-cloud' ? provider.config : null;- const decisionConfig = await resolveCurrentDecisionConfig(stored, compass, { feature });+ const decisionConfig = await resolveCurrentDecisionConfig(stored, compass, { feature, inBrowserModels: () => this._inBrowserModels(provider) });return decisionFeatureEnabled(decisionConfig, feature) && !this.strictSecretMode && (decisionConfig.local || globalThis.navigator?.onLine !== false) ? { ...stored, decisionConfig } : null;}diff --git a/src/chrome/src/agent/completion-runtime.js b/src/chrome/src/agent/completion-runtime.jsindex 28dcf0700..d5fe6daa1 100644--- a/src/chrome/src/agent/completion-runtime.js+++ b/src/chrome/src/agent/completion-runtime.js@@ -331,7 +331,9 @@ async function evaluateBrowserCompletion(agent, tabId, options = {}) {}const stored = await chrome.storage.local.get(DECISION_SETTINGS_KEYS);const compass = provider.config?.providerName === 'webbrain-cloud' ? provider.config : null;- const config = await resolveCurrentDecisionConfig(stored, compass, { feature: 'done' });+ // The models this task keeps in the in-browser worker, which a decision must not unload.+ const inBrowserModels = () => agent._inBrowserModels?.(provider);+ const config = await resolveCurrentDecisionConfig(stored, compass, { feature: 'done', inBrowserModels });const context = agent.systemOneContext(tabId);const signal = agent._runAbortSignal(tabId);const guard = agent._planExecutionGuards.get(tabId);@@ -343,7 +345,7 @@ async function evaluateBrowserCompletion(agent, tabId, options = {}) {&& (!calculationEvidence || captureCalculationEvidence(agent, tabId, calculationEvidence))&& scope === JSON.stringify([agent.completionInvariants.get(tabId)?.runToken, agent.completionInvariants.get(tabId)?.lastAction?.sequence, agent._progressTaskKeyHash(tabId), config.provider, config.model, config.url, provider.model, provider.supportsVision, JSON.stringify(config)]);const currentIdentity = async evidence => !!evidence.identity && currentRun()- && JSON.stringify(await resolveCurrentDecisionConfig(await chrome.storage.local.get(DECISION_SETTINGS_KEYS), compass, { feature: 'done' })) === JSON.stringify(config)+ && JSON.stringify(await resolveCurrentDecisionConfig(await chrome.storage.local.get(DECISION_SETTINGS_KEYS), compass, { feature: 'done', inBrowserModels })) === JSON.stringify(config)&& evidence.identity === await agent._completionDocumentStamp(tabId, true) && currentRun();const current = async evidence => {if (!await currentIdentity(evidence)) return false;diff --git a/src/chrome/src/agent/decision-availability.js b/src/chrome/src/agent/decision-availability.jsindex 6079762d5..4404c30c5 100644--- a/src/chrome/src/agent/decision-availability.js+++ b/src/chrome/src/agent/decision-availability.js@@ -12,8 +12,8 @@ import { d1PackageReady } from '../providers/d1-cache.js';// while the user's Download or Load stands: Unload, Remove cached model and// switching decisions Off end it (background.js d1_control). The lookup is one// storage read and D1's ready marker, without the offscreen document or the-// GPU, so per-check callers can afford it. A downloaded chat or vision model-// never enables decisions.+// GPU, so per-check callers can afford it. Of the downloaded chat and vision+// models, only Compass VLD Tiny v5 enables decisions (chatDecisionModelReady).export async function d1LocalAssistReady(api = globalThis.browser || globalThis.chrome, storageManager = globalThis.navigator?.storage) {try {const stored = await api.storage.local.get(D1_KEEP_LOADED_KEY);@@ -37,11 +37,27 @@ export async function chatDecisionModelReady(cacheStorage = globalThis.caches) {} catch { return false; }}+// The offscreen WebGPU worker holds one in-browser model at a time. Asking+// Compass VLD Tiny v5 a question would unload another model a task keeps there+// (its chat model, or the one reading its screenshots), and the task's next+// turn or screenshot would load that one again. `inBrowserModels` lists the+// task's own (agent.js _inBrowserModels), or is a function that returns them,+// called only when the answer matters. Auto asks the chat model only while+// they are that model or none; when they cannot be read, it does not.+export async function chatDecisionModelFree(inBrowserModels = null) {+ try {+ const models = typeof inBrowserModels === 'function' ? await inBrowserModels() : inBrowserModels;+ return Array.from(models || [], model => String(model || '').trim()).every(model => model === WEBGPU_CHAT_DECISION_MODEL);+ } catch { return false; }+}+// The decision configuration that applies right now, for `feature` when the// caller names the decision it asks (decision-config.js DECISION_FEATURES).-// Auto uses the in-browser chat model when it is downloaded, else D1.-export async function resolveCurrentDecisionConfig(stored = {}, compass = null, { feature = null } = {}) {- const chatAssistReady = decisionNeedsChatAssist(stored, compass, feature) && await chatDecisionModelReady();+// Auto uses the in-browser chat model when it is downloaded and free for the+// task (`inBrowserModels`, chatDecisionModelFree), else D1.+export async function resolveCurrentDecisionConfig(stored = {}, compass = null, { feature = null, inBrowserModels = null } = {}) {+ const chatAssistReady = decisionNeedsChatAssist(stored, compass, feature)+ && await chatDecisionModelReady() && await chatDecisionModelFree(inBrowserModels);const localAssistReady = !chatAssistReady && decisionNeedsLocalAssist(stored, compass, feature) && await d1LocalAssistReady();return resolveDecisionConfig(stored, compass, { localAssistReady, chatAssistReady, feature });}diff --git a/src/chrome/src/agent/scheduler.js b/src/chrome/src/agent/scheduler.jsindex 0b6835917..5e7df9a45 100644--- a/src/chrome/src/agent/scheduler.js+++ b/src/chrome/src/agent/scheduler.js@@ -1736,7 +1736,10 @@ export class ScheduledJobManager {|| null;const compass = runMeta.compass?? (String(activeProvider?.config?.providerName || '').trim().toLowerCase() === 'webbrain-cloud' ? activeProvider.config : null);- const config = runMeta.decisionConfig || await resolveCurrentDecisionConfig(settings, compass, { feature: isWatch ? 'watch' : 'completion' });+ const config = runMeta.decisionConfig || await resolveCurrentDecisionConfig(settings, compass, {+ feature: isWatch ? 'watch' : 'completion',+ inBrowserModels: () => this.agent?._inBrowserModels?.(activeProvider),+ });if (!this.systemOneJudge || !decisionFeatureEnabled(config, isWatch ? 'watch' : 'completion')) return skip('disabled');if (settings.strictSecretMode || runMeta.sidecarAllowed === false || runMeta.signal?.aborted) return skip('unavailable');const state = systemOneEvidenceState(job.prompt || job.resumeInstruction || job.reason || '', runMeta.evidence, isWatch ? job.watch?.systemOneBaseline : null);diff --git a/src/chrome/src/background.js b/src/chrome/src/background.jsindex 05e079d68..98af690ae 100644--- a/src/chrome/src/background.js+++ b/src/chrome/src/background.js@@ -3503,15 +3503,27 @@ async function d1UsedForDecisions(api) {if (agent.strictSecretMode) return false;if (providerManager.providers.size === 0) await providerManager.load();let compass = null;+ let provider = null;try {- const provider = providerManager.getActive();+ provider = providerManager.getActive();if (provider?.config?.providerName === 'webbrain-cloud') compass = provider.config;} catch { /* no active provider yet */ }- const config = await resolveCurrentDecisionConfig(await api.storage.local.get(DECISION_SETTINGS_KEYS), compass);+ const config = await resolveCurrentDecisionConfig(await api.storage.local.get(DECISION_SETTINGS_KEYS), compass,+ { inBrowserModels: () => agent._inBrowserModels(provider) });return config.provider === 'webgpu_d1' && config.enabled === true;} catch { return false; }}+// The in-browser models the active provider's tasks keep loaded (agent.js+// _inBrowserModels), so what Settings tests and shows for Auto is what the+// agent uses (decision-availability.js chatDecisionModelFree).+async function activeInBrowserModels() {+ if (providerManager.providers.size === 0) await providerManager.load();+ let provider = null;+ try { provider = providerManager.getActive(); } catch { /* no active provider yet */ }+ return agent._inBrowserModels(provider);+}+async function handleMessage(msg, sender) {if (msg.action === 'failure_recovery_response') return handleFailureRecoveryResponse(msg, sender);if (['chat_start', 'chat', 'chat_stream'].includes(msg.action)) assertChatRequestInput(msg);@@ -4949,6 +4961,11 @@ async function handleMessage(msg, sender) {readiness: await providerManager.getWebgpuVisionReadiness(),};}+ case 'get_in_browser_models': {+ // Settings' Auto decision status follows the agent's rule+ // (decision-availability.js chatDecisionModelFree).+ return { ok: true, models: await activeInBrowserModels() };+ }case 'set_webgpu_vision_choice': {// Choosing WebBrain VL 2 450M can re-enable it under consent already// given, so only the two pages that show the choice may change it.@@ -5078,7 +5095,7 @@ async function handleMessage(msg, sender) {// would use now, and there is nothing to test when it uses nothing.const testsConfigured = !msg.settings || ['on', undefined].includes(msg.settings.decisionMode);// Auto's D1 needs the experimental-model consent the draft does not carry.- let config = msg.settings ? (testsConfigured ? resolveDecisionConfig({ ...msg.settings, decisionMode: 'on' }) : await resolveCurrentDecisionConfig({ ...await chrome.storage.local.get(D1_CONSENT_KEY), ...msg.settings })) : undefined;+ let config = msg.settings ? (testsConfigured ? resolveDecisionConfig({ ...msg.settings, decisionMode: 'on' }) : await resolveCurrentDecisionConfig({ ...await chrome.storage.local.get(D1_CONSENT_KEY), ...msg.settings }, null, { inBrowserModels: activeInBrowserModels })) : undefined;if (config && !testsConfigured && !config.enabled) throw new Error('No decision model is in use.');if (config?.provider === 'openrouter' && (!msg.settings.decisionVisionMode || msg.settings.decisionVisionMode === 'auto')) {try { const card = (await listDecisionModels(config)).find(m => m.id === config.model); if (card) config = { ...config, supportsVision: card.supportsVision }; } catch {}diff --git a/src/chrome/src/ui/settings.js b/src/chrome/src/ui/settings.jsindex 97bad7aa3..b19e7847e 100644--- a/src/chrome/src/ui/settings.js+++ b/src/chrome/src/ui/settings.js@@ -1,7 +1,7 @@import { DECISION_MODE_KEY, DECISION_SETTINGS_KEYS, materializeLegacyDecisionFeatures, DEFAULT_DECISION_MODEL, WEBGPU_CHAT_DECISION_MODEL, resolveDecisionConfig, resolveDecisionMode } from '../agent/decision-config.js';import { normalizeLeanModeSetting } from '../agent/lean-mode.js';import { D1_CONSENT_KEY, D1_CONSENT_VERSION, D1_MODEL_ID } from '../providers/d1-config.js';-import { chatDecisionModelReady, d1LocalAssistReady } from '../agent/decision-availability.js';+import { chatDecisionModelFree, chatDecisionModelReady, d1LocalAssistReady } from '../agent/decision-availability.js';import { initD1Settings } from './d1-settings.js';/*** WebBrain Settings pages — settings.html (preferences, budgets, memory,@@ -316,9 +316,11 @@ async function syncDecisionStatus() {// Strict Secret Mode keeps page content away from every decision model, so Auto has nothing to use.const strict = strictSecretModeOn;const compass = !strict && activeProviderIsCompass();- // Auto uses Compass VLD Tiny v5 once it is downloaded, else D1, Compass or- // not (decision-availability.js).- const chatModel = !strict && await chatDecisionModelReady();+ // Auto uses Compass VLD Tiny v5 once it is downloaded, unless the active+ // provider keeps another in-browser model loaded, else D1, Compass or not+ // (decision-availability.js).+ const chatModel = !strict && await chatDecisionModelReady()+ && await chatDecisionModelFree(() => sendToBackground('get_in_browser_models').then(result => result?.models));const local = !strict && !chatModel&& (await chrome.storage.local.get(D1_CONSENT_KEY).catch(() => ({})))?.[D1_CONSENT_KEY] === D1_CONSENT_VERSION&& await d1LocalAssistReady();diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 45af823c6..85b4dcc58 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -8864,12 +8864,18 @@ export class Agent extends LoopDetector {return image;}+ // Firefox runs no in-browser models; Chrome lists a task's own here for its+ // decision routing (decision-availability.js chatDecisionModelFree).+ async _inBrowserModels() {+ return [];+ }+// The decision settings when the decision model answers `feature`// (decision-config.js DECISION_FEATURES), otherwise null.async _jevSettings(tabId, provider = this._activeProvider(tabId), feature = 'semantic') {const stored = await browser.storage.local.get([...JEV_FAST_KEYS, ...DECISION_SETTINGS_KEYS]);const compass = provider?.config?.providerName === 'webbrain-cloud' ? provider.config : null;- const decisionConfig = await resolveCurrentDecisionConfig(stored, compass, { feature });+ const decisionConfig = await resolveCurrentDecisionConfig(stored, compass, { feature, inBrowserModels: () => this._inBrowserModels(provider) });return decisionFeatureEnabled(decisionConfig, feature) && !this.strictSecretMode && (decisionConfig.local || globalThis.navigator?.onLine !== false) ? { ...stored, decisionConfig } : null;}diff --git a/src/firefox/src/agent/completion-runtime.js b/src/firefox/src/agent/completion-runtime.jsindex 28dcf0700..d5fe6daa1 100644--- a/src/firefox/src/agent/completion-runtime.js+++ b/src/firefox/src/agent/completion-runtime.js@@ -331,7 +331,9 @@ async function evaluateBrowserCompletion(agent, tabId, options = {}) {}const stored = await chrome.storage.local.get(DECISION_SETTINGS_KEYS);const compass = provider.config?.providerName === 'webbrain-cloud' ? provider.config : null;- const config = await resolveCurrentDecisionConfig(stored, compass, { feature: 'done' });+ // The models this task keeps in the in-browser worker, which a decision must not unload.+ const inBrowserModels = () => agent._inBrowserModels?.(provider);+ const config = await resolveCurrentDecisionConfig(stored, compass, { feature: 'done', inBrowserModels });const context = agent.systemOneContext(tabId);const signal = agent._runAbortSignal(tabId);const guard = agent._planExecutionGuards.get(tabId);@@ -343,7 +345,7 @@ async function evaluateBrowserCompletion(agent, tabId, options = {}) {&& (!calculationEvidence || captureCalculationEvidence(agent, tabId, calculationEvidence))&& scope === JSON.stringify([agent.completionInvariants.get(tabId)?.runToken, agent.completionInvariants.get(tabId)?.lastAction?.sequence, agent._progressTaskKeyHash(tabId), config.provider, config.model, config.url, provider.model, provider.supportsVision, JSON.stringify(config)]);const currentIdentity = async evidence => !!evidence.identity && currentRun()- && JSON.stringify(await resolveCurrentDecisionConfig(await chrome.storage.local.get(DECISION_SETTINGS_KEYS), compass, { feature: 'done' })) === JSON.stringify(config)+ && JSON.stringify(await resolveCurrentDecisionConfig(await chrome.storage.local.get(DECISION_SETTINGS_KEYS), compass, { feature: 'done', inBrowserModels })) === JSON.stringify(config)&& evidence.identity === await agent._completionDocumentStamp(tabId, true) && currentRun();const current = async evidence => {if (!await currentIdentity(evidence)) return false;diff --git a/src/firefox/src/agent/decision-availability.js b/src/firefox/src/agent/decision-availability.jsindex 6079762d5..4404c30c5 100644--- a/src/firefox/src/agent/decision-availability.js+++ b/src/firefox/src/agent/decision-availability.js@@ -12,8 +12,8 @@ import { d1PackageReady } from '../providers/d1-cache.js';// while the user's Download or Load stands: Unload, Remove cached model and// switching decisions Off end it (background.js d1_control). The lookup is one// storage read and D1's ready marker, without the offscreen document or the-// GPU, so per-check callers can afford it. A downloaded chat or vision model-// never enables decisions.+// GPU, so per-check callers can afford it. Of the downloaded chat and vision+// models, only Compass VLD Tiny v5 enables decisions (chatDecisionModelReady).export async function d1LocalAssistReady(api = globalThis.browser || globalThis.chrome, storageManager = globalThis.navigator?.storage) {try {const stored = await api.storage.local.get(D1_KEEP_LOADED_KEY);@@ -37,11 +37,27 @@ export async function chatDecisionModelReady(cacheStorage = globalThis.caches) {} catch { return false; }}+// The offscreen WebGPU worker holds one in-browser model at a time. Asking+// Compass VLD Tiny v5 a question would unload another model a task keeps there+// (its chat model, or the one reading its screenshots), and the task's next+// turn or screenshot would load that one again. `inBrowserModels` lists the+// task's own (agent.js _inBrowserModels), or is a function that returns them,+// called only when the answer matters. Auto asks the chat model only while+// they are that model or none; when they cannot be read, it does not.+export async function chatDecisionModelFree(inBrowserModels = null) {+ try {+ const models = typeof inBrowserModels === 'function' ? await inBrowserModels() : inBrowserModels;+ return Array.from(models || [], model => String(model || '').trim()).every(model => model === WEBGPU_CHAT_DECISION_MODEL);+ } catch { return false; }+}+// The decision configuration that applies right now, for `feature` when the// caller names the decision it asks (decision-config.js DECISION_FEATURES).-// Auto uses the in-browser chat model when it is downloaded, else D1.-export async function resolveCurrentDecisionConfig(stored = {}, compass = null, { feature = null } = {}) {- const chatAssistReady = decisionNeedsChatAssist(stored, compass, feature) && await chatDecisionModelReady();+// Auto uses the in-browser chat model when it is downloaded and free for the+// task (`inBrowserModels`, chatDecisionModelFree), else D1.+export async function resolveCurrentDecisionConfig(stored = {}, compass = null, { feature = null, inBrowserModels = null } = {}) {+ const chatAssistReady = decisionNeedsChatAssist(stored, compass, feature)+ && await chatDecisionModelReady() && await chatDecisionModelFree(inBrowserModels);const localAssistReady = !chatAssistReady && decisionNeedsLocalAssist(stored, compass, feature) && await d1LocalAssistReady();return resolveDecisionConfig(stored, compass, { localAssistReady, chatAssistReady, feature });}diff --git a/src/firefox/src/agent/scheduler.js b/src/firefox/src/agent/scheduler.jsindex 330f50322..9c730f18f 100644--- a/src/firefox/src/agent/scheduler.js+++ b/src/firefox/src/agent/scheduler.js@@ -1712,7 +1712,10 @@ export class ScheduledJobManager {|| null;const compass = runMeta.compass?? (String(activeProvider?.config?.providerName || '').trim().toLowerCase() === 'webbrain-cloud' ? activeProvider.config : null);- const config = runMeta.decisionConfig || await resolveCurrentDecisionConfig(settings, compass, { feature: isWatch ? 'watch' : 'completion' });+ const config = runMeta.decisionConfig || await resolveCurrentDecisionConfig(settings, compass, {+ feature: isWatch ? 'watch' : 'completion',+ inBrowserModels: () => this.agent?._inBrowserModels?.(activeProvider),+ });if (!this.systemOneJudge || !decisionFeatureEnabled(config, isWatch ? 'watch' : 'completion')) return skip('disabled');if (settings.strictSecretMode || runMeta.sidecarAllowed === false || runMeta.signal?.aborted) return skip('unavailable');const state = systemOneEvidenceState(job.prompt || job.resumeInstruction || job.reason || '', runMeta.evidence, isWatch ? job.watch?.systemOneBaseline : null);diff --git a/test/completion-verifier.mjs b/test/completion-verifier.mjsindex e3dbccf4c..5b0803aad 100644--- a/test/completion-verifier.mjs+++ b/test/completion-verifier.mjs@@ -592,6 +592,36 @@ for (const build of ['chrome', 'firefox']) {assert.equal(mainCalls, expected.mainCalls, decisionOutcome);}}, { decisionMode: 'on', decisionProvider: 'webgpu_chat', systemOneEnabled: true, systemOneDoneEnabled: true }));+ // The in-browser worker holds one model at a time: a check on the chat+ // decision model would unload the task's own in-browser model.+ test(`${build}: Auto checks completion with the downloaded chat model only while the task keeps no other in-browser model loaded`, withDecisionRuntime(async () => {+ const { webgpuTextReadyMarkerUrl, WEBGPU_LOCAL_ASSIST_MODEL_ID } = await import('../src/chrome/src/providers/webgpu-model-cache.js');+ const cachesDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'caches');+ const marker = webgpuTextReadyMarkerUrl(WEBGPU_LOCAL_ASSIST_MODEL_ID);+ globalThis.caches = { match: async (url, options = {}) => (options.cacheName === 'transformers-cache' && url === marker ? new Response('{}') : undefined) };+ try {+ for (const [inBrowserModels, asked] of [[[], build === 'chrome'], [['webbrain-one/webbrain-compass-tiny-v2.1'], false]]) {+ const providers = [];+ let mainCalls = 0;+ const agent = stagedFormAgent({ messages: [], guard: { enabled: true, requiresSubmission: false, requiresStateChange: true }, captures: { count: 0 }, decisionOutcome: 'pending',+ onDecision: args => providers.push(args.config.provider),+ onChat: () => { mainCalls++; return { content: JSON.stringify({ outcome: 'failed', reason: 'the page still shows the form' }) }; } });+ agent._inBrowserModels = async provider => { assert.equal(provider, agent._activeProvider(1)); return inBrowserModels; };+ const verdict = await runtime.verifyBrowserCompletion(agent, 1, { pageUrl: 'https://forms.example/signup' });+ const label = JSON.stringify(inBrowserModels);+ if (asked) {+ assert.ok(providers.length > 0 && providers.every(provider => provider === 'webgpu_chat'), `${label}: the chat model answered`);+ assert.equal(verdict.engine, 'webgpu_chat', label);+ } else {+ assert.deepEqual(providers, [], `${label}: no decision model was asked`);+ assert.equal(verdict.engine, 'llm', label);+ assert.equal(mainCalls, 1, label);+ }+ }+ } finally {+ if (cachesDescriptor) Object.defineProperty(globalThis, 'caches', cachesDescriptor); else delete globalThis.caches;+ }+ }, { decisionMode: 'auto' }));test(`${build}: Auto checks completion with a downloaded D1, and a positive D1 answer still needs the main model`, async () => {const pin = await import(`../src/${build}/src/providers/d1-config.js`);const previousChrome = globalThis.chrome, previousBrowser = globalThis.browser;diff --git a/test/decision-mode.mjs b/test/decision-mode.mjsindex e4ab68228..f36935a8c 100644--- a/test/decision-mode.mjs+++ b/test/decision-mode.mjs@@ -7,7 +7,7 @@ const area = { get: async () => ({}), set: async () => {} };globalThis.chrome = globalThis.browser = { storage: { local: area, session: area }, runtime: { getURL: x => x, sendMessage: async () => ({}) } };const cache = await import('../src/chrome/src/providers/webgpu-model-cache.js');-const { WEBGPU_BONSAI2_VL_2B_MODEL_ID } = await import('../src/chrome/src/providers/webgpu.js');+const { WEBGPU_BONSAI2_VL_2B_MODEL_ID, WEBGPU_COMPASS_TINY_V2_MODEL_ID, WEBGPU_VISION_MODEL_ID } = await import('../src/chrome/src/providers/webgpu.js');// Compass VLD Tiny v5, the in-browser chat model fine-tuned for decisions, and// Ternary Bonsai 2 2B Vision, a chat model that reads screenshots but whose// decisions failed validation.@@ -238,6 +238,87 @@ for (const build of ['chrome', 'firefox']) {});});+ // The offscreen WebGPU worker holds one in-browser model at a time: a check+ // on the chat decision model would unload the task's own chat or screenshot+ // model, and its next turn or screenshot would load that again.+ test(`${build}: Auto asks the in-browser chat model only while the task keeps no other in-browser model loaded`, async () => {+ const V5 = config.WEBGPU_CHAT_DECISION_MODEL;+ assert.equal(await availability.chatDecisionModelFree(), true, 'a task with no in-browser model');+ assert.equal(await availability.chatDecisionModelFree([]), true);+ assert.equal(await availability.chatDecisionModelFree([V5]), true, 'a task on the chat decision model itself shares it');+ assert.equal(await availability.chatDecisionModelFree([V5, WEBGPU_VISION_MODEL_ID]), false);+ assert.equal(await availability.chatDecisionModelFree(async () => [WEBGPU_COMPASS_TINY_V2_MODEL_ID]), false);+ assert.equal(await availability.chatDecisionModelFree(async () => { throw new Error('unreadable'); }), false,+ 'when the task cannot say what it keeps loaded, the chat model is not asked');+ const asked = [];+ const models = list => async () => { asked.push(list); return list; };+ await withModelCache([CHAT_DECISION_MARKER], async () => {+ const busy = await availability.resolveCurrentDecisionConfig({}, null, { feature: 'done', inBrowserModels: models([WEBGPU_COMPASS_TINY_V2_MODEL_ID]) });+ assert.equal(busy.source, 'none', 'with another in-browser model serving the task, the check stays with the main model');+ const shared = await availability.resolveCurrentDecisionConfig({}, COMPASS, { feature: 'watch', inBrowserModels: models([V5]) });+ assert.equal(shared.provider, build === 'chrome' ? 'webgpu_chat' : 'compass');+ assert.equal(asked.length, build === 'chrome' ? 2 : 0, 'Firefox never asks');+ asked.length = 0;+ await availability.resolveCurrentDecisionConfig({ decisionMode: 'off' }, null, { inBrowserModels: models([]) });+ await availability.resolveCurrentDecisionConfig({ decisionMode: 'on', decisionProvider: 'local' }, null, { inBrowserModels: models([]) });+ await availability.resolveCurrentDecisionConfig({}, COMPASS, { feature: 'semantic', inBrowserModels: models([]) });+ assert.deepEqual(asked, [], 'only a check Auto could give the chat model reads them');+ });+ await withModelCache([], async () => {+ await availability.resolveCurrentDecisionConfig({}, null, { inBrowserModels: models([]) });+ assert.deepEqual(asked, [], 'nor without its download');+ });+ await withD1Download(pin, {}, async ({ consent }) => {+ await withModelCache([CHAT_DECISION_MARKER], async () => {+ const local = await availability.resolveCurrentDecisionConfig(consent, null, { feature: 'done', inBrowserModels: [WEBGPU_COMPASS_TINY_V2_MODEL_ID] });+ assert.equal(local.provider, 'webgpu_d1', 'D1, in its own worker, takes the checks instead');+ });+ });+ });++ test(`${build}: a task's in-browser models are its WebGPU chat model and the in-browser model reading its screenshots`, async () => {+ const V5 = config.WEBGPU_CHAT_DECISION_MODEL;+ const { Agent } = await import(`../src/${build}/src/agent/agent.js`);+ const routes = [];+ let route = { provider: { model: WEBGPU_VISION_MODEL_ID }, route: 'local_fallback' };+ const agent = new Agent({ getActive: () => ({ config: {} }), resolveVisionRoute: async provider => { routes.push(provider); return route; } });+ const webgpu = (model, supportsVision) => ({ name: 'webgpu', model, supportsVision, config: {} });+ const textOnly = { name: 'deepseek', model: 'deepseek-chat', supportsVision: false, config: {} };+ if (build === 'firefox') {+ assert.deepEqual(await agent._inBrowserModels(webgpu(WEBGPU_COMPASS_TINY_V2_MODEL_ID, false)), [], 'Firefox runs no in-browser models');+ assert.deepEqual(routes, []);+ return;+ }+ assert.deepEqual(await agent._inBrowserModels(null), []);+ assert.deepEqual(await agent._inBrowserModels(webgpu(V5, true)), [V5]);+ assert.deepEqual(await agent._inBrowserModels({ name: 'anthropic', model: 'claude', supportsVision: true, config: {} }), []);+ assert.deepEqual(routes, [], 'a provider that sees screenshots needs no reader');+ assert.deepEqual(await agent._inBrowserModels(webgpu(WEBGPU_COMPASS_TINY_V2_MODEL_ID, false)), [WEBGPU_COMPASS_TINY_V2_MODEL_ID, WEBGPU_VISION_MODEL_ID]);+ assert.deepEqual(await agent._inBrowserModels(textOnly), [WEBGPU_VISION_MODEL_ID], 'a text-only provider keeps its screenshot reader loaded');+ route = { provider: { model: 'gpt-4o-mini' }, route: 'explicit_override', rawImage: false };+ assert.deepEqual(await agent._inBrowserModels(textOnly), [], 'an external endpoint reads them outside the browser');+ // Auto's completion checks follow them.+ await withModelCache([CHAT_DECISION_MARKER], async () => {+ assert.equal(await agent._jevSettings(1, webgpu(WEBGPU_COMPASS_TINY_V2_MODEL_ID, false), 'done'), null,+ 'a check would unload the chat model the task runs on');+ assert.equal((await agent._jevSettings(1, webgpu(V5, true), 'done'))?.decisionConfig.provider, 'webgpu_chat');+ });+ });++ test(`${build}: scheduled checks leave the in-browser chat model alone while the task keeps another in-browser model loaded`, async () => {+ const judge = { evaluate: async () => { throw new Error('no decision model is in use'); } };+ const h = makeSchedulerHarness(scheduler, { systemOneJudge: judge });+ const providers = [];+ h.manager.agent._inBrowserModels = async provider => { providers.push(provider); return [WEBGPU_COMPASS_TINY_V2_MODEL_ID]; };+ const provider = { name: 'webgpu', model: WEBGPU_COMPASS_TINY_V2_MODEL_ID, config: {} };+ await withModelCache([CHAT_DECISION_MARKER], async () => {+ const verdict = await h.manager._evaluateSystemOne({ source: 'watch', prompt: 'Watch status', tabId: 77 }, '', 'success',+ { settings: {}, evidence: { observations: [{ data: 'Status: done' }] }, provider });+ assert.equal(verdict.reason, 'disabled');+ assert.deepEqual(providers, build === 'chrome' ? [provider] : []);+ });+ });+test(`${build}: Auto uses the downloaded chat decision model for its own checks, before D1 and never over a saved choice`, async () => {const ready = config.resolveDecisionConfig({ decisionVisionMode: 'off', decisionProvider: 'openrouter', systemOneFastBrowser: true }, null, { chatAssistReady: true });if (build === 'firefox') {diff --git a/test/systemone-ui.mjs b/test/systemone-ui.mjsindex b30d280ff..31fd7704f 100644--- a/test/systemone-ui.mjs+++ b/test/systemone-ui.mjs@@ -79,7 +79,8 @@ function installStub({ lang, build, version, seed = {} }) {webbrain_cloud: { label: 'WebBrain Cloud', category: 'cloud', providerName: 'webbrain-cloud', configured: true } }, active: sessionStorage.getItem('active-provider') || 'llamacpp' }: msg.action === 'test_system_one' ? { success: true, model: msg.settings?.decisionModel || 'jev-1.13.0', visionVerified: msg.settings?.decisionProvider === 'openrouter' }: msg.action === 'list_decision_models' ? { success: true, models: [{ id: 'cloudflare/clef-flash', name: 'Decider', supportsVision: true, inputRate: .02, outputRate: 0 }, { id: 'another/publisher', name: 'Another decision model', supportsVision: false, inputRate: .1, outputRate: 0 }] }- : msg.action === 'get_user_memory' ? { ok: true, enabled: true, records: [] } : {};+ : msg.action === 'get_user_memory' ? { ok: true, enabled: true, records: [] }+ : msg.action === 'get_in_browser_models' ? { ok: true, models: window.testInBrowserModels || [] } : {};callback?.(result); return Promise.resolve(result);} },commands: { getAll: async () => [] }, tabs: { create: async () => ({}) },@@ -151,6 +152,16 @@ try {assert.equal(await page.locator('#btn-test-system-one').isVisible(), true, 'the chat model runs here, so Auto can test it');await page.locator('#system-one-card').screenshot({ animations: 'disabled', caret: 'hide', path: `${output}/${build}-${lang}-${width}-auto-chat-model.png` });assert.equal(await page.evaluate(() => testRequests.filter(r => r.action === 'test_system_one').length), 0);+ // While the active provider keeps another in-browser model loaded, a+ // check would unload it, so Auto does not use the chat model.+ await page.evaluate(() => { window.testInBrowserModels = ['webbrain-one/webbrain-compass-tiny-v2.1']; dispatchEvent(new Event('focus')); });+ await page.waitForFunction(() => document.querySelector('#decision-auto-status').dataset.state === 'inactive');+ assert.doesNotMatch(await statusText(), /Compass VLD Tiny v5/);+ assert.equal(await page.locator('#btn-test-system-one').isVisible(), false);+ await page.evaluate(() => { window.testInBrowserModels = ['webbrain-one/webbrain-compass-vld-tiny-v5-onnx']; dispatchEvent(new Event('focus')); });+ await page.waitForFunction(() => document.querySelector('#decision-auto-status').dataset.state === 'active');+ assert.match(await statusText(), /Compass VLD Tiny v5/, 'a provider chatting on the chat decision model shares it');+ await page.evaluate(() => { delete window.testInBrowserModels; });await page.evaluate(async () => { await caches.delete('transformers-cache'); dispatchEvent(new Event('focus')); });await page.waitForFunction(() => document.querySelector('#decision-auto-status').dataset.state === 'inactive');}