From cbc21877051b1a6f1b2fa5c2419629d0429196f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sat, 20 Jun 2026 12:59:29 +0200 Subject: [PATCH] fix(coach): guard empty reasoning SSE frame against literal undefined A reasoning frame with no text appended the string "undefined" to the thinking disclosure. Coalesce evt.text to an empty string on both the streaming and the trailing-flush paths. --- src/components/insights/coach-panel/use-coach.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/insights/coach-panel/use-coach.ts b/src/components/insights/coach-panel/use-coach.ts index 7c59eb0e0..5517d5237 100644 --- a/src/components/insights/coach-panel/use-coach.ts +++ b/src/components/insights/coach-panel/use-coach.ts @@ -515,10 +515,12 @@ export function useSendCoachMessage(opts: UseSendCoachMessageOptions = {}) { // v1.18.9 — additive reasoning-summary frame. Append so // multiple chunks accumulate; the disclosure renders it // when present, else falls back to the elapsed-time label. - collectedReasoning += evt.text; + // Guard the text: a `reasoning` frame with no `text` must not + // append a literal "undefined". + collectedReasoning += evt.text ?? ""; setStreaming((prev) => ({ ...prev, - reasoning: prev.reasoning + evt.text, + reasoning: prev.reasoning + (evt.text ?? ""), })); break; case "done": @@ -543,7 +545,7 @@ export function useSendCoachMessage(opts: UseSendCoachMessageOptions = {}) { } else if (evt.type === "error") { lastError = evt.code; } else if (evt.type === "reasoning") { - collectedReasoning += evt.text; + collectedReasoning += evt.text ?? ""; } } } catch (err) {