Skip to content

[Ollama] Streaming crashes with "Ollama stopped unexpectedly. Reason: tool_calls" when the runtime reports done_reason=tool_calls #17971

Description

@johnsonfarmsus

Bug Description

Chat requests through the Ollama provider crash with:

Error in Ollama streaming: Ollama stopped unexpectedly. Reason: tool_calls
Error handling chat interaction: Error: Ollama stopped unexpectedly. Reason: tool_calls

whenever the model ends a streaming turn by requesting tool calls.

The provider treats any done_reason other than "stop" as an unexpected termination:

if (chunk.done_reason && chunk.done_reason !== 'stop') {
    throw new Error('Ollama stopped unexpectedly. Reason: ' + chunk.done_reason);
}

Newer Ollama runtimes — notably every Ollama Cloud model today — report done_reason: "tool_calls" when the model stops to invoke tools (aligned with the OpenAI-style finish_reason: "tool_calls"). That is a normal, successful stop, but the guard converts it into a hard failure, so any agent with tools enabled crashes on the first tool invocation.

Reproduction

  1. Configure the Ollama provider against an Ollama host with cloud models (e.g. minimax-m3:cloud), or any runtime that reports done_reason: "tool_calls".
  2. Use any chat agent with at least one tool/function enabled.
  3. Ask something that triggers a tool call.
  4. The stream aborts with the error above; the tool call is never executed.

The response shape is easy to confirm outside Theia:

$ curl -s http://localhost:11434/api/chat -d '{
  "model": "minimax-m3:cloud", "stream": false,
  "messages": [{"role": "user", "content": "List my files. Use the tool."}],
  "tools": [{"type": "function", "function": {"name": "list_files",
    "description": "List files", "parameters": {"type": "object", "properties": {}}}}]
}' | jq '{done_reason, has_tool_calls: (.message.tool_calls != null)}'
{
  "done_reason": "tool_calls",
  "has_tool_calls": true
}

Local models served by older Ollama builds report done_reason: "stop" for the same flow, which is why this mostly bites cloud models today — but it will spread as local runtimes adopt the same reporting.

Suggested fix

Treat "tool_calls" as an expected termination in both guard sites:

if (chunk.done_reason && chunk.done_reason !== 'stop' && chunk.done_reason !== 'tool_calls') {

We patched exactly this (string-patching the two occurrences in the bundled backend/main.js of the Theia IDE image) on a multi-user deployment, and tool calling through Ollama Cloud models works normally again with no side effects observed — the tool_calls chunks were already being handled correctly by the surrounding code; only the guard was in the way.

Environment

  • Theia IDE Docker image ghcr.io/eclipse-theia/theia-ide/theia-ide — reproduced on 1.72.300; the same guard is present in the 1.74.100 bundle.
  • Ollama Cloud models (minimax-m3:cloud, others); any runtime emitting done_reason: "tool_calls".

Happy to turn the suggested fix into a PR if useful.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugbugs found in the applicationtheia-aiissues related to TheiaAI

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions