Skip to content

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

fix: preserve sibling WebGPU transfer in Settings; reset stale dtype on model switch

Barack Sokullud6222636d9b9
diff --git a/src/chrome/src/providers/manager.js b/src/chrome/src/providers/manager.js
index e4c24f432..756390f9f 100644
--- a/src/chrome/src/providers/manager.js
+++ b/src/chrome/src/providers/manager.js
@@ -1854,6 +1854,13 @@ export class ProviderManager {
if (preset?.contextWindow && !Object.hasOwn(updates, 'contextWindow')) {
merged.contextWindow = preset.contextWindow;
}
+ // A retained Bonsai dtype ('q1') must not leak into a new target: a
+ // custom ONNX repository would otherwise request model_q1.onnx instead
+ // of the documented q4f16 graph. Reset to the preset (or ONNX default)
+ // whenever the model changes unless the update explicitly supplies one.
+ if (!Object.hasOwn(updates, 'dtype')) {
+ merged.dtype = preset?.dtype || WEBGPU_DTYPE;
+ }
}
if (this._providerDefinitionId(id, current) === 'ollama') {
merged.visionMode = OLLAMA_VISION_MODES.has(merged.visionMode) ? merged.visionMode : 'auto';
diff --git a/src/chrome/src/ui/settings.js b/src/chrome/src/ui/settings.js
index d630453e4..fce91f066 100644
--- a/src/chrome/src/ui/settings.js
+++ b/src/chrome/src/ui/settings.js
@@ -2721,14 +2721,42 @@ function normalizeWebgpuDownloadSnapshot(snapshot = {}) {
const progress = status === 'ready'
? 100
: Math.max(0, Math.min(100, Number(snapshot.progress) || (total > 0 ? loaded / total * 100 : 0)));
+ const rawTransfer = snapshot.activeTransfer && typeof snapshot.activeTransfer === 'object'
+ ? snapshot.activeTransfer
+ : null;
+ // Preserve the sibling transfer (e.g. Bonsai downloading while the ONNX
+ // card queries Compass): dropping it stops polling and hides Stop control.
+ let activeTransfer = null;
+ if (rawTransfer) {
+ const transferStatus = allowedStatuses.has(rawTransfer.status) ? rawTransfer.status : 'not-downloaded';
+ const transferLoaded = Math.max(0, Number(rawTransfer.loaded) || 0);
+ const transferTotal = Math.max(0, Number(rawTransfer.total) || 0);
+ const transferProgress = transferStatus === 'ready'
+ ? 100
+ : Math.max(0, Math.min(100, Number(rawTransfer.progress) || (transferTotal > 0 ? transferLoaded / transferTotal * 100 : 0)));
+ activeTransfer = {
+ status: transferStatus,
+ ready: rawTransfer.ready === true || transferStatus === 'ready',
+ progress: Math.round(transferProgress),
+ error: String(rawTransfer.error || ''),
+ modelId: String(rawTransfer.modelId || rawTransfer.model || ''),
+ };
+ }
return {
status,
ready: snapshot.ready === true || status === 'ready',
progress: Math.round(progress),
error: String(snapshot.error || ''),
+ modelId: String(snapshot.modelId || snapshot.model || ''),
+ activeTransfer,
};
}
+function isActiveWebgpuTransfer(state) {
+ return !!state && state.ready !== true
+ && ['checking', 'downloading', 'paused', 'stopping'].includes(state.status);
+}
+
function webgpuDownloadCardLabel(state) {
if (state.ready || ['downloading', 'paused', 'stopping'].includes(state.status)) {
return t('st.providers.webgpu_download.stop');
@@ -2757,11 +2785,26 @@ function webgpuDownloadStatusLine(state) {
function renderWebgpuDownloadControl(id, state) {
const btn = document.querySelector(`.btn-webgpu-download[data-provider="${id}"]`);
const line = document.querySelector(`[data-webgpu-download-status="${id}"]`);
+ // When the user edits the Model field mid-download, the status for the
+ // newly displayed model is `not-downloaded` while `activeTransfer` still
+ // carries the running sibling transfer. Render the running transfer so its
+ // Stop control stays visible instead of flipping to Start with no way back.
+ const transferActive = isActiveWebgpuTransfer(state.activeTransfer)
+ && !isActiveWebgpuTransfer(state)
+ && state.ready !== true;
+ const display = transferActive ? state.activeTransfer : state;
if (btn) {
- btn.textContent = webgpuDownloadCardLabel(state);
- btn.disabled = webgpuDownloadActionInFlight || ['checking', 'stopping'].includes(state.status);
+ btn.textContent = webgpuDownloadCardLabel(display);
+ btn.disabled = webgpuDownloadActionInFlight || ['checking', 'stopping'].includes(display.status);
+ // Stopping must target the running transfer, not the newly typed model.
+ if (transferActive && display.modelId) btn.dataset.activeTransferModel = display.modelId;
+ else delete btn.dataset.activeTransferModel;
+ }
+ if (line) {
+ line.textContent = transferActive && display.modelId
+ ? `${webgpuDownloadStatusLine(display)} (${display.modelId})`
+ : webgpuDownloadStatusLine(display);
}
- if (line) line.textContent = webgpuDownloadStatusLine(state);
}
function getDisplayedWebgpuModel(id = 'webgpu') {
@@ -2789,7 +2832,7 @@ async function refreshWebgpuDownloadControls() {
const query = model ? { model } : {};
const state = normalizeWebgpuDownloadSnapshot(await sendToBackground('get_webgpu_download_status', query) || {});
renderWebgpuDownloadControl(id, state);
- if (!state.ready && ['checking', 'downloading', 'paused', 'stopping'].includes(state.status)) active = true;
+ if (isActiveWebgpuTransfer(state) || isActiveWebgpuTransfer(state.activeTransfer)) active = true;
} catch (error) {
const line = document.querySelector(`[data-webgpu-download-status="${id}"]`);
if (line) line.textContent = String(error?.message || error);
@@ -2818,9 +2861,19 @@ async function handleWebgpuDownloadButton(btn) {
const model = getDisplayedWebgpuModel(id);
const msg = model ? { model } : {};
const state = normalizeWebgpuDownloadSnapshot(await sendToBackground('get_webgpu_download_status', msg) || {});
- if (state.ready || ['downloading', 'paused'].includes(state.status)) {
- const removedReadyModel = state.ready === true;
- await sendToBackground('stop_webgpu_download', msg);
+ // If the user typed a new model while a sibling transfer runs, the status
+ // for the displayed model is `not-downloaded` with the running transfer in
+ // `activeTransfer`. Stopping must target the running transfer so its Stop
+ // control keeps working instead of attempting to start a blocked download.
+ const siblingActive = isActiveWebgpuTransfer(state.activeTransfer)
+ && !isActiveWebgpuTransfer(state)
+ && state.ready !== true;
+ const stopTarget = siblingActive && state.activeTransfer.modelId
+ ? { model: state.activeTransfer.modelId }
+ : msg;
+ if (state.ready || ['downloading', 'paused'].includes(state.status) || siblingActive) {
+ const removedReadyModel = state.ready === true && !siblingActive;
+ await sendToBackground('stop_webgpu_download', stopTarget);
// Removing a ready model while WebGPU is the selected chat provider
// would leave every subsequent chat failing its readiness check until
// the user re-downloads or manually picks another provider. Fall back
diff --git a/test/run.js b/test/run.js
index b80acef2f..a48f1299f 100644
--- a/test/run.js
+++ b/test/run.js
@@ -62524,6 +62524,12 @@ test('Chrome exposes separate endpoint-free WebGPU text and vision providers', a
await manager.updateProvider('webgpu', { model: '' });
assert.equal(manager.getAll().webgpu.model, WEBGPU_COMPASS_TINY_V2_MODEL_ID);
assert.equal(manager.getAll().webgpu.contextWindow, 32768);
+ await manager.updateProvider('webgpu', { model: WEBGPU_BONSAI27_MODEL_ID, dtype: 'q1' });
+ assert.equal(manager.getAll().webgpu.dtype, 'q1');
+ await manager.updateProvider('webgpu', { model: 'custom-owner/custom-model-2' });
+ assert.equal(manager.getAll().webgpu.dtype, WEBGPU_DTYPE, 'switching from Bonsai to a custom ONNX model must reset the stale q1 dtype');
+ await manager.updateProvider('webgpu', { model: WEBGPU_COMPASS_TINY_V2_MODEL_ID });
+ assert.equal(manager.getAll().webgpu.dtype, WEBGPU_DTYPE, 'switching to the Compass preset must restore q4f16');
const provider = await manager.getLocalVisionFallbackProvider();
assert.ok(provider instanceof WebGPUVisionProvider);
@@ -63585,7 +63591,7 @@ test('WebGPU worker follows local text-generation and WebBrain VL vision contrac
'Settings download actions must target the currently displayed model');
assert.match(settingsScript, /sendToBackground\('start_webgpu_download', msg\)/,
'the Settings download control must pass the target model when starting');
- assert.match(settingsScript, /sendToBackground\('stop_webgpu_download', msg\)/,
+ assert.match(settingsScript, /sendToBackground\('stop_webgpu_download', (msg|stopTarget)\)/,
'the Settings download control must pass the target model when stopping');
assert.match(settingsScript, /removedReadyModel/,
'removing a ready WebGPU model must track whether the deleted model was ready');
@@ -63593,6 +63599,12 @@ test('WebGPU worker follows local text-generation and WebBrain VL vision contrac
'removing the selected WebGPU model must fall back to a usable provider');
assert.match(settingsScript, /didFallbackProvider/,
'the provider fallback must re-render cards so the Selected badge stays accurate');
+ assert.match(settingsScript, /activeTransfer/,
+ 'the Settings download control must preserve the sibling active transfer instead of hiding Stop');
+ assert.match(settingsScript, /isActiveWebgpuTransfer/,
+ 'the Settings poll must stay alive while a sibling transfer runs');
+ assert.match(settingsScript, /stopTarget/,
+ 'stopping from Settings must target the running transfer when the model field changed');
assert.match(settingsScript, /sendToBackground\('get_webgpu_download_status', query\)/,
'the Settings download control must query the displayed model status');
assert.match(settingsScript, /data-webgpu-download-status/,