Repository navigation
Description
Summary
With #1069 merged (fd6ba602), the REST trigger works and outbound calls now place and ring — but the call drops within ~1s of answer, and Twilio logs error 31920 (Stream – WebSocket – Handshake Error). Root cause: the Media Streams auth ticket is passed in the query string of the <Stream> URL, and Twilio Media Streams does not forward query parameters on the <Stream url> WebSocket. The backend WS handler therefore sees ticket=None, closes before accept(), and the handshake fails with HTTP 403.
VoIP outbound is still unusable end-to-end. Observed on dev HEAD fd6ba602.
Backend log (real call)
services.voip_service: VoIP outbound placed: agent=cornelius-m call_id=voip_u4swU... twilio_sid=CA1e91...
INFO: 172.28.0.6:35086 - "WebSocket /api/voip/voice/voip_u4swU..." 403
INFO: connection rejected (403 Forbidden)
Root cause
services/voip_service.py:104buildswss://HOST/api/voip/voice/{call_id}?ticket={ticket}.routers/voip.py:225readsticket: Optional[str] = Query(default=None).adapters/transports/twilio_media_stream.py:177:info = consume_ticket(ticket) if ticket else None; if not info or info.get("scope") != f"voip:{call_id}": await websocket.close(code=4001, ...).
Closing before accept() surfaces as HTTP 403 during the WS handshake → Twilio 31920 → PSTN leg drops on answer. Twilio requires custom data to be passed via <Parameter> child elements, not the URL query string.
Evidence it's the query string, not the tunnel/proxy
Controlled isolation test on a live instance behind Cloudflare Tunnel:
- Minted a throwaway ticket via
POST /api/ws/ticket; confirmed RedisEXISTS ws_ticket:<t>= 1. - Opened a WebSocket through the public Cloudflare tunnel to
wss://HOST/api/voip/voice/PROBE?ticket=<t>(got 403 — scope mismatch, expected). - Re-checked Redis:
EXISTS ws_ticket:<t>= 0 —consume_ticketran andGETDEL'd it.
→ The proxy/tunnel does forward the WS query string and the backend reads it. The only difference in the failing real-call path is the Twilio client, which doesn't send the query string. (The real call's minted voip ticket stayed unconsumed in Redis until TTL expiry.)
Suggested fix
Pass the ticket as a Media Streams <Parameter> (Twilio forwards these in the start event), keep call_id in the path:
<Response><Connect>
<Stream url="wss://HOST/api/voip/voice/{call_id}">
<Parameter name="ticket" value="{ticket}"/>
</Stream>
</Connect></Response>In handle_media_stream, accept() first, read start.customParameters.ticket from the first Twilio start frame, validate, and close if invalid (reordering auth to after accept). Optionally keep the query-string read as a fallback for non-Twilio clients. Add an integration test feeding a Twilio-style start event with customParameters.ticket.
Environment
construct @ fd6ba602, VOIP_ENABLED=true, tunnel api/voip/.* confirmed forwarding WS+query, per-agent Twilio binding configured. Everything except this ticket-transport mismatch is in place.
Filed by the Trinity Ops Agent while bringing up VoIP on the construct instance. Follow-on to #1069.
Activity
vybe commentedon Jun 4, 2026
/claim
github-actions commentedon Jun 4, 2026
Claimed by @vybe. Label
status-in-progressadded.Next steps:
feature/1073-<short-slug>Fixes #1073test(voip): exempt #1069/#1073 VoIP unit tests from sys.modules lint
fix(voip): pass Media Streams ticket via <Parameter>, not query string (
vybe commentedon Jun 4, 2026
Merged to
devvia #1075 (squashcfee2754). Awaiting the next release cut (dev→main) to close. Validation: 26 VoIP unit tests pass, sys.modules lint green, security clean.