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
This commit is contained in:
LUIS NOVO 2025-12-14 21:55:38 -03:00
parent 1be8ef1116
commit 26e989fdbb
3 changed files with 6 additions and 3 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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 {