Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): thread search snippets start with whole emoji #47038

Mergedpeakoshi(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/47038/headmerged by juliusmarminge View on GitHub

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):

  1. 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.
  2. Send x👩‍💻👩‍💻👩‍💻👩‍💻👩‍💻👩‍💻--needlesample.
  3. Type needlesample into the sidebar Search threads field.
  4. 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)
    1. Pushed58a327f

    2. 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.

      Base 2b7b085254Head 58a327ffe8
      Result❌ failed
      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)
      ✅ passed
      whole emoji search excerptBase 2b7b085254: whole emoji search excerptHead 58a327ffe8: whole emoji search excerpt
      failureBase 2b7b085254: failure

      | Recording | Before | After |

      Scenario driver

      Head contains: …👩‍💻👩‍💻👩‍💻👩‍💻--needlesample.

      Not shown:

      • Flag/regional-indicator variant was not exercised; this proof covers the reported woman-technologist ZWJ reproduction.
      • Emoji glyph appearance could not be assessed because headless Chromium lacks a color-emoji font; exact DOM content confirms the boundary.
    3. juliusmarminge added labelstakeover:ready

    4. juliusmarminge removed labelstakeover:in-progress

    5. juliusmarminge merged this21625d3

    6. juliusmarminge closed this

    7. juliusmarminge removed labelstakeover:ready

Sign in to join this conversation.