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: prefer distinct active transfer; sync Settings selection after WebGPU fallback
Barack Sokullud399bbaa481f
diff --git a/src/chrome/src/background.js b/src/chrome/src/background.jsindex fd32ffba6..0123a798c 100644--- a/src/chrome/src/background.js+++ b/src/chrome/src/background.js@@ -3971,7 +3971,7 @@ async function handleMessage(msg, sender) {await providerManager.updateProvider(msg.providerId, msg.config, {markConfigured: msg.markConfigured !== false,});- return { ok: true };+ return { ok: true, activeProviderId: providerManager.activeProviderId };}case 'duplicate_provider':diff --git a/src/chrome/src/ui/settings.js b/src/chrome/src/ui/settings.jsindex fce91f066..6402e002e 100644--- a/src/chrome/src/ui/settings.js+++ b/src/chrome/src/ui/settings.js@@ -2789,9 +2789,15 @@ function renderWebgpuDownloadControl(id, state) {// 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.+ // A distinct active transfer wins even when the displayed model is cached+ // (ready): otherwise its remove action would delete the cached model while+ // the sibling download runs hidden.+ const displayedModel = String(state.modelId || '').trim().toLowerCase();+ const transferModel = String(state.activeTransfer?.modelId || '').trim().toLowerCase();+ const distinctTransfer = !!transferModel && transferModel !== displayedModel;const transferActive = isActiveWebgpuTransfer(state.activeTransfer)&& !isActiveWebgpuTransfer(state)- && state.ready !== true;+ && distinctTransfer;const display = transferActive ? state.activeTransfer : state;if (btn) {btn.textContent = webgpuDownloadCardLabel(display);@@ -2862,12 +2868,17 @@ async function handleWebgpuDownloadButton(btn) {const msg = model ? { model } : {};const state = normalizeWebgpuDownloadSnapshot(await sendToBackground('get_webgpu_download_status', 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.+ // for the displayed model is `not-downloaded` (or ready, when switching+ // to a cached model) 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 or deleting+ // the cached displayed model while the sibling runs hidden.+ const displayedForTransfer = String(state.modelId || model || '').trim().toLowerCase();+ const siblingTransferModel = String(state.activeTransfer?.modelId || '').trim().toLowerCase();+ const distinctSibling = !!siblingTransferModel && siblingTransferModel !== displayedForTransfer;const siblingActive = isActiveWebgpuTransfer(state.activeTransfer)&& !isActiveWebgpuTransfer(state)- && state.ready !== true;+ && distinctSibling;const stopTarget = siblingActive && state.activeTransfer.modelId? { model: state.activeTransfer.modelId }: msg;@@ -3977,7 +3988,15 @@ async function saveProvider(id, { showFlash = true, markConfigured = true } = {}setProviderConfigValue(config, input.dataset.key, value);});apiKeyWarning = providerApiKeyWarning(id, config);- await sendToBackground('update_provider', { providerId: id, config, markConfigured });+ const updateRes = await sendToBackground('update_provider', { providerId: id, config, markConfigured });+ // updateProvider may fall back to another active provider (e.g. the active+ // WebGPU model was edited to an undownloaded target). Sync the page-local+ // selection so the Selected badge does not lie about subsequent chats.+ if (updateRes && typeof updateRes.activeProviderId === 'string'+ && updateRes.activeProviderId !== activeProviderId) {+ activeProviderId = updateRes.activeProviderId;+ requestedActiveProviderId = updateRes.activeProviderId;+ }} catch (e) {if (showFlash) setProviderTestResult(id, 'fail', t('st.providers.failed', { error: e.message }));throw e;@@ -3995,6 +4014,29 @@ async function saveProvider(id, { showFlash = true, markConfigured = true } = {}if (markConfigured) providersData[id].configured = id !== 'webbrain_cloud';}if (markConfigured) dirtyProviderIds.delete(id);+ // If the background fell back to another active provider, re-render all+ // cards so every Selected badge reflects the persisted selection.+ if (requestedActiveProviderId === activeProviderId && document.querySelector('.provider-card')) {+ const selectedCards = [...document.querySelectorAll('.provider-card.selected')].map((card) => card.dataset.providerId);+ const shouldRerender = selectedCards.length !== 1 || selectedCards[0] !== activeProviderId;+ if (shouldRerender) {+ try {+ syncInputsIntoProvidersData();+ } catch {+ // Draft preservation is best-effort; selection accuracy wins.+ }+ renderProviders();+ refreshVisionStatus(id);+ if (showFlash) {+ if (apiKeyWarning) setProviderTestResult(id, 'warn', apiKeyWarning);+ else {+ const testEl = setProviderTestResult(id, 'ok', t('st.providers.saved'));+ if (testEl) setTimeout(() => testEl.classList.remove('show'), 2000);+ }+ }+ return;+ }+ }refreshProviderCardStatus(id);refreshVisionStatus(id);diff --git a/test/run.js b/test/run.jsindex 13a0288df..505ff720e 100644--- a/test/run.js+++ b/test/run.js@@ -63617,6 +63617,14 @@ test('WebGPU worker follows local text-generation and WebBrain VL vision contrac'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, /distinctTransfer/,+ 'a cached displayed model must not hide a distinct running transfer');+ assert.match(settingsScript, /distinctSibling/,+ 'stopping must prefer a distinct running transfer even when the displayed model is ready');+ assert.match(settingsScript, /activeProviderId = updateRes\.activeProviderId/,+ 'Settings must sync the selected provider after the background fallback');+ assert.match(background, /case 'update_provider'[\s\S]*?activeProviderId: providerManager\.activeProviderId/,+ 'update_provider must report the persisted active provider so Settings can refresh after fallback');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/,