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
- 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".
- Use any chat agent with at least one tool/function enabled.
- Ask something that triggers a tool call.
- 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.
Bug Description
Chat requests through the Ollama provider crash with:
whenever the model ends a streaming turn by requesting tool calls.
The provider treats any
done_reasonother than"stop"as an unexpected termination: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-stylefinish_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
minimax-m3:cloud), or any runtime that reportsdone_reason: "tool_calls".The response shape is easy to confirm outside Theia:
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:We patched exactly this (string-patching the two occurrences in the bundled
backend/main.jsof 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
ghcr.io/eclipse-theia/theia-ide/theia-ide— reproduced on 1.72.300; the same guard is present in the 1.74.100 bundle.minimax-m3:cloud, others); any runtime emittingdone_reason: "tool_calls".Happy to turn the suggested fix into a PR if useful.