The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a half-arrived reasoning tag at a block boundary is held back too
kshitijk4poor74b4d0e41c1c
diff --git a/apps/desktop/src/components/assistant-ui/streaming-text-fidelity.test.tsx b/apps/desktop/src/components/assistant-ui/streaming-text-fidelity.test.tsxindex 2d2fa6dfcd2..b03049f56e7 100644--- a/apps/desktop/src/components/assistant-ui/streaming-text-fidelity.test.tsx+++ b/apps/desktop/src/components/assistant-ui/streaming-text-fidelity.test.tsx@@ -27,11 +27,8 @@ it('never paints the chain of thought, and never un-paints an answer, in any 3-cexpect(visible).not.toContain('let me think')expect(visible).not.toMatch(/<\/?thinking/)- // A half-arrived tag (`<thin`) is not a tag yet, so those frames sit outside the curve.- if (!/<[a-z]*$/i.test(frame)) {- expect(norm(visible).startsWith(previous)).toBe(true)- previous = norm(visible)- }+ expect(norm(visible).startsWith(previous)).toBe(true)+ previous = norm(visible)}expect(container.textContent).toBe('Resposta final com acentuação.')diff --git a/apps/desktop/src/lib/markdown-preprocess.ts b/apps/desktop/src/lib/markdown-preprocess.tsindex d202a7d9d13..e54b250d0c2 100644--- a/apps/desktop/src/lib/markdown-preprocess.ts+++ b/apps/desktop/src/lib/markdown-preprocess.ts@@ -18,6 +18,19 @@ const REASONING_BLOCK_RE = new RegExp(`(?:<(${REASONING_TAGS})>[\\s\\S]*?<\\/\\1// while prose that merely mentions `<thinking>` mid-sentence survives — the same// line agent/think_scrubber.py draws.const OPEN_REASONING_BLOCK_RE = new RegExp(`(^|\\n)[ \\t]*<(${REASONING_TAGS})>[\\s\\S]*$`, 'i')++// A half-arrived open tag (`<thin`) at a block boundary is not a tag yet, so the+// pass above lets it paint as prose for one frame and then erase it — the same+// paint/un-paint class as #62774, one frame long. Hold it back the way+// agent/think_scrubber.py `_hold_partial`/`_max_partial_suffix` does, but only+// for prefixes of the known tag names so `<div` at a line start still renders.+const REASONING_TAG_PREFIXES = Array.from(+ new Set(+ REASONING_TAGS.split('|').flatMap((tag) => Array.from({ length: tag.length }, (_, i) => tag.slice(0, i + 1))),+ ),+).join('|')++const PARTIAL_OPEN_REASONING_TAG_RE = new RegExp(`(^|\\n)[ \\t]*<(?:${REASONING_TAG_PREFIXES})?$`, 'i')const PREVIEW_MARKER_RE = /\[Preview:[^\]]+\]\(#preview[:/][^)]+\)/giconst FENCE_LINE_RE = /^([ \t]*)(`{3,}|~{3,})([^\n]*)$/@@ -184,7 +197,7 @@ function stripReasoningBlocks(text: string): string {return prev && next && !/\s/.test(prev) && !/\s/.test(next) ? ' ' : ''})- return closed.replace(OPEN_REASONING_BLOCK_RE, '$1')+ return closed.replace(OPEN_REASONING_BLOCK_RE, '$1').replace(PARTIAL_OPEN_REASONING_TAG_RE, '$1')}function stripEmptyFenceBlocks(text: string): string {diff --git a/apps/desktop/src/lib/markdown-reasoning-stream.test.ts b/apps/desktop/src/lib/markdown-reasoning-stream.test.tsindex b687e9c82b8..b179108864a 100644--- a/apps/desktop/src/lib/markdown-reasoning-stream.test.ts+++ b/apps/desktop/src/lib/markdown-reasoning-stream.test.ts@@ -15,6 +15,8 @@ describe('reasoning blocks in streamed markdown', () => {it('hides an unterminated block at a block boundary but keeps a mid-sentence mention', () => {expect(preprocessMarkdown('<thinking>let me think about the render pipeline')).toBe('')expect(preprocessMarkdown('Resposta final.\n<reasoning_scratchpad>checking')).toBe('Resposta final.\n')+ expect(preprocessMarkdown('Answer.\n<thin')).toBe('Answer.\n')+ expect(preprocessMarkdown('Answer.\n<div')).toBe('Answer.\n<div')const quoted = 'O texto acima explica o formato do bloco <thinking> sem nunca fechá-lo'expect(preprocessMarkdown(quoted)).toBe(quoted)