fix(server): thread search finds phrases inside quotes and their comments #22553
main fromrefs/pull/22553/head·merged by juliusmarminge View on GitHubProblem#
Thread search can't find a phrase inside a quote or its comment (https://git.cafe/pingdotgg/t3code/issues/22304). A quote is stored in the message text as an [Assistant quote](t3-citation://v1/…) link, and URLSearchParams encodes the quote and comment inside it: what are you talking about is stored as what+are+you+talking+about. Thread search matches that stored text, both through the message index and the fallback scan, so phrases with spaces never match, and accented, CJK and apostrophe words in a quote never match through the index. Single words do, including words from the quote's hidden prefix and suffix selection context, so a thread can show up for a word its reader never saw in it.
Change#
- When
ProjectionStoreprojects a message, it now storessearch_textonorchestration_v2_projection_messages:assistantCitationsToPlainText(text), the helper the queued-message and stash previews already use. A quote becomes its text plusComment: …, without the link or its hidden context. The column isNULLwhen that equals the stored text, so plain messages aren't stored twice. Everymessage.updatedupsert rewrites it, so edits keep it current. - Migration 081 adds the column, recreates the message search triggers, and backfills existing history. The backfill pages through messages whose payload contains
t3-citation://, 500 at a time bymessage_id, and writessearch_textonly where the readable text differs; the update trigger re-indexes each message it changes. - The search triggers come from the shared
createMessageSearchTriggers, which now indexessearch_textonce the column exists. Migrations 069 and 074 are unchanged and, running before 081, keep indexing the stored text; a later migration that recreates the triggers through the helper keeps quote indexing instead of reverting it. Migration 081 recreates them through a newrecreateMessageSearchTriggers.rebuildMessageSearch(t3 doctor,migrate-dev-db) indexes the same text. - Thread search matches
COALESCE(search_text, text), the check for short words outside ASCII included, and builds the snippet from the same value, through onemessageSearchTexthelper, on the same reader-worker query. - Migration id: 081, the next id after main's 080.
Scope and approval#
Refs https://git.cafe/pingdotgg/t3code/issues/22304. This fixes its matching half. @EtanHey reported it, traced both halves and suggested a derived search-text column written at projection time; this builds that.
Snippets come from the matched text, so a quoted match also shows readable text instead of the encoded link.
Verification#
Linux (Ubuntu 26.04). Each app run started a dev server of main (ba4d01cf7f) first, then this branch (2d999f791e) on a copy of the same state; the upgrade ran only 82_ProjectionMessageSearchText. Since 2d999f791e the PR's own patch changed only that migration's number (now 081) and dropped one test; search behaves the same. The servers ran under the machine name "Test machine" with synthetic threads from the dev Replay provider. Web input was clicks and typing in T3's Browser panel; desktop input was sent through the app's debugging port.
Main stores a quote's comment encoded. On main I selected a line of a Replay reply, chose Cite, added the comment what are you talking about, moved the quote into a new thread with quiet silver lantern, sent it, and renamed that thread Clarify write confirmation so its title doesn't hold the phrase. The stored text, read from the test database:
# main ba4d01cf7f web state, read-only, after the quote was sent and the server stopped
# last two migrations:
80|ScheduledTaskThreadMode
79|DelegatedRecoveryIndexes
# quoting message, stored text:
user|[Assistant quote](t3-citation://v1/9abb548a-9677-440c-ae3b-4aaa13f4cc6a/mcp%3Ac557626c-71da-48e9-bcb9-c3855b43ee10/message%3Aprovider%3AacpRegistry%3Anative-item%3Aprovider-instance%253AdevReplay%253Afd305561-0809-4240-821e-9e903fcdbf8d%253Aturn%253A1%253Aassistant%253A1?text=Asks+before+it+writes%0A%0A&start=76&end=98&prefix=+pass.+Reads+the+manifest+first+&suffix=Streams+a+terminal+result+clamp%28&comment=what+are+you+talking+about) quiet silver lantern
Searching for the comment finds the quoting thread after the upgrade, with a readable snippet.
| main | this branch |
|---|---|
![]() | ![]() |
![]() | ![]() |
Desktop (Linux Electron under Xvfb): the same result
Desktop (Linux Electron under Xvfb, vp run dev:desktop). Desktop dev has no Replay provider, so these runs used a copy of the web run's main state:
| main | this branch |
|---|---|
![]() | ![]() |
Mobile, from an earlier head of this branch: the same result
Kept from an earlier head of this branch, at or before 7c15aaf30e (2026-10-31; the exact commit was not recorded), before main was merged in: T3 Code Dev client on an Android 16 emulator and an iOS 26.5 simulator.
| main | this branch | |
|---|---|---|
| Android | ![]() | ![]() |
| iOS | ![]() | ![]() |
A phrase inside a quote finds the quoting thread. On main I quoted the reply todo list fixture complete from a Replay thread "Plan the beacon maintenance" into a Showcase thread (harbor log entry, renamed Review harbor log). Main finds only the reply it came from; this branch also finds the quoting thread.
| main | this branch |
|---|---|
![]() | ![]() |
A quote sent after the upgrade goes through the projection path and is found by its comment.

Index matching, hidden context, edits and the backfill are covered by the new tests. Before: main's ThreadSearch.ts under this branch's tests. After: this branch.
# main ba4d01cf7f ThreadSearch.ts under the head 2d999f791e tests (bound read-only over the head's file)
$ vp test run src/orchestration-v2/ThreadSearch.test.ts 2>&1 | grep -E '×|Test Files|Tests '
× matches the readable text of quotes and their comments 7ms
× finds accented, CJK, and apostrophe words of a quote through the index 3ms
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
Test Files 1 failed (1)
Tests 2 failed | 29 passed (31)
This branch: 8 test files, 111 passed
# head f659f078e4
$ vp test run src/orchestration-v2/ThreadSearch.test.ts src/persistence/Migrations/081_ProjectionMessageSearchText.test.ts src/persistence/Migrations/077_RepairBooleanSettledOverride.test.ts src/persistence/Migrations/069_ThreadMessageSearch.test.ts src/persistence/Migrations.test.ts src/persistence/reconcileV2PreviewMigration.test.ts src/persistence/DatabaseMaintenance.test.ts src/orchestration-v2/ProjectionStore.test.ts 2>&1 | grep -E '^ (✓|×) |Test Files|Tests '
✓ src/orchestration-v2/ProjectionStore.test.ts (54 tests) 4680ms
✓ src/orchestration-v2/ThreadSearch.test.ts (31 tests) 860ms
✓ src/persistence/DatabaseMaintenance.test.ts (5 tests) 148ms
✓ src/persistence/reconcileV2PreviewMigration.test.ts (5 tests) 159ms
✓ src/persistence/Migrations.test.ts (9 tests) 217ms
✓ src/persistence/Migrations/069_ThreadMessageSearch.test.ts (5 tests) 160ms
✓ src/persistence/Migrations/081_ProjectionMessageSearchText.test.ts (1 test) 135ms
✓ src/persistence/Migrations/077_RepairBooleanSettledOverride.test.ts (1 test) 57ms
Test Files 8 passed (8)
Tests 111 passed (111)
With the trigger helper forced back to the stored text, the 081 backfill case and the index case in ThreadSearch fail (2 failed, 30 passed). vp run check:changed: format, lint, knip, typecheck and tests pass.
Not checked:
- Desktop on macOS and Windows. They run the same server and web UI.
- Hidden-context searches in the app: the Replay replies hold the words around each quote, so those words also match the replies there. The unit tests cover them.
- Migration time on a large database. The backfill test crosses one 500-row page.
Prior PRs: https://git.cafe/pingdotgg/t3code/pulls/22391 fixed the snippet only and was closed as a duplicate of this PR. No open or closed PR changes the matching. https://git.cafe/pingdotgg/t3code/pulls/16858 (open) edits the same query for qualifiers and may need a small rebase.
Generated with Claude Opus 5.5 in T3 Code Nightly
Fixes pingdotgg/t3code#22304
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
694931aMacroscope's review found this PR approvable — This is a focused server bug fix that makes thread search use readable citation text while preserving existing behavior for ordinary messages. The additive migration, fallback logic, and targeted projection/replay tests keep the change bounded and backward-compatible.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.- Last reviewed commit: 8e7ea08b318617730ea6c87437489dadd7c94fb9
- Latest commit, not reviewed: f659f078e4411fd933a8f3620184e248523cec69
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Use the checkboxes below for quick actions:
- Resume reviews
- Trigger review
No actionable comments were generated in the recent review.
Walkthrough
-
The change adds readable citation text to projected messages and search indexing. Thread search uses the shared message-text expression for scans, indexed queries, and substring filters. Migration 81 adds and backfills the search-text column and recreates search triggers.
Changes: Citation-aware thread search
Layer / File(s) Summary Add and index readable search text
apps/server/src/orchestration-v2/messageSearchIndex.ts,apps/server/src/persistence/Migrations/081_ProjectionMessageSearchText.ts,apps/server/src/persistence/Migrations/081_ProjectionMessageSearchText.test.ts,apps/server/src/persistence/Migrations.ts,apps/server/src/persistence/reconcileV2PreviewMigration.test.tsMigration 81 adds search_text, backfills readable text for eligible citation messages, and recreates search triggers. Indexing and rebuilds use the selected text, with a stored-text fallback when the column is absent. Migration registration and tests cover the backfill and index behavior.Maintain search text on projected messages
apps/server/src/orchestration-v2/ProjectionStore.tsMessage inserts and conflict updates write search_textderived from message text.Search readable citation text
apps/server/src/orchestration-v2/ThreadSearch.ts,apps/server/src/orchestration-v2/ThreadSearch.test.tsScanned and indexed queries and substring filters use messageSearchText(sql). Tests cover citation quote and comment matching, hidden citation context, apostrophe variants, accented and CJK text, index rebuilding, and message updates.Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
sequenceDiagram participant ProjectionStore participant ProjectionMessages participant MessageSearchIndex participant ThreadSearch ProjectionStore->>ProjectionMessages: Write payload and readable search_text ProjectionMessages->>MessageSearchIndex: Trigger index update ThreadSearch->>MessageSearchIndex: Resolve messageSearchText(sql) MessageSearchIndex-->>ThreadSearch: Return schema-aware text expression ThreadSearch->>ProjectionMessages: Query matching message textPossibly related PRs
- pingdotgg/t3code#24343: Adds the indexed message-search paths that this change extends to use readable citation text.
Suggested reviewers:
maria-rcks,juliusmarminge
Merge Risk:
Minimal · up to8e7ea-
Thread search now matches quoted text and quote comments. No concrete merge-blocking issue was found. The migration backfill time on very large databases was not measured.
Architecture risk:
Low · up tobb269-
The change affects 1 system.
Changed systems:
apps/serverArchitecture concerns No architecture-level concerns identified.
Review details
-
Systems and components
- observed — apps/server (service) was modified; 7 changed files map to changed impact.
Before / after behavior
- observed — Modified behavior in apps/server/src/orchestration-v2/ProjectionStore.ts: Added the
assistantCitationsToPlainTextimport used to derive searchable message text. - observed — Modified behavior in apps/server/src/orchestration-v2/ProjectionStore.ts:
message.updatednow derives citation-stripped plain text from the message text for search indexing. - observed — Modified behavior in apps/server/src/orchestration-v2/ProjectionStore.ts: The projected messages insert now includes the
search_textcolumn. - observed — Modified behavior in apps/server/src/orchestration-v2/ProjectionStore.ts: Message inserts store normalized citation text, using
NULLwhen it matches the original message text.
-
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly describes the main change: thread search can find phrases inside quotes and comments. Linked Issues check Issue #22304requires thread search to match readable quote text and comments, and to show readable snippets.ProjectionStorewritessearch_textfromassistantCitationsToPlainTextand refreshes …Out of Scope Changes check The changes support issue #22304. The migration, trigger updates, index rebuild logic, projection writes, and tests implement or maintain searchable readable quote text and snippets. No unrelated chan…Description check The description follows the required Problem, Change, Scope and approval, and Verification sections. It explains the issue, implementation, linked issue and approval context, focused test results, man… Full details: Linked Issues check
-
Explanation
Issue
#22304requires thread search to match readable quote text and comments, and to show readable snippets.ProjectionStorewritessearch_textfromassistantCitationsToPlainTextand refreshes it on message upserts. Migration 081 adds and backfills the column, then recreates the search triggers.ThreadSearchusesCOALESCE(search_text, text)for indexed and fallback matching, including short-word checks. The added tests cover quote and comment phrases, hidden prefix and suffix context, non-ASCII words, index rebuilds, and edits that remove a quote. The PR summary reports readable snippets from the same search text.
Full details: Out of Scope Changes check
-
Explanation
The changes support issue
#22304. The migration, trigger updates, index rebuild logic, projection writes, and tests implement or maintain searchable readable quote text and snippets. No unrelated change is evident in the reviewed diff or change summary.
Full details: Description check
-
Explanation
The description follows the required Problem, Change, Scope and approval, and Verification sections. It explains the issue, implementation, linked issue and approval context, focused test results, manual checks, screenshots, limitations, and agent usage.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: f12bb62
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
918cc1a3-f4f6-42c7-9005-15d2c5085a69
Commits-
Reviewing files that changed from the base of the PR and between 7c15aaf30eafd1d7542a56c2bd07b2794ebbfadf and 8e7ea08b318617730ea6c87437489dadd7c94fb9.
Files selected for processing: 8-
apps/server/src/orchestration-v2/ProjectionStore.tsapps/server/src/orchestration-v2/ThreadSearch.test.tsapps/server/src/orchestration-v2/ThreadSearch.tsapps/server/src/orchestration-v2/messageSearchIndex.tsapps/server/src/persistence/Migrations.tsapps/server/src/persistence/Migrations/081_ProjectionMessageSearchText.test.tsapps/server/src/persistence/Migrations/081_ProjectionMessageSearchText.tsapps/server/src/persistence/reconcileV2PreviewMigration.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
-
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:gate-failed
Note
🤖 Opus 5.5 replying on behalf of Victor.
I merged main into this branch in 8e7ea08b31 to clear the conflicts in
Migrations.ts,ProjectionStore.tsand the V2 preview migration test.- Main now has migrations 077 to 080, so the search text migration is now 081. Its test migrates to 080 first and then runs only 081.
- The new check for short words outside ASCII (#30332) now reads the same readable text as the other search checks, so a short word inside a quote or its comment matches too. A new row in the quote test covers this.
- I dropped the test that replayed projections from events. Main no longer replays projections outside its test oracle.
I updated the description to match.
Note
🤖 Opus 5.5 replying on behalf of Victor.
The search text migration is now 082 instead of 081, because another open PR (#28751) also adds a migration 081. Main still ends at 080. Commit 2d999f791e renames the migration and its test and updates the manifest row, the expected migration history and the comments that name the number. The migration itself is unchanged. I updated the description to match.
Evidence#
Real web client, Chromium, 1280×800, light theme, fresh synthetic data on each commit. Send a citation with the lighthouse sentence, comment
what are you talking about, and appendedquiet silver lanternthrough the composer in Thread B. Search both citation phrases in the sidebar and the comment in the command palette.The base misses the citation phrases; the fix finds Thread B with readable snippets. The scenario comparison exited 0.
Capture Before — a0efdaeb89 After — f659f078e4 Comment phrase 

Quoted phrase 

Appended phrase snippet 

Command palette 

Hidden selection context 

Recording Before interaction After interaction AI-assisted; verified with the tests and tools listed above.
Not shown:
- Existing-history upgrade migration was not exercised: both commits used fresh databases.
- The selection/Cite/move interaction was not driven; the scenario submitted an equivalent synthetic serialized citation through the web composer.
- The reported hidden-context false positive and raw citation URL display were not reproduced on base: hidden context returned no results and the appended-phrase snippet displayed 'Assistant quote'.
- Command-palette quoted-phrase search was not separately captured; command-palette comment search and sidebar searches for both phrases were captured.
juliusmarminge merged thisa536ff7
juliusmarminge closed this
Sign in to join this conversation.












macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes