Skip to content

The agent that grows with you

fix(desktop): render already-glued reasoning as separate blocks

Brooklyn Nicholsona5cddcd8dce6
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 8bcc9464538..df42bc17542 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 00000000000..cab4ab90e25
--- /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 00000000000..a1122bd7478
--- /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 = /(?<!\*)\*{4}(?!\*)/g
+const GLUED_AFTER_PROSE = /(?<=[^\s*])(\*\*(?=[^\s*])[^\n]*?\*\*)/g
+
+export function separateGluedReasoningBlocks(text: string): string {
+ return text.replace(GLUED_HEADING_RUN, '**\n\n**').replace(GLUED_AFTER_PROSE, '\n\n$1')
+}