From 5586cddd5d1b8f212e6948abc68eb07dc6eff8c9 Mon Sep 17 00:00:00 2001 From: VoidChecksum <89574102+VoidChecksum@users.noreply.github.com> Date: Sun, 10 May 2026 23:52:31 +0200 Subject: [PATCH] fix(ai): strip thinking field from history messages on ollama-cloud Ollama cloud rejects requests (HTTP 400) when assistant history messages contain the `thinking` field. The field is valid as output from the model (streamed thinking blocks), but the cloud API does not accept it as an input in conversation history. Root-cause trace: a kimi-k2.6 response containing both `thinking` and `tool_calls` was stored in history. The following request echoed it back, triggering a 400. Requests containing only `tool_calls` (no `thinking`) succeeded, isolating the `thinking` field as the cause. Strip the field from converted assistant messages when the provider is `ollama-cloud`. Local Ollama instances (provider `ollama`) are unaffected and continue to receive `thinking` in history for models that support it. --- packages/ai/src/providers/ollama.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/ai/src/providers/ollama.ts b/packages/ai/src/providers/ollama.ts index fb9f72092..4234a62f4 100644 --- a/packages/ai/src/providers/ollama.ts +++ b/packages/ai/src/providers/ollama.ts @@ -199,7 +199,18 @@ function convertMessages(model: Model<"ollama-chat">, context: Context): OllamaM }); } messages.push(...context.messages); - return transformMessages(messages, model).map(convertMessage); + const isCloud = model.provider === "ollama-cloud"; + return transformMessages(messages, model).map(msg => { + const converted = convertMessage(msg); + // Ollama cloud rejects requests when assistant history messages contain the `thinking` + // field — it's valid in model responses but not accepted as a history input. Strip it + // to prevent HTTP 400 errors. Local Ollama instances are unaffected. + if (isCloud && converted.role === "assistant" && converted.thinking) { + const { thinking: _t, ...rest } = converted; + return rest; + } + return converted; + }); } function convertTools(tools: Tool[] | undefined): OllamaFunctionTool[] | undefined {