Skip to content

voice/twilio: a-leg place_call should fail fast on busy / no-answer / failed instead of waiting the full stream-connect timeout #984

Description

@drewdrewthis

What happens

With attach_stream="a-leg" (#762, PR #982), place_call() issues Calls.create and then waits on _stream_connected for timeout (default 120s). If the callee never answers — Twilio marks the call busy, no-answer, failed or canceled within seconds — the adapter still sits for the full timeout before _abandon_originated_call hangs up and raises TimeoutError.

Observed twice on 2026-09-09 while producing the proof: Twilio returned busy at +6s, the adapter raised at +120s.

Proposal

Fail fast as soon as Twilio reports a terminal non-answered status, and surface it as a distinct error (CallNotAnsweredError(status=...)) rather than TimeoutError. Two ways to learn the status, either is fine:

  1. Pass status_callback=<public_base_url>/twilio/status with status_callback_event=["answered","completed"] on Calls.create and have the server set an event; the a-leg path already owns the tunnel + server.
  2. Poll calls(sid).fetch().status every ~2s while waiting on _stream_connected.

Keep TimeoutError for the case where the call is in-progress but the stream never connects (tunnel/WS problem).

Same for the JS adapter (placeCall / _abandonOriginatedCall).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tc6K2QfkvcWiasy8ane6EG

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions