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): keep the summarize button pending until the scan lands (#102566)

posthog[bot]5517c962c8bd
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 88d7a9da0549..242ddaf0bcee 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6833,25 +6833,25 @@ snapshots:
replay-scenes-activity-modal--event-explorer-with-modal-not-found--light:
hash: v1.k794b7964.f2b33d0679138737db8621af75e44a5721bf94b162c78dd3f710b0ed204e8a19.BC5ExSw0oEO_bhd7247_scbKegkYMOzZh1DhgwINf20
replay-scenes-group--group-events-tab-with-modal-not-found--dark:
- hash: v1.k794b7964.1827697903c0368b3ba5e37b51d4c68f6b6906368bfe59abf8351aee89c80df6.y-4cxo8BrgiTcbQRuCWkNfzf_OczP9jc8s8niK6U_S4
+ hash: v1.k794b7964.16f472961d350d8731b8c72b0eff95b37399b57f5e825c0c99463a0d0d63db86.af7j7JwHTbaS6cxgFLoumkVowRSFCO4KHyaQfcvmI5Y
replay-scenes-group--group-events-tab-with-modal-not-found--light:
- hash: v1.k794b7964.79e18c73c32da6970472b0efaf28be54b3a7ac5f0e6cce9a0823522f0f6ccb82.Wq0QqpowpJSZu-5lG9k-8EdF2NiLZJgKD-WH64pDMdw
+ hash: v1.k794b7964.fb8d7ea4cd14495b48edfbe5b98a8fa0e6041fba2a6b04c193b3af9dcba40420.OEnNoyPZZ4jeRoA7BdS9ug_wOUFLwI77rUiz-Pqi_KU
replay-scenes-group--group-recording-tab-empty--dark:
hash: v1.k794b7964.0660887202ba71055373168f4b9df5cdc8251c89f0f96b77c4b3196845362f70.VFxGeaTyLzGuovqDxnkS9wWUmq2J0edku92QEPb1mJI
replay-scenes-group--group-recording-tab-empty--light:
hash: v1.k794b7964.06998246ac4a34809c233b8a664de4341ef8646c7c25865c31c34d15714b1904.ikkcZU-qTv5OBMBa0nR_7vnmBJwSfllp_59gzEO6w4I
replay-scenes-group--group-recording-tab-multiple-and-not-found--dark:
- hash: v1.k794b7964.41649e1eac2037c35dd85348effb5381fd09d14a6f6f69d229466f955522a24d.CB7_6BffEqh-oe0Wy6IvY_punU0qAW-gem-nkuFpo0U
+ hash: v1.k794b7964.d42c3d4ddd4845edf7eb36d3661392d903df2c5390e4a3f0b6839458304d23da.FOzZSvQEF8DvpZfcB_fAecFEt4z80SjjJNG4WyiPYm4
replay-scenes-group--group-recording-tab-multiple-and-not-found--light:
- hash: v1.k794b7964.f310f1c95bd6ef34dff09dd114572243bd1a500535d9f465dd18891731d8a8ea.wtA98Xwks_LtmU5V4NS77-lI4_eOkFblBqY60VZ__PU
+ hash: v1.k794b7964.437527112814dc18f12bb43b83a89bcfb814fd0e533e4497488426c3bf3e198d.ER5WbwkxMRs29faKXD3RA5IzDTu4mHzKRGOUXlAiZig
replay-scenes-person--person-recording-tab-empty--dark:
hash: v1.k794b7964.d337c9b3822884b424ceca688c767202c2b1a72e2b0e466092ae5f9795dbcabd.TZsx90e31kbDKuYkmYXRtlH0jo7mxK0xNIrohR9Jf-Y
replay-scenes-person--person-recording-tab-empty--light:
hash: v1.k794b7964.e29314b81472a69779a7da88417f5d840eec03de97125db890eafa3d5190e0c5.y27QikyGJb8Eoewgpuj-zbqSGWjYT4ZmwD_GUvqyL4I
replay-scenes-person--person-recording-tab-multiple-and-not-found--dark:
- hash: v1.k794b7964.cbd227523190d7be68c2e98c84dc25d6d1b3ad983c1be037e9447fdc125d6110.6sKPrZm4bDLl1BZD031TJ44C8a8v430pk8WBdk8LO9Y
+ hash: v1.k794b7964.13a4342adc88a293d41e64a194f7dbe2f536f7d87d59eeca746ddadd6a19d910.rcxpMH2zFNwryt_YkbKAHGvQI_yOmL_ZYJHa9BX2spQ
replay-scenes-person--person-recording-tab-multiple-and-not-found--light:
- hash: v1.k794b7964.a2a07400359f1e84484d49e49bd12891c3c365c71ed8049a12061e6f5bf35c3c.xp30F76kidXK9P7SCBUHDuCiMPUsaiA7F-wJj-3kkgU
+ hash: v1.k794b7964.ee2549def042253bd5b7e96c44dc027cbdc0bc6e5b95e415f6c293d953a1817f.OEVxIRLxz4WqNlcyeH4MrDQ43lYxBzpU6btOvcfOTQE
replay-sharing--private-link--dark:
hash: v1.k794b7964.5ef4bd7e1d49d4506c360881a3a1482e857b5240362d76c855692eab18fc0764.0IvXqC6Lmuj5NeaGPbu0_5gr6mVBAtiGtBfKu7gvQXA
replay-sharing--private-link--light:
@@ -6873,9 +6873,9 @@ snapshots:
replay-tabs-comments--replay-comments-empty--light:
hash: v1.k794b7964.eacc112601665aaad99a28267264805387b57496ee35b89bafef74db2c2c2794.pTNBJCYNg6D28_QldfksZRa-Bzl-VSAcEWzL5AeegF8
replay-tabs-home-failure--not-found--dark:
- hash: v1.k794b7964.976b4bc71204d3fdd7d22bc696a779a418376dfa7d6fc74cf50ebc5023c672b9.gyNSfDI5sGG3Hamw70N9MALDuDtbPb3jeSZzD9-IC5g
+ hash: v1.k794b7964.bf1fc2024924b2d2d156739c04e8acade818852ad91dfd6e01210665b246149f.6nwqTT8W_PljoKoR11Dup9D06jQVw8-SBZQbAM43gks
replay-tabs-home-failure--not-found--light:
- hash: v1.k794b7964.68ea14164788313df082ab6a0376077a82369dbdb3365ce8427640ad453aa9d6.laeHUCIfmZ8CHubdHCTK_PaLsSGS3XkBTsQRSma6qoE
+ hash: v1.k794b7964.d9b15fdde17563eeb620d2a170d2b73434cc960fb55818fd07bb725d5a077700.LAZBeOy08kO2WM7ec--oJjkn8R_3VYZ-Wqvcg6IDD-8
replay-tabs-home-filters-banner--page-filter-nudge--dark:
hash: v1.k794b7964.33db55efe063b4a0e5cf7399851c5e16172fd4b78dda3587881c7e58974e9507.6F1xl1LtKP40SgXwQBJF6ZZ65QMLRIXKXm1c5EzgCCE
replay-tabs-home-filters-banner--page-filter-nudge--light:
diff --git a/products/replay_vision/frontend/components/ObservationsDock.tsx b/products/replay_vision/frontend/components/ObservationsDock.tsx
index d8c45c640a0c..a6b6b7245fe2 100644
--- a/products/replay_vision/frontend/components/ObservationsDock.tsx
+++ b/products/replay_vision/frontend/components/ObservationsDock.tsx
@@ -1,4 +1,5 @@
import { useActions, useValues } from 'kea'
+import posthog from 'posthog-js'
import { useRef, useState } from 'react'
import { IconChevronDown, IconInfo, IconLogomark, IconNotebook } from '@posthog/icons'
@@ -7,6 +8,7 @@ import { LemonButton, Spinner, Tooltip } from '@posthog/lemon-ui'
import { Resizer } from 'lib/components/Resizer/Resizer'
import { ResizerLogicProps, resizerLogic } from 'lib/components/Resizer/resizerLogic'
import { LemonMenuItem, LemonMenuOverlay } from 'lib/lemon-ui/LemonMenu/LemonMenu'
+import { sessionRecordingDataCoordinatorLogic } from 'scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic'
import { sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'
import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'
import { AIConsentPopoverWrapper } from 'scenes/settings/organization/AIConsentPopoverWrapper'
@@ -16,6 +18,7 @@ import { AccessControlLevel } from '~/types'
import type { ReplayScannerApi } from '../generated/api.schemas'
import { observationsDockLogic } from '../logics/observationsDockLogic'
import { visionQuotaLogic } from '../logics/visionQuotaLogic'
+import { LIMIT_REACHED_TOOLTIP } from '../replay_scanners/scannerCopy'
import { getReplayVisionEditDisabledReason } from '../utils/accessControl'
import { BUILT_IN_SUMMARY_LABEL, dockObservations, isUnsuccessfulScan } from '../utils/observation'
import { quotaUx } from '../utils/quotaProjection'
@@ -29,43 +32,69 @@ const MIN_EXPANDED_HEIGHT = 120
const MAX_EXPANDED_HEIGHT = 800
export function ObservationsDock(): JSX.Element | null {
- const { sessionRecordingId } = useValues(sessionRecordingPlayerLogic)
+ const { sessionRecordingId, logicProps } = useValues(sessionRecordingPlayerLogic)
+ // The dock is a sibling of the player frame, so it kept its summarize button on screen even when
+ // the frame had swapped itself for the "Recording not found" or "deleted" screen — a control that
+ // could never summarize a recording that is not there. There is nothing to scan, so drop the dock.
+ const { isNotFound, isRecordingDeleted } = useValues(sessionRecordingDataCoordinatorLogic(logicProps))
- if (!sessionRecordingId) {
+ if (!sessionRecordingId || isNotFound || isRecordingDeleted) {
return null
}
return <ObservationsDockContent sessionId={sessionRecordingId} />
}
+/**
+ * Why a summary cannot run on this recording right now, whatever summarizer would run it.
+ *
+ * Both paths are scanner writes: an inline scan mints a scanner, and `observe` is a write action on
+ * the scanner it runs. Each also exposes recording contents, so both need recording read as well. A
+ * recording the scan-time gate would refuse is refused for every summarizer, so it blocks the button
+ * and each menu row rather than spending a scan that comes back ineligible. Pass a scanner for the
+ * object-level check, so one this user cannot edit is refused here rather than by a 403.
+ *
+ * The bar reads this too: a disabled button explains itself on hover only, which is why people kept
+ * clicking one that could never run.
+ */
+function useSummarizeBlockedReason(
+ scanBlock: ScanBlock | null
+): (scanner?: ReplayScannerApi | null) => string | null | undefined {
+ const { quota } = useValues(visionQuotaLogic)
+ const { disabledReason: quotaDisabledReason } = quotaUx(quota)
+ return (scanner) =>
+ getReplayVisionEditDisabledReason((scanner?.user_access_level as AccessControlLevel | null) ?? undefined) ??
+ // `observe` answers 402 for a scanner that has spent its own credit limit, so a capped one is
+ // refused here rather than by a failed request. The built-in prompt has no per-scanner limit.
+ (scanner?.limit_reached ? LIMIT_REACHED_TOOLTIP : null) ??
+ scanBlock?.reason ??
+ quotaDisabledReason
+}
+
/** Runs whichever summarizer `resolveSummarizer` settles on, and lets the user pick another. */
function SummarizeButton({ sessionId, scanBlock }: { sessionId: string; scanBlock: ScanBlock | null }): JSX.Element {
const logic = observationsDockLogic({ sessionId })
- const { summarizing, defaultSummarizer, summarizerScanners } = useValues(logic)
+ const { summarizePending, defaultSummarizer, summarizerScanners } = useValues(logic)
const { summarize, summarizeWith } = useActions(logic)
const { quota } = useValues(visionQuotaLogic)
const { dataProcessingAccepted } = useValues(aiConsentLogic)
const [consentRequested, setConsentRequested] = useState(false)
- const { disabledReason: quotaDisabledReason, tooltip: quotaTooltip } = quotaUx(quota)
+ const { tooltip: quotaTooltip } = quotaUx(quota)
+ const blockedReason = useSummarizeBlockedReason(scanBlock)
// `loading` only disables the button itself. The caret and the menu rows are their own buttons, so
// without this a second summarizer is one click away mid-run, and it spends the quota again.
- const inFlightDisabledReason = summarizing ? 'A summary is already running' : null
- // Both paths are scanner writes: an inline scan mints a scanner, and `observe` is a write action on
- // the scanner it runs. Each also exposes recording contents, so both need recording read as well.
- // A recording the scan-time gate would refuse is refused for every summarizer, so it blocks the
- // button and each menu row rather than spending a scan that comes back ineligible.
- const builtInDisabledReason =
- inFlightDisabledReason ?? getReplayVisionEditDisabledReason() ?? scanBlock?.reason ?? quotaDisabledReason
- // Object-level, so a scanner this user cannot edit is disabled rather than answering with a 403.
+ const inFlightDisabledReason = summarizePending ? 'A summary is already running' : null
+ const builtInDisabledReason = inFlightDisabledReason ?? blockedReason()
const scannerDisabledReason = (scanner: ReplayScannerApi): string | null | undefined =>
- inFlightDisabledReason ??
- getReplayVisionEditDisabledReason(scanner.user_access_level as AccessControlLevel | null) ??
- scanBlock?.reason ??
- quotaDisabledReason
- // Nobody could tell which summarizer the button used, so it says so.
- const label = defaultSummarizer ? `Summarize with ${defaultSummarizer.name}` : 'Summarize this recording'
- const summarizerTooltip = defaultSummarizer
- ? `Runs your "${defaultSummarizer.name}" scanner on this recording.`
- : 'Writes a summary using a built-in prompt.'
+ inFlightDisabledReason ?? blockedReason(scanner)
+ // Nobody could tell which summarizer the button used, so it says so. While a scan is running the
+ // label is the only thing that says the click landed: the summary takes minutes to arrive.
+ const idleLabel = defaultSummarizer ? `Summarize with ${defaultSummarizer.name}` : 'Summarize this recording'
+ const label = summarizePending ? 'Summarizing…' : idleLabel
+ const summarizerTooltip = summarizePending
+ ? 'Watching this recording. The summary appears below when it is ready.'
+ : defaultSummarizer
+ ? `Runs your "${defaultSummarizer.name}" scanner on this recording.`
+ : 'Writes a summary using a built-in prompt.'
const menuItems: LemonMenuItem[] = [
...summarizerScanners.map((scanner) => ({
@@ -102,9 +131,22 @@ function SummarizeButton({ sessionId, scanBlock }: { sessionId: string; scanBloc
size="small"
type="secondary"
icon={<IconNotebook />}
- loading={summarizing}
+ loading={summarizePending}
// The endpoint refuses without org AI approval, so ask for it here rather than toasting a 400.
- onClick={() => (dataProcessingAccepted ? summarize() : setConsentRequested(true))}
+ onClick={() => {
+ posthog.capture('replay_vision_summarize_clicked', {
+ // Repeat clicks are the point of this event, and `$session_id` cannot tell them
+ // apart from one click each on two recordings.
+ recording_id: sessionId,
+ summarizer: defaultSummarizer ? 'configured' : 'built-in',
+ consent_needed: !dataProcessingAccepted,
+ })
+ if (dataProcessingAccepted) {
+ summarize()
+ } else {
+ setConsentRequested(true)
+ }
+ }}
disabledReason={defaultSummarizer ? scannerDisabledReason(defaultSummarizer) : builtInDisabledReason}
tooltip={quotaTooltip ?? summarizerTooltip}
data-attr="vision-summarize-recording"
@@ -179,7 +221,8 @@ function SummarizeExplainer(): JSX.Element {
function ObservationsDockContent({ sessionId }: { sessionId: string }): JSX.Element {
const logic = observationsDockLogic({ sessionId })
- const { observations, observationsLoading, dockOpen, retryingObservationIds } = useValues(logic)
+ const { observations, observationsLoading, dockOpen, retryingObservationIds, defaultSummarizer, summarizePending } =
+ useValues(logic)
const { setDockOpen, retryObservation } = useActions(logic)
// sessionRecordingPlayerLogic is keyed by playerKey+sessionRecordingId; seek the exact mounted
// player by its bound props rather than a propless default instance.
@@ -188,6 +231,11 @@ function ObservationsDockContent({ sessionId }: { sessionId: string }): JSX.Elem
sessionRecordingPlayerLogic.findMounted(logicProps)?.actions.seekToTime(ms)
}
const scanBlock = recordingScanBlock(sessionPlayerMetaData)
+ // Why the button the bar just rendered cannot run, whatever summarizer it points at. Shown as a
+ // visible line so the reason no longer hides behind a hover, which is what left people clicking a
+ // control that could never fire. A running summary is not a block, so it is left out.
+ const blockedReason = useSummarizeBlockedReason(scanBlock)
+ const summarizeBlockedReason = summarizePending ? null : blockedReason(defaultSummarizer)
const dockRef = useRef<HTMLDivElement>(null)
const resizerProps: ResizerLogicProps = {
@@ -220,13 +268,14 @@ function ObservationsDockContent({ sessionId }: { sessionId: string }): JSX.Elem
<div className="flex items-center gap-2 lg:gap-3 h-11 px-3 shrink-0">
<SummarizeButton sessionId={sessionId} scanBlock={scanBlock} />
<SummarizeExplainer />
- {scanBlock &&
+ {summarizeBlockedReason &&
!hasContent && (
// Collapsed with nothing to expand, the disabled button's tooltip is the only place
- // the skip is explained, so the bar says it outright.
- <Tooltip title={scanBlock.reason}>
+ // the reason is explained, so the bar says it outright. A scan-block has a short
+ // label to lead with; a quota or access block carries only its full sentence.
+ <Tooltip title={summarizeBlockedReason}>
<span className="ml-auto text-muted text-xs truncate" data-attr="vision-dock-skipped">
- Skipped: {scanBlock.label.toLowerCase()}
+ {scanBlock ? `Skipped: ${scanBlock.label.toLowerCase()}` : summarizeBlockedReason}
</span>
</Tooltip>
)}
diff --git a/products/replay_vision/frontend/logics/observationsDockLogic.test.ts b/products/replay_vision/frontend/logics/observationsDockLogic.test.ts
index 104be45b4faa..8f44e3170165 100644
--- a/products/replay_vision/frontend/logics/observationsDockLogic.test.ts
+++ b/products/replay_vision/frontend/logics/observationsDockLogic.test.ts
@@ -6,6 +6,7 @@ import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import type { ReplayObservationApi, ReplayScannerApi } from '../generated/api.schemas'
+import { OBSERVE_POLL_GRACE_MS } from './observationPolling'
import { observationsDockLogic } from './observationsDockLogic'
import { visionDockPreferenceLogic } from './visionDockPreferenceLogic'
import { visionScannersListLogic } from './visionScannersListLogic'
@@ -38,6 +39,7 @@ describe('observationsDockLogic', () => {
let releaseScanners: () => void
let inlineScanOutcome: string
let observationResults: ReplayObservationApi[]
+ let observationsFail: boolean
let scannerResults: ReplayScannerApi[]
beforeEach(() => {
@@ -46,6 +48,7 @@ describe('observationsDockLogic', () => {
inlineScanCalls = 0
inlineScanOutcome = 'started'
observationResults = []
+ observationsFail = false
scannerResults = []
useMocks({
get: {
@@ -55,7 +58,8 @@ describe('observationsDockLogic', () => {
})
return [200, { results: scannerResults }]
},
- '/api/projects/:team/vision/observations/': () => [200, { results: observationResults }],
+ '/api/projects/:team/vision/observations/': () =>
+ observationsFail ? [500, {}] : [200, { results: observationResults }],
},
post: {
'/api/projects/:team/vision/scanners/:id/observe/': async () => {
@@ -135,6 +139,9 @@ describe('observationsDockLogic', () => {
await new Promise((resolve) => setTimeout(resolve, 0))
expect(inlineScanCalls).toBe(1)
+ // The second click is dropped, but it now says so rather than leaving the user in front of a
+ // button that looked live and did nothing.
+ expect(lemonToast.info).toHaveBeenCalled()
})
it('warns rather than promising a result when an already-summarized row is unreadable', async () => {
@@ -223,6 +230,167 @@ describe('observationsDockLogic', () => {
expect(inlineScanCalls).toBe(routingCase.runsOwnScanner ? 0 : 1)
})
+ it('stays pending while a summary row is still running, and settles once it is not', async () => {
+ // The reason the button kept reverting mid-scan: the old spinner cleared on the trigger
+ // response, not on the summary itself. `summarizePending` reads the row's own status, so it
+ // holds a recording that was opened with a summary already in flight, then clears when the
+ // scan lands — no click needed to reproduce either state.
+ const runningRow = {
+ id: 'obs-run',
+ scanner_id: 'scanner-x',
+ session_id: 'sess-1',
+ status: 'running',
+ scanner_snapshot: { scanner_type: 'summarizer' },
+ } as ReplayObservationApi
+
+ observationResults = [runningRow]
+ logic.actions.loadObservations()
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+ await expectLogic(logic).toMatchValues({ summaryInFlight: true, summarizePending: true })
+
+ observationResults = [{ ...runningRow, status: 'succeeded' } as ReplayObservationApi]
+ logic.actions.loadObservations()
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+ await expectLogic(logic).toMatchValues({ summaryInFlight: false, summarizePending: false })
+ })
+
+ it('does not treat a running monitor scan as a summary in flight', async () => {
+ // The summarize button only owns summaries. A monitor scan the sidebar started is in flight
+ // too, but claiming it here would leave the button pending over a run it never triggered.
+ observationResults = [
+ {
+ id: 'obs-mon',
+ scanner_id: 'scanner-m',
+ session_id: 'sess-1',
+ status: 'running',
+ scanner_snapshot: { scanner_type: 'monitor' },
+ } as ReplayObservationApi,
+ ]
+ logic.actions.loadObservations()
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+ await expectLogic(logic).toMatchValues({ summaryInFlight: false, summarizePending: false })
+ })
+
+ it('keeps the summary pending when a scan the sidebar started fails', async () => {
+ // The sidebar picker runs on this same keyed logic, so its `observeFailure` arrives on the
+ // summary's reducer. It used to clear the button, putting the idle label back under a user
+ // whose summary was still running — the exact symptom this PR removes.
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+ observationResults = [
+ { id: 'obs-mon', scanner_id: 'm1', session_id: 'sess-1', status: 'succeeded' } as ReplayObservationApi,
+ ]
+ logic.actions.loadObservations()
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+
+ logic.actions.summarize()
+ await expectLogic(logic).toMatchValues({ summarizePending: true })
+
+ // A sidebar pick of a scanner that already ran here, which is one of the failure paths.
+ logic.actions.observe('m1')
+
+ await expectLogic(logic).toDispatchActions(['observeFailure'])
+ await expectLogic(logic).toMatchValues({ summarizePending: true })
+ })
+
+ // Both triggers share one in-flight guard, so which run the guard rejected decides whether the
+ // button still has a summary to wait for. Rejecting the click either way is what the guard is
+ // for; leaving it pending over a scan it never started is not.
+ test.each([
+ { blocker: 'a sidebar scan', firstClick: (): void => logic.actions.observe('m1'), stillPending: false },
+ { blocker: 'its own first click', firstClick: (): void => logic.actions.summarize(), stillPending: true },
+ ])('summarize blocked by $blocker stays pending: $stillPending', async (guardCase) => {
+ await loadScanners([scanner('s1', 'summarizer'), scanner('m1', 'monitor')])
+
+ guardCase.firstClick()
+ // Let the first request reach the mock, so its in-flight flag is set before the next click.
+ await new Promise((resolve) => setTimeout(resolve, 0))
+ logic.actions.summarize()
+ await new Promise((resolve) => setTimeout(resolve, 0))
+
+ expect(observeCalls).toBe(1)
+ expect(lemonToast.info).toHaveBeenCalled()
+ await expectLogic(logic).toMatchValues({ summarizePending: guardCase.stillPending })
+ })
+
+ it('settles the button when a fast summary lands inside the grace window', async () => {
+ // The grace window covers the wait for a row that does not exist yet. A summary that finished
+ // inside it used to hold the button on "Summarizing…" for the rest of the window, right next
+ // to the finished summary the dock had already rendered.
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+ logic.actions.summarize()
+ await new Promise((resolve) => setTimeout(resolve, 0))
+ releaseInlineScan()
+ await expectLogic(logic).toDispatchActions(['summarizeSuccess'])
+ await expectLogic(logic).toMatchValues({ summarizePending: true })
+
+ // The row this scan created, terminal while the grace window is still open.
+ observationResults = [summaryObservation()]
+ logic.actions.loadObservations()
+
+ await expectLogic(logic).toDispatchActions(['summarizeSettled'])
+ await expectLogic(logic).toMatchValues({ summarizePending: false })
+ })
+
+ it('settles the button while an unrelated sidebar scan is still being started', async () => {
+ // `observeInFlight` names which run is open. Gating on it being set at all let a sidebar scan's
+ // open request hold "Summarizing…" after the summary itself had already settled.
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+ logic.actions.summarize()
+ await new Promise((resolve) => setTimeout(resolve, 0))
+ releaseInlineScan()
+ await expectLogic(logic).toDispatchActions(['summarizeSuccess'])
+
+ // A monitor scan started from the sidebar, its request still open.
+ logic.actions.observe('m1')
+ await new Promise((resolve) => setTimeout(resolve, 0))
+
+ observationResults = [summaryObservation()]
+ logic.actions.loadObservations()
+
+ await expectLogic(logic).toDispatchActions(['summarizeSettled'])
+ await expectLogic(logic).toMatchValues({ summarizePending: false })
+ })
+
+ it('keeps the button pending while the scanner it started has no row yet', async () => {
+ // The grace window ends on the row this run created, not on any summary row. A recording that
+ // already carries an older summary must not settle the button for a second summarizer whose
+ // own row is still on its way.
+ await loadScanners([scanner('s1', 'summarizer')])
+ observationResults = [summaryObservation()]
+ logic.actions.loadObservations()
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+
+ logic.actions.summarize()
+ await new Promise((resolve) => setTimeout(resolve, 0))
+ releaseObserve()
+ await expectLogic(logic).toDispatchActions(['observeSuccess'])
+
+ logic.actions.loadObservations()
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+ await expectLogic(logic).toMatchValues({ summarizePending: true })
+ })
+
+ it('stops showing the summary as pending once the reload keeps failing', async () => {
+ // With no summary row ever loaded, the grace window is the only thing keeping the poll alive.
+ // A run of failed reloads used to stop polling with nothing left to clear the pending state,
+ // so the button read "Summarizing…" until the dock remounted.
+ await expectLogic(logic).toDispatchActions(['loadObservationsSuccess'])
+ logic.actions.summarize()
+ await new Promise((resolve) => setTimeout(resolve, 0))
+ releaseInlineScan()
+ await expectLogic(logic).toDispatchActions(['summarizeSuccess'])
+ await expectLogic(logic).toMatchValues({ summarizePending: true })
+
+ // Past the grace window with the row still absent, so the next failure is the last poll.
+ const nowSpy = jest.spyOn(Date, 'now').mockReturnValue(Date.now() + OBSERVE_POLL_GRACE_MS + 1)
+ observationsFail = true
+ logic.actions.loadObservations()
+
+ await expectLogic(logic).toDispatchActions(['loadObservationsFailure', 'summarizeSettled'])
+ await expectLogic(logic).toMatchValues({ summarizePending: false })
+ nowSpy.mockRestore()
+ })
+
it('keeps the summarizer picked from the dropdown on the next recording', async () => {
// Picking from the dropdown has to outlive the recording it was picked on, or a team with
// several summarizers re-picks on every recording and the button never settles on their choice.
diff --git a/products/replay_vision/frontend/logics/observationsDockLogic.ts b/products/replay_vision/frontend/logics/observationsDockLogic.ts
index ab89e9e0af97..3f5096d7cbc1 100644
--- a/products/replay_vision/frontend/logics/observationsDockLogic.ts
+++ b/products/replay_vision/frontend/logics/observationsDockLogic.ts
@@ -44,8 +44,10 @@ export interface observationsDockLogicValues {
scannerPickerOpen: boolean
scannerSearch: string
seekbarMarks: ObservationSeekbarMark[]
+ summarizePending: boolean
summarizerScanners: ReplayScannerApi[]
summarizing: boolean
+ summaryInFlight: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -65,7 +67,11 @@ export interface observationsDockLogicActions {
loadObservationsSuccess: (observations: ReplayObservationApi[]) => {
observations: ReplayObservationApi[]
}
- observe: (scannerId: string) => {
+ observe: (
+ scannerId: string,
+ forSummary?: boolean
+ ) => {
+ forSummary: boolean
scannerId: string
}
observeFailure: () => {
@@ -98,6 +104,9 @@ export interface observationsDockLogicActions {
summarizeFailure: () => {
value: true
}
+ summarizeSettled: () => {
+ value: true
+ }
summarizeSuccess: () => {
value: true
}
@@ -111,6 +120,8 @@ export interface observationsDockLogicMeta {
key: string
__keaTypeGenInternalSelectorTypes: {
hasObservationsInFlight: (observations: ReplayObservationApi[]) => boolean
+ summaryInFlight: (observations: ReplayObservationApi[]) => boolean
+ summarizePending: (summarizing: boolean, summaryInFlight: boolean) => boolean
seekbarMarks: (observations: ReplayObservationApi[]) => ObservationSeekbarMark[]
summarizerScanners: (scanners: ReplayScannerApi[]) => ReplayScannerApi[]
defaultSummarizer: (
@@ -148,7 +159,7 @@ export const observationsDockLogic = kea<observationsDockLogicType>([
loadObservations: true,
loadObservationsSuccess: (observations: ReplayObservationApi[]) => ({ observations }),
loadObservationsFailure: true,
- observe: (scannerId: string) => ({ scannerId }),
+ observe: (scannerId: string, forSummary: boolean = false) => ({ scannerId, forSummary }),
observeSuccess: true,
observeFailure: true,
retryObservation: (observationId: string) => ({ observationId }),
@@ -161,6 +172,7 @@ export const observationsDockLogic = kea<observationsDockLogicType>([
summarizeWith: (scannerId: string | null) => ({ scannerId }),
summarizeSuccess: true,
summarizeFailure: true,
+ summarizeSettled: true,
}),
reducers({
@@ -186,17 +198,20 @@ export const observationsDockLogic = kea<observationsDockLogicType>([
observeFailure: () => false,
},
],
+ // True from the click until the summary itself settles, not until the trigger request returns.
+ // The request only starts a scan that runs for a minute or more, so clearing this on its
+ // response put the idle label back under a user whose summary had not started arriving yet.
summarizing: [
false,
{
summarize: () => true,
summarizeWith: () => true,
- summarizeSuccess: () => false,
+ // Nothing started, so there is nothing to wait for. `summarize` hands off to
+ // `observe` when the team has its own summarizer, and that listener reports its dead
+ // ends here too. It cannot be `observeFailure`: the sidebar picker runs on this same
+ // keyed logic, so its failures are not the summary's to settle.
summarizeFailure: () => false,
- // `summarize` hands off to `observe` when the team has its own summarizer, so the
- // button's spinner has to settle on that run's outcome too.
- observeSuccess: () => false,
- observeFailure: () => false,
+ summarizeSettled: () => false,
},
],
dockOpen: [
@@ -249,6 +264,19 @@ export const observationsDockLogic = kea<observationsDockLogicType>([
(observations: ReplayObservationApi[]): boolean =>
observations.some((o) => o.status === 'pending' || o.status === 'running'),
],
+ // Only a summary counts here: a monitor scanner the sidebar started is in flight too, and the
+ // summarize button must not claim that run as its own.
+ summaryInFlight: [
+ (s) => [s.observations],
+ (observations: ReplayObservationApi[]): boolean =>
+ observations.some((o) => isSummaryObservation(o) && (o.status === 'pending' || o.status === 'running')),
+ ],
+ // What the button shows. `summarizing` covers the window before the row exists; the row covers
+ // a summary that was already running when this recording was opened.
+ summarizePending: [
+ (s) => [s.summarizing, s.summaryInFlight],
+ (summarizing: boolean, summaryInFlight: boolean): boolean => summarizing || summaryInFlight,
+ ],
seekbarMarks: [
(s) => [s.observations],
(observations: ReplayObservationApi[]): ObservationSeekbarMark[] => observationSeekbarMarks(observations),
@@ -291,6 +319,22 @@ export const observationsDockLogic = kea<observationsDockLogicType>([
actions.setDockOpen(true)
}
}
+ // The button stays pending for as long as the run it started has something left to report: a
+ // summary row still running, or the grace period in which the row the scan will create has not
+ // landed yet. The cache flags hold it pending while the trigger request is still open, before
+ // either applies. The grace period is only the wait for a missing row, so that row landing ends
+ // it early; a summary that finishes fast must not keep the button pending beside its result.
+ const settleSummarizeIfDone = (): void => {
+ if (cache.summarizeInFlight || cache.observeInFlight === 'summary' || !values.summarizing) {
+ return
+ }
+ const startedRowLanded =
+ !!cache.summarizeScannerId && values.observations.some((o) => o.scanner_id === cache.summarizeScannerId)
+ const graceUntil = startedRowLanded ? 0 : values.pollUntil
+ if (!shouldPollObservations(values.summaryInFlight, graceUntil)) {
+ actions.summarizeSettled()
+ }
+ }
// Show the row that is coming, and re-read the quota the scan spent. Only call this when a scan
// actually started, or the poll window opens for work that will never land.
const afterScanStarted = (): void => {
@@ -306,12 +350,15 @@ export const observationsDockLogic = kea<observationsDockLogicType>([
// is just `observe`, which already owns its double-click guard and its already-run check.
const runSummary = async (scannerId: string | null): Promise<void> => {
if (scannerId) {
- actions.observe(scannerId)
+ // Flagged as the summary's run, so only this one settles the button.
+ actions.observe(scannerId, true)
return
}
// A cache flag for the same reason `observe` uses one: the reducer has already flipped
- // `summarizing` by the time this runs.
+ // `summarizing` by the time this runs. Say so rather than dropping the click, which left
+ // the user in front of a control that looked live and answered with nothing.
if (cache.summarizeInFlight) {
+ lemonToast.info('A summary of this recording is already starting.')
return
}
const teamId = teamLogic.values.currentTeamId
@@ -371,6 +418,7 @@ export const observationsDockLogic = kea<observationsDockLogicType>([
if (outcome === 'started' || outcome === 'already_running') {
// A scan is in flight either way — ours, or one this project already had running
// against the shared inline scanner — so the poll window has a row to wait for.
+ cache.summarizeScannerId = response.scan_id
actions.summarizeSuccess()
actions.setDockOpen(true)
afterScanStarted()
@@ -413,36 +461,62 @@ export const observationsDockLogic = kea<observationsDockLogicType>([
// Poll while in flight and through the observe grace window; rescheduled on failure so one hiccup can't kill it.
loadObservationsSuccess: () => {
openDockForExistingSummary()
+ settleSummarizeIfDone()
+ reschedulePoll()
+ },
+ // Settles here too: with no summary row loaded, `pollUntil` is the only poll condition
+ // left, so a run of failed reloads would otherwise stop polling with the button still
+ // pending and nothing to clear it before the dock remounts.
+ loadObservationsFailure: () => {
+ settleSummarizeIfDone()
reschedulePoll()
},
- loadObservationsFailure: reschedulePoll,
// Every open and close runs through here, so the preference tracks the last one the user made.
setDockOpen: ({ open }) => actions.setSummaryDockAutoExpand(open),
- observe: async ({ scannerId }) => {
+ observe: async ({ scannerId, forSummary }) => {
+ // The button waits on the summary, so every path here that starts no scan has to
+ // release it. A scan the sidebar started must not, even though it shares this logic.
+ const failSummarize = (): void => {
+ if (forSummary) {
+ actions.summarizeFailure()
+ }
+ }
// A cache flag, not `values.observing`: the reducer has already flipped that to true by the
- // time this listener runs, so it would reject every call.
+ // time this listener runs, so it would reject every call. Say so rather than dropping the
+ // click, which left the user in front of a control that looked live and answered with nothing.
+ // It names who is running, because a second summarize click is rejected by the run it
+ // is already waiting for, while a sidebar scan leaves it nothing to wait for.
if (cache.observeInFlight) {
+ lemonToast.info('A scan of this recording is already starting.')
+ if (cache.observeInFlight !== 'summary') {
+ failSummarize()
+ }
return
}
actions.setScannerPickerOpen(false)
const teamId = teamLogic.values.currentTeamId
if (!teamId) {
actions.observeFailure()
+ failSummarize()
return
}
// Backend keys the workflow id on (scanner, session); re-triggering the same pair silently no-ops.
if (values.observations.some((o) => o.scanner_id === scannerId)) {
lemonToast.info('This scanner has already been run on this recording.')
actions.observeFailure()
+ failSummarize()
actions.setDockOpen(true)
return
}
- cache.observeInFlight = true
+ cache.observeInFlight = forSummary ? 'summary' : 'scan'
try {
await visionScannersObserveCreate(String(teamId), scannerId, { session_id: props.sessionId })
lemonToast.success('Observation started')
+ if (forSummary) {
+ cache.summarizeScannerId = scannerId
+ }
actions.observeSuccess()
afterScanStarted()
} catch (error) {
@@ -454,8 +528,9 @@ export const observationsDockLogic = kea<observationsDockLogicType>([
'Failed to start observation'
)
actions.observeFailure()
+ failSummarize()
} finally {
- cache.observeInFlight = false
+ cache.observeInFlight = null
}
},