Your always-on AI coworkers that move between text, calls, and Slack.
TypeScript
fix: allow retrying failed voice compute turns (#13)
Charan Rathore6b67b743668e
diff --git a/src/server/voice.ts b/src/server/voice.tsindex 232ebf5..66cfce9 100644--- a/src/server/voice.ts+++ b/src/server/voice.ts@@ -5,6 +5,7 @@ export class VoiceService {{controller: AbortController;calls: Map<string, Promise<string>>;+ attempts: number;deadline: ReturnType<typeof setTimeout>;providerId?: string;}@@ -46,7 +47,12 @@ export class VoiceService {void this.expire(call.id, 'Call connection expired before activation.');}, 30_000);deadline.unref();- this.jobs.set(call.id, { controller, calls: new Map(), deadline });+ this.jobs.set(call.id, {+ controller,+ calls: new Map(),+ attempts: 0,+ deadline,+ });const timeout = AbortSignal.timeout(20_000);const dot = this.platform.workspace.dot(this.platform.workspace.requireThread(threadId).dotId,@@ -177,17 +183,25 @@ export class VoiceService {if (!job) throw new Error('Call session expired; start a new call.');const existing = job.calls.get(toolCallId);if (existing) return existing;- if (job.calls.size >= 6)+ if (job.attempts >= 6)throw new Error('This call reached its six compute-turn limit. Start another call to continue.',);+ job.attempts += 1;const pending = this.platform.turn(call.threadId,request,AbortSignal.any([job.controller.signal, AbortSignal.timeout(90_000)]),);job.calls.set(toolCallId, pending);- return pending;+ try {+ return await pending;+ } catch (error) {+ // Deduplicate in-flight and successful turns, and let a failed turn retry under the same ID.+ // Every attempt still counts toward the six-turn cap.+ job.calls.delete(toolCallId);+ throw error;+ }}async end(id: string, transcript: string) {const previous = this.platform.workspace.call(id);diff --git a/tests/voice.test.ts b/tests/voice.test.tsindex 75e5345..00b803c 100644--- a/tests/voice.test.ts+++ b/tests/voice.test.ts@@ -248,3 +248,83 @@ it('sanitizes custom provider transport error names', async () => {'The local call stopped, but provider hangup failed (transport error).',);});+it('allows a rejected compute call to be retried with the same tool ID', async () => {+ const f = fixture();+ const call = await f.voice.begin(+ 'thread',+ offer,+ new AbortController().signal,+ );+ f.voice.activate(call.id);+ f.turn.mockRejectedValueOnce(new Error('Provider unavailable'));+ await expect(f.voice.compute(call.id, 'retry', 'Research')).rejects.toThrow(+ 'Provider unavailable',+ );+ await expect(f.voice.compute(call.id, 'retry', 'Research')).resolves.toBe(+ 'Current answer',+ );+ expect(f.turn).toHaveBeenCalledTimes(2);+ await f.voice.end(call.id, '');+});+it('counts failed compute attempts toward the six-turn limit', async () => {+ const f = fixture();+ const call = await f.voice.begin(+ 'thread',+ offer,+ new AbortController().signal,+ );+ f.voice.activate(call.id);+ for (let i = 0; i < 6; i++) {+ f.turn.mockRejectedValueOnce(new Error('Provider unavailable'));+ await expect(+ f.voice.compute(call.id, `failed-${i}`, 'Research'),+ ).rejects.toThrow('Provider unavailable');+ }+ await expect(f.voice.compute(call.id, 'success', 'Research')).rejects.toThrow(+ 'six compute-turn limit',+ );+ expect(f.turn).toHaveBeenCalledTimes(6);+ await f.voice.end(call.id, '');+});+it('counts a retry of the same tool ID as another attempt', async () => {+ const f = fixture();+ const call = await f.voice.begin(+ 'thread',+ offer,+ new AbortController().signal,+ );+ f.voice.activate(call.id);+ for (let i = 0; i < 6; i++) {+ f.turn.mockRejectedValueOnce(new Error('Provider unavailable'));+ await expect(f.voice.compute(call.id, 'same', 'Research')).rejects.toThrow(+ 'Provider unavailable',+ );+ }+ await expect(f.voice.compute(call.id, 'same', 'Research')).rejects.toThrow(+ 'six compute-turn limit',+ );+ expect(f.turn).toHaveBeenCalledTimes(6);+ await f.voice.end(call.id, '');+});+it('keeps successful compute turns cached and enforces the six-turn cap', async () => {+ const f = fixture();+ const call = await f.voice.begin(+ 'thread',+ offer,+ new AbortController().signal,+ );+ f.voice.activate(call.id);+ for (let i = 0; i < 6; i++) {+ await expect(f.voice.compute(call.id, String(i), 'Research')).resolves.toBe(+ 'Current answer',+ );+ }+ await expect(f.voice.compute(call.id, '0', 'Research')).resolves.toBe(+ 'Current answer',+ );+ expect(f.turn).toHaveBeenCalledTimes(6);+ await expect(f.voice.compute(call.id, 'extra', 'Research')).rejects.toThrow(+ 'six compute-turn limit',+ );+ await f.voice.end(call.id, '');+});