mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 18:07:00 +01:00
fix(voice): clear rejected call admission before a new attempt
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
05b07417d9
commit
7bec940bf1
2 files changed
+15
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user