Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(replay-vision): stop large run-tab selections failing with http 414 (#119424)

Tue Haulundb648d647fecd
diff --git a/products/replay_vision/frontend/replay_scanners/scannerRunTabLogic.test.ts b/products/replay_vision/frontend/replay_scanners/scannerRunTabLogic.test.ts
index 6339e54c3b1e..501e0d3d7272 100644
--- a/products/replay_vision/frontend/replay_scanners/scannerRunTabLogic.test.ts
+++ b/products/replay_vision/frontend/replay_scanners/scannerRunTabLogic.test.ts
@@ -80,6 +80,38 @@ describe('scannerRunTabLogic', () => {
expect(lookupUrl).toContain('limit=12')
})
+ it('splits a large selection into short lookups and keeps the chunks that succeed', async () => {
+ const sessionIds = Array.from(
+ { length: 120 },
+ (_, i) => `0190f5c2-0000-7000-8000-${String(i).padStart(12, '0')}`
+ )
+ const lookedUp: string[][] = []
+ useMocks({
+ get: {
+ '/api/projects/:team/vision/scanners/:id/observations/': ({ request }: { request: Request }) => {
+ const ids = new URL(request.url).searchParams.get('session_id')?.split(',') ?? []
+ lookedUp.push(ids)
+ if (ids.includes(sessionIds[0])) {
+ return [500, {}]
+ }
+ return [
+ 200,
+ { results: ids.map((id) => ({ id: `obs-${id}`, session_id: id, status: 'succeeded' })) },
+ ]
+ },
+ },
+ })
+
+ await expectLogic(logic, () => logic.actions.setVisibleSessionIds(sessionIds)).toDispatchActions([
+ 'loadObservationsSuccess',
+ ])
+
+ expect(Math.max(...lookedUp.map((ids) => ids.length))).toBeLessThanOrEqual(50)
+ expect(lookedUp.flat().sort()).toEqual([...sessionIds].sort())
+ // The first chunk's lookup failed, so only the other chunks' sessions carry an observation.
+ expect(Object.keys(logic.values.observationBySession).sort()).toEqual(sessionIds.slice(50).sort())
+ })
+
it('releases the pending bridge once the scanned session lands in the lookup', async () => {
await expectLogic(logic, () => {
logic.actions.setPendingId('s1')
diff --git a/products/replay_vision/frontend/replay_scanners/scannerRunTabLogic.ts b/products/replay_vision/frontend/replay_scanners/scannerRunTabLogic.ts
index ae2513e8bc62..f64dce4c38b7 100644
--- a/products/replay_vision/frontend/replay_scanners/scannerRunTabLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/scannerRunTabLogic.ts
@@ -14,6 +14,7 @@ import {
import posthog from 'posthog-js'
import { lemonToast } from 'lib/lemon-ui/LemonToast'
+import { chunk } from 'lib/utils/arrays'
import { teamLogic } from 'scenes/teamLogic'
import { visionScannersBulkObserveCreate, visionScannersObservationsList } from '../generated/api'
@@ -50,6 +51,8 @@ const BULK_SKIP_REASONS: Record<BulkSkipOutcome, string> = {
// Headroom per visible session for the observations a retry stacks on top of the original scan.
const OBSERVATIONS_PER_SESSION_ALLOWANCE = 4
+// The lookup puts session ids in the query string, and a few hundred of them overflow the URL limit (HTTP 414).
+const SESSIONS_PER_LOOKUP = 50
// The API rejects a whole batch over its per-request cap, so a select-all would start nothing at all.
const MAX_SESSIONS_PER_REQUEST = visionScannersBulkObserveCreateBodySessionIdsMax
@@ -387,14 +390,23 @@ export const scannerRunTabLogic = kea<scannerRunTabLogicType>([
// Ordering pinned: the newest-wins mapping below depends on it, not on the API default.
// Without a limit the server's default page truncates the tail and those sessions read
// as "Not scanned" when they have been.
- const response = await visionScannersObservationsList(String(teamId), props.scannerId, {
- session_id: sessionIds.join(','),
- order_by: '-created_at',
- limit: sessionIds.length * OBSERVATIONS_PER_SESSION_ALLOWANCE,
- })
+ // A failed lookup only blanks its own sessions, so one 5xx doesn't discard the rest of the poll.
+ const settled = await Promise.allSettled(
+ chunk(sessionIds, SESSIONS_PER_LOOKUP).map((ids) =>
+ visionScannersObservationsList(String(teamId), props.scannerId, {
+ session_id: ids.join(','),
+ order_by: '-created_at',
+ limit: ids.length * OBSERVATIONS_PER_SESSION_ALLOWANCE,
+ })
+ )
+ )
breakpoint()
+ const responses = settled.flatMap((result) => (result.status === 'fulfilled' ? [result.value] : []))
+ if (responses.length === 0) {
+ throw (settled[0] as PromiseRejectedResult).reason
+ }
const bySession: Record<string, RowObservation> = {}
- for (const observation of response.results ?? []) {
+ for (const observation of responses.flatMap((response) => response.results ?? [])) {
// Results are newest-first — the first observation per session is the one the row reflects.
if (!(observation.session_id in bySession)) {
bySession[observation.session_id] = {