openfang icon indicating copy to clipboard operation
openfang copied to clipboard

Agent chat produces no response with Ollama provider — WebSocket returns 404

Open Bodge-IT opened this issue 8 months ago • 6 comments

Description

When chatting with an agent configured to use the Ollama provider, the UI shows "generating" indefinitely and then produces no response. No errors are displayed in the UI. The server logs show the agent WebSocket endpoint returning 404: GET /api/agents/{id}/ws status=404. Chat messages from the browser never reach the backend.

After a period of inactivity, the heartbeat marks the agent as crashed: Agent is unresponsive agent=assistant inactive_secs=210 timeout_secs=180.

This occurs with all Ollama models tested (qwen3.5:latest, qwen2.5:7b, mistral:latest, granite4:latest). Direct curl requests to Ollama's /v1/chat/completions endpoint from the same machine return correct responses.

Expected Behavior

The agent should stream the LLM response back to the chat UI.

Steps to Reproduce

  1. Install Ollama with at least one model (e.g. mistral:latest)
  2. Configure OpenFang with Ollama provider:
  [default_model]
  provider = "ollama"
  model = "mistral:latest"
  base_url = "http://localhost:11434/v1"

  [provider_urls]
  ollama = "http://localhost:11434/v1"
  1. Also tested with the LAN IP (http://192.168.1.1:11434/v1) in both base_url and provider_urls — same result
  2. Also tested updating the provider URL via the Settings UI — same result
  3. Start the daemon and open the dashboard
  4. Create an agent and send any message
  5. Observe: UI shows "generating", no response appears, agent eventually crashes

OpenFang Version

0.5.1

Operating System

Linux (x86_64)

Logs / Screenshots

Version: 0.5.1 (also reproduced on 0.4.9 and latest main branch)

WARN openfang_kernel::heartbeat: Agent is unresponsive agent=assistant inactive_secs=210 WARN openfang_kernel::kernel: Unresponsive Running agent marked as Crashed INFO openfang_api::middleware: GET /api/agents/{id}/ws status=404

Bodge-IT avatar Mar 23 '26 08:03 Bodge-IT

I'm using it with local Ollama without problems. This is the config format I use. Please take note that ollama is running in other machine, so thats why I need to point it to an ip and not localhost. Maybe the base_url parameter is conflicting somehow?

[default_model]
api_key_env = "OLLAMA_API_KEY"
model = "mycustommodel"
provider = "ollama"

[memory]
decay_rate = 0.05

[provider_urls]
ollama = "http://ip.of.machine.with.ollama:11434/v1"

Hope this helps

Geotig avatar Mar 27 '26 13:03 Geotig

@Geotig tried removing the base_url and relying on the provider_url, made no difference. It's not the connection, it's how the websocket handler responds. Not sure what the issue is but defo something. Tested across diff versions, repeatable.

Bodge-IT avatar Mar 27 '26 13:03 Bodge-IT

Investigated this against recent changes (#770 splice reactivity, #836 tool call IDs, #844 heartbeat skip idle).

Finding: NOT fully fixed. The heartbeat fix (#844) addresses the secondary symptom (agent marked as crashed due to inactivity), but the root 404 is still a real problem.

Root cause analysis:

The GET /api/agents/{id}/ws status=404 log does NOT mean the route is missing — the route is registered at server.rs:242. The 404 comes from ws.rs:200-201:

if state.kernel.registry.get(agent_id).is_none() {
    return axum::http::StatusCode::NOT_FOUND.into_response();
}

This means the agent UUID is valid but registry.get() returns None — the agent is not in the kernel's in-memory registry at the moment the WS upgrade is attempted. Possible causes:

  1. Spawn timing race: The frontend navigates to chat and calls connectWs(agent.id) before the kernel has finished registering the agent. The agent spawn is async — if the Ollama provider connection or model validation is slow, the registry entry may not exist yet when the WS upgrade arrives.

  2. Silent spawn failure with Ollama: The agent spawn may be failing silently with Ollama providers (e.g., base_url/provider_url mismatch, model validation failure, or connection timeout during provider health check). The agent appears in the API list (stored in config) but never gets registered in the kernel's runtime registry.

  3. Agent state lifecycle: If the agent was previously crashed and removed from the registry, subsequent WS connections will 404 until the agent is re-spawned.

Suggested fix direction: The WS handler should either (a) auto-start a stopped/crashed agent on WS connect, or (b) return a more descriptive error (e.g., {"error": "agent_not_running", "state": "crashed"}) instead of a bare 404, so the frontend can show "Agent is not running — click to restart" instead of silently failing.

@Bodge-IT — can you confirm: does the 404 happen on the very first WS connection after creating the agent, or only after the agent has been running for a while and then crashes?

jaberjaber23 avatar Mar 27 '26 20:03 jaberjaber23

I would say from anecdote that it was immediately after and several further attempts got better or shifted to a diff issue. Since 0.5.5, it has been much harder to replicate and even more so since we suspected a corrupted nombic-embed-text model, now reloaded. However, now I think on it, I was only trying from the "General Assistant" which I think is auto-activated?

Bodge-IT avatar Mar 30 '26 10:03 Bodge-IT

Quick feedback from the community: https://github.com/librefang/librefang

Jengro777 avatar Mar 31 '26 22:03 Jengro777

Fixed. WebSocket upgrade now retries agent lookup up to 5 times with 200ms delays to handle the spawn-to-register race condition.

jaberjaber23 avatar Apr 10 '26 17:04 jaberjaber23