Problem#
buildSearchSnippet in apps/server/src/orchestration-v2/ThreadSearch.ts skips lone low surrogates, combining marks, skin-tone modifiers, and ZWJ characters (#45061), but can still cut inside a joined emoji sequence (such as 👩💻) or a regional-indicator flag (such as 🇨🇦). When the snippet starts mid-grapheme, the sidebar search result shows a stray trailing component like …💻👩💻 instead of …👩💻.
Steps to reproduce (no sign-in required):
- Start the local dev app with a fresh project and a Replay (dev) (Multi turn) thread titled
Weekly notes. Send Start as the first message.
- Send
x👩💻👩💻👩💻👩💻👩💻👩💻--needlesample.
- Type
needlesample into the sidebar Search threads field.
- Expected: the snippet starts on a whole emoji (
…👩💻👩💻👩💻👩💻--needlesample). Actual on main: the snippet starts with a stray laptop (…💻👩💻👩💻👩💻👩💻--needlesample).
Change#
Use a module-level Intl.Segmenter(undefined, { granularity: "grapheme" }) in ThreadSearch.ts when start borders a non-ASCII code unit. Walk back to the nearest ASCII boundary (preserving exact Regional Indicator flag parity while avoiding O(N) full-string segmentation on large ASCII messages) and bound the forward slice to start + SNIPPET_LENGTH * 2. If start lands inside a grapheme cluster, advance to the end of that cluster when it stays at or before matchStart, or back up to the cluster start when doing so stays within SNIPPET_LEAD so oversized clusters cannot hide the match.
Scope#
Small fix for an obvious Unicode truncation bug on the leading edge of server-generated thread search snippets, following #45061 and #46906, so no separate issue. Trailing snippet truncation at SNIPPET_LENGTH is intentionally left unchanged to keep this PR scoped to one problem.
Verification#
vp test run apps/server/src/orchestration-v2/ThreadSearch.test.ts -t "starts snippets a few words before the match" failed on main (891bf1afa3, returning …💻👩💻👩💻👩💻👩💻--needle) and passed on 85af4618f3 (38/38 tests in ThreadSearch.test.ts pass, including ZWJ 👩💻, flag 🇨🇦, and giant \u0600 cluster match-visibility cases).
- Verified with a 200,000-string random Unicode fuzz check (zero split leading graphemes across ZWJ, flags, keycaps, combining marks, Prepend, and Devanagari) and perf check (
0.001 ms median on 10 MB ASCII messages).
- Real-app Chromium scenario
scripts/scenarios/thread-search-keeps-joined-emoji.e2e.ts failed on main (891bf1afa3) and passed with the fix.
vp fmt, vp lint, and vp run knip:check passed on 85af4618f3; vp run check:changed passed on the pre-rebase head (format, lint, knip, graphql, 3 package typechecks, 40/40 tests).
- Verified in the web client on Windows. Not checked: native desktop, iOS, and Android clients (all consume the same server snippet).
Before (main) | After (fix) |
|---|
 |  |
Evidence#
Created project demo and Replay (dev), multi-turn thread Weekly notes with Start; opened the thread, sent x👩💻👩💻👩💻👩💻👩💻👩💻--needlesample through the composer, waited for second fixture turn complete, searched needlesample in Search threads, captured the results, and checked for …👩💻👩💻👩💻👩💻--needlesample.
Environment on both sides: real web dev app, headless Chromium, 1280×800, light theme, fresh isolated databases, recorded Replay agent. Emoji render as missing-glyph boxes; the DOM assertion identifies the grapheme boundary.
Scenario: Thread search snippets start with a whole joined emoji#
Proven: the scenario fails on base 2b7b085254 and passes on head 58a327ffe8.
ASSERTION_FAILED: expect.toContainText failed
locator: getByRole("listbox", name: "Thread search results")
expected: text containing "…👩💻👩💻👩💻👩💻--needlesample"
observed: text "DO Weekly notes now You: …💻👩💻👩💻👩💻👩💻--needlesample" (match count 1)
| Recording | Before | After |
Scenario driver
Head contains:
…👩💻👩💻👩💻👩💻--needlesample.Not shown: