Skip to content

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

fix: recycle worker on device loss; bind diagnostics for vision runtimes

Barack Sokullu8dda2cbd9412
diff --git a/src/chrome/src/offscreen/inference-worker.js b/src/chrome/src/offscreen/inference-worker.js
index f5e6bb11a..98736b8fd 100644
--- a/src/chrome/src/offscreen/inference-worker.js
+++ b/src/chrome/src/offscreen/inference-worker.js
@@ -365,6 +365,10 @@ function bindWebGpuDeviceDiagnostics(library) {
// reaching the generate paths, so flag the runtimes dirty now: the next
// run disposes them and rebuilds instead of burning one failing turn.
markWebgpuRuntimeDirty();
+ // ONNX Runtime initializes its Dawn device once per worker lifetime, so an
+ // in-worker rebuild still runs against the dead adapter. Ask the host for
+ // a fresh worker so the first request after a confirmed loss recovers.
+ requestWebgpuWorkerRecycle('device-lost');
console.error('[webgpu] device lost:', lastWebGpuDeviceLost);
}).catch(() => {});
}
@@ -642,6 +646,7 @@ async function getVisionRuntime(modelId, dtype, device, {
}
const processor = processorResult.value;
const model = modelResult.value;
+ bindWebGpuDeviceDiagnostics(library);
visionRuntime = { library, processor, model };
visionRuntimeKey = key;
visionRuntimeModelKey = textModelKey(modelId, dtype);
diff --git a/test/run.js b/test/run.js
index 2b1b3b331..01d4eebd4 100644
--- a/test/run.js
+++ b/test/run.js
@@ -63515,6 +63515,10 @@ test('WebGPU worker follows local text-generation and WebBrain VL vision contrac
'a persisted WebGPU selection must be revalidated on startup so evicted caches fall back');
assert.match(worker, /payload\?\.probeActive === true[\s\S]*?textDownloadSnapshot/,
'text-download-status probes must return the active transfer when requested');
+ assert.match(worker, /device\.lost\?\.then\(info => \{[\s\S]*?requestWebgpuWorkerRecycle\('device-lost'\)/,
+ 'a confirmed device loss without OrtRun must still recycle the worker instead of rebuilding in place');
+ assert.match(worker, /const processor = processorResult\.value;[\s\S]*?bindWebGpuDeviceDiagnostics\(library\)/,
+ 'vision-backed runtimes must bind device diagnostics so device loss is observed');
assert.match(host, /sendTextWorkerMessage\(message\.model, 'text-download-status'/);
assert.match(host, /'webgpu-dispose'/);
assert.match(host, /'webgpu-vision-dispose'/);