Repository navigation
Don't retry call-placing requests after an ambiguous failure - #32
Open
zorionarrillaga wants to merge 1 commit into
Open
zorionarrillaga wants to merge 1 commit into
zorionarrillaga wants to merge 1 commit into
Conversation
POST /call, /campaign and /v2/campaign take no idempotency key, so the default retry on 5xx, 408, 409 or a dropped connection could dial the same customer twice. These requests are now retried only on 429 and on connection errors raised before the request was sent. Other requests keep their retries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proof of concept for #31. The SDK is generated, so this shows the change and its tests for carrying over to the generator.
What broke
HttpClient.request(src/vapi/core/http_client.py) retries every request up to 2 times by default:_should_retry);httpx.RemoteProtocolError, a connection dropped before the reply arrived.calls.create()isPOST /call, andcampaigns.campaign_controller_create()/_v_2()arePOST /campaignandPOST /v2/campaign. All three place outbound phone calls. A 5xx or a dropped connection can come after Vapi has already dialled: a gateway timeout, or a proxy losing the reply. The API takes no idempotency key, so it can't tell the retry from a new request. The customer's phone rings a second time, the org pays for two calls, and the caller only gets back the second call id.How it was reproduced
I used a local mock of
POST /callon 127.0.0.1 only; no Vapi account or real API was involved. The mock records every POST as a dialled call and answers the first one with502 Bad Gateway. Oneclient.calls.create(assistant_id=..., phone_number_id=..., customer={"number": "+14155550199"}):main(01ebf69)call-1,call-2)call-1,call-2)call-1)call-2call-2ApiError502The PyPI 3.0.0 wheel's
vapi/package is byte-identical tomain(diff -ris empty).What changed
core/http_client.py: a new helper,_places_calls(method, path). It is true forPOSTtocall,campaignorv2/campaign. For those requests, in both the sync and the async client:httpx.ConnectError(the request was never sent).RemoteProtocolErroris raised to the caller instead.assistants.create, keeps its current retries.tests/custom/test_call_placing_retries.py(new, 26 cases). It uses an in-memoryhttpx.MockTransportthrough the realVapi/AsyncVapiclients:calls.create, campaign create and campaign create v2 each hit the server exactly once after 500/502/503/504/408/409 (18 cases) and after a dropped connection (3);calls.createis still retried on 429, and when the connection never opened;calls.list()(GET) andassistants.create()(another POST) are still retried on 503;calls.createis sent once after a 502, and once after a dropped connection..fernignore: lists the new test, as for their other custom tests.How it was tested
main(every "sent once" case). The 3 "still retried" cases pass on both. All 26 pass on the branch.pytest -n 4 tests, Python 3.11.14): 105 passed, 4 skipped on the branch. HEAD gives 79 passed, 4 skipped.mypy .(1.13.0, their pin):Success: no issues found in 2512 source files.ruff checkandruff format --check(0.11.5, their pin): clean on both changed files.