fix: don't double-wrap WebRTCError raised inside connect()#48
Merged
AdirAmsalem merged 6 commits intomainfrom Apr 20, 2026
Merged
fix: don't double-wrap WebRTCError raised inside connect()#48AdirAmsalem merged 6 commits intomainfrom
AdirAmsalem merged 6 commits intomainfrom
Conversation
The blanket `except Exception` handler in connect() was re-wrapping every WebRTCError into another WebRTCError (message=str(original), cause=original) and emitting it through on_error a second time — once from the original raise site (e.g. _handle_error), once from the except block. Catch WebRTCError separately and re-raise as-is so callers see a single, unwrapped error with no redundant cause chain.
2 tasks
The prior fix skipped on_error for all WebRTCError exceptions in connect(), which regressed direct-raise paths (e.g. ack timeouts) that don't flow through _handle_error. Gate the skip on _connection_error being set so only the _handle_error path (which already emitted on_error) is deduped.
_connection_error was doubling as a proxy for "on_error was already fired". That coupling was implicit and would break silently if a future code path set _connection_error without firing on_error. Replace with a dedicated flag that expresses intent directly and is set at each call site.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e9ab59b. Configure here.
The new except WebRTCError branch was missing the logger.error call that
the generic except Exception branch has, so client-side timeout paths
(ack timeouts from _send_initial_{prompt,image}_and_wait) had no log
entry. Server-originated errors were still logged by _handle_error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Errors surfaced through
realtime.connect()were being reported twice and with a redundant nested cause. When aWebRTCErrorwas raised from insideconnect()(e.g. a server capacity rejection, or an initial image/prompt failure), the outerexcept Exceptionhandler re-wrapped it into anotherWebRTCErrorand emitted it through theon_errorcallback a second time — once from the original raise site, once from the except block.Callers now see a single, unwrapped error;
on_errorfires once per failure. Follow-up to #47, addressing review feedback.Test plan
causeand no duplicateon_errorinvocationNote
Low Risk
Small, localized error-handling change with added unit coverage; main risk is subtly altering callback firing order/behavior on edge-case connection failures.
Overview
Prevents
WebRTCConnection.connect()from double-wrapping aWebRTCError(and from emittingon_errortwice) by adding a per-connect()_on_error_firedguard and a dedicatedexcept WebRTCErrorpath that re-raises as-is.Adds regression tests covering both a server-error/
_handle_errorrace and directWebRTCErrorraises (e.g., ack timeouts), asserting no nestedcauseand exactly oneon_errorcallback invocation.Reviewed by Cursor Bugbot for commit a40c2ad. Bugbot is set up for automated code reviews on this repo. Configure here.