Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(voice): cancel source stream after write failure

vastsad77157421f9a
diff --git a/apps/desktop/test/voice-model-download.test.mjs b/apps/desktop/test/voice-model-download.test.mjs
index 8217616af..ab8435198 100644
--- a/apps/desktop/test/voice-model-download.test.mjs
+++ b/apps/desktop/test/voice-model-download.test.mjs
@@ -81,13 +81,25 @@ test("a mid-stream source failure rejects and leaves neither the final file nor
test("an unwritable .part path surfaces a download failure instead of crashing the process", async (t) => {
const dir = await tmpDir(t);
- setBehavior(() => responseFrom([[1, 2, 3]]));
+ let sourceCancelled = false;
+ setBehavior(() => ({
+ headers: { get: () => "3" },
+ body: new ReadableStream({
+ start(controller) {
+ controller.enqueue(new Uint8Array([1, 2, 3]));
+ },
+ cancel() {
+ sourceCancelled = true;
+ },
+ }),
+ }));
// A directory sitting at the .part path makes the WriteStream's open fail
// asynchronously — the exact "unhandled stream error" shape that used to
// take down the Electron main process.
await mkdir(join(dir, "ggml-small-q8_0.bin.part"));
await assert.rejects(consume(downloadModel(MODEL, dir)));
+ assert.equal(sourceCancelled, true, "a write failure cancels the open response body");
const entries = await readdir(dir);
assert.deepEqual(entries, ["ggml-small-q8_0.bin.part"], "final path never created");
});
diff --git a/packages/voice-runtime/src/model-downloader.ts b/packages/voice-runtime/src/model-downloader.ts
index 0df1a0461..bfb930c69 100644
--- a/packages/voice-runtime/src/model-downloader.ts
+++ b/packages/voice-runtime/src/model-downloader.ts
@@ -90,6 +90,9 @@ export async function* downloadModel(
await rename(partPath, targetPath);
yield 1;
} catch (error) {
+ // A sink error can win the race while reader.read() is still waiting.
+ // Cancel the response so a failed disk write does not keep downloading.
+ await reader.cancel(error).catch(() => {});
writer.destroy();
await writerClosed;
// Clean up the partial download; the final path is never touched.