From cbbb6d776d020bf60fb7a353014a3e07fe45c720 Mon Sep 17 00:00:00 2001 From: Kian Jones <11655409+kianjones9@users.noreply.github.com> Date: Fri, 6 Feb 2026 16:46:59 -0800 Subject: [PATCH] fix(core): unwrap ExceptionGroup in OAuth stream generator (#9346) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes Datadog issue 5efbb1d4-eec5-11f0-8f8e-da7ad0900000 Add ExceptionGroup unwrapping in OAuth stream exception handler. The bug was caused by ExceptionGroup not being caught by the general `except Exception` handler, since ExceptionGroup is a subclass of BaseException, not Exception. This caused TaskGroup errors to escape as unhandled ExceptionGroups in Datadog. The fix adds an explicit ExceptionGroup handler before the general Exception handler, following the same unwrapping pattern used in other parts of the codebase (mcp_tool_executor.py, base_client.py). 🐾 Generated with [Letta Code](https://letta.com) Co-authored-by: Letta --- letta/server/rest_api/routers/v1/tools.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/letta/server/rest_api/routers/v1/tools.py b/letta/server/rest_api/routers/v1/tools.py index a17590c1..1884b425 100644 --- a/letta/server/rest_api/routers/v1/tools.py +++ b/letta/server/rest_api/routers/v1/tools.py @@ -742,6 +742,13 @@ async def connect_mcp_server( async for event in server.mcp_manager.handle_oauth_flow(request=request, actor=actor, http_request=http_request): yield event return + except ExceptionGroup as eg: + # Handle ExceptionGroup wrapping (Python 3.11+ async TaskGroup can wrap exceptions) + # Unwrap and handle the first exception in the group + exception_to_handle = eg.exceptions[0] if eg.exceptions else eg + detailed_error = drill_down_exception(exception_to_handle) + logger.error(f"Error in OAuth stream (ExceptionGroup):\n{detailed_error}") + yield oauth_stream_event(OauthStreamEvent.ERROR, message=f"Internal error: {detailed_error}") except Exception as e: detailed_error = drill_down_exception(e) logger.error(f"Error in OAuth stream:\n{detailed_error}")