From 7bec940bf13bb081a76c98fe1f17fe2d2fd86688 Mon Sep 17 00:00:00 2001 From: Dotta Date: Fri, 9 Oct 2026 15:20:02 -0500 Subject: [PATCH] fix(voice): clear rejected call admission before a new attempt Co-Authored-By: Paperclip --- ui/src/lib/voice-call-attempt.test.ts | 10 ++++++++++ ui/src/lib/voice-call-attempt.ts | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/ui/src/lib/voice-call-attempt.test.ts b/ui/src/lib/voice-call-attempt.test.ts index e7f827ae32f..4c2d4e9d5fc 100644 --- a/ui/src/lib/voice-call-attempt.test.ts +++ b/ui/src/lib/voice-call-attempt.test.ts @@ -14,6 +14,16 @@ function fixture() { return { rows, storage, client, journal }; } describe("voice reload recovery", () => { + it.each([400, 401, 403, 404, 422])("allows a new endpoint after definitive admission rejection %s", async (status) => { + const f = fixture(); + f.client.start.mockRejectedValueOnce(new ApiError("Rejected", status, {error: "Rejected"})); + const attempt = createVoiceCallAttempt("company", f.client, f.journal); + await expect(attempt.start({endpointId: "stale"})).rejects.toBeInstanceOf(ApiError); + expect(f.journal.read()).toBeUndefined(); + await attempt.start({endpointId: "valid", issueId: "new-task"}); + expect(f.client.start.mock.calls[1]?.[1]).toMatchObject({endpointId: "valid", issueId: "new-task"}); + expect(f.client.start.mock.calls[1]?.[1].idempotencyKey).not.toBe(f.client.start.mock.calls[0]?.[1].idempotencyKey); + }); it("retains exact cleanup identity and a safe credit reason after a rejected creation", async () => { const f=fixture();f.client.start.mockRejectedValue(new ApiError("private provider detail",409,{details:{code:"voice_credits_required",sessionId:"failed-call"}})); const attempt=createVoiceCallAttempt("company",f.client,f.journal); diff --git a/ui/src/lib/voice-call-attempt.ts b/ui/src/lib/voice-call-attempt.ts index 615815618c4..a24bb101b64 100644 --- a/ui/src/lib/voice-call-attempt.ts +++ b/ui/src/lib/voice-call-attempt.ts @@ -54,6 +54,11 @@ export function createVoiceCallAttempt(companyId: string, client: typeof voiceSe try { journal?.write(attempt); } catch { /* Exact identity still reaches cleanup. */ } throw new VoiceSessionStartError(attempt.sessionId, body.details.code === "voice_credits_required" ? "credits_required" : undefined); } + if (error instanceof ApiError && [400, 401, 403, 404, 422].includes(error.status)) { + // These responses reject admission before creating a provider call. + // Network errors and ambiguous provider outcomes keep their identity. + journal?.clear(); attempt = undefined; recovering = false; + } throw error; } attempt.sessionId = result.session.id;