Skip to content

fix(inbox): forward reviewer search query to the server#2800

Open
pauldambra wants to merge 1 commit into
mainfrom
posthog-code/forward-reviewer-search-query
Open

fix(inbox): forward reviewer search query to the server#2800
pauldambra wants to merge 1 commit into
mainfrom
posthog-code/forward-reviewer-search-query

Conversation

@pauldambra

Copy link
Copy Markdown
Member

Problem

Assigning a reviewer in the Inbox only surfaced people whose first name fell in roughly the first half of the alphabet (up to ~"M"), and typing a name that came later returned "No users found" — even for someone who is definitely in the org. This blocked assigning a large set of teammates as reviewers.

Changes

The Add-reviewer popover called useInboxAvailableSuggestedReviewers with no query and then filtered the result client-side. The backend available_reviewers endpoint returns only the first 100 users sorted by first name, so anyone after the cutoff was never in the fetched set and couldn't be found by searching.

This forwards the popover's deferredQuery into the hook so the search hits the server, which filters before applying its 100-row cap — making any teammate findable by typing their name. The hook already plumbs the query through its query key and into the API call; this just passes it in.

Note: this is the frontend half. The backend [:100] cap (in PostHog/posthog products/signals/backend/views.py) still truncates the default unsearched list and should be revisited separately.

How did you test this?

Not run — node_modules isn't installed in this environment, so the workspace typecheck can't resolve. The change only passes a string into an options field already typed as query?: string, and the hook already handles query forwarding and cache-keying.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code from a Slack thread

The Add-reviewer popover fetched the available-reviewers list once with no
query and filtered it client-side. The backend caps that list at 100 entries
sorted by first name, so reviewers later in the alphabet were never in the
fetched set and could not be found by typing their name.

Pass the popover's search query into useInboxAvailableSuggestedReviewers so it
forwards to the available_reviewers endpoint, which filters before applying its
cap. The hook already plumbs the query through the query key and the API call.

Generated-By: PostHog Code
Task-Id: d1b4a6ce-de4c-43a6-98a0-4cb45275dde0
@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 4cb81e8.

@pauldambra pauldambra marked this pull request as ready for review June 20, 2026 16:00
@pauldambra pauldambra requested review from a team and rafaeelaudibert June 20, 2026 16:00
@greptile-apps

greptile-apps Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (1)

  1. packages/ui/src/features/inbox/components/SuggestedReviewersSection.tsx, line 109-122 (link)

    P2 The client-side filter is now redundant. The hook already trims and forwards deferredQuery to the API call, so availableReviewers.results already contains only server-matched entries. Re-filtering that set with the same deferredQuery is a no-op in the normal case, but in an edge case it can silently drop results: if the server matched a user via a field the client doesn't check (e.g. a display name alias), the client filter will exclude them even though the server intentionally included them.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: packages/ui/src/features/inbox/components/SuggestedReviewersSection.tsx
    Line: 109-122
    
    Comment:
    The client-side filter is now redundant. The hook already trims and forwards `deferredQuery` to the API call, so `availableReviewers.results` already contains only server-matched entries. Re-filtering that set with the same `deferredQuery` is a no-op in the normal case, but in an edge case it can silently drop results: if the server matched a user via a field the client doesn't check (e.g. a display name alias), the client filter will exclude them even though the server intentionally included them.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
packages/ui/src/features/inbox/components/SuggestedReviewersSection.tsx:109-122
The client-side filter is now redundant. The hook already trims and forwards `deferredQuery` to the API call, so `availableReviewers.results` already contains only server-matched entries. Re-filtering that set with the same `deferredQuery` is a no-op in the normal case, but in an edge case it can silently drop results: if the server matched a user via a field the client doesn't check (e.g. a display name alias), the client filter will exclude them even though the server intentionally included them.

```suggestion
  const addableOptions = useMemo(() => {
    return buildSuggestedReviewerFilterOptions(
      availableReviewers?.results ?? [],
      currentUser,
    );
  }, [availableReviewers?.results, currentUser]);
```

Reviews (1): Last reviewed commit: "fix(inbox): forward reviewer search quer..." | Re-trigger Greptile

Copy link
Copy Markdown
Member Author

