{"record":{"id":"dd46c2dd817c6a09","repo":"Crosstalk-Solutions/project-nomad","slug":"no-response-from-ollama","errorCode":null,"errorMessage":"No response from Ollama","messagePattern":"No response from Ollama","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"admin/inertia/components/chat/index.tsx","lineNumber":166,"sourceCode":"    onSuccess: () => {\n      queryClient.invalidateQueries({ queryKey: ['chatSessions'] })\n      setActiveSessionId(null)\n      setMessages([])\n      closeAllModals()\n    },\n  })\n\n  const chatMutation = useMutation({\n    mutationFn: (request: {\n      model: string\n      messages: Array<{ role: 'system' | 'user' | 'assistant'; content: string }>\n      sessionId?: number\n      think?: boolean\n      collection?: string\n    }) => api.sendChatMessage({ ...request, stream: false }),\n    onSuccess: async (data) => {\n      if (!data || !activeSessionId) {\n        throw new Error('No response from Ollama')\n      }\n\n      // Add assistant message\n      const assistantMessage: ChatMessage = {\n        id: `msg-${Date.now()}-assistant`,\n        role: 'assistant',\n        content: data.message?.content || 'Sorry, I could not generate a response.',\n        timestamp: new Date(),\n      }\n\n      setMessages((prev) => [...prev, assistantMessage])\n\n      // Refresh sessions to pick up backend-persisted messages and title\n      queryClient.invalidateQueries({ queryKey: ['chatSessions'] })\n      setTimeout(() => queryClient.invalidateQueries({ queryKey: ['chatSessions'] }), 3000)\n    },\n    onError: (error) => {\n      console.error('Error sending message:', error)","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/Crosstalk-Solutions/project-nomad/blob/0bd1c6f4f9888d577fe232de06ac144bb8337131/admin/inertia/components/chat/index.tsx#L148-L184","documentation":"In the Chat component's non-streaming send mutation onSuccess, this throws when the completed request has no data payload or the active session id disappeared mid-flight (activeSessionId is null, e.g. the user switched or closed the session while the request was in flight). Because it is thrown inside onSuccess, it rejects the mutation and lands in onError handling rather than indicating an Ollama transport failure per se.","triggerScenarios":"api.sendChatMessage resolves with a null/empty body, or activeSessionId is null by the time onSuccess runs — typically the user changed session, logged out, or the component unmounted/remounted state reset while awaiting the response.","commonSituations":"Slow LLM response during which the user navigates away or switches sessions; backend returning 200 with empty body on Ollama error; race between session switching logic and in-flight completions.","solutions":["Check whether the failure correlates with session switches — guard onSuccess with a stale-check (compare a request/session token) and return silently instead of throwing when stale.","Inspect the network response body for the chat completion; empty bodies usually mean the backend swallowed an Ollama error.","Confirm Ollama is reachable from the backend (the message text mentioning Ollama is a hint, but the throw is really a null-response guard).","Return early in onSuccess when !data separately from when !activeSessionId, so each case logs its own cause."],"exampleFix":"// before\nonSuccess: async (data) => {\n  if (!data || !activeSessionId) {\n    throw new Error('No response from Ollama')\n  }\n// after\nonSuccess: async (data) => {\n  if (!data) throw new Error('No response from Ollama (empty completion body)')\n  if (!activeSessionId) return // stale response after session switch; ignore\n","handlingStrategy":"try-catch","validationCode":"// guard state before awaiting: capture session token and compare in callback\nconst sessionAtSend = activeSessionId\n// ... in onSuccess: if (sessionAtSend !== activeSessionIdRef.current) return","typeGuard":"function hasCompletion(data: unknown): data is { content: string } {\n  return typeof data === 'object' && data !== null && 'content' in data\n}","tryCatchPattern":"onError: (err) => setChatError(err.message === 'No response from Ollama' ? 'Empty completion — backend/Ollama issue, check server logs' : err.message)","preventionTips":["Separate the !data and !activeSessionId conditions — ignore stale responses instead of throwing","Use request tokens to drop responses from previous sessions","Log the raw backend body when data is missing"],"tags":["react","chat","ollama","race-condition","inertia"],"backgroundTag":"stale-async-response","analyzedSha":"0bd1c6f4f9888d577fe232de06ac144bb8337131","analyzedAt":"2026-08-27T05:34:15.424Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}