Commit c24ea70
authored
fix(inworld-tts): don't poison receive stream with stale-context errors (#539)
Two related issues caused TTS calls to fail with `Context not found
during sendText` after >60 seconds of inactivity, leaving the agent
unable to speak its proactive responses.
1. **`_keepalive_loop` sends `send_text` without a `contextId`.**
When `_active_context_id` is `None`, the keepalive payload still
contains `{"send_text": {"text": ""}}` with no `contextId`. The
server cannot route this to a context and responds with an error
message. The error then sits in the WebSocket receive buffer and
surfaces on the next valid TTS call, breaking it. Fix: skip the
keepalive iteration when no active context exists. The websockets
library handles TCP-level keepalive via PING/PONG independently.
2. **`_receive_audio` did not filter errors by `contextId`.** Audio
chunks were filtered by `msg_context_id != context_id`, but the
error/status check ran first and raised regardless of which context
the message was for. Fix: pull the `contextId` mismatch check above
the status/error checks so messages addressed to a different (or
stale) context are dropped early. Server-wide errors with no
`contextId` (e.g. "max contexts limit reached") still pass through.1 parent 57d0923 commit c24ea70
1 file changed
Lines changed: 22 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
211 | 212 | | |
212 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
213 | 223 | | |
214 | 224 | | |
215 | 225 | | |
| |||
221 | 231 | | |
222 | 232 | | |
223 | 233 | | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | 234 | | |
229 | 235 | | |
230 | 236 | | |
| |||
362 | 368 | | |
363 | 369 | | |
364 | 370 | | |
365 | | - | |
366 | | - | |
367 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
368 | 382 | | |
369 | 383 | | |
370 | 384 | | |
| |||
0 commit comments