From d38241026addc69e698e0e09dfe4c20913aa4ff0 Mon Sep 17 00:00:00 2001 From: jackmazac Date: Thu, 30 Apr 2026 17:13:55 -0700 Subject: [PATCH] session: synthesize reasoning-start when stream omits it wrapStream middleware enqueues reasoning-start before delta/end when the provider skipped the opening chunk for that id. --- packages/opencode/src/session/llm.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/opencode/src/session/llm.ts b/packages/opencode/src/session/llm.ts index b8b8911858fc..30df74567cda 100644 --- a/packages/opencode/src/session/llm.ts +++ b/packages/opencode/src/session/llm.ts @@ -397,6 +397,24 @@ const live: Layer.Layer< } return args.params }, + async wrapStream({ doStream }) { + const result = await doStream() + const started = new Set() + const fix = new TransformStream({ + transform(chunk, controller) { + if (chunk.type === "reasoning-start") started.add(chunk.id) + if ( + (chunk.type === "reasoning-delta" || chunk.type === "reasoning-end") && + !started.has(chunk.id) + ) { + started.add(chunk.id) + controller.enqueue({ type: "reasoning-start", id: chunk.id }) + } + controller.enqueue(chunk) + }, + }) + return { ...result, stream: result.stream.pipeThrough(fix) } + }, }, ], }),