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
Keep Load available after a transient cached-model error
Claude1853a2b9bb27
diff --git a/src/chrome/src/providers/d1-worker.js b/src/chrome/src/providers/d1-worker.jsindex 24cd127e5..b222d751b 100644--- a/src/chrome/src/providers/d1-worker.js+++ b/src/chrome/src/providers/d1-worker.js@@ -71,7 +71,13 @@ async function readyMarker() {const currentPackage = marker => marker?.revision === D1_RELEASE.revision && marker?.manifestSha256 === D1_RELEASE.manifestSha256;async function status() {- if (transfer || runtime || loading || ['error', 'stopped'].includes(state.status)) return { ...state, ready: !!runtime };+ if (transfer || runtime || loading || ['error', 'stopped'].includes(state.status)) {+ // An error or a stop leaves the verified cache in place (a lost GPU device+ // after a good download, say); report it so Settings can retry with Load+ // instead of falling back to a full download pass.+ const cached = !transfer && !runtime && !loading && currentPackage(await readyMarker());+ return { ...state, ready: !!runtime, cached };+ }const marker = await readyMarker();return marker ? { ...state, status: currentPackage(marker) ? 'cached' : 'idle', ready: false, loaded: false } : { ...state, ready: false };}diff --git a/src/chrome/src/ui/d1-settings.js b/src/chrome/src/ui/d1-settings.jsindex 65420a7aa..456d6f2e0 100644--- a/src/chrome/src/ui/d1-settings.js+++ b/src/chrome/src/ui/d1-settings.js@@ -16,7 +16,7 @@ export function initD1Settings(send) {// cache it only loads, which skips the download pass's second verification.const loadButton = document.getElementById('d1-load');const showLoadButton = snapshot => {- const cached = snapshot?.loaded === true || ['cached', 'ready'].includes(snapshot?.status);+ const cached = snapshot?.loaded === true || snapshot?.cached === true || ['cached', 'ready'].includes(snapshot?.status);loadButton.dataset.d1Command = cached ? 'load' : 'download';loadButton.dataset.i18n = cached ? 'st.d1.load' : 'st.d1.download';loadButton.textContent = t(loadButton.dataset.i18n);diff --git a/src/firefox/src/providers/d1-worker.js b/src/firefox/src/providers/d1-worker.jsindex 24cd127e5..b222d751b 100644--- a/src/firefox/src/providers/d1-worker.js+++ b/src/firefox/src/providers/d1-worker.js@@ -71,7 +71,13 @@ async function readyMarker() {const currentPackage = marker => marker?.revision === D1_RELEASE.revision && marker?.manifestSha256 === D1_RELEASE.manifestSha256;async function status() {- if (transfer || runtime || loading || ['error', 'stopped'].includes(state.status)) return { ...state, ready: !!runtime };+ if (transfer || runtime || loading || ['error', 'stopped'].includes(state.status)) {+ // An error or a stop leaves the verified cache in place (a lost GPU device+ // after a good download, say); report it so Settings can retry with Load+ // instead of falling back to a full download pass.+ const cached = !transfer && !runtime && !loading && currentPackage(await readyMarker());+ return { ...state, ready: !!runtime, cached };+ }const marker = await readyMarker();return marker ? { ...state, status: currentPackage(marker) ? 'cached' : 'idle', ready: false, loaded: false } : { ...state, ready: false };}diff --git a/src/firefox/src/ui/d1-settings.js b/src/firefox/src/ui/d1-settings.jsindex 65420a7aa..456d6f2e0 100644--- a/src/firefox/src/ui/d1-settings.js+++ b/src/firefox/src/ui/d1-settings.js@@ -16,7 +16,7 @@ export function initD1Settings(send) {// cache it only loads, which skips the download pass's second verification.const loadButton = document.getElementById('d1-load');const showLoadButton = snapshot => {- const cached = snapshot?.loaded === true || ['cached', 'ready'].includes(snapshot?.status);+ const cached = snapshot?.loaded === true || snapshot?.cached === true || ['cached', 'ready'].includes(snapshot?.status);loadButton.dataset.d1Command = cached ? 'load' : 'download';loadButton.dataset.i18n = cached ? 'st.d1.load' : 'st.d1.download';loadButton.textContent = t(loadButton.dataset.i18n);diff --git a/test/d1-decision.mjs b/test/d1-decision.mjsindex 6a2ce2be8..5a1178b72 100644--- a/test/d1-decision.mjs+++ b/test/d1-decision.mjs@@ -49,7 +49,9 @@ for (const build of ['chrome', 'firefox']) {await new Promise(resolve => setTimeout(resolve, 0));const result = messages.find(message => message.id === 2).result;assert.equal(result.status, 'error'); assert.equal(result.ready, false); assert.equal(result.loaded, false);- assert.match(result.error, /Hardware WebGPU/); assert.equal(cacheReads, 0);+ assert.match(result.error, /Hardware WebGPU/);+ // The error stays, but the verified cache is reported so Settings can retry with Load.+ assert.equal(result.cached, true); assert.equal(cacheReads, 1);} finally {if (oldNavigator) Object.defineProperty(globalThis, 'navigator', oldNavigator); else delete globalThis.navigator;if (oldSelf) Object.defineProperty(globalThis, 'self', oldSelf); else delete globalThis.self;diff --git a/test/d1-settings-ui.mjs b/test/d1-settings-ui.mjsindex b648d04cc..d6f71fe37 100644--- a/test/d1-settings-ui.mjs+++ b/test/d1-settings-ui.mjs@@ -42,7 +42,7 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {runtime: { getURL: path => `${location.origin}/src/${build}/${path}`, getManifest: () => ({ version }), onMessage: { addListener() {} }, sendMessage(msg, callback) {window.testRequests.push(msg);const result = msg.action === 'd1_control'- ? { success: true, result: msg.command === 'status' ? { status: window.d1Status, ready: window.d1Status === 'ready', loaded: window.d1Status === 'ready' } : { started: true } }+ ? { success: true, result: msg.command === 'status' ? { status: window.d1Status, ready: window.d1Status === 'ready', loaded: window.d1Status === 'ready', cached: window.d1Cached === true } : { started: true } }: msg.action === 'get_providers' ? { providers: {}, active: '' } : { success: true };callback?.(result); return Promise.resolve(result);} },@@ -61,6 +61,14 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {await page.evaluate(() => { window.d1Status = 'cached'; });await page.waitForFunction(() => document.querySelector('#d1-load').textContent === 'Load', null, { timeout: 5000 });assert.equal(await load.getAttribute('data-d1-command'), 'load');+ // A transient load error keeps the cache: retrying still only loads.+ await page.evaluate(() => { window.d1Status = 'error'; window.d1Cached = true; });+ await page.waitForFunction(() => document.querySelector('#d1-status').textContent.startsWith('error'), null, { timeout: 5000 });+ assert.equal(await load.getAttribute('data-d1-command'), 'load', 'a cached model with an error retries with Load');+ await page.evaluate(() => { window.d1Cached = false; });+ await page.waitForFunction(() => document.querySelector('#d1-load').dataset.d1Command === 'download', null, { timeout: 5000 });+ await page.evaluate(() => { window.d1Status = 'cached'; window.d1Cached = false; });+ await page.waitForFunction(() => document.querySelector('#d1-load').textContent === 'Load', null, { timeout: 5000 });await page.locator('#d1-consent').check();await load.click();await page.waitForFunction(() => window.testRequests.some(msg => msg.action === 'd1_control' && msg.command === 'load'));