fix(copilot): prevent infinite refetch loop when backend errors

- Only invalidate session queries on successful completion (status='ready')
- Previously invalidated on both 'ready' and 'error' status
- When backend returned 500, error status triggered refetch which caused infinite loop
- Fixes spam of 'Let me check!' messages when backend is unavailable
This commit is contained in:
Zamil Majdy
2026-02-21 19:59:26 +07:00
parent 2bc6481522
commit eead01f919
2 changed files with 211 additions and 2494 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -203,8 +203,9 @@ export function useCopilotPage() {
prevStatusRef.current = status;
const wasActive = prev === "streaming" || prev === "submitted";
const isIdle = status === "ready" || status === "error";
if (wasActive && isIdle && sessionId) {
const isReady = status === "ready";
// Only invalidate on successful completion, not on error to avoid infinite refetch loop
if (wasActive && isReady && sessionId) {
queryClient.invalidateQueries({
queryKey: getGetV2GetSessionQueryKey(sessionId),
});