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): skip run status update in error_aware_stream for background runs (#10059)

jnjpng47756d64325a
diff --git a/letta/services/streaming_service.py b/letta/services/streaming_service.py
index fcf7a53b1..faac656c8 100644
--- a/letta/services/streaming_service.py
+++ b/letta/services/streaming_service.py
@@ -641,17 +641,26 @@ class StreamingService:
finally:
# If run_status was never set and the stream ended without [DONE],
# mark as failed so the run doesn't stay "running" forever.
+ # For background runs, the background stream processor handles
+ # terminal state updates (and has better error context), so we
+ # only log here to avoid overwriting the correct stop_reason.
if run_id and self.runs_manager and run_status is None and not saw_done:
- logger.warning(f"Run {run_id} stream ended without setting run_status or emitting [DONE]. Marking as failed.")
- run_status = RunStatus.failed
- stop_reason = LettaStopReason(stop_reason=StopReasonType.error)
- error_data = {
- "error": {
- "run_id": run_id,
- "error_type": "stream_incomplete",
- "message": "Stream ended unexpectedly without a terminal event.",
+ if is_background:
+ logger.warning(
+ f"Run {run_id} stream ended without setting run_status or emitting [DONE]. "
+ f"Skipping run update — background stream processor will handle terminal state."
+ )
+ else:
+ logger.warning(f"Run {run_id} stream ended without setting run_status or emitting [DONE]. Marking as failed.")
+ run_status = RunStatus.failed
+ stop_reason = LettaStopReason(stop_reason=StopReasonType.error)
+ error_data = {
+ "error": {
+ "run_id": run_id,
+ "error_type": "stream_incomplete",
+ "message": "Stream ended unexpectedly without a terminal event.",
+ }
}
- }
# always update run status, whether success or failure
if run_id and self.runs_manager and run_status: