Skip to content

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

fix(agent): verify moving visual evidence with fresh AX

Emre Sokullu09547141c638
diff --git a/docs/providers-and-models.md b/docs/providers-and-models.md
index 6dcf4389a..59bef4d77 100644
--- a/docs/providers-and-models.md
+++ b/docs/providers-and-models.md
@@ -33,7 +33,18 @@ Verify completion (`done`) defaults on when outsourcing is configured, with a
90% acceptance threshold separate from the scheduled-check threshold. Compass
always uses its managed `/v1/decisions` route regardless of personal decision
settings. The fallback chain is decision model, active LLM, then existing
-completion checks. Each judge prefers a fresh screenshot and tries AX if images
+completion checks. These outsourcing toggles control the decision model only;
+with outsourcing disabled or unconfigured, completion still uses a dedicated
+call to the active LLM, subject to its normal cost allowance, followed by the
+existing checks. Strict Secret Mode disables these additional calls.
+
+| Active provider | First completion verifier | Fallback |
+| --- | --- | --- |
+| WebBrain Compass | Managed decision model | 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 |
+
+Each judge prefers a fresh screenshot and tries AX if images
are unavailable or inconclusive. Confident pending/failed results require
recovery. Accepted fresh proof can establish generic publication evidence;
explicit recipient, payment, download, authorization and workflow contracts
diff --git a/src/chrome/src/agent/completion-runtime.js b/src/chrome/src/agent/completion-runtime.js
index 7a3662c35..af4e598dd 100644
--- a/src/chrome/src/agent/completion-runtime.js
+++ b/src/chrome/src/agent/completion-runtime.js
@@ -49,8 +49,12 @@ async function evaluateBrowserCompletion(agent, tabId, { pageState = {}, pageUrl
// new redacted, budgeted capture after the request; never reuse that cache.
let fresh;
try { fresh = await capture('vision', true); }
- catch (error) { if (completionStopError(error, signal)) throw error; return false; }
- return fresh?.key === (evidence.key || evidence.evidenceKey) && await currentIdentity(evidence);
+ catch (error) { if (completionStopError(error, signal)) throw error; }
+ if (!await currentIdentity(evidence)) return false;
+ if (fresh?.key === (evidence.key || evidence.evidenceKey)) return true;
+ // Moving pixels cannot certify the old image, but need not mean the task
+ // changed. Discard that verdict and judge a fresh AX read instead.
+ throw Object.assign(new Error('Visual evidence changed or could not be refreshed.'), { code: 'COMPLETION_VISUAL_CHANGED' });
};
const messages = agent.conversations.get(tabId) || [];
const toolNames = new Map(messages.flatMap(m => (m.tool_calls || []).map(call => [call.id, call.function?.name])));
@@ -96,7 +100,11 @@ async function evaluateBrowserCompletion(agent, tabId, { pageState = {}, pageUrl
return evidence;
};
const prior = agent._completionVerdicts.get(tabId);
- if (prior?.scope === scope && prior.outcome !== 'uncertain' && await current(prior)) {
+ const priorCurrent = prior?.scope === scope && prior.outcome !== 'uncertain' && await current(prior).catch(error => {
+ if (error?.code === 'COMPLETION_VISUAL_CHANGED') return false;
+ throw error;
+ });
+ if (priorCurrent) {
const fresh = await capture(prior.modality);
if (fresh?.key === prior.evidenceKey) return prior;
}
@@ -113,6 +121,8 @@ async function evaluateBrowserCompletion(agent, tabId, { pageState = {}, pageUrl
return decisionCompletionVerdict(result, config.threshold);
},
} : null;
+ // These switches outsource checks to the decision sidecar. The approved
+ // routing still uses the active LLM when that sidecar is off/unconfigured.
const llm = typeof provider.chat === 'function' && (online || provider.config?.category === 'local') ? {
name: 'llm', supportsVision: provider.supportsVision,
evaluate: async (evidence, modality) => {
diff --git a/src/chrome/src/agent/completion-verifier.js b/src/chrome/src/agent/completion-verifier.js
index 53556b030..595db3235 100644
--- a/src/chrome/src/agent/completion-verifier.js
+++ b/src/chrome/src/agent/completion-verifier.js
@@ -50,8 +50,9 @@ export async function verifyCompletion({ decision, llm, capture, isCurrent, sign
if (completionStopError(error, signal)) throw error;
const status = error?.status ?? error?.httpStatus;
onAttempt({ engine: engine.name, modality, outcome: 'uncertain', reason: error?.code || (status ? `http_${status}` : 'unavailable') });
- // Only an image-contract error can retry a failed request as AX.
- if (!(modality === 'vision' && [400, 413, 415, 422].includes(status))) break;
+ // Moving pixels invalidate the image verdict, not the whole task.
+ // Transport failures still skip this judge without a second request.
+ if (!(modality === 'vision' && (error?.code === 'COMPLETION_VISUAL_CHANGED' || [400, 413, 415, 422].includes(status)))) break;
}
}
}
diff --git a/src/chrome/src/config-transfer.js b/src/chrome/src/config-transfer.js
index bc9bf6b0f..7437499e5 100644
--- a/src/chrome/src/config-transfer.js
+++ b/src/chrome/src/config-transfer.js
@@ -13,6 +13,7 @@ import {
import { AUTO_GROUP_TABS_KEY } from './tab-group-preference.js';
import { normalizeSettings as normalizeSafeSocialSettings, SETTINGS_KEY as SAFE_SOCIAL_SETTINGS_KEY } from './safesocial/config.js';
import { normalizeUiScale, UI_SCALE_STORAGE_KEY } from './ui/ui-scale.js';
+import { resolveDecisionConfig } from './agent/decision-config.js';
export const CONFIG_SCHEMA = 'webbrain-config/1';
export const MAX_CONFIG_IMPORT_CHARS = 10_000_000;
@@ -233,6 +234,13 @@ function sanitizeProviders(value, { strict = false } = {}) {
}
function validSettingValue(key, value) {
+ if (key === 'decisionProvider') return ['', 'openrouter', 'typesafe', 'local'].includes(value);
+ if (key === 'decisionVisionMode') return ['auto', 'on', 'off'].includes(value);
+ if (key === 'decisionBaseUrl') {
+ if (typeof value !== 'string') return false;
+ try { resolveDecisionConfig({ decisionProvider: 'local', decisionBaseUrl: value }); return true; }
+ catch { return false; }
+ }
if (BOOLEAN_KEYS.has(key)) return typeof value === 'boolean';
if (NUMBER_KEYS.has(key)) return typeof value === 'number' && Number.isFinite(value);
if (STRING_KEYS.has(key)) return typeof value === 'string';
diff --git a/src/chrome/src/ui/locales/decision-copy.mjs b/src/chrome/src/ui/locales/decision-copy.mjs
index 86dd05251..7ed220d9f 100644
--- a/src/chrome/src/ui/locales/decision-copy.mjs
+++ b/src/chrome/src/ui/locales/decision-copy.mjs
@@ -12,6 +12,7 @@ export const decisionEnglish = {
'st.decision.vision': 'Image support', 'st.decision.auto': 'Auto (model capabilities)',
'st.decision.on': 'On (custom override)', 'st.decision.off': 'Off (AX only)',
'st.decision.done': 'Verify completion (done)', 'st.decision.threshold': 'Completion probability threshold (%)',
+ 'st.decision.done_desc': 'Use the selected decision model for completion checks. When outsourcing is off or unconfigured, the active LLM still verifies completion before existing checks; its usual cost limits apply.',
'st.decision.vision_unverified': 'Image support was not verified. Auto mode will use AX.',
'st.decision.compass': 'Compass verifies completion through its managed decision model automatically. Test checks image-only facts when image support is enabled; unsupported images use AX.',
};
@@ -25,6 +26,7 @@ export const decisionTranslations = {
'st.decision.endpoint': 'Sunucu temel adresi', 'st.decision.refresh': 'Mevcut modelleri yükle', 'st.decision.models_loaded': '{count} karar modeli yüklendi',
'st.decision.vision': 'Görsel desteği', 'st.decision.auto': 'Otomatik (model özellikleri)', 'st.decision.on': 'Açık (özel ayar)', 'st.decision.off': 'Kapalı (yalnızca AX)',
'st.decision.done': 'Tamamlanmayı doğrula (done)', 'st.decision.threshold': 'Tamamlanma olasılığı eşiği (%)',
+ 'st.decision.done_desc': 'Tamamlanma kontrollerinde seçilen karar modelini kullanır. Devretme kapalıysa veya yapılandırılmamışsa, etkin dil modeli mevcut kontrollerden önce tamamlanmayı yine doğrular; normal maliyet sınırları geçerlidir.',
'st.decision.vision_unverified': 'Görsel desteği doğrulanmadı. Otomatik mod AX kullanacak.',
'st.decision.compass': 'Compass tamamlanmayı yönetilen karar modeliyle otomatik doğrular. Görsel desteği açıksa test yalnızca görselde bulunan bilgileri kontrol eder; desteklenmeyen görsellerde AX kullanılır.',
},
diff --git a/src/chrome/src/ui/settings.html b/src/chrome/src/ui/settings.html
index 7649b7497..631c315e8 100644
--- a/src/chrome/src/ui/settings.html
+++ b/src/chrome/src/ui/settings.html
@@ -2261,7 +2261,7 @@
<div class="field"><label for="decision-vision" data-i18n="st.decision.vision"></label>
<select id="decision-vision"><option value="auto" data-i18n="st.decision.auto"></option><option value="on" data-i18n="st.decision.on"></option><option value="off" data-i18n="st.decision.off"></option></select>
</div>
- <div class="setting-row"><div class="setting-info"><div class="setting-label" data-i18n="st.decision.done"></div></div>
+ <div class="setting-row"><div class="setting-info"><div class="setting-label" data-i18n="st.decision.done"></div><div class="setting-desc" data-i18n="st.decision.done_desc"></div></div>
<label class="toggle"><input type="checkbox" id="toggle-decision-done" checked><span class="toggle-slider"></span></label>
</div>
<div class="field"><label for="decision-done-threshold" data-i18n="st.decision.threshold"></label>
diff --git a/src/firefox/src/agent/completion-runtime.js b/src/firefox/src/agent/completion-runtime.js
index 5b384d9da..87e5c6071 100644
--- a/src/firefox/src/agent/completion-runtime.js
+++ b/src/firefox/src/agent/completion-runtime.js
@@ -49,8 +49,12 @@ async function evaluateBrowserCompletion(agent, tabId, { pageState = {}, pageUrl
// new redacted, budgeted capture after the request; never reuse that cache.
let fresh;
try { fresh = await capture('vision', true); }
- catch (error) { if (completionStopError(error, signal)) throw error; return false; }
- return fresh?.key === (evidence.key || evidence.evidenceKey) && await currentIdentity(evidence);
+ catch (error) { if (completionStopError(error, signal)) throw error; }
+ if (!await currentIdentity(evidence)) return false;
+ if (fresh?.key === (evidence.key || evidence.evidenceKey)) return true;
+ // Moving pixels cannot certify the old image, but need not mean the task
+ // changed. Discard that verdict and judge a fresh AX read instead.
+ throw Object.assign(new Error('Visual evidence changed or could not be refreshed.'), { code: 'COMPLETION_VISUAL_CHANGED' });
};
const messages = agent.conversations.get(tabId) || [];
const toolNames = new Map(messages.flatMap(m => (m.tool_calls || []).map(call => [call.id, call.function?.name])));
@@ -96,7 +100,11 @@ async function evaluateBrowserCompletion(agent, tabId, { pageState = {}, pageUrl
return evidence;
};
const prior = agent._completionVerdicts.get(tabId);
- if (prior?.scope === scope && prior.outcome !== 'uncertain' && await current(prior)) {
+ const priorCurrent = prior?.scope === scope && prior.outcome !== 'uncertain' && await current(prior).catch(error => {
+ if (error?.code === 'COMPLETION_VISUAL_CHANGED') return false;
+ throw error;
+ });
+ if (priorCurrent) {
const fresh = await capture(prior.modality);
if (fresh?.key === prior.evidenceKey) return prior;
}
@@ -113,6 +121,8 @@ async function evaluateBrowserCompletion(agent, tabId, { pageState = {}, pageUrl
return decisionCompletionVerdict(result, config.threshold);
},
} : null;
+ // These switches outsource checks to the decision sidecar. The approved
+ // routing still uses the active LLM when that sidecar is off/unconfigured.
const llm = typeof provider.chat === 'function' && (online || provider.config?.category === 'local') ? {
name: 'llm', supportsVision: provider.supportsVision,
evaluate: async (evidence, modality) => {
diff --git a/src/firefox/src/agent/completion-verifier.js b/src/firefox/src/agent/completion-verifier.js
index 53556b030..595db3235 100644
--- a/src/firefox/src/agent/completion-verifier.js
+++ b/src/firefox/src/agent/completion-verifier.js
@@ -50,8 +50,9 @@ export async function verifyCompletion({ decision, llm, capture, isCurrent, sign
if (completionStopError(error, signal)) throw error;
const status = error?.status ?? error?.httpStatus;
onAttempt({ engine: engine.name, modality, outcome: 'uncertain', reason: error?.code || (status ? `http_${status}` : 'unavailable') });
- // Only an image-contract error can retry a failed request as AX.
- if (!(modality === 'vision' && [400, 413, 415, 422].includes(status))) break;
+ // Moving pixels invalidate the image verdict, not the whole task.
+ // Transport failures still skip this judge without a second request.
+ if (!(modality === 'vision' && (error?.code === 'COMPLETION_VISUAL_CHANGED' || [400, 413, 415, 422].includes(status)))) break;
}
}
}
diff --git a/src/firefox/src/config-transfer.js b/src/firefox/src/config-transfer.js
index bc9bf6b0f..7437499e5 100644
--- a/src/firefox/src/config-transfer.js
+++ b/src/firefox/src/config-transfer.js
@@ -13,6 +13,7 @@ import {
import { AUTO_GROUP_TABS_KEY } from './tab-group-preference.js';
import { normalizeSettings as normalizeSafeSocialSettings, SETTINGS_KEY as SAFE_SOCIAL_SETTINGS_KEY } from './safesocial/config.js';
import { normalizeUiScale, UI_SCALE_STORAGE_KEY } from './ui/ui-scale.js';
+import { resolveDecisionConfig } from './agent/decision-config.js';
export const CONFIG_SCHEMA = 'webbrain-config/1';
export const MAX_CONFIG_IMPORT_CHARS = 10_000_000;
@@ -233,6 +234,13 @@ function sanitizeProviders(value, { strict = false } = {}) {
}
function validSettingValue(key, value) {
+ if (key === 'decisionProvider') return ['', 'openrouter', 'typesafe', 'local'].includes(value);
+ if (key === 'decisionVisionMode') return ['auto', 'on', 'off'].includes(value);
+ if (key === 'decisionBaseUrl') {
+ if (typeof value !== 'string') return false;
+ try { resolveDecisionConfig({ decisionProvider: 'local', decisionBaseUrl: value }); return true; }
+ catch { return false; }
+ }
if (BOOLEAN_KEYS.has(key)) return typeof value === 'boolean';
if (NUMBER_KEYS.has(key)) return typeof value === 'number' && Number.isFinite(value);
if (STRING_KEYS.has(key)) return typeof value === 'string';
diff --git a/src/firefox/src/ui/locales/decision-copy.mjs b/src/firefox/src/ui/locales/decision-copy.mjs
index 86dd05251..7ed220d9f 100644
--- a/src/firefox/src/ui/locales/decision-copy.mjs
+++ b/src/firefox/src/ui/locales/decision-copy.mjs
@@ -12,6 +12,7 @@ export const decisionEnglish = {
'st.decision.vision': 'Image support', 'st.decision.auto': 'Auto (model capabilities)',
'st.decision.on': 'On (custom override)', 'st.decision.off': 'Off (AX only)',
'st.decision.done': 'Verify completion (done)', 'st.decision.threshold': 'Completion probability threshold (%)',
+ 'st.decision.done_desc': 'Use the selected decision model for completion checks. When outsourcing is off or unconfigured, the active LLM still verifies completion before existing checks; its usual cost limits apply.',
'st.decision.vision_unverified': 'Image support was not verified. Auto mode will use AX.',
'st.decision.compass': 'Compass verifies completion through its managed decision model automatically. Test checks image-only facts when image support is enabled; unsupported images use AX.',
};
@@ -25,6 +26,7 @@ export const decisionTranslations = {
'st.decision.endpoint': 'Sunucu temel adresi', 'st.decision.refresh': 'Mevcut modelleri yükle', 'st.decision.models_loaded': '{count} karar modeli yüklendi',
'st.decision.vision': 'Görsel desteği', 'st.decision.auto': 'Otomatik (model özellikleri)', 'st.decision.on': 'Açık (özel ayar)', 'st.decision.off': 'Kapalı (yalnızca AX)',
'st.decision.done': 'Tamamlanmayı doğrula (done)', 'st.decision.threshold': 'Tamamlanma olasılığı eşiği (%)',
+ 'st.decision.done_desc': 'Tamamlanma kontrollerinde seçilen karar modelini kullanır. Devretme kapalıysa veya yapılandırılmamışsa, etkin dil modeli mevcut kontrollerden önce tamamlanmayı yine doğrular; normal maliyet sınırları geçerlidir.',
'st.decision.vision_unverified': 'Görsel desteği doğrulanmadı. Otomatik mod AX kullanacak.',
'st.decision.compass': 'Compass tamamlanmayı yönetilen karar modeliyle otomatik doğrular. Görsel desteği açıksa test yalnızca görselde bulunan bilgileri kontrol eder; desteklenmeyen görsellerde AX kullanılır.',
},
diff --git a/src/firefox/src/ui/settings.html b/src/firefox/src/ui/settings.html
index d93b0fae2..7992ad0ae 100644
--- a/src/firefox/src/ui/settings.html
+++ b/src/firefox/src/ui/settings.html
@@ -2130,7 +2130,7 @@
<div class="field"><label for="decision-vision" data-i18n="st.decision.vision"></label>
<select id="decision-vision"><option value="auto" data-i18n="st.decision.auto"></option><option value="on" data-i18n="st.decision.on"></option><option value="off" data-i18n="st.decision.off"></option></select>
</div>
- <div class="setting-row"><div class="setting-info"><div class="setting-label" data-i18n="st.decision.done"></div></div>
+ <div class="setting-row"><div class="setting-info"><div class="setting-label" data-i18n="st.decision.done"></div><div class="setting-desc" data-i18n="st.decision.done_desc"></div></div>
<label class="toggle"><input type="checkbox" id="toggle-decision-done" checked><span class="toggle-slider"></span></label>
</div>
<div class="field"><label for="decision-done-threshold" data-i18n="st.decision.threshold"></label>
diff --git a/test/completion-verifier.mjs b/test/completion-verifier.mjs
index c24ca2583..4dd5c1984 100644
--- a/test/completion-verifier.mjs
+++ b/test/completion-verifier.mjs
@@ -19,6 +19,18 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(selected.config.inputCostPerMillionUsd, .042); assert.equal(legacy.systemOneWatchEnabled, true);
assert.equal(legacy.systemOneWatchThreshold, .85); assert.equal(legacy.systemOneCompletionThreshold, .75); assert.equal(selected.threshold, .9);
});
+ test(`${build}: full and sparse imports reject invalid decision enums and endpoints before persistence`, () => {
+ for (const parser of [transfer.parseConfigImport, transfer.parseConfigPatchImport]) {
+ for (const settings of [{ decisionProvider: 'unknown' }, { decisionVisionMode: 'maybe' }, { decisionProvider: 'local', decisionBaseUrl: 'not a URL' },
+ { decisionBaseUrl: 'javascript:alert(1)' }, { decisionBaseUrl: 'http://remote.example.com' }, { decisionBaseUrl: 'https://user:[email protected]' }]) {
+ assert.throws(() => parser(JSON.stringify({ schema: transfer.CONFIG_SCHEMA, settings })), /Invalid value for configuration setting/);
+ }
+ for (const decisionBaseUrl of ['', 'http://127.0.0.1:8009', 'http://localhost:8009', 'http://[::1]:8009', 'https://example.com/v1']) {
+ const imported = parser(JSON.stringify({ schema: transfer.CONFIG_SCHEMA, settings: { decisionProvider: 'local', decisionBaseUrl } })).settings;
+ assert.doesNotThrow(() => config.resolveDecisionConfig(imported));
+ }
+ }
+ });
test(`${build}: new defaults and legacy/local configuration`, () => {
assert.equal(config.resolveDecisionConfig().model, config.DEFAULT_DECISION_MODEL);
const legacy = config.resolveDecisionConfig({ typesafeApiKey: 'legacy', systemOneEnabled: true, systemOneWatchEnabled: true });
@@ -179,7 +191,7 @@ for (const build of ['chrome', 'firefox']) {
if (navigatorDescriptor) Object.defineProperty(globalThis, 'navigator', navigatorDescriptor); else delete globalThis.navigator;
}
});
- test(`${build}: runtime revalidates pixels changed during a decision or LLM request`, async () => {
+ test(`${build}: stale image verdicts cannot succeed without fresh evidence`, async () => {
const previousChrome = globalThis.chrome, previousBrowser = globalThis.browser;
const navigatorDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'navigator');
Object.defineProperty(globalThis, 'navigator', { configurable: true, value: { onLine: true } });
@@ -188,7 +200,7 @@ for (const build of ['chrome', 'firefox']) {
const stored = { decisionProvider: 'local', systemOneEnabled: engine === 'decision', decisionVisionMode: 'on' };
globalThis.chrome = globalThis.browser = { storage: { local: { get: async () => stored } } };
let pixels = 'data:image/png;base64,original', captures = 0, requests = 0;
- const active = { model: 'local-model', supportsVision: true, config: { category: 'local' }, chat() {} };
+ const active = { model: 'local-model', supportsVision: true, config: { category: 'local' }, ...(engine === 'llm' ? { chat() {} } : {}) };
const guard = { semanticSubmissionVerified: true, verifiedSubmissionEvidence: true };
const agent = {
_activeProvider: () => active, _runAbortSignal: () => null, systemOneContext: () => ({ isCurrent: () => true }),
@@ -198,17 +210,25 @@ for (const build of ['chrome', 'firefox']) {
_completionDocumentStamp: async () => 'unchanged-text-and-inputs',
_captureCompletionJudgeImage: async () => { captures++; return pixels; },
_budgetForCapture: () => ({ maxTargetPx: 1408, maxTargetTokens: 1400 }), _shrinkImageForBudget: async dataUrl => ({ dataUrl }),
- executeTool: async () => { throw new Error('Stale pixels must not be reversed by an AX judge'); },
+ executeTool: async () => ({ success: true, pageContent: 'AX has no evidence establishing the image contents.' }),
_newCostRunState: () => ({}), recordSystemOneVerdict() {},
};
const changePixels = () => { requests++; pixels = change === 'capture_unavailable' ? null : `data:image/png;base64,changed-${change}`; };
- agent.evaluateSystemOne = async () => { changePixels(); const result = response(); result.model = 'kev-latest'; return result; };
- agent._chatWithCostAllowance = async () => { changePixels(); return { content: '{"outcome":"succeeded","reason":"Image matches"}' }; };
+ agent.evaluateSystemOne = async (_tab, _client, args) => {
+ const vision = args.state[1].type === 'image_url';
+ if (vision) changePixels(); else requests++;
+ const result = response(vision ? 'succeeded' : 'uncertain'); result.model = 'kev-latest'; return result;
+ };
+ agent._chatWithCostAllowance = async (_provider, messages) => {
+ const vision = Array.isArray(messages[1].content);
+ if (vision) changePixels(); else requests++;
+ return { content: JSON.stringify({ outcome: vision ? 'succeeded' : 'uncertain', reason: 'Image details are not verifiable from AX.' }) };
+ };
const verdict = await runtime.verifyBrowserCompletion(agent, 1);
- assert.equal(verdict.outcome, 'pending', `${engine}/${change}: stale pixels must not establish success`);
- assert.equal(verdict.engine, 'freshness');
+ assert.equal(verdict.outcome, 'uncertain', `${engine}/${change}: stale pixels must not establish success`);
+ assert.equal(verdict.engine, 'legacy');
assert.equal(captures, 2, 'pixels must be captured again after the response');
- assert.equal(requests, 1, 'a stale response must not fall through to another judge');
+ assert.equal(requests, 2, 'changed pixels require a new AX judgment, not acceptance of the stale image');
assert.equal(guard.semanticSubmissionVerified, false);
assert.equal(guard.verifiedSubmissionEvidence, false);
}
@@ -217,6 +237,46 @@ for (const build of ['chrome', 'firefox']) {
if (navigatorDescriptor) Object.defineProperty(globalThis, 'navigator', navigatorDescriptor); else delete globalThis.navigator;
}
});
+ test(`${build}: moving pixels fall back to fresh AX and disabled outsourcing retains the approved LLM route`, async () => {
+ const previousChrome = globalThis.chrome, previousBrowser = globalThis.browser;
+ const navigatorDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'navigator');
+ Object.defineProperty(globalThis, 'navigator', { configurable: true, value: { onLine: true } });
+ try {
+ for (const stored of [{ decisionProvider: 'local', systemOneEnabled: true }, {}, { systemOneEnabled: false }, { decisionProvider: 'local', systemOneEnabled: true, systemOneDoneEnabled: false }]) {
+ globalThis.chrome = globalThis.browser = { storage: { local: { get: async () => ({ ...stored, decisionVisionMode: 'on' }) } } };
+ let captures = 0, reads = 0;
+ const calls = [];
+ const provider = { model: 'local', supportsVision: true, config: { category: 'local' }, chat() {} };
+ const agent = {
+ _activeProvider: () => provider, _runAbortSignal: () => null, systemOneContext: () => ({ isCurrent: () => true }),
+ _latestTaskText: () => 'Verify the published post', _originalTaskText: () => '', _progressTaskKeyHash: () => 'task',
+ _planExecutionGuards: new Map(), completionInvariants: new Map([[1, { runToken: 'run' }]]),
+ _completionSubmitStates: new Map(), conversationIds: new Map(), conversations: new Map(),
+ _completionDocumentStamp: async () => 'same-published-document',
+ _captureCompletionJudgeImage: async () => `data:image/png;base64,animation-frame-${++captures}`,
+ _budgetForCapture: () => ({ maxTargetPx: 1408, maxTargetTokens: 1400 }), _shrinkImageForBudget: async dataUrl => ({ dataUrl }),
+ executeTool: async () => { reads++; return { success: true, pageContent: 'Published requested post; no draft or validation error' }; },
+ _newCostRunState: () => ({}), recordSystemOneVerdict() {},
+ evaluateSystemOne: async (_tab, _client, args) => {
+ calls.push('decision:' + (args.state[1].type === 'image_url' ? 'vision' : 'ax'));
+ const result = response(); result.model = 'kev-latest'; return result;
+ },
+ _chatWithCostAllowance: async (_provider, messages) => {
+ calls.push('llm:' + (Array.isArray(messages[1].content) ? 'vision' : 'ax'));
+ return { content: '{"outcome":"succeeded","reason":"Fresh AX establishes publication"}' };
+ },
+ };
+ const verdict = await runtime.verifyBrowserCompletion(agent, 1);
+ const engine = stored.systemOneEnabled === true && stored.systemOneDoneEnabled !== false ? 'decision' : 'llm';
+ assert.equal(verdict.outcome, 'succeeded'); assert.equal(verdict.modality, 'ax');
+ assert.deepEqual(calls, [`${engine}:vision`, `${engine}:ax`]);
+ assert.equal(reads, 1); assert.equal(captures, 2);
+ }
+ } finally {
+ globalThis.chrome = previousChrome; globalThis.browser = previousBrowser;
+ if (navigatorDescriptor) Object.defineProperty(globalThis, 'navigator', navigatorDescriptor); else delete globalThis.navigator;
+ }
+ });
test(`${build}: finite screenshot budgets preserve freshness capacity or select AX`, async () => {
const previousChrome = globalThis.chrome, previousBrowser = globalThis.browser;
const navigatorDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'navigator');