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.

feat(replay-vision): add banners for when quota is approaching (#61004)

Hayne Ryu53f8796125cd
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 27f6aab1fad7..1c6b2a325b8a 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -445,7 +445,7 @@ importers:
'@storybook/theming':
specifier: ^8.6.14
'@storybook/types':
specifier: 'catalog:'
@@ -1803,7 +1803,7 @@ importers:
'@storybook/theming':
specifier: ^8.6.14
'@tailwindcss/vite':
specifier: ^4.1.17
@@ -3254,6 +3254,9 @@ importers:
kea-forms:
specifier: 'catalog:'
+ kea-loaders:
+ specifier: 'catalog:'
kea-router:
specifier: 'catalog:'
@@ -10430,11 +10433,6 @@ packages:
typescript:
optional: true
- '@storybook/[email protected]':
- resolution: {integrity: sha512-HNR2mC5I4Z5ek8kTrVZlIY/B8gJGs5b3XdZPBPBopTIN6U/YHXiDyOjY3JlaS4fSG1fVhp/Qp1TpMn1w/9m1pw==}
- peerDependencies:
- storybook: ^8.2.0 || ^8.3.0-0 || ^8.4.0-0 || ^8.5.0-0 || ^8.6.0-0
-
'@storybook/[email protected]':
resolution: {integrity: sha512-55yViiZzPS/cPBuOeW4QGxGqrusjXVyxuknmbYCIwDtFyyvI/CgbjXRHdxNBaIjz+IlftxvBmmSaOqFG5+/dkA==}
peerDependencies:
@@ -10496,11 +10494,6 @@ packages:
peerDependencies:
storybook: ^8.6.18
- '@storybook/[email protected]':
- resolution: {integrity: sha512-ez0Zihuy17udLbfHZQXkGqwtep0mSGgHcNzGN7iZrMP1m+VmNo+7aGCJJdvXi7+iU3yq8weXSQFWg5DqWgLS7g==}
- peerDependencies:
- storybook: ^8.2.0 || ^8.3.0-0 || ^8.4.0-0 || ^8.5.0-0 || ^8.6.0-0
-
'@storybook/[email protected]':
resolution: {integrity: sha512-BjIp12gEMgzFkEsgKpDIbZdnSWTZpm2dlws8WiPJCpgJtG+HWSxZ0/Ms30Au9yfwzQEKRSbV/5zpsKMGc2SIJw==}
peerDependencies:
@@ -10518,11 +10511,6 @@ packages:
typescript:
optional: true
- '@storybook/[email protected]':
- resolution: {integrity: sha512-2GhcCd4dNMrnD7eooEfvbfL4I83qAqEyO0CO7JQAmIO6Rxb9BsOLLI/GD5HkvQB73ArTJ+PT50rfaO820IExOQ==}
- peerDependencies:
- storybook: ^8.2.0 || ^8.3.0-0 || ^8.4.0-0 || ^8.5.0-0 || ^8.6.0-0
-
'@storybook/[email protected]':
resolution: {integrity: sha512-joXRXh3GdVvzhbfIgmix1xs90p8Q/nja7AhEAC2egn5Pl7SKsIYZUCYI6UdrQANb2myg9P552LKXfPect8llKg==}
peerDependencies:
@@ -10603,11 +10591,6 @@ packages:
peerDependencies:
storybook: ^8.6.18
- '@storybook/[email protected]':
- resolution: {integrity: sha512-r4y+LsiB37V5hzpQo+BM10PaCsp7YlZ0YcZzQP1OCkPlYXmUAFy2VvDKaFRpD8IeNPKug2u4iFm/laDEbs03dg==}
- peerDependencies:
- storybook: ^8.2.0 || ^8.3.0-0 || ^8.4.0-0 || ^8.5.0-0 || ^8.6.0-0
-
'@storybook/[email protected]':
resolution: {integrity: sha512-n6OEjEtHupa2PdTwWzRepr7cO8NkDd4rgF6BKLitRbujOspLxzMBEqdphs+QLcuiCIgf33SqmEA64QWnbSMhPw==}
peerDependencies:
@@ -22732,6 +22715,11 @@ packages:
resolution: {integrity: sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==}
engines: {node: '>= 6'}
+ resolution: {integrity: sha512-ml/JPOj9fOQK8RNnWojA67GbZ0ApXAUlN2UQclwv2eVgTgn7O9gg9o7paZWKMp4g0H3nTLtS9LVzhkpOFIKzog==}
+ engines: {node: '>= 14.6'}
+ hasBin: true
+
resolution: {integrity: sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==}
engines: {node: '>= 14.6'}
@@ -31988,10 +31976,6 @@ snapshots:
- uglify-js
- webpack-cli
- dependencies:
- storybook: 8.6.18([email protected])
-
dependencies:
storybook: 8.6.18([email protected])
@@ -32061,10 +32045,6 @@ snapshots:
'@vitest/utils': 2.1.9
storybook: 8.6.18([email protected])
- dependencies:
- storybook: 8.6.18([email protected])
-
dependencies:
storybook: 8.6.18([email protected])
@@ -32104,10 +32084,6 @@ snapshots:
- uglify-js
- webpack-cli
- dependencies:
- storybook: 8.6.18([email protected])
-
dependencies:
storybook: 8.6.18([email protected])
@@ -32219,7 +32195,7 @@ snapshots:
'@storybook/core-common': 8.6.14([email protected]([email protected]))
'@storybook/csf': 0.1.13
'@storybook/csf-tools': 8.6.14([email protected]([email protected]))
- '@storybook/preview-api': 8.6.14([email protected]([email protected]))
+ '@storybook/preview-api': 8.6.18([email protected]([email protected]))
'@swc/core': 1.15.18
'@swc/jest': 0.2.37(@swc/[email protected])
expect-playwright: 0.8.0
@@ -32253,7 +32229,7 @@ snapshots:
'@storybook/core-common': 8.6.14([email protected]([email protected]))
'@storybook/csf': 0.1.13
'@storybook/csf-tools': 8.6.14([email protected]([email protected]))
- '@storybook/preview-api': 8.6.14([email protected]([email protected]))
+ '@storybook/preview-api': 8.6.18([email protected]([email protected]))
'@swc/core': 1.15.18
'@swc/jest': 0.2.37(@swc/[email protected])
expect-playwright: 0.8.0
@@ -32288,10 +32264,6 @@ snapshots:
'@vitest/spy': 2.0.5
storybook: 8.6.18([email protected])
- dependencies:
- storybook: 8.6.18([email protected])
-
dependencies:
storybook: 8.6.18([email protected])
@@ -41000,7 +40972,7 @@ snapshots:
micromatch: 4.0.8
pidtree: 0.6.0
string-argv: 0.3.2
- yaml: 2.9.0
+ yaml: 2.8.4
transitivePeerDependencies:
- supports-color
@@ -45452,12 +45424,12 @@ snapshots:
dependencies:
- '@storybook/components': 8.6.14([email protected]([email protected]))
+ '@storybook/components': 8.6.18([email protected]([email protected]))
'@storybook/core-events': 8.6.14([email protected]([email protected]))
'@storybook/global': 5.0.0
- '@storybook/manager-api': 8.6.14([email protected]([email protected]))
- '@storybook/theming': 8.6.14([email protected]([email protected]))
+ '@storybook/manager-api': 8.6.18([email protected]([email protected]))
+ '@storybook/theming': 8.6.18([email protected]([email protected]))
fast-deep-equal: 3.1.3
memoizerific: 1.11.3
transitivePeerDependencies:
@@ -47622,6 +47594,8 @@ snapshots:
+
diff --git a/products/replay_vision/frontend/components/ObservationsDock.tsx b/products/replay_vision/frontend/components/ObservationsDock.tsx
index 75e6f74239ba..a79c4842cd40 100644
--- a/products/replay_vision/frontend/components/ObservationsDock.tsx
+++ b/products/replay_vision/frontend/components/ObservationsDock.tsx
@@ -6,18 +6,38 @@ import { LemonButton, LemonInput, Link, Spinner } from '@posthog/lemon-ui'
import { Resizer } from 'lib/components/Resizer/Resizer'
import { ResizerLogicProps, resizerLogic } from 'lib/components/Resizer/resizerLogic'
+import { dayjs } from 'lib/dayjs'
import { LemonDropdown } from 'lib/lemon-ui/LemonDropdown/LemonDropdown'
import { sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'
import { urls } from 'scenes/urls'
-import type { ReplayScannerApi } from '../generated/api.schemas'
+import type { ReplayScannerApi, VisionQuotaApi } from '../generated/api.schemas'
import { observationsDockLogic } from '../logics/observationsDockLogic'
+import { visionQuotaLogic } from '../logics/visionQuotaLogic'
import { ObservationDockCard } from './ObservationCard'
const COLLAPSED_HEIGHT = 44
const DEFAULT_EXPANDED_HEIGHT = 480
const MIN_EXPANDED_HEIGHT = 120
const MAX_EXPANDED_HEIGHT = 800
+const QUOTA_WARN_THRESHOLD = 0.8
+
+// Assumes block-only overage policy; revisit when `usage_based` lands so we don't disable buttons on metered orgs.
+function quotaUx(quota: VisionQuotaApi | null): { disabledReason?: string; tooltip?: string } {
+ if (!quota || quota.monthly_quota <= 0) {
+ return {}
+ }
+ const resetsOn = dayjs(quota.period_end).format('MMM D')
+ if (quota.exhausted) {
+ return { disabledReason: `Monthly Vision quota reached. Resets ${resetsOn}.` }
+ }
+ if (quota.usage_this_month / quota.monthly_quota >= QUOTA_WARN_THRESHOLD) {
+ return {
+ tooltip: `${quota.remaining.toLocaleString()} Vision observations left this month (resets ${resetsOn})`,
+ }
+ }
+ return {}
+}
export function ObservationsDock(): JSX.Element | null {
const { sessionRecordingId } = useValues(sessionRecordingPlayerLogic)
@@ -33,6 +53,8 @@ function ScannerPicker({ sessionId }: { sessionId: string }): JSX.Element {
const logic = observationsDockLogic({ sessionId })
const { scanners, filteredScanners, scannerSearch, scannerPickerOpen, observing } = useValues(logic)
const { observe, setScannerSearch, setScannerPickerOpen } = useActions(logic)
+ const { quota } = useValues(visionQuotaLogic)
+ const { disabledReason: quotaDisabledReason, tooltip: quotaTooltip } = quotaUx(quota)
return (
<LemonDropdown
@@ -84,6 +106,8 @@ function ScannerPicker({ sessionId }: { sessionId: string }): JSX.Element {
icon={<IconEye />}
sideIcon={<IconChevronDown />}
loading={observing}
+ disabledReason={quotaDisabledReason}
+ tooltip={quotaTooltip}
data-attr="vision-observe-recording"
>
Scan this recording
diff --git a/products/replay_vision/frontend/logics/visionQuotaLogic.ts b/products/replay_vision/frontend/logics/visionQuotaLogic.ts
new file mode 100644
index 000000000000..34291013bab5
--- /dev/null
+++ b/products/replay_vision/frontend/logics/visionQuotaLogic.ts
@@ -0,0 +1,35 @@
+import { afterMount, kea, path } from 'kea'
+import { loaders } from 'kea-loaders'
+
+import { teamLogic } from 'scenes/teamLogic'
+
+import { environmentVisionQuotaRetrieve } from '../generated/api'
+import type { VisionQuotaApi } from '../generated/api.schemas'
+import type { visionQuotaLogicType } from './visionQuotaLogicType'
+
+export const visionQuotaLogic = kea<visionQuotaLogicType>([
+ path(['products', 'replay_vision', 'frontend', 'logics', 'visionQuotaLogic']),
+
+ loaders({
+ quota: [
+ null as VisionQuotaApi | null,
+ {
+ loadQuota: async () => {
+ const teamId = teamLogic.values.currentTeamId
+ if (!teamId) {
+ return null
+ }
+ try {
+ return await environmentVisionQuotaRetrieve(String(teamId))
+ } catch {
+ return null
+ }
+ },
+ },
+ ],
+ }),
+
+ afterMount(({ actions }) => {
+ actions.loadQuota()
+ }),
+])
diff --git a/products/replay_vision/frontend/replay_scanners/ReplayScanner.tsx b/products/replay_vision/frontend/replay_scanners/ReplayScanner.tsx
index dbc26ef8091c..e2c347450255 100644
--- a/products/replay_vision/frontend/replay_scanners/ReplayScanner.tsx
+++ b/products/replay_vision/frontend/replay_scanners/ReplayScanner.tsx
@@ -15,6 +15,7 @@ import {
} from '@posthog/lemon-ui'
import { AccessControlAction } from 'lib/components/AccessControlAction'
+import { dayjs } from 'lib/dayjs'
import { More } from 'lib/lemon-ui/LemonButton/More'
import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'
@@ -25,6 +26,7 @@ import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
import { ProductKey } from '~/queries/schema/schema-general'
import { AccessControlLevel, AccessControlResourceType } from '~/types'
+import { visionQuotaLogic } from '../logics/visionQuotaLogic'
import { ScannerObservationsTable } from './components/ScannerObservationsTable'
import { ScannerTriggers } from './components/ScannerTriggers'
import { ScannerTypeConfigEditor } from './components/ScannerTypeConfigEditor'
@@ -206,6 +208,8 @@ export function ReplayScannerSceneComponent({ tabId }: { tabId: string }): JSX.E
{hasUnsavedChanges && !isNew && <LemonBanner type="info">You have unsaved changes.</LemonBanner>}
+ <QuotaBanner />
+
<Form logic={replayScannerLogic} props={{ id: scannerId, tabId }} formKey="scanner" enableFormOnSubmit>
<LemonTabs
activeKey={activeTab}
@@ -217,4 +221,32 @@ export function ReplayScannerSceneComponent({ tabId }: { tabId: string }): JSX.E
)
}
+const QUOTA_WARN_THRESHOLD = 0.8
+
+// Assumes block-only overage policy; revisit when `usage_based` ships so we don't scare metered orgs.
+function QuotaBanner(): JSX.Element | null {
+ const { quota } = useValues(visionQuotaLogic)
+ if (!quota || quota.monthly_quota <= 0) {
+ return null
+ }
+ const resetsOn = dayjs(quota.period_end).format('MMM D')
+ if (quota.exhausted) {
+ return (
+ <LemonBanner type="warning">
+ Monthly Vision quota reached ({quota.usage_this_month.toLocaleString()} /{' '}
+ {quota.monthly_quota.toLocaleString()}). Scheduled scans are paused until {resetsOn}.
+ </LemonBanner>
+ )
+ }
+ if (quota.usage_this_month / quota.monthly_quota >= QUOTA_WARN_THRESHOLD) {
+ return (
+ <LemonBanner type="warning">
+ Approaching monthly Vision quota: {quota.usage_this_month.toLocaleString()} of{' '}
+ {quota.monthly_quota.toLocaleString()} used. Schedules will pause once the cap is reached on {resetsOn}.
+ </LemonBanner>
+ )
+ }
+ return null
+}
+
export default ReplayScannerSceneComponent
diff --git a/products/replay_vision/frontend/replay_scanners/components/VisionQuotaMeter.tsx b/products/replay_vision/frontend/replay_scanners/components/VisionQuotaMeter.tsx
index b426e6eba714..8ef94cf893a1 100644
--- a/products/replay_vision/frontend/replay_scanners/components/VisionQuotaMeter.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/VisionQuotaMeter.tsx
@@ -3,13 +3,26 @@ import { useValues } from 'kea'
import { Tooltip } from '@posthog/lemon-ui'
import { LemonProgress } from 'lib/lemon-ui/LemonProgress'
+import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'
-import { replayScannersLogic } from '../replayScannersLogic'
+import { visionQuotaLogic } from '../../logics/visionQuotaLogic'
export function VisionQuotaMeter(): JSX.Element | null {
- const { quota } = useValues(replayScannersLogic)
+ const { quota, quotaLoading } = useValues(visionQuotaLogic)
if (!quota) {
+ if (quotaLoading) {
+ return (
+ <div className="border rounded p-3 bg-bg-light space-y-2">
+ <div className="flex items-center justify-between">
+ <LemonSkeleton className="h-4 w-48" />
+ <LemonSkeleton className="h-4 w-20" />
+ </div>
+ <LemonSkeleton className="h-2 w-full" />
+ <LemonSkeleton className="h-3 w-24" />
+ </div>
+ )
+ }
return null
}
diff --git a/products/replay_vision/frontend/replay_scanners/replayScannersLogic.test.ts b/products/replay_vision/frontend/replay_scanners/replayScannersLogic.test.ts
index f42546e814e3..48e07f714ee1 100644
--- a/products/replay_vision/frontend/replay_scanners/replayScannersLogic.test.ts
+++ b/products/replay_vision/frontend/replay_scanners/replayScannersLogic.test.ts
@@ -49,7 +49,6 @@ describe('replayScannersLogic', () => {
useMocks({
get: {
'/api/projects/:team/vision/scanners/': { results: [] },
- '/api/projects/:team/vision/quota/': () => [404, {}],
},
})
initKeaTests()
diff --git a/products/replay_vision/frontend/replay_scanners/replayScannersLogic.ts b/products/replay_vision/frontend/replay_scanners/replayScannersLogic.ts
index 47e2877f5e2e..9892d1bdba2d 100644
--- a/products/replay_vision/frontend/replay_scanners/replayScannersLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/replayScannersLogic.ts
@@ -9,7 +9,6 @@ import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import {
- environmentVisionQuotaRetrieve,
visionScannersCreate,
visionScannersDestroy,
visionScannersList,
@@ -22,7 +21,6 @@ import {
SCANNER_TYPE_OPTIONS,
ScannerType,
ReplayScanner,
- VisionQuota,
scannerFromApi,
scannerToApiBody,
scannersFromApi,
@@ -55,8 +53,6 @@ export const replayScannersLogic = kea<replayScannersLogicType>([
loadScanners: true,
loadScannersSuccess: (scanners: ReplayScanner[]) => ({ scanners }),
loadScannersFailure: (error: string) => ({ error }),
- loadQuota: true,
- loadQuotaSuccess: (quota: VisionQuota | null) => ({ quota }),
deleteScanner: (id: string) => ({ id }),
deleteScannerSuccess: (id: string) => ({ id }),
duplicateScanner: (id: string) => ({ id }),
@@ -88,12 +84,6 @@ export const replayScannersLogic = kea<replayScannersLogicType>([
loadScannersFailure: () => false,
},
],
- quota: [
- null as VisionQuota | null,
- {
- loadQuotaSuccess: (_, { quota }) => quota,
- },
- ],
search: [
'',
{
@@ -132,19 +122,6 @@ export const replayScannersLogic = kea<replayScannersLogicType>([
}
},
- loadQuota: async () => {
- const teamId = teamLogic.values.currentTeamId
- if (!teamId) {
- return
- }
- try {
- const response = await environmentVisionQuotaRetrieve(String(teamId))
- actions.loadQuotaSuccess(response)
- } catch {
- actions.loadQuotaSuccess(null)
- }
- },
-
deleteScanner: async ({ id }) => {
const teamId = teamLogic.values.currentTeamId
if (!teamId) {
@@ -284,6 +261,5 @@ export const replayScannersLogic = kea<replayScannersLogicType>([
afterMount(({ actions }) => {
actions.loadScanners()
- actions.loadQuota()
}),
])
diff --git a/products/replay_vision/frontend/replay_scanners/types.ts b/products/replay_vision/frontend/replay_scanners/types.ts
index f81863a9b878..c8cccec5a7a6 100644
--- a/products/replay_vision/frontend/replay_scanners/types.ts
+++ b/products/replay_vision/frontend/replay_scanners/types.ts
@@ -205,8 +205,6 @@ export interface ScorerScanner extends BaseReplayScanner {
export type ReplayScanner = MonitorScanner | SummarizerScanner | ClassifierScanner | ScorerScanner
-export type { VisionQuotaApi as VisionQuota } from '../generated/api.schemas'
-
// The API exposes scanner_config and query as `unknown`. The client narrows them via
// the scanner_type discriminator, so conversion is contained to this single boundary.
export function scannerFromApi(api: ReplayScannerApi): ReplayScanner {
diff --git a/products/replay_vision/package.json b/products/replay_vision/package.json
index 6273612e47a1..b899031bc1e6 100644
--- a/products/replay_vision/package.json
+++ b/products/replay_vision/package.json
@@ -6,6 +6,7 @@
"dependencies": {
"kea": "catalog:",
"kea-forms": "catalog:",
+ "kea-loaders": "catalog:",
"kea-router": "catalog:"
},
"devDependencies": {