Skip to content

Report conversation disconnection details - #907

Merged
kraenhansen merged 5 commits into
elevenlabs:mainfrom
gauravch-code:fix/892-disconnection-details
Oct 27, 2026
Merged

kraenhansen merged 5 commits into
elevenlabs:mainfrom
gauravch-code:fix/892-disconnection-details

Conversation

@gauravch-code

@gauravch-code gauravch-code commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #892

Adds an optional callback_disconnect(details) callback to Conversation and AsyncConversation. It reports whether the user, agent, or an error ended the session, along with received WebSocket close details and error messages.

Existing callback_end_session callbacks keep their zero-argument signature. Shutdown notifications run once, including during concurrent or reentrant shutdown.

Adds documentation and 39 regression tests covering normal/error closures, connection loss, setup failures, and callback behavior.

@cursor

cursor Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches core session teardown and WebSocket error paths for sync and async conversations, but keeps backward compatibility and is heavily regression-tested.

Overview
Adds callback_disconnect and a DisconnectionDetails payload so apps can tell whether a ConvAI session ended because the user called end_session(), the agent closed the WebSocket normally, or an error occurred (with close code/reason and error text when available). callback_end_session still runs first but is deprecated with a DeprecationWarning.

Shutdown is centralized in _end_session: disconnect callbacks fire once under concurrent/reentrant end_session, audio stop only runs if capture actually started, and setup/connection/WebSocket failures route through the same cleanup path. README documents the new callback; tests/test_convai_disconnect.py adds broad sync/async regression coverage.

Reviewed by Cursor Bugbot for commit 77e2107. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 6b943f7. Configure here.

Comment thread tests/test_convai_disconnect.py Resolved
…sconnect

Aligns with onDisconnect in the JS, Kotlin, Swift, Flutter and Unity SDKs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kraenhansen and others added 2 commits October 27, 2026 08:54
…ssion_end

Restores the behaviour on main, where awaiting the session task raised on
connection, initiation or audio start failures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kraenhansen

Copy link
Copy Markdown
Member

Thanks @gauravch-code! I pushed three commits on top:

  • 7d6da18, 30ed272: deprecate callback_end_session in favour of callback_disconnect (docstrings, README and a DeprecationWarning), matching onDisconnect in the other Agents SDKs. Removal is tracked in Remove deprecated callback_end_session (breaking) #908.
  • 77e2107: AsyncConversation._run re-raises after reporting the disconnect, so await wait_for_session_end() raises on connection, initiation or audio start failures again, as it does on main.

One thing left for you: test_{sync,async}_connection_failure_reports_error hang on macOS, since connecting to a bound but non-listening port times out there rather than being refused. Closing the socket after reading its port fixes it.

@kraenhansen
kraenhansen merged commit dfb2194 into elevenlabs:main Oct 27, 2026
1 check passed
gh-worker-dd-mergequeue-cf854d Bot pushed a commit to DataDog/dd-trace-py that referenced this pull request Nov 3, 2026
## Description

Adds test coverage for elevenlabs 2.75.0, the latest release, alongside 2.70.0, the oldest supported version. Both are tested on Python 3.12, 3.13, 3.14 and 3.15. The integration needs no changes: every method it patches is unchanged in 2.75.0, and no new functionality is traced.

2.75.0 changes how Agents conversations shut down ([elevenlabs-python#907](elevenlabs/elevenlabs-python#907), [v2.75.0 release](https://github.com/elevenlabs/elevenlabs-python/releases/tag/v2.75.0)):
- The SDK now sets its stop flag before cleanup.
- A server-closed session now ends without calling `end_session()`.

The existing aborted-shutdown test relies on the old order, so it now runs only on SDKs older than 2.75.0. Two new tests run the real SDK against a local WebSocket server and cover a server close and an aborted shutdown on both versions.

## Testing

`scripts/run-tests` on all 8 `llmobs::elevenlabs` environments:
- 2.70.0: 144 passed.
- 2.75.0: 138 passed, 6 skipped (the version-gated test).

`scripts/lint checks` passes.

## Risks

None. The diff only touches tests and test metadata.

## Additional Notes

No release note, because nothing users run changes (`changelog/no-changelog`).

🤖 Generated with [Claude Code](https://claude.com/claude-code)


Co-authored-by: william.conti <[email protected]>
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.

Pass disconnection details to callback_end_session

2 participants