Skip to content

Fix/broad exception handling #6280 #6647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

tejas-dharani
Copy link
Contributor

Why are these changes needed?

This fix addresses proper WebSocket disconnect handling in the team chat application. The current implementation catches WebSocketDisconnect exceptions with broad except Exception: blocks and re-raises them as RuntimeError, preventing graceful handling of client disconnections. This causes server errors when clients disconnect normally and breaks the expected flow when UserProxyAgent is waiting for input.

Related issue number

Closes #6280

What changes are included in this PR?

Changes Made

  1. Added specific WebSocketDisconnect handling in _user_input function:

    • Catches WebSocketDisconnect specifically and allows it to propagate instead of masking it with broad exception handling
    • Adds informative logging for disconnect events
  2. Added specific WebSocketDisconnect handling in main message processing loop:

    • Gracefully exits the loop when client disconnects during message processing
    • Prevents attempts to send messages to closed connections
  3. Improved error message handling with disconnect detection:

    • Handles disconnections that occur while sending error messages
    • Prevents server errors when client disconnects unexpectedly

Checks

…on guide- Fix version format from 0.4.0-dev-1 to 0.4.0-dev.1 for all packages- Remove reference to non-existent Microsoft.AutoGen.Extensions package- Add correct extension packages: Aspire, MEAI, and SemanticKernel- Fix typo: RuntimeGatewway -> RuntimeGateway- Improve documentation structure with clear section headersFixes microsoft#6244
Fix issue microsoft#6277 where TextMessage was used but not imported in three code cells
of the custom agents documentation, causing NameError when users run the examples.

Changes:
- Add TextMessage to imports in ArithmeticAgent section
- Add TextMessage to imports in GeminiAssistantAgent section
- Add TextMessage to imports in Declarative GeminiAssistantAgent section

The CountDownAgent section already had the correct import.

Fixes microsoft#6277
…_team.py

- Add specific WebSocketDisconnect exception handling in _user_input function
- Handle client disconnects during message processing without RuntimeError
- Prevent attempts to send messages to closed WebSocket connections
- Add graceful cleanup when clients disconnect while waiting for input

Fixes microsoft#6280: Heavy use of broad Exceptions leads to incorrect error handling

The previous implementation caught WebSocketDisconnect with broad Exception
handlers and re-raised as RuntimeError, preventing graceful disconnect handling.
This fix allows proper exception propagation and clean connection termination.
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.

Heavy use of broad Exceptions leads to incorrect error handling
1 participant