Note

🤖 Automated comment by QA Swarm — not written by a human

Multi-perspective review: qa-team (correctness/tests), paul-reviewer (pragmatism), xp-reviewer (UX/DX), security-audit

Verdict: ✅ APPROVE

One-line change that forwards deferredQuery into useInboxAvailableSuggestedReviewers, activating server-side reviewer search. All supporting plumbing (API client query param via URLSearchParams.set, per-query React Query key, cache-bypass for non-empty queries, retained client-side filter as a safety net) was already in place — this completes the wiring correctly. No correctness, UX, or security concerns.

Key findings

No findings.

Convergence

None.

Reviewer summaries

Reviewer Assessment
🔍 qa-team Correct value (deferredQuery) forwarded into already-tested hook; query key namespaces per search, client filter retained safely. No test needed for a prop forward.
👤 paul Minimal, obviously-correct completion of existing wiring. Ships.
📐 xp Deferred value keeps typing responsive; empty-query path keeps cached base list so no spinner flash. Good UX.
🛡 security-audit Query encoded via URLSearchParams on a team-scoped authed GET; no injection/IDOR/SSRF surface. Clean.

Automated by QA Swarm — not a human review

@pauldambra pauldambra added the Stamphog This will request an autostamp by stamphog on small changes label Jun 20, 2026 — with PostHog

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Single-line fix passing an already-computed deferred query value to the hook — purely additive, no risk of data loss or breakage.

pauldambra added a commit to PostHog/posthog that referenced this pull request Jun 20, 2026
…65029)

## Problem

Assigning a reviewer in the Self-driving Inbox only surfaced org members whose first name fell in roughly the first half of the alphabet (up to ~"M"), and searching for anyone after that returned nothing — even for people who are definitely in the org. Reported from a Slack thread about a large org.

The cause is here: `available_reviewers` sorts members by first name and slices to the first 100 **before** returning. So any org with >100 GitHub-linked members silently loses the tail of the alphabet, and because the slice runs server-side the frontend can't page past it.

## Changes

- **Drop the `[:100]` cap** — return the full candidate set (sort retained for stable ordering). The whole member set is already loaded in memory, so the slice only ever truncated; it never saved work. Org membership is tiny in practice, so even the biggest org serialises to well under 100 KB.
- **Add a named OTel span** `signals.available_reviewers` with `candidate_count` / `result_count` attributes, so this endpoint's latency and payload size are actually measurable next time (today there's no route-level span for it).
- **Capture a non-blocking exception when an org exceeds 1200 candidates** — a tripwire telling us to add real pagination before the unpaginated payload could get large. Gated on the unfiltered request so search-as-you-type doesn't spam it.

A paired frontend change ([PostHog/code#2800](PostHog/code#2800)) forwards the picker's search box to this endpoint's `query` param so search hits the server.

## How did you test this code?

I'm an agent (PostHog Code). I added automated tests in `test_signal_report_api.py` (`TestAvailableReviewersAPI`) covering: all members returned past the old 100 cap, server-side search filtering, the threshold capture firing above 1200 / staying silent below it and on search requests, and the empty-org / unknown-team paths. I could **not** run the suite in my environment (no configured Postgres/ClickHouse dev env); `python -m py_compile` and `ruff check` both pass, and CI will execute the tests.

## Automatic notifications

- [ ] Publish to changelog?
- [ ] Alert Sales and Marketing teams?

## 🤖 Agent context

**Autonomy:** Human-driven (agent-assisted)

Investigation started from a Slack thread about the reviewer picker stopping at "M". Traced the data flow front-to-back, then confirmed via the warehouse that org membership is small enough that the full list fits comfortably in one response (well under 100 KB even for the largest orgs) — which ruled out pagination in favour of simply removing the cap, with a 1200 tripwire for the future. Tooling: PostHog Code agent with the PostHog MCP (HogQL `execute-sql`, APM span queries). No repo skills were invoked.

---
*Created with [PostHog Code](https://posthog.com/code?ref=pr) from a [Slack thread](https://posthog.slack.com/archives/C09G8Q32R6F/p1781901413265679?thread_ts=1781901413.265679&cid=C09G8Q32R6F)*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant