Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix(core): catch BaseException in stream to diagnose stream_incomplete errors (#10033)

jnjpng87f6f1b73018
diff --git a/letta/services/streaming_service.py b/letta/services/streaming_service.py
index cfdfaae66..fcf7a53b1 100644
--- a/letta/services/streaming_service.py
+++ b/letta/services/streaming_service.py
@@ -609,6 +609,16 @@ class StreamingService:
run_status = None # Signal to finally block to skip update
# Send [DONE] to properly close the stream
yield "data: [DONE]\n\n"
+ except asyncio.CancelledError:
+ # CancelledError is a BaseException (Python 3.9+) that bypasses
+ # `except Exception`. Caused by task cancellation or client disconnect.
+ logger.warning(
+ f"Run {run_id} stream interrupted by asyncio.CancelledError "
+ f"(likely client disconnect or task cancellation). "
+ f"saw_done={saw_done}, saw_error={saw_error}, "
+ f"agent stop_reason={agent_loop.stop_reason}"
+ )
+ raise
except Exception as e:
run_status = RunStatus.failed
stop_reason = LettaStopReason(stop_reason=StopReasonType.error)