Fix long dictation retry backpressure

Treat Node IPC backpressure as a queue signal instead of a failed send, and pace buffered dictation replay so finish waits for the backlog to flush.
This commit is contained in:
Mohamed Boudra
2026-06-04 13:35:10 +07:00
parent e381117b1c
commit f0370a3c20
5 changed files with 197 additions and 12 deletions
@@ -137,4 +137,30 @@ describe("DictationStreamSender", () => {
expect(client.chunks.map((c) => c.seq)).toEqual([0, 1]);
});
it("does not replay long buffered native dictation in one synchronous burst", async () => {
const client = new FakeDaemonClient();
client.isConnected = false;
const sender = new DictationStreamSender({
client: client as unknown as DaemonClient,
format: "audio/pcm;rate=16000;bits=16",
createDictationId: () => "d1",
});
for (let seq = 0; seq < 480; seq += 1) {
sender.enqueueSegment(`native-frame-${seq}`);
}
client.isConnected = true;
const finish = sender.finish(sender.getFinalSeq());
await tick();
expect(client.chunks.length).toBeLessThanOrEqual(128);
await expect(finish).resolves.toEqual({
dictationId: "d1",
text: "ok",
});
expect(client.finishes).toEqual([{ dictationId: "d1", finalSeq: 479 }]);
});
});