fix(server): thread search snippets no longer end in half an emoji after long whitespace #47109
main fromrefs/pull/47109/head·merged by juliusmarminge View on GitHubProblem#
Thread search reads at most 480 raw characters for a snippet and, before this change, only moved that cut past a split surrogate pair. When whitespace (indented code, blank lines) collapses, the whole raw window fits in the snippet, so a flag or joined emoji cut at the window edge shows partly: half a flag draws as a different letter, and a family emoji loses members. This reaches users through ThreadSearch search results (buildSearchSnippet at the snippet: field of each hit), shown in the web and mobile search/command palette and returned by the t3_thread_search MCP tool.
Deterministic repro on origin/main (4ce01933e99722924479c2ea99c09e5783eb1a97), from apps/server with node --experimental-strip-types:
const { buildSearchSnippet } = await import("./src/orchestration-v2/ThreadSearch.ts");
buildSearchSnippet("match" + " ".repeat(474) + "🇺🇸 🇫🇷 rest", 0);
buildSearchSnippet("match" + " ".repeat(470) + "👨👩👧 rest", 0);
- Observed:
"match 🇺…"(only U+1F1FA) and"match 👨👩…"(1f468 200d 1f469, no girl). - Expected:
"match 🇺🇸…"and"match 👨👩👧…", the same as the existing"needle 🚀…"case keeps a whole emoji at that edge.
In the app: send a Replay message match + 470 spaces + 👨👩👧 rest, then search match; the result snippet shows two people.
Change#
buildSearchSnippet now moves the raw read end to the end of the grapheme cluster it cuts, using the segmenter the function already has, in place of the surrogate-pair-only step. The 240-character budget loop from #47027 is unchanged, so a cluster that does not fit still drops. Server-only; web, mobile, and MCP read the same snippet, and there is no contract change.
Scope#
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification#
- Added the two repro inputs to the snippet test in
apps/server/src/orchestration-v2/ThreadSearch.test.ts.- Base:
AssertionError: expected 'match 🇺…' to equal 'match 🇺🇸…'. - Head: all 38 tests in the file pass, including the existing
"needle 🚀…"and #47027 budget-cut cases.
- Base:
vp run check:changedpassed (format, lint, knip, typecheck, tests).- Before/after runtime transcript: https://gist.github.com/saphid/5d98c65e0ac6e0dcc4b042358481c687
Not shown: no screenshot of the search UI. The client renders the server's snippet string as-is, and the transcript shows that string before and after.
Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).
Not shown#
- Draft PR body:10 — The app repro was not run as a scenario; specify an active, pre-named Replay thread whose title does not match
match, send the exact user-message fixture, and assert the excerpt in the In messages result. - Draft PR body:29 — The reported
vp run check:changedexit 0 is not included in the linked transcript; attach a HEAD-stamped result forb7dd1b088dcbf93ce735386b58c11297c3070cb9or note that the reviewer did not independently rerun it.
- 1
- 2
Pushed99bfaaa
Evidence#
On each fresh database, create two Replay multi-turn threads idle after their first turn. Send through the composer: A = "match" + 470 ASCII spaces + "👨👩👧 rest" (488 UTF-16 units); B = "match" + 474 ASCII spaces + "🇺🇸 🇫🇷 rest" (493 units). Wait for the second fixture turn to finish. Press Ctrl+K, search "match", and capture In messages.
Environment on both sides: real web dev stack, Linux Chromium 156, 1280×800, light theme, fresh synthetic state, Noto Color Emoji. The existing Replay multi-turn model was registered as a custom model because initial discovery advertised only default.
Scenario: Search snippets preserve emojis after long whitespace#
Proven: the scenario fails on base 11193d8e6f and passes on head 99bfaaacd8.
Base 11193d8e6f Head 99bfaaacd8 Result ❌ failed
ASSERTION_FAILED: expect.toContainText failed
locator: getByRole("dialog")
expected: text containing "match 👨👩👧…"
observed: text "Settings Project grouping Settings · General In messages Flag emojis Emoji search demo You: match 🇺… just now Family emoji Emoji search demo You: match 👨👩… just now Navigate Enter Select Esc Close" (match count 1)✅ passed emoji search results 

failure 
Scenario driver · Before recording · After recording
Observed base:
match 🇺…andmatch 👨👩…. Observed head:match 🇺🇸…andmatch 👨👩👧….Not shown:
- The existing maximum snippet length was not independently exercised with a long post-collapse message; these reported inputs produce short excerpts.
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged this91c162c
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.
coderabbitai[bot](GitHub profile, opens in a new tab) reviewed
908d5e1b-429d-447e-bae7-ddce5e08fc3eReviewing files that changed from the base of the PR and between 266e60e27f23369ed06aa8b7809159163d79da34 and 99bfaaacd87868465408aebb1002cb1ba6589468.
apps/server/src/orchestration-v2/ThreadSearch.test.tsapps/server/src/orchestration-v2/ThreadSearch.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.