From 0173ed073403871249f11c572be8762b1a2a785d Mon Sep 17 00:00:00 2001 From: Shadman Taqi <61359614+iamshadmantaqi@users.noreply.github.com> Date: Fri, 27 Nov 2026 15:25:00 +0600 Subject: [PATCH 1/2] test(server): keep a better title match over a weaker one found by its messages --- .../src/orchestration-v2/ThreadSearch.test.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/apps/server/src/orchestration-v2/ThreadSearch.test.ts b/apps/server/src/orchestration-v2/ThreadSearch.test.ts index 327d3cb5f70a2..229d565f11190 100644 --- a/apps/server/src/orchestration-v2/ThreadSearch.test.ts +++ b/apps/server/src/orchestration-v2/ThreadSearch.test.ts @@ -1419,6 +1419,37 @@ it.layer(layerTest)("ThreadSearch.searchThreads", (it) => { }), ); + it.effect("keeps a better title match over a weaker one found by its messages", () => + Effect.gen(function* () { + const projections = yield* ProjectionStore.ProjectionStoreV2; + const search = yield* ThreadSearch.ThreadSearch; + const project = ProjectId.make("project:heron"); + yield* createProject(project); + // Six titled threads that each also name the word in a message. + yield* Effect.forEach( + Array.from({ length: 6 }, (_, index) => { + const id = ThreadId.make(`thread:heron-${index + 1}`); + return [ + thread(id, project, { title: `Heron ${index + 1}` }), + message(id, `heron-${index + 1}`, "user", "a heron sighting", { minute: 2 }), + ]; + }).flat(), + projections.apply, + { discard: true }, + ); + const byTitle = (yield* search.searchThreads({ query: "heron", limit: 6 })).matches; + assert.deepStrictEqual( + byTitle.map((match) => match.source), + Array.from({ length: 6 }, () => "title"), + ); + const { matches } = yield* search.searchThreads({ query: "heron", limit: 5 }); + assert.deepStrictEqual( + matches.map((match) => match.threadId), + byTitle.slice(0, 5).map((match) => match.threadId), + ); + }), + ); + it.effect("leaves titled threads out before the hit limit", () => Effect.gen(function* () { const projections = yield* ProjectionStore.ProjectionStoreV2; From 21de9d16f7c498a9175f90d7fc4bc4c73bc66a4d Mon Sep 17 00:00:00 2001 From: Shadman Taqi <61359614+iamshadmantaqi@users.noreply.github.com> Date: Fri, 27 Nov 2026 15:25:35 +0600 Subject: [PATCH 2/2] fix(server): keep a better title match over a weaker one in thread search --- .../src/orchestration-v2/ThreadSearch.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/apps/server/src/orchestration-v2/ThreadSearch.ts b/apps/server/src/orchestration-v2/ThreadSearch.ts index bb00171eb6041..c296dba2c32d8 100644 --- a/apps/server/src/orchestration-v2/ThreadSearch.ts +++ b/apps/server/src/orchestration-v2/ThreadSearch.ts @@ -660,21 +660,22 @@ export const make = Effect.gen(function* () { }, ]), ); - const titleHits: ThreadSearchHit[] = rankSearchItems(candidates, (row, options) => + const titleRanked = rankSearchItems(candidates, (row, options) => // An agent's search has no use for the user's palette picks. scoreThreadSearch(normalizedQuery, subjectById.get(row.thread.id)!, now, { ...options, picks: false, }), - ) - .slice(0, limit) - .map(({ item }) => ({ - threadId: item.thread.id, - projectId: item.thread.projectId, - title: item.thread.title, - source: "title", - })); - const shown = new Set(titleHits.map((hit) => hit.threadId)); + ); + const titleHits: ThreadSearchHit[] = titleRanked.slice(0, limit).map(({ item }) => ({ + threadId: item.thread.id, + projectId: item.thread.projectId, + title: item.thread.title, + source: "title", + })); + // The message slots are for threads the titles miss: a weaker title match + // found again by its messages would push out a better one. + const shown = new Set(titleRanked.map(({ item }) => item.thread.id)); const { matches } = yield* searchMessages({ query: input.query, limit: 50,