Skip to content

Commit 191b721

Browse files
fix(web): keep reasoning previews that only have leading whitespace
A long trace whose only whitespace is leading (for example CJK text after blank lines) was cut at that whitespace, leaving an empty preview that fell back to "Thought". Fall back to the bounded head when the word cut is blank. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ab30fde commit 191b721

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎apps/web/src/components/chat/TimelineWorkEntryRow.logic.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ describe("thoughtPreviewSource", () => {
1313
expect(source.endsWith("word")).toBe(true);
1414
});
1515

16+
it("keeps the text when the only whitespace is leading", () => {
17+
const source = thoughtPreviewSource(`\n\n${"字".repeat(2_001)}`);
18+
expect(source).toBe(`\n\n${"字".repeat(1_998)}`);
19+
});
20+
1621
it("never cuts inside an emoji when the trace has no whitespace", () => {
1722
expect(thoughtPreviewSource(`${"a".repeat(1_999)}🙂${"b".repeat(10)}`)).toBe("a".repeat(1_999));
1823
});

‎apps/web/src/components/chat/TimelineWorkEntryRow.logic.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ export function thoughtPreviewSource(text: string): string {
196196
if (text.length <= THOUGHT_PREVIEW_MAX_CHARS) return text;
197197
const head = text.slice(0, THOUGHT_PREVIEW_MAX_CHARS);
198198
const boundary = head.search(/\s\S*$/);
199-
// Without whitespace, drop a lone high surrogate so the cut never splits an emoji.
200-
return boundary > 0 ? head.slice(0, boundary) : head.replace(/[\uD800-\uDBFF]$/, "");
199+
const wordCut = boundary > 0 ? head.slice(0, boundary) : "";
200+
if (wordCut.trim()) return wordCut;
201+
// Without a usable word boundary, drop a lone high surrogate so the cut never splits an emoji.
202+
return head.replace(/[\uD800-\uDBFF]$/, "");
201203
}
202204

203205
/** Compact reasoning keeps formulas while flattening other Markdown into label text. */

0 commit comments

Comments
 (0)