Skip to content

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

fix: release WebGPU runtimes on automatic provider fallback

Barack Sokullu33ae9ed69875
diff --git a/src/chrome/src/providers/manager.js b/src/chrome/src/providers/manager.js
index e9b794562..54fe85ea6 100644
--- a/src/chrome/src/providers/manager.js
+++ b/src/chrome/src/providers/manager.js
@@ -416,8 +416,8 @@ export class ProviderManager {
try {
const download = await this.providers.get('webgpu')?.downloadStatus?.().catch(() => null);
if (download && download.ready !== true) {
- this.activeProviderId = WEBBRAIN_CLOUD_PROVIDER_ID;
- providerStateMigrated = true;
+ await this.setActive(WEBBRAIN_CLOUD_PROVIDER_ID);
+ providerStateMigrated = false; // setActive persisted the migrated configs too.
}
} catch {
// Probe failures must not block startup; chat will report the missing download.
@@ -1819,10 +1819,10 @@ export class ProviderManager {
const currentModel = this.providers.get('webgpu')?.config?.model;
const status = await this._webgpuProvider().downloadStatus({ model: currentModel }).catch(() => null);
if (status && status.ready !== true) {
- this.activeProviderId = this.providers.has(WEBBRAIN_CLOUD_PROVIDER_ID)
+ const fallback = this.providers.has(WEBBRAIN_CLOUD_PROVIDER_ID)
? WEBBRAIN_CLOUD_PROVIDER_ID
: [...this.providers.keys()].find((candidate) => candidate !== 'webgpu') || WEBBRAIN_CLOUD_PROVIDER_ID;
- await this.save();
+ await this.setActive(fallback);
}
} catch {
// Keep the selection; chat will report the missing download.
@@ -1934,9 +1934,13 @@ export class ProviderManager {
try {
const download = await this.providers.get('webgpu')?.downloadStatus?.();
if (download && download.ready !== true) {
- this.activeProviderId = this.providers.has(WEBBRAIN_CLOUD_PROVIDER_ID)
+ const fallback = this.providers.has(WEBBRAIN_CLOUD_PROVIDER_ID)
? WEBBRAIN_CLOUD_PROVIDER_ID
: [...this.providers.keys()].find((candidate) => candidate !== 'webgpu') || WEBBRAIN_CLOUD_PROVIDER_ID;
+ // Reuse normal switching so the abandoned resident model releases
+ // its GPU allocations as well as persisting the new selection.
+ await this.setActive(fallback);
+ return;
}
} catch {
// Probe failures must not block saving; chat will report the missing download.
diff --git a/test/run.js b/test/run.js
index f7bfdd595..0ca445133 100644
--- a/test/run.js
+++ b/test/run.js
@@ -62424,6 +62424,7 @@ test('Chrome exposes separate endpoint-free WebGPU text and vision providers', a
const manager = new ProviderManagerCh();
const webgpuConfig = manager._defaultConfigs().webgpu;
+ manager.providers.set('webbrain_cloud', manager._createProvider('webbrain_cloud', manager._defaultConfigs().webbrain_cloud));
assert.equal(WEBGPU_VISION_MODEL_ID, 'webbrain-one/webbrain-vl-2-450M-onnx');
assert.equal(WEBGPU_VISION_CONSENT_VERSION, 2,
'switching the shipped vision model must require explicit consent again');
@@ -62535,16 +62536,21 @@ test('Chrome exposes separate endpoint-free WebGPU text and vision providers', a
const fallbackProbeBase = sentMessages.length;
await manager.updateProvider('webgpu', { model: 'custom-owner/undownloaded-model' });
assert.equal(manager.activeProviderId, 'webbrain_cloud', 'editing the active WebGPU model to an undownloaded target must fall back to a usable provider');
+ assert.equal(sentMessages.at(-1).type, 'webgpu-dispose', 'edit fallback must release the previous resident model');
textModelReady = true;
manager.activeProviderId = 'webgpu';
+ const disposalsBeforeReadyEdit = sentMessages.filter(message => message.type === 'webgpu-dispose').length;
await manager.updateProvider('webgpu', { model: WEBGPU_COMPASS_TINY_V2_MODEL_ID });
assert.equal(manager.activeProviderId, 'webgpu', 'editing the active WebGPU model to a ready target must keep the selection');
+ assert.equal(sentMessages.filter(message => message.type === 'webgpu-dispose').length, disposalsBeforeReadyEdit,
+ 'a ready edit must not dispose the runtime while WebGPU stays selected');
sentMessages.length = fallbackProbeBase;
manager.activeProviderId = 'webgpu';
textModelReady = false;
const stopProbeBase = sentMessages.length;
await manager.stopWebgpuDownload({ model: WEBGPU_COMPASS_TINY_V2_MODEL_ID });
assert.equal(manager.activeProviderId, 'webbrain_cloud', 'removing the active WebGPU model must fall back centrally so Apocalypse removal stays usable');
+ assert.equal(sentMessages.at(-1).type, 'webgpu-dispose', 'removal fallback must release any remaining text runtime');
sentMessages.length = stopProbeBase;
textModelReady = true;