fix(scouts): batch emissions + report lookups in the scout signals panel#2996
Conversation
The scout detail Signals section fanned out one emissions request and one report-link request per visible run (2xN requests, N ClickHouse scans). Mirror PostHog/posthog#66823: call the new batched endpoints (runs/emissions/batch, runs/emissions/reports/batch) once for the whole visible-run window — 2 requests, 1 ClickHouse scan. - api-client: add scoutPost helper; replace listScoutRunEmissions / listScoutEmissionReports with batchScoutRunEmissions / batchScoutEmissionReports (run_ids body, empty-list short-circuit). - hooks: key the batched queries on the sorted run-id window, keep prior data while a widened window refetches. - ScoutSignalsSection: fetch once at the section level, group emissions by run_id locally, make RunEmissions presentational. - tests: cover the empty short-circuit, request shape, paginated unwrap, and non-OK error for the batched client methods.
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d0bb67d35
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Address PR review feedback: - api-client: chunk batchScoutRunEmissions / batchScoutEmissionReports at 200 ids (parallel POSTs, concatenated) so a window with >200 emitted runs no longer fails the whole Signals panel. - tests: parameterise the shared empty/non-OK/request-shape cases over both batch methods, and add a >200-id chunking test. - ScoutSignalsSection: memoize emittedRuns / visibleRuns so the visibleRunIds memo can actually skip recomputation. Generated-By: PostHog Code Task-Id: 1dacbd86-8ba2-4213-924a-0ff8495a2f7b
Problem
Opening the Signals section in a scout's detail view was slow.
ScoutSignalsSectionrendered oneRunEmissionsper visible run, and each one fired two per-run requests —runs/<id>/emissions/andruns/<id>/emissions/reports/. With N visible emitted runs that's 2×N requests and N ClickHouse scans on open (eachemissions/reportsrequest runs its own unmaterializedJSONExtractscan overdocument_embeddings).This is the desktop twin of the web fix in PostHog/posthog#66823, which replaced the same fan-out in the web app's
findingsLogic.Changes
Call the two batched endpoints added by #66823 once for the whole visible-run window:
runs/emissions/batch— every visible run's emitted findings in one Postgres query, each row keeps itsrun_id.runs/emissions/reports/batch— resolves every run's findings to their inbox report in a single ClickHouse round-trip.Specifically:
scoutPosthelper; replacedlistScoutRunEmissions/listScoutEmissionReportswithbatchScoutRunEmissions/batchScoutEmissionReports(POST arun_idslist, short-circuit on empty, handle array or paginated body).useScoutRunEmissions/useScoutEmissionReportsnow take a run-id list, key the query on the sorted ids, and usekeepPreviousDataso "Show more" doesn't blank the already-rendered cards while the widened window refetches.run_idlocally;RunEmissionsis now presentational (no hooks).Net effect: 2×N requests / N CH scans → 2 requests / 1 CH scan on panel open.
The desktop window is small (
INITIAL_EMITTED_RUNS = 10, "Show more" expands to the full emitted-runs window), well under the backend's 200-id batch cap, so no client-side chunking is needed.The
runs/emissions/batchandruns/emissions/reports/batchendpoints are added by PostHog/posthog#66823, which is not yet merged. This PR must not ship until #66823 is merged and deployed to US + EU — otherwise the Signals panel will 404 on open. Keeping this as a draft until then.How tested
Agent (Claude Code), human-directed. Automated only — no manual UI testing.
pnpm --filter @posthog/api-client --filter @posthog/ui typecheckclean.batched scout emissions): empty short-circuit, request shape +run_idsbody, paginated unwrap, non-OK error. Fullposthog-client.test.tspasses (34 tests).