From a5cddcd8dce6d29f8e51221f265ad0805bbf2479 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Thu, 6 Aug 2026 22:02:46 -0500 Subject: [PATCH] fix(desktop): render already-glued reasoning as separate blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Repairs what is already in the transcript: reasoning persisted before the backend fix, and any provider still gluing its parts. Handles both shapes — heading-onto-heading (the **** run) and prose-onto-heading (vercel/ai#6742). Verified against 46 real glued messages from a gpt-5.6-sol session; all repair cleanly and idempotently. --- .../assistant-ui/thread/message-parts.tsx | 3 +- apps/desktop/src/lib/reasoning-blocks.test.ts | 48 +++++++++++++++++++ apps/desktop/src/lib/reasoning-blocks.ts | 31 ++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 apps/desktop/src/lib/reasoning-blocks.test.ts create mode 100644 apps/desktop/src/lib/reasoning-blocks.ts diff --git a/apps/desktop/src/components/assistant-ui/thread/message-parts.tsx b/apps/desktop/src/components/assistant-ui/thread/message-parts.tsx index 8bcc946453..df42bc1754 100644 --- a/apps/desktop/src/components/assistant-ui/thread/message-parts.tsx +++ b/apps/desktop/src/components/assistant-ui/thread/message-parts.tsx @@ -16,6 +16,7 @@ import { GeneratedImage } from '@/components/chat/generated-image-result' import { SCAFFOLD_LABEL_CLASS, SCAFFOLD_META_CLASS, ScaffoldRow } from '@/components/chat/scaffold-row' import { useI18n } from '@/i18n' import { generatedImageFromResult } from '@/lib/generated-images' +import { separateGluedReasoningBlocks } from '@/lib/reasoning-blocks' import { useEnterAnimation } from '@/lib/use-enter-animation' import { cn } from '@/lib/utils' @@ -249,7 +250,7 @@ const ReasoningTextPart: ReasoningMessagePartComponent = () => { containerProps={{ 'data-slot': 'aui_reasoning-text' } as ComponentProps<'div'>} disableArtifacts isRunning={status.type === 'running' || messageRunning} - text={text.trimStart()} + text={separateGluedReasoningBlocks(text.trimStart())} /> ) } diff --git a/apps/desktop/src/lib/reasoning-blocks.test.ts b/apps/desktop/src/lib/reasoning-blocks.test.ts new file mode 100644 index 0000000000..cab4ab90e2 --- /dev/null +++ b/apps/desktop/src/lib/reasoning-blocks.test.ts @@ -0,0 +1,48 @@ +import { describe, expect, it } from 'vitest' + +import { separateGluedReasoningBlocks } from '@/lib/reasoning-blocks' + +describe('separateGluedReasoningBlocks', () => { + it('splits heading-onto-heading parts (the `****` run)', () => { + const glued = + '**Investigating likely culprit PRs****Inspecting message schema****Analyzing interrupted tool call impact**' + + expect(separateGluedReasoningBlocks(glued)).toBe( + [ + '**Investigating likely culprit PRs**', + '', + '**Inspecting message schema**', + '', + '**Analyzing interrupted tool call impact**' + ].join('\n') + ) + }) + + it('splits prose-onto-heading parts (vercel/ai#6742 repro)', () => { + const glued = + '**Simulating a greeting stream**\n\nIt feels like a streaming interaction!**Simulating a greeting stream**\n\nI want to meet the request.' + + expect(separateGluedReasoningBlocks(glued)).toContain('interaction!\n\n**Simulating') + expect(separateGluedReasoningBlocks(glued)).not.toContain('interaction!**') + }) + + it('is idempotent on already-separated text', () => { + const separated = '**One**\n\n**Two**' + + expect(separateGluedReasoningBlocks(separated)).toBe(separated) + }) + + it('leaves emphasis inside prose alone', () => { + const prose = 'Looking at the logs, the **signature** field is missing — so the replay 400s.' + + expect(separateGluedReasoningBlocks(prose)).toBe(prose) + }) + + it('leaves an unclosed emphasis run alone', () => { + expect(separateGluedReasoningBlocks('weighing options **')).toBe('weighing options **') + }) + + it('does not split a heading that already opens the text', () => { + expect(separateGluedReasoningBlocks('**Only one part**')).toBe('**Only one part**') + }) +}) diff --git a/apps/desktop/src/lib/reasoning-blocks.ts b/apps/desktop/src/lib/reasoning-blocks.ts new file mode 100644 index 0000000000..a1122bd747 --- /dev/null +++ b/apps/desktop/src/lib/reasoning-blocks.ts @@ -0,0 +1,31 @@ +/** + * Reasoning-summary models (OpenAI's gpt-5.x family, and anything relaying the + * Responses API onto the OpenAI chat wire) emit one delta per *completed* + * summary part, each opening with a bold markdown heading: + * + * **Investigating likely culprit PRs** + * **Inspecting message schema** + * + * The Responses API delimits those parts with `summary_index`; the chat wire + * carries no such field, so concatenated deltas glue into + * `...PRs****Inspecting...` — a `****` run markdown reads as neither a bold + * close nor a bold open, leaving one unbroken, unspaced, half-bold paragraph. + * The AI SDK hit the same bug (vercel/ai#6742). + * + * The backend now inserts the break as the deltas arrive. This repairs the text + * we display: reasoning persisted before that fix, and any provider still + * gluing its parts. Idempotent — a break already present is left alone. + */ + +// A heading butting straight onto the previous part, in the two shapes the +// wire produces: +// 1. heading-onto-heading — `**One****Two**`, a bare `****` run. +// 2. prose-onto-heading — `interaction!**Two**`. +// Emphasis that legitimately follows whitespace is left alone, and a heading +// must close on its own line to count as a summary part. +const GLUED_HEADING_RUN = /(?