Skip to content

VAPI-3985: hold the call open after Connect/Stream with StopStream wait="true" - #26

Merged
mramasubramanian-bw merged 2 commits into
mainfrom
VAPI-3985/connect-stream-stopstream-wait
Sep 21, 2026
Merged

mramasubramanian-bw merged 2 commits into
mainfrom
VAPI-3985/connect-stream-stopstream-wait

Conversation

@mramasubramanian-bw

@mramasubramanian-bw mramasubramanian-bw commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Twilio <Connect><Stream> translated to a bare <StartStream> with nothing after it. Bandwidth ends a call when BXML execution runs out of verbs, so every translated AI-voice flow hung up on answer (30 ms after stream start on a real call), and the translator reported hasErrors: false.

The fix emits <StopStream name="..." wait="true"/> immediately after the <StartStream>, as the StartStream docs recommend for bidirectional streams. BXML execution blocks there until the bot closes the WebSocket. This also restores Twilio's <Connect> semantics: verbs after <Connect> now run once the stream ends instead of immediately over the bot's first words.

Changes

  • src/translator/translate.ts: emit StopStream wait="true" after StartStream for Connect/Stream. Generate a per-document stream name (connect-stream-N) when the TwiML <Stream> has none, since StopStream must name the stream it stops. Add a Connect warning finding explaining the inserted verb.
  • src/matrix/twilio-voice.json, AGENTS.md: update the Connect note.
  • Tests: update the one case that pinned the bare output; add coverage for the new shape, generated names, per-document name reset, trailing-verb ordering, and "StartStream is never the last verb".
  • Start/Stream (unidirectional fork) is unchanged.

Before / after

Input:

<Response><Connect><Stream url="wss://bot.test/ws"/></Connect><Say>Goodbye</Say></Response>

Before:

<Response><StartStream destination="wss://bot.test/ws" mode="bidirectional" tracks="inbound"/><SpeakSentence>Goodbye</SpeakSentence></Response>

After:

<Response><StartStream name="connect-stream-1" destination="wss://bot.test/ws" mode="bidirectional" tracks="inbound"/><StopStream name="connect-stream-1" wait="true"/><SpeakSentence>Goodbye</SpeakSentence></Response>

Verification

  • npm run typecheck && npx vitest run: 44 files, 309 passed, 6 skipped.
  • Real calls on 2026-09-17 (account 9900778): the identical StartStream followed by StopStream wait="true" held the call with audio both ways until hangup. Bare StartStream dropped in 0.03 s.

…it="true"

Twilio <Connect><Stream> translated to a bare <StartStream> with nothing after
it. Bandwidth ends a call when BXML execution runs out of verbs, so every
translated AI-voice flow hung up on answer (30 ms after stream start on a real
call), and the translator reported hasErrors: false.

Per the StartStream docs (Bidirectional streams), emit
<StopStream name="..." wait="true"/> immediately after the StartStream. BXML
execution blocks there until the bot closes the WebSocket, which also restores
Twilio's <Connect> semantics: verbs after <Connect> now run once the stream
ends instead of immediately over the bot's first words.

- Generate a per-document stream name (connect-stream-N) when the TwiML
  <Stream> has none, since StopStream must name the stream it stops.
- Emit a Connect warning finding explaining the inserted verb.
- Start/Stream (unidirectional fork) is unchanged.
- Update the Connect matrix note and AGENTS.md; update tests that pinned the
  bare output and add coverage for the new shape, generated names, and
  trailing-verb ordering.

Verified on real calls 2026-09-17 (account 9900778): the identical StartStream
followed by StopStream wait="true" held the call with audio both ways until
hangup; bare StartStream dropped in 0.03 s.
@mramasubramanian-bw
mramasubramanian-bw requested review from a team as code owners September 18, 2026 19:20
@bwappsec

bwappsec commented Sep 18, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@mramasubramanian-bw
mramasubramanian-bw requested a review from a team as a code owner September 21, 2026 18:05
@mramasubramanian-bw
mramasubramanian-bw merged commit bcfc980 into main Sep 21, 2026
6 checks passed
@mramasubramanian-bw
mramasubramanian-bw deleted the VAPI-3985/connect-stream-stopstream-wait branch September 21, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants