Skip to content

feat(j5): people a thread is shared with can search its messages - #808

Merged
Jacksondr5 merged 3 commits into
j5/mainfrom
j5/696-shared-message-search
Oct 31, 2026
Merged

Jacksondr5 merged 3 commits into
j5/mainfrom
j5/696-shared-message-search

Conversation

@Jacksondr5

@Jacksondr5 Jacksondr5 commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Problem

People a thread or project is shared with (narrowed connections: Viewers, and Collaborators below server scope) got no "In messages" section in Cmd+K, because orchestration.searchThreads was refused to them. And a narrowed Collaborator's opens changed the thread's shared opens record, which ranks the Owner's Cmd+K. Closes #696, per Jackson's 2026-10-31 decision.

What changed

  • Search is scoped on the server, before the cut. PersonAccess.reachableThreads(personId) lists every thread the person holds a level over, by the same parent rule as threadLevel (the rule is now one shared SQL fragment), and returns null for a level at server scope. A new GuestView hook, searchThreads, wraps the ws.ts handler. It passes the thread list into upstream's message query as a server-only threadIds condition inside the eligible CTE, ahead of the hit limit, so results aren't filtered after the cut. It also drops olderSettledBefore, projectIds and environmentLabel: a narrowed sidebar has no older-settled cut, and that path returns full shell rows from every settled thread. An unclaimed device, or someone who reaches nothing, gets { matches: [] } and no query runs. Reach is read on each search, so a share that is taken away ends with the next search.
  • Narrowed results are ranked without opens. A server-only withoutOpens input makes the ranking treat the thread's opens as null: no picks and no open-count boost. The owner's palette queries therefore don't change which shared threads make the cut or how they are ordered. Owner ranking is unchanged.
  • Narrowed visits don't count. CommandAdmission admits a narrowed Collaborator's thread.visit without opened and searchQuery, so the read marker still moves, opens stays the same, and no error is shown. I chose this over refusing the visit, which would also have dropped the read marker. A Viewer's visit is refused today (every narrowed command needs Collaborator) and still is. Upstream's client sends visits with reportFailure: false, so the Viewer sees nothing.
  • ACCESS_RPC_RULES lists searchThreads as narrowed.
  • Known limit (Captain's ruling). Upstream's floor of the newest 10,000 index hits for a word is counted across the whole server, before the reach condition. On a big server, a word with more than 10,000 matches finds only the shared person's matches among those newest ones. It cuts the Owner's results the same way, and nothing from an unreachable thread is returned, counted or shown.

MCP t3_thread_search is unchanged, because no MCP caller is ever narrowed. accessHttpRule strips a narrowed session's permissions on every route except /ws, thread loads, preview streams and the artifact read, so /mcp is refused. MCP clients have subject mcp-client, which isServiceSubject treats as wide, and they are approved only by an Owner (FORK.md case 70). Agents' MCP sessions are service sessions.

UI changes

There's no UI code change. Upstream's palette shows "In messages" once the RPC answers. Captures are from an isolated test server, 1280×800, with the same data before (j5/main) and after (26eacd211c).

State Before After
Thread Viewer: only shared messages become searchable Before After
Owner: both message matches remain available Before After
Thread Viewer: private-only text returns no results Before After

The Viewer's result shows the Owner's message as "You:". Upstream's palette labels every hit from a person's message that way. An Owner searching already sees a Collaborator's messages as "You:", and this PR now shows the label to shared people too. Naming the author needs author data in the search result; that is tracked in #809, not fixed here.

Live testing

Verdict: pass for the web flows exercised. Tested at 26eacd211c on an isolated test server (j5-live-test), with a second browser paired as the shared person. The head is now d66e2fd489, which changes only messageSearch.test.ts (each test seeds its own projects), so it wasn't re-tested live.

  • A thread Viewer and a thread Collaborator find only the shared thread's messages; a word that appears only in a private thread finds nothing.
  • A project Viewer finds matches in both threads of the shared project.
  • The Owner's results are unchanged.
  • Opening a thread from a narrowed connection leaves the thread's opens byte-identical. An Owner opening the same thread records the query and raises the score.
  • Picking a result as a Viewer shows no toast or error.
  • After a restart, the Viewer's matching and non-matching searches give the same results.
  • Two real Claude Haiku turns created the fixture threads on the baseline; on the head, search and visits were checked directly.

Not exercised live:

  • Read-marker movement on a narrowed visit: the fixture thread was already read. CommandAdmission.integration.test.ts covers it.
  • A project-scope Collaborator, or a second shared project.
  • MCP, Codex turns, mobile, the packaged desktop app, and remote transports (LAN, Tailscale, tunnel). The scoping is keyed by session, not transport.

Upstream impact

  • apps/server/src/orchestration-v2/ThreadSearch.ts: server-only threadIds and withoutOpens on search's input and SearchRequest, and one condition in the eligible CTE (FORK.md case 69; file-table row updated).
  • apps/server/src/orchestration-v2/ThreadSearch.test.ts: the query-plan test passes threadIds: null (case 69; row added).
  • apps/server/src/ws.ts: the searchThreads handler runs inside j5View.searchThreads (case 69, already in the table).

What upstream's product does for wide sessions (Owners, server-scope Collaborators, services) is unchanged. The narrowing belongs to J5's sharing (case 69, register D33), and the decision is linked above.

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior. messageSearch.test.ts covers project-scope and thread-scope shares, Viewer and Collaborator, a server Viewer, a match only in an unreachable thread, unclaimed and empty reach (no query runs), a deliberately sent olderSettledBefore (no rows), and ranking that ignores picks. PersonAccess.test.ts checks that reachableThreads agrees with threadLevel over every fixture thread: a subagent, a seat in another project, a grandchild seat, a fork and a forked-from seat excluded, a thread + project union, and a revoked share. CommandAdmission.integration.test.ts runs a visit through upstream's real orchestrator: the Owner's visit records the open, and the Collaborator's leaves opens byte-identical while the read marker moves. That test fails on j5/main. AccessGate.test.ts now expects searchThreads to run.
  • UI changes: before/after screenshots above
  • Live testing: the section above says what ran live and what did not
  • Upstream-owned files: each one is recorded in FORK.md (case text and file-table row) in this PR
  • Upstream product: no change for wide sessions; the narrowed behavior follows Jackson's decision on Cmd+K message search and open ranking for people a thread is shared with #696
  • Surfaces. Entry points: Cmd+K is the only caller (the sidebar search uses the same RPC). Clients: web and desktop, through the shared client-runtime. Mobile, left to its owner: the mobile palette calls the same orchestration.searchThreads through packages/client-runtime, so it needs no code change, but it hasn't been checked on a device. Agents: MCP is unchanged (see above). Contracts: no wire change; threadIds and withoutOpens are server-only. Reverse states: removing a share drops its threads from the next search. Connection modes: scoping is keyed by session, not transport.
  • Docs: docs/j5/product/features/shared-conversations.md is rewritten for search and opens (AC21, AC22, a scenario and a History line). The user docs had no search passage to correct.

Built by Claude Opus 5.5 in Claude Code (J5 Code crew seat).

🤖 Generated with Claude Code

Cmd+K's "In messages" search was refused to narrowed connections. It now
runs for them, held on the server to the threads the person can open
(PersonAccess.reachableThreads) before upstream's search cuts its results,
and ranked without the owner's opens. A narrowed Collaborator's visit no
longer records opens or palette queries; it still moves the read marker.

Closes #696

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
j5-code Ready Ready Preview Oct 31, 2026 3:45pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 13 billable files and costs up to $3.25.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 33 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 3 included reviews currently available. Your 44 included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 6a6aa43 and 8f47737.

Files selected for processing: 13
  • FORK.md
  • apps/server/src/j5/sharing/AccessGate.test.ts
  • apps/server/src/j5/sharing/AccessGate.ts
  • apps/server/src/j5/sharing/CommandAdmission.integration.test.ts
  • apps/server/src/j5/sharing/CommandAdmission.ts
  • apps/server/src/j5/sharing/GuestView.ts
  • apps/server/src/j5/sharing/PersonAccess.test.ts
  • apps/server/src/j5/sharing/PersonAccess.ts
  • apps/server/src/j5/sharing/messageSearch.test.ts
  • apps/server/src/orchestration-v2/ThreadSearch.test.ts
  • apps/server/src/orchestration-v2/ThreadSearch.ts
  • apps/server/src/ws.ts
  • docs/j5/product/features/shared-conversations.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 effective changed lines (test files excluded in mixed PRs). labels Oct 31, 2026
Jacksondr5 added a commit that referenced this pull request Oct 31, 2026

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combined review of #808 at 26eacd211c, from Opus 5.5 (lead), Sol 6.1 and Fable 5.1 (security). The panel agreed these findings before posting. No security or functional findings. There are three small fixes, all in tests or docs.

What we verified in source

  • Scoped on the server, not filtered after. threadIds sits in messageHitsQuery's eligible CTE, ahead of MESSAGE_HIT_LIMIT. Hit counts and snippets are computed only from rows that CTE admits. A match only in an unreachable thread returns { matches: [] }. Upstream's global FTS candidate floor is unchanged, per the Captain's ruling; the PR body and the feature doc both state it.
  • Ranking without opens. withoutOpens nulls the subject's opens (ThreadSearch.ts:492), which removes both the picks and the open-count boost. The test flips the top result with an owner pick.
  • No wire control. OrchestrationV2SearchThreadsInput is unchanged, and decoding strips threadIds and withoutOpens. ws.ts also spreads narrowed after the request, so a narrowed caller can't widen the search.
  • No older-settled rows for a narrowed session. olderSettledBefore, projectIds and environmentLabel are dropped for every narrowed session, the server-scope Viewer included, and the deliberately sent case is tested.
  • Reach. reachableThreads shares parentInChain with threadLevel and uses the same project rule as coveringThread. Its test asserts that the two agree for every fixture thread: a cross-project seat, a grandchild seat, forked-from, a fork, a union, a revoked share, and a server Viewer (null). Reach is read on every search. An unclaimed device is refused at the gate (narrowed without unknownToo) and again in the view, without running a query.
  • Visits. The strip runs after requireLevel(…, "collaborator"), and dispatchCommand dispatches the stripped admitted command. The integration test drives upstream's real orchestrator: opens stays byte-identical while lastVisitedAt moves, and an Owner visit still records the open. A Viewer's visit stays refused, and both web call sites use reportFailure: false, so the Viewer sees no error.
  • Owner path. MEMBER_VIEW.searchThreads is a strict pass-through, and isWide returns early in CommandAdmission, so Owners, server-scope Collaborators and services are unchanged.
  • MCP. t3_thread_search has no narrowed caller: mcp-client is a service subject (PersonAccess.isServiceSubject), and /mcp has no session-cookie fallback.
  • FORK.md case 69. The case text, the "nine handlers" count, the pin-advance guidance and the file-table row are all accurate.
  • Cost. We timed the reach query read-only against a real database (928 live threads): about 22 ms per narrowed search. That's acceptable, so it isn't a finding.

Findings

  1. [P2] apps/server/src/j5/sharing/messageSearch.test.ts: two tests depend on run order. Only the first test calls createProject(SHARED). The older-settled test and the ranking test seed threads in SHARED, and messageHitsQuery inner-joins projection_projects. Run alone with vp test run apps/server/src/j5/sharing/messageSearch.test.ts -t 'ranks a narrowed search', the ranking test fails at :292 (expected [thread:search-picked], got []). The full file passes 4/4. Fix: create the project in each test that needs it.
  2. [nit] docs/j5/product/features/shared-conversations.md: criteria order. The new ### Search section (AC21, AC22) comes before ### Scheduled runs (AC20), so the criteria read 19, 21, 22, 20. Move it after.
  3. [nit] The same doc: wording. The "Thread state is shared" paragraph says "the server's Owners' and wide Collaborators'". "Wide" is code vocabulary. Use AC22's own wording, "a Collaborator at server scope".

Optional, not blocking: when the person holds no thread-level share, reachableThreads could skip the recursive half. The query is already cheap at real sizes.

Pending, and already marked unticked in the PR: the tester's before/after Cmd+K captures and the live-test report.

Claude Opus 5.5 (lead reviewer), with Sol 6.1 and Fable 5.1, in J5 Code

Search criteria follow Scheduled runs in the definition, the opens line
names Collaborators at server scope, and reachableThreads walks ancestor
lines only for someone who holds a thread.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked at 8f47737ced: all three findings are resolved.

  1. Each search test now seeds its own projects (seed creates them if they're missing), and every test passes when run alone.
  2. AC20, AC21 and AC22 are in order.
  3. The doc now says "Collaborators at server scope".

The optional change is also in: reachableThreads walks ancestor lines only for someone who holds a thread-scope share. The project-only path is covered end to end by the project Viewer and project Collaborator cases in messageSearch.test.ts. Nothing is open from the panel. Live-test evidence is still pending.

Claude Opus 5.5 (lead reviewer), in J5 Code

@Jacksondr5
Jacksondr5 merged commit 75cd4da into j5/main Oct 31, 2026
35 checks passed
@Jacksondr5
Jacksondr5 deleted the j5/696-shared-message-search branch October 31, 2026 16:13
Jacksondr5 added a commit that referenced this pull request Nov 23, 2026

This branch was successfully deployed

1 active deployment
Preview — 8f47737c Deployed Oct 31, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 effective changed lines (test files excluded in mixed PRs). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cmd+K message search and open ranking for people a thread is shared with

1 participant