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): confirm a summary exists before pointing at it (#81207)

posthog[bot]ae403f45693b
diff --git a/products/replay_vision/frontend/logics/observationsDockLogic.test.ts b/products/replay_vision/frontend/logics/observationsDockLogic.test.ts
index 7ca706e6678b..71c6fa888d77 100644
--- a/products/replay_vision/frontend/logics/observationsDockLogic.test.ts
+++ b/products/replay_vision/frontend/logics/observationsDockLogic.test.ts
@@ -1,11 +1,18 @@
import { expectLogic } from 'kea-test-utils'
+import { lemonToast } from 'lib/lemon-ui/LemonToast'
+
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
+import type { ReplayObservationApi } from '../generated/api.schemas'
import { observationsDockLogic } from './observationsDockLogic'
import { visionScannersListLogic } from './visionScannersListLogic'
+jest.mock('lib/lemon-ui/LemonToast', () => ({
+ lemonToast: { success: jest.fn(), info: jest.fn(), warning: jest.fn(), error: jest.fn() },
+}))
+
describe('observationsDockLogic', () => {
let logic: ReturnType<typeof observationsDockLogic.build>
let observeCalls: number
@@ -14,11 +21,14 @@ describe('observationsDockLogic', () => {
let releaseInlineScan: () => void
let releaseScanners: () => void
let inlineScanOutcome: string
+ let observationResults: ReplayObservationApi[]
beforeEach(() => {
+ jest.clearAllMocks()
observeCalls = 0
inlineScanCalls = 0
inlineScanOutcome = 'started'
+ observationResults = []
useMocks({
get: {
'/api/projects/:team/vision/scanners/': async () => {
@@ -27,7 +37,7 @@ describe('observationsDockLogic', () => {
})
return [200, { results: [] }]
},
- '/api/projects/:team/vision/observations/': () => [200, { results: [] }],
+ '/api/projects/:team/vision/observations/': () => [200, { results: observationResults }],
},
post: {
'/api/projects/:team/vision/scanners/:id/observe/': async () => {
@@ -103,16 +113,40 @@ describe('observationsDockLogic', () => {
expect(inlineScanCalls).toBe(1)
})
- it('re-reads observations when the recording was already summarized', async () => {
- // The inline scanner is shared across the project, so the existing row can postdate this dock's
- // mount-time load. Without the refetch the user reads "already summarized" over an empty dock.
+ it('warns rather than promising a result when an already-summarized row is unreadable', async () => {
+ // The slot check runs unscoped, so `already_scanned` can come back for a row RBAC hides from the
+ // dock, or the reload can fail. The old copy claimed a result over an empty dock; guard that the
+ // reload happens first and the message admits nothing is shown.
inlineScanOutcome = 'already_scanned'
+ // Consume the mount-time load so its response can't overwrite the reload below.
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+
logic.actions.summarize()
// The mock holds the request open, and its release hook only exists once the handler runs.
await new Promise((resolve) => setTimeout(resolve, 0))
releaseInlineScan()
- await expectLogic(logic).toDispatchActions(['summarizeFailure', 'loadObservations'])
- await expectLogic(logic).toMatchValues({ dockOpen: true })
+ await expectLogic(logic).toDispatchActions(['summarizeFailure', 'loadObservationsSuccess'])
+ await expectLogic(logic).toMatchValues({ dockOpen: true, observations: [] })
+ expect(lemonToast.warning).toHaveBeenCalled()
+ expect(lemonToast.info).not.toHaveBeenCalled()
+ })
+
+ it('confirms the result when the already-summarized row is readable', async () => {
+ // The reload surfaces the inline scanner's row (matched by scan_id), so the dock can point at it.
+ inlineScanOutcome = 'already_scanned'
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+ observationResults = [
+ { id: 'obs-1', scanner_id: 'scanner-x', session_id: 'sess-1', status: 'succeeded' } as ReplayObservationApi,
+ ]
+
+ logic.actions.summarize()
+ await new Promise((resolve) => setTimeout(resolve, 0))
+ releaseInlineScan()
+
+ await expectLogic(logic).toDispatchActions(['summarizeFailure', 'loadObservationsSuccess'])
+ await expectLogic(logic).toMatchValues({ dockOpen: true, observations: observationResults })
+ expect(lemonToast.info).toHaveBeenCalled()
+ expect(lemonToast.warning).not.toHaveBeenCalled()
})
})
diff --git a/products/replay_vision/frontend/logics/observationsDockLogic.ts b/products/replay_vision/frontend/logics/observationsDockLogic.ts
index dccf2f3f7aa2..8b974fc1cdd7 100644
--- a/products/replay_vision/frontend/logics/observationsDockLogic.ts
+++ b/products/replay_vision/frontend/logics/observationsDockLogic.ts
@@ -327,6 +327,36 @@ export const observationsDockLogic = kea<observationsDockLogicType>([
// One session in, so one result out. The inline scanner is shared per project, so a
// recording somebody already summarized comes back settled instead of started.
const outcome = response.results?.[0]?.scan_outcome
+ if (outcome === 'already_scanned') {
+ // A row settled server-side, but the inline scanner is shared and RBAC-scoped, so
+ // the row may not be readable here, and the reload can also fail. Confirm the row
+ // is in hand before naming it, and leave a way to re-read when it stays hidden.
+ actions.summarizeFailure()
+ actions.setDockOpen(true)
+ const tryAgain = { label: 'Try again', action: () => actions.loadObservations() }
+ try {
+ const reloaded = await visionObservationsList(String(teamId), {
+ session_id: props.sessionId,
+ })
+ const results = reloaded.results ?? []
+ actions.loadObservationsSuccess(results)
+ if (response.scan_id && results.some((o) => o.scanner_id === response.scan_id)) {
+ // The row is readable below. A failed or ineligible one still shows its retry
+ // control there, so the user has a way to run the summary again.
+ lemonToast.info('This recording already has a result below.')
+ } else {
+ lemonToast.warning(
+ 'This recording was already summarized, but the result is not available here.',
+ { button: tryAgain }
+ )
+ }
+ } catch {
+ metricCount('replay_vision_frontend_observations_load_failures')
+ actions.loadObservationsFailure()
+ lemonToast.warning("Couldn't load this recording's summary.", { button: tryAgain })
+ }
+ return
+ }
const { level, message } = summarizeOutcomeMessage(outcome)
lemonToast[level](message)
if (outcome === 'started' || outcome === 'already_running') {
@@ -334,12 +364,6 @@ export const observationsDockLogic = kea<observationsDockLogicType>([
// against the shared inline scanner — so the poll window has a row to wait for.
actions.summarizeSuccess()
afterScanStarted()
- } else if (outcome === 'already_scanned') {
- // Settled server-side, but the scanner is shared, so the row may have landed after
- // this dock loaded. Re-read rather than trusting what is already on screen.
- actions.summarizeFailure()
- actions.setDockOpen(true)
- actions.loadObservations()
} else {
// Nothing started and nothing to read, so the poll window would watch for a row
// that never arrives.
diff --git a/products/replay_vision/frontend/logics/summarizeRecording.test.ts b/products/replay_vision/frontend/logics/summarizeRecording.test.ts
index 35e29505e7c9..76911dd594ce 100644
--- a/products/replay_vision/frontend/logics/summarizeRecording.test.ts
+++ b/products/replay_vision/frontend/logics/summarizeRecording.test.ts
@@ -6,7 +6,6 @@ describe('summarizeRecording', () => {
// success toast tells the user a summary is coming when the quota or the in-flight cap refused it.
it.each<[ScanOutcomeEnumApi | undefined, SummarizeOutcomeMessage['level']]>([
['started', 'success'],
- ['already_scanned', 'info'],
['already_running', 'info'],
['skipped_quota', 'warning'],
['skipped_limit', 'warning'],
diff --git a/products/replay_vision/frontend/logics/summarizeRecording.ts b/products/replay_vision/frontend/logics/summarizeRecording.ts
index feb7b23bbe16..2e017595d1ab 100644
--- a/products/replay_vision/frontend/logics/summarizeRecording.ts
+++ b/products/replay_vision/frontend/logics/summarizeRecording.ts
@@ -32,6 +32,9 @@ export interface SummarizeOutcomeMessage {
* The endpoint answers 202 whether or not anything started, reporting the reason per session, so
* only the outcome distinguishes a summary that is on its way from one the quota refused. A cap is
* a warning rather than an error, matching how the scanner run tab reports the same two outcomes.
+ *
+ * `already_scanned` is absent on purpose: a settled row may be unreadable here, so its message
+ * depends on what a reload returns and is decided by the caller, not this pure mapping.
*/
export function summarizeOutcomeMessage(outcome: ScanOutcomeEnumApi | undefined): SummarizeOutcomeMessage {
switch (outcome) {
@@ -39,10 +42,6 @@ export function summarizeOutcomeMessage(outcome: ScanOutcomeEnumApi | undefined)
return { level: 'success', message: 'Summary started' }
case 'already_running':
return { level: 'info', message: 'A summary of this recording is already being generated.' }
- case 'already_scanned':
- // `already_scanned` covers every terminal status, so the existing row may be a failure or an
- // ineligible recording rather than a summary. Point at the result instead of claiming success.
- return { level: 'info', message: 'This recording already has a summary result below.' }
case 'skipped_quota':
return { level: 'warning', message: "You've hit the monthly Replay vision credit limit." }
case 'skipped_limit':