Multiplayer agent harness for work.
Remove materialization barriers from entry search (#1379)
Regan Bell1ea3e28b06e5
diff --git a/src/sessions/postgres-session-store.ts b/src/sessions/postgres-session-store.tsindex 637d73846..879032f3f 100644--- a/src/sessions/postgres-session-store.ts+++ b/src/sessions/postgres-session-store.ts@@ -1245,20 +1245,13 @@ export function createPostgresSessionStore(connectionString: string, opts: Storeconst ts = tsPrefixQuery(query);if (!ts) return [];const rows = await q(- `WITH viewer AS MATERIALIZED (- SELECT session_id, valid_from_seq, valid_from, valid_to_seq, valid_to, title, archived- FROM participants WHERE principal_id = $1- ), candidates AS MATERIALIZED (- SELECT session_id, seq, type, author, text, created_at- FROM session_entry_search- WHERE session_id = ANY(ARRAY(SELECT session_id FROM viewer))- AND search_tsv @@ to_tsquery('simple', $2)- )- SELECT h.*, s.scope_id, COALESCE(p.title, s.title) AS title, s.channel_name, s.surface, p.archived- FROM candidates h- JOIN viewer p ON p.session_id = h.session_id+ `SELECT h.session_id, h.seq, h.type, h.author, h.text, h.created_at,+ s.scope_id, COALESCE(p.title, s.title) AS title, s.channel_name, s.surface, p.archived+ FROM session_entry_search h+ JOIN participants p ON p.session_id = h.session_id AND p.principal_id = $1JOIN sessions s ON s.id = h.session_id- WHERE ${withinParticipantWindow("h", "p")}+ WHERE h.search_tsv @@ to_tsquery('simple', $2)+ AND ${withinParticipantWindow("h", "p")}ORDER BY h.created_at DESC, h.session_id, h.seq DESCLIMIT $3`,[principalId, ts, Math.max(1, Math.min(limit, 200))],diff --git a/test/postgres-store.test.ts b/test/postgres-store.test.tsindex 4943d7228..2d1a7e685 100644--- a/test/postgres-store.test.ts+++ b/test/postgres-store.test.ts@@ -1914,6 +1914,43 @@ test("pg search: full-text over entries with prefix match, window ACL, and typeassert.deepEqual(await s.searchEntries("USRCH", "memo missing"), [], "every term must match");});+test("pg search: participation windows filter global matches before the result limit", { skip }, async () => {+ let at = Date.now();+ const s = createPostgresSessionStore(URL!, { now: () => at });+ const scope = scopeId("personal", "SEARCH-WINDOW");+ const session = await s.getOrCreateByThread("search-window-limit", "dm", scope);+ const lease = (await s.acquireLease(session.id)).lease!;+ const append = async (text: string) => {+ at += 1;+ return s.append(lease, { type: "user", payload: { text }, scopeLabel: scope });+ };+ await append("limitwindow before joining");+ await s.addParticipant(session.id, "SEARCH-WINDOW");+ const visible = await append("limitwindow visible");+ await s.removeParticipant(session.id, "SEARCH-WINDOW");+ await append("limitwindow after leaving");+ await s.releaseLease(lease);++ const hidden = await s.getOrCreateByThread("search-hidden-limit", "dm", scope);+ const hiddenLease = (await s.acquireLease(hidden.id)).lease!;+ at += 1;+ await s.append(hiddenLease, {+ type: "user",+ payload: { text: "limitwindow inaccessible session" },+ scopeLabel: scope,+ });+ await s.releaseLease(hiddenLease);++ for (const limit of [1, 200]) {+ const hits = await s.searchEntries("SEARCH-WINDOW", "limitwindow", limit);+ assert.deepEqual(+ hits.map((hit) => [hit.sessionId, hit.seq]),+ [[session.id, visible.seq]],+ );+ }+ assert.deepEqual(await s.searchEntries("SEARCH-OUTSIDER", "limitwindow", 1), []);+});+test("pg search: message writes populate the index and tool results stay unfindable", { skip }, async () => {const s = createPostgresSessionStore(URL!);const scope = scopeId("personal", "UIDX");