You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pass disconnection details to callback_end_session #892
In Conversation and AsyncConversation (src/elevenlabs/conversational_ai/conversation.py), callback_end_session is called with no arguments (Callable[[], None] / Callable[[], Awaitable[None]]).
When the WebSocket closes in _run(), the SDK catches ConnectionClosedOK and Exception, logs non-1000 errors, and calls end_session(), discarding the WebSocket code, reason, and exception. Callers cannot distinguish between:
I'd like to work on this. I checked the current sync and async shutdown paths; both still call callback_end_session() without forwarding the close details.
My proposed approach is a small DisconnectionDetails type carrying the close code, close reason, and user/agent/error classification, exposed through an optional callback_disconnect(details) callback. The existing zero-argument callback_end_session would remain unchanged. That avoids inspecting callback signatures or catching TypeError that might come from inside a user's callback.
I'd add local WebSocket regression tests for normal server closure, error closure, and user-initiated shutdown, covering sync/async parity and existing callbacks. These shouldn't need a hosted agent or audio hardware.
Would you prefer this separate callback, or extending callback_end_session as suggested in the issue? I'd like to confirm the public API before implementing it.
Activity
gauravch-code commentedon Oct 21, 2026
I'd like to work on this. I checked the current sync and async shutdown paths; both still call
callback_end_session()without forwarding the close details.My proposed approach is a small
DisconnectionDetailstype carrying the close code, close reason, and user/agent/error classification, exposed through an optionalcallback_disconnect(details)callback. The existing zero-argumentcallback_end_sessionwould remain unchanged. That avoids inspecting callback signatures or catchingTypeErrorthat might come from inside a user's callback.I'd add local WebSocket regression tests for normal server closure, error closure, and user-initiated shutdown, covering sync/async parity and existing callbacks. These shouldn't need a hosted agent or audio hardware.
Would you prefer this separate callback, or extending
callback_end_sessionas suggested in the issue? I'd like to confirm the public API before implementing it.corbin-caldwell commentedon Oct 26, 2026
Hey @gauravch-code , adding a separate callback would work!