fix(backend/copilot): yield final StreamError after transient retry exhaustion for _HandledStreamError

When _run_stream_attempt raises a _HandledStreamError and all transient
retries are exhausted, the outer retry loop sets ended_with_stream_error
but stream_err remains None.  The post-loop code only emits a StreamError
when stream_err is not None, so the SSE stream closes silently and the
frontend never learns the request failed.

Yield a StreamError with the attempt's error message and code just before
breaking out of the retry loop, ensuring clients always receive an error
notification.
This commit is contained in:
Zamil Majdy
2026-04-02 16:49:18 +02:00
parent a68f48e6b7
commit 2a969e5018

View File

@@ -2274,6 +2274,14 @@ async def stream_chat_completion_sdk(
retryable=True,
)
ended_with_stream_error = True
# After exhausting all transient retries the stream is about
# to end. Yield a final StreamError so the client knows the
# request failed — without this the SSE stream would close
# silently and the frontend would never show an error.
yield StreamError(
errorText=exc.error_msg or FRIENDLY_TRANSIENT_MSG,
code=exc.code or "transient_api_error",
)
break
except Exception as e:
stream_err = e