From 26e989fdbb4831c0d267bece9b34f3d4445259b5 Mon Sep 17 00:00:00 2001 From: LUIS NOVO Date: Sun, 14 Dec 2025 21:55:38 -0300 Subject: [PATCH] fix: query key consistency and timeout configuration - Use QUERY_KEYS.sourcesInfinite for infinite scroll query key Starting with ['sources', ...] ensures mutations that invalidate ['sources'] will also invalidate the infinite scroll cache - Use httpx.Timeout for chat service with short connect (10s) and long read (600s) timeouts. Prevents 10 min wait on connection errors --- api/chat_service.py | 4 +++- frontend/src/lib/api/query-client.ts | 1 + frontend/src/lib/hooks/use-sources.ts | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/api/chat_service.py b/api/chat_service.py index 3a6cbb1..34bc3cf 100644 --- a/api/chat_service.py +++ b/api/chat_service.py @@ -135,7 +135,9 @@ class ChatService: if model_override is not None: data["model_override"] = model_override - async with httpx.AsyncClient(timeout=600.0) as client: # 10 min timeout for Ollama/local LLMs + # Short connect timeout (10s), long read timeout (10 min) for Ollama/local LLMs + timeout = httpx.Timeout(connect=10.0, read=600.0, write=30.0, pool=10.0) + async with httpx.AsyncClient(timeout=timeout) as client: response = await client.post( f"{self.base_url}/api/chat/execute", json=data, diff --git a/frontend/src/lib/api/query-client.ts b/frontend/src/lib/api/query-client.ts index ee20db0..b5cd519 100644 --- a/frontend/src/lib/api/query-client.ts +++ b/frontend/src/lib/api/query-client.ts @@ -20,6 +20,7 @@ export const QUERY_KEYS = { notes: (notebookId?: string) => ['notes', notebookId] as const, note: (id: string) => ['notes', id] as const, sources: (notebookId?: string) => ['sources', notebookId] as const, + sourcesInfinite: (notebookId: string) => ['sources', 'infinite', notebookId] as const, source: (id: string) => ['sources', id] as const, settings: ['settings'] as const, sourceChatSessions: (sourceId: string) => ['source-chat', sourceId, 'sessions'] as const, diff --git a/frontend/src/lib/hooks/use-sources.ts b/frontend/src/lib/hooks/use-sources.ts index 994f508..c03e864 100644 --- a/frontend/src/lib/hooks/use-sources.ts +++ b/frontend/src/lib/hooks/use-sources.ts @@ -31,7 +31,7 @@ export function useNotebookSources(notebookId: string) { const queryClient = useQueryClient() const query = useInfiniteQuery({ - queryKey: ['notebookSources', notebookId], + queryKey: QUERY_KEYS.sourcesInfinite(notebookId), queryFn: async ({ pageParam = 0 }) => { const data = await sourcesApi.list({ notebook_id: notebookId, @@ -60,7 +60,7 @@ export function useNotebookSources(notebookId: string) { // Refetch function that resets to first page const refetch = useCallback(() => { - queryClient.invalidateQueries({ queryKey: ['notebookSources', notebookId] }) + queryClient.invalidateQueries({ queryKey: QUERY_KEYS.sourcesInfinite(notebookId) }) }, [queryClient, notebookId]) return {