Keep a page error or a busy engine from blanking the app

A user on Upload got a white page while the engine's proxy answered
many requests with nginx's rate-limit 503.

- Pages render inside an error boundary, so a crash shows a message
  with Try again and Reload instead of unmounting the whole app.
- A 503 or 429 without the engine's JSON reads "The engine is busy",
  and queries wait 5s, then 10s, before asking again instead of 1s.
- Upload asks for knowledge details two at a time and reuses them
  until the document's knowledge status changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Iqbal
2026-10-29 18:38:18 +07:00
parent a47fe0f845
commit dfb3275afe
8 changed files with 97 additions and 5 deletions

View File

@@ -21,7 +21,12 @@ const queryClient: QueryClient = new QueryClient({
mutationCache: new MutationCache({ onSettled: () => queryClient.invalidateQueries({ queryKey: ['credits'] }) }),
defaultOptions: {
// Retrying a 4xx (auth, credits, validation) only repeats the same answer.
queries: { retry: (n, e) => n < 2 && !(e instanceof EngineError && e.status >= 400 && e.status < 500) },
queries: {
retry: (n, e) => n < 2 && !(e instanceof EngineError && e.status >= 400 && e.status < 500 && e.status !== 429),
// A busy engine (rate limited) is asked again only after it has had time to recover; an
// immediate retry from every query at once is what keeps it over the limit.
retryDelay: (n, e) => (e instanceof EngineError && (e.status === 503 || e.status === 429) ? 5000 : 1000) * 2 ** n,
},
},
})