Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(voice): reset playback clocks for reopened clients

rubenluetke10-beep0a55a2dbebdf
diff --git a/jarvis/ui/web/frontend/src/lib/realtimeAudio.test.ts b/jarvis/ui/web/frontend/src/lib/realtimeAudio.test.ts
index 693191f780..42bc1891f4 100644
--- a/jarvis/ui/web/frontend/src/lib/realtimeAudio.test.ts
+++ b/jarvis/ui/web/frontend/src/lib/realtimeAudio.test.ts
@@ -233,6 +233,22 @@ describe("realtime audio client", () => {
expect(readTimedSpeechPlayback("stale-wire")).toBeNull();
socket.receive({ type: "audio_closed" });
await client.disconnect();
+ const reconnecting = client.connect();
+ await vi.waitFor(() => expect(FakeWebSocket.instances).toHaveLength(2));
+ const freshSocket = FakeWebSocket.instances[1];
+ freshSocket.open();
+ freshSocket.receive({ type: "audio_ready", webrtc_answer_sdp: "new-answer",
+ output_transport: "timed_pcm", output_sample_rate: 24000 });
+ await reconnecting;
+ freshSocket.receive({ type: "speech_timing", epoch: 0, line_id: "new-call", text: "New",
+ char_start: 0, char_end: 3, start_ms: 0, end_ms: 1000 });
+ freshSocket.receive({ type: "audio_timed", epoch: 0, start_ms: 0, end_ms: 1000,
+ sample_rate: 24000, audio: Buffer.from(new Int16Array(24000).buffer).toString("base64") });
+ expect(readTimedSpeechPlayback("new-call")?.chars).toBe(0);
+ const newPlayer = FakeAudioNode.instances.filter(node => node.name === "pcm-playback").at(-1)!;
+ expect(newPlayer.port.postMessage.mock.calls.some(([m]) => m.type === "pcm")).toBe(true);
+ freshSocket.receive({ type: "audio_closed" });
+ await client.disconnect();
});
it("does not consume the media deadline while microphone permission is pending", async () => {
vi.useFakeTimers();
diff --git a/jarvis/ui/web/frontend/src/lib/realtimeAudio.ts b/jarvis/ui/web/frontend/src/lib/realtimeAudio.ts
index faf3e181e6..6e0eab084a 100644
--- a/jarvis/ui/web/frontend/src/lib/realtimeAudio.ts
+++ b/jarvis/ui/web/frontend/src/lib/realtimeAudio.ts
@@ -687,6 +687,13 @@ export class RealtimeAudioClient {
}
private async open(): Promise<void> {
+ // A reused client starts a new source timeline. Keep the local render
+ // generation monotonic so callbacks from the old worklet stay obsolete.
+ this.timedOutput = false;
+ this.timedEpoch = 0;
+ this.lastTimedAudioEnd = -1;
+ this.flushPlayback();
+ setTimedSpeechSession("");
this.startupAt = performance.now();
this.startupMarks = {};
this.intentionalClose = false;