fix(frontend/copilot): reconnect on transient API errors to show Try Again button

StreamError.to_sse() strips the code field per AI SDK protocol, so the
frontend can't detect retryable errors from the live SSE event alone.
The retryable prefix is only in the persisted session message. Fix by
triggering a reconnect (session reload) when the error text matches a
transient API error, so the persisted retryable marker is loaded and
the "Try Again" button appears immediately.
This commit is contained in:
Zamil Majdy
2026-03-17 16:39:15 +07:00
parent 7f9c06e758
commit 1fc37f0e61

View File

@@ -222,12 +222,17 @@ export function useCopilotStream({
return;
}
// Only reconnect on network errors (not HTTP errors), and never
// reconnect when the user explicitly stopped the stream.
// Reconnect on network errors or transient API errors so the
// persisted retryable-error marker is loaded and the "Try Again"
// button appears. Without this, transient errors only show in the
// onError callback (where StreamError strips the retryable prefix).
if (isUserStoppingRef.current) return;
const isNetworkError =
error.name === "TypeError" || error.name === "AbortError";
if (isNetworkError) {
const isTransientApiError = errorDetail.includes(
"connection interrupted",
);
if (isNetworkError || isTransientApiError) {
handleReconnect(sessionId);
}
},