Crosstalk-Solutions/project-nomad · error
No response from Ollama
Error message
No response from Ollama
What it means
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.
Source
Thrown at admin/inertia/components/chat/index.tsx:166
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['chatSessions'] })
setActiveSessionId(null)
setMessages([])
closeAllModals()
},
})
const chatMutation = useMutation({
mutationFn: (request: {
model: string
messages: Array<{ role: 'system' | 'user' | 'assistant'; content: string }>
sessionId?: number
think?: boolean
collection?: string
}) => api.sendChatMessage({ ...request, stream: false }),
onSuccess: async (data) => {
if (!data || !activeSessionId) {
throw new Error('No response from Ollama')
}
// Add assistant message
const assistantMessage: ChatMessage = {
id: `msg-${Date.now()}-assistant`,
role: 'assistant',
content: data.message?.content || 'Sorry, I could not generate a response.',
timestamp: new Date(),
}
setMessages((prev) => [...prev, assistantMessage])
// Refresh sessions to pick up backend-persisted messages and title
queryClient.invalidateQueries({ queryKey: ['chatSessions'] })
setTimeout(() => queryClient.invalidateQueries({ queryKey: ['chatSessions'] }), 3000)
},
onError: (error) => {
console.error('Error sending message:', error)View on GitHub (pinned to 0bd1c6f4f9)
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.
Example fix
// before
onSuccess: async (data) => {
if (!data || !activeSessionId) {
throw new Error('No response from Ollama')
}
// after
onSuccess: async (data) => {
if (!data) throw new Error('No response from Ollama (empty completion body)')
if (!activeSessionId) return // stale response after session switch; ignore
Defensive patterns
Strategy: try-catch
Validate before calling
// guard state before awaiting: capture session token and compare in callback const sessionAtSend = activeSessionId // ... in onSuccess: if (sessionAtSend !== activeSessionIdRef.current) return
Type guard
function hasCompletion(data: unknown): data is { content: string } {
return typeof data === 'object' && data !== null && 'content' in data
} Try / catch
onError: (err) => setChatError(err.message === 'No response from Ollama' ? 'Empty completion — backend/Ollama issue, check server logs' : err.message)
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Preflight returned no data
- An unknown error occurred during the preflight check.
- res.message
- Ollama service not ready yet
- Failed to create chat session
AI-assisted analysis of Crosstalk-Solutions/project-nomad@0bd1c6f4f9 (2026-08-27).
Data as JSON: /api/errors/dd46c2dd817c6a09.
Report an issue: GitHub.