From 55da6ca449155f9de5d68bf6634b8a0961c07ac0 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 11 Jan 2026 11:00:01 +0000 Subject: [PATCH] fix: keep reasoning for tool-only turns --- patches/@mariozechner__pi-ai@0.42.2.patch | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/patches/@mariozechner__pi-ai@0.42.2.patch b/patches/@mariozechner__pi-ai@0.42.2.patch index 2ad02c0f4..cc333ebbc 100644 --- a/patches/@mariozechner__pi-ai@0.42.2.patch +++ b/patches/@mariozechner__pi-ai@0.42.2.patch @@ -48,3 +48,14 @@ index f07085c64390b211340d6a826b28ea9c2e77302f..71509b70c5aa762872eab3b5ffc7a425 const reasoningItem = JSON.parse(block.thinkingSignature); output.push(reasoningItem); } +@@ -430,7 +431,7 @@ export const streamOpenAIResponses = (model, context, options) => { + const hasAssistantMessage = output.some((item) => item.type === "message"); + const hasFunctionCall = output.some((item) => item.type === "function_call"); +- if (!hasAssistantMessage && hasFunctionCall) { ++ // Keep reasoning for tool-only turns; OpenAI expects reasoning before function_call. ++ if (!hasAssistantMessage && !hasFunctionCall) { + for (let i = output.length - 1; i >= 0; i -= 1) { + if (output[i].type === "reasoning") { + output.splice(i, 1); + } + }