fix(server): thread search snippets no longer end in half a flag or joined emoji #47027
Mergediamshadmantaqi(GitHub profile, opens in a new tab)merged 4 commits into
main fromrefs/pull/47027/headmerged by juliusmarminge View on GitHubtanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
- @@ -225,5 +226,6 @@225226 .replace(/\*\*|`+/g, "")226227 .replace(/\s+/g, " ")227228 .trim();228- let end = Math.min(shown.length, SNIPPET_LENGTH - 2);229- if (isLowSurrogate(shown.charCodeAt(end))) end--;229+ // Stop between grapheme clusters: half a flag or a joined emoji draws as another character.230+ let end = 0;231+ for (const { segment } of snippetGraphemes.segment(shown)) {
juliusmarminge added labelstakeover:in-progress
Pushed57beb12
- @@ -253,5 +253,7 @@253253 .replace(/\*\*|`+/g, "")254254 .replace(/\s+/g, " ")255255 .trim();256- let end = Math.min(shown.length, SNIPPET_LENGTH - 2);257- if (isLowSurrogate(shown.charCodeAt(end))) end--;256+ // Stop between grapheme clusters: half a flag or a joined emoji draws as another character.257+ let end = 0;258+ for (const { segment } of snippetGraphemes.segment(shown)) {259+ if (end + segment.length > SNIPPET_LENGTH - 2) break;
juliusmarminge merged this699b871
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.



Walkthrough
buildSearchSnippetnow truncates at grapheme-cluster boundaries. Tests cover truncation before flag and joined family emojis when including them would exceed the limit.Changes: Snippet truncation
apps/server/src/orchestration-v2/ThreadSearch.ts,apps/server/src/orchestration-v2/ThreadSearch.test.tsbuildSearchSnippetaccumulates complete grapheme clusters up to the snippet limit, replacing the prior UTF-16 cutoff and low-surrogate adjustment. Tests cover flag and joined family emojis.Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related PRs
buildSearchSnippetusing grapheme segmentation, complementing this change to the trailing edge.buildSearchSnippetto avoid detached grapheme components and updates the same test case.Suggested reviewers:
juliusmarminge,maria-rcks,macroscopeappMerge Risk:
Low · up to
57bebThread-search snippets now avoid ending in half an emoji in the common cases. Two rare edge cases remain: a half flag after heavy whitespace collapse, and a snippet cut short by an oversized grapheme cluster. They are low impact and can be fixed after merge.
Pre-merge checks:
4
Full details: Title check
Explanation
The title "fix(server): thread search snippets no longer end in half a flag or joined emoji" matches the main change. The raw summary and objectives show buildSearchSnippet in ThreadSearch.ts now truncates by grapheme clusters so snippets do not end inside a flag or joined emoji. The title is a conventional commit, specific, and accurate.
Full details: Description check
Explanation
The description follows the template closely. It has Problem, Change, Scope, and Verification sections. The Problem section gives expected and actual behavior with reproduction steps. The Change section explains the Intl.Segmenter fix and its relation to earlier fixes. The Scope section justifies no linked issue for a small obvious bug. Verification gives a failing-then-passing test result and states what was not verified. The model and harness are named at the end, as the template asks. The description is complete.
Finishing Touches
Generate unit tests (beta)