Skip to content

Commit afaf723

Browse files
PaulAsjesclaude
andcommitted
Capture event_id upfront in send_response for string path
The string response path called _send_agent_response twice without an explicit event_id, reading self._current_event_id at each call. An interruption between the two awaits could stamp the terminator with the wrong event_id. Now captures event_id once and passes it through, matching the stream path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4b4e2fb commit afaf723

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/elevenlabs/speech_engine/session.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,22 @@ async def send_response(
300300
)
301301
return
302302

303+
event_id = self._current_event_id
304+
303305
if isinstance(response, str):
304306
self._log(
305307
'sending string response: "%s", event_id=%s',
306308
response,
307-
self._current_event_id,
309+
event_id,
308310
)
309-
await self._send_agent_response(response, False)
310-
await self._send_agent_response("", True)
311+
await self._send_agent_response(response, False, event_id)
312+
await self._send_agent_response("", True, event_id)
311313
else:
312314
self._log(
313315
"starting streamed response, event_id=%s",
314-
self._current_event_id,
316+
event_id,
315317
)
316-
await self._stream_response(response)
318+
await self._stream_response(response, event_id)
317319

318320
def close(self) -> None:
319321
"""Close the session and the underlying WebSocket connection."""
@@ -435,8 +437,9 @@ async def _run_transcript_handlers(
435437
finally:
436438
self._in_transcript_handler = False
437439

438-
async def _stream_response(self, stream: typing.Any) -> None:
439-
event_id = self._current_event_id
440+
async def _stream_response(
441+
self, stream: typing.Any, event_id: typing.Optional[int] = None
442+
) -> None:
440443
chunks = 0
441444
try:
442445
async for chunk in stream:

0 commit comments

Comments
 (0)