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): show the startup program cap on vision spend (#75760)

Arno Hillen8c83bd25b4c6
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index aa9b8993efd2..e47ef456b64e 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6929,7 +6929,11 @@ snapshots:
scenes-app-replay-vision--scanners-list--dark:
hash: v1.k794b7964.c7d4eef5eaeda5b9784039a6b70c0d883567f4003504cdc600672407b846aed9.TmqvlGFuTRANDAG5NUWvJT9qYZ4ixI0t7nlG6Dq7eYQ
scenes-app-replay-vision--scanners-list--light:
- hash: v1.k794b7964.785bb74cc201022c1cd1a8dca488fb32879c774cbe93193ca26e57e4d77e44f2.c5RK9ubMopTPwQKPOi3QQPOBLnElg0HJis-KcoKPSgA
+ hash: v1.k794b7964.99f5f4499dca089b44d7bce7dee60424c7bdeefb860a8882d5ca8cbf06abce69.MHJZLg5-Q8USBaHeY-N_hqBMtEfuRArXAsAgnwEk4gs
+ scenes-app-replay-vision--startup-program-cap--dark:
+ hash: v1.k794b7964.01d5414d5bee2c03544970d601b94f151deb98e471639d0564872cd8f7bba2ed.Rh9iqIwvltkj-mDCKnLOMm6hLerDbP61TvR1mL-hKR0
+ scenes-app-replay-vision--startup-program-cap--light:
+ hash: v1.k794b7964.e8d4fcf9e0a4ceede4a5de71eedcd1e55f78f575c63c5a03a0e031618a68d3c1.l4eQH8X-BzhBVFmCNPcRiBMT3gGCcP5HgscW8SnPF44
scenes-app-replay-vision--summarizer-overview--dark:
hash: v1.k794b7964.e5827be3112c9cb7af5526a41eb02da1c5ef1982eb9d2af887e0649119f8def5.-yMhrm4zkIgcYpOcdAKwqy1w5SEDHRXT5pTfaNENKFg
scenes-app-replay-vision--summarizer-overview--light:
diff --git a/products/replay_vision/frontend/logics/visionQuotaLogic.test.ts b/products/replay_vision/frontend/logics/visionQuotaLogic.test.ts
index a31df3bb38e4..bbeab5f22c2c 100644
--- a/products/replay_vision/frontend/logics/visionQuotaLogic.test.ts
+++ b/products/replay_vision/frontend/logics/visionQuotaLogic.test.ts
@@ -1,9 +1,13 @@
import { expectLogic } from 'kea-test-utils'
+import { billingLogic } from 'scenes/billing/billingLogic'
+
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
+import { BillingType, StartupProgramLabel } from '~/types'
import { makeQuota } from '../utils/quotaTestUtils'
+import { STARTUP_CAP_CREDITS } from '../utils/startupCap'
import { visionQuotaLogic } from './visionQuotaLogic'
const quota = makeQuota({
@@ -46,6 +50,42 @@ describe('visionQuotaLogic', () => {
expect(logic.values.quota).toBeNull()
})
+ it('displayQuota shows the startup cap once billing reports the org is enrolled', async () => {
+ await expectLogic(logic).toDispatchActions(['loadQuotaSuccess'])
+ logic.actions.loadQuotaSuccess(makeQuota({ credit_limit: null, remaining: null }))
+
+ expect(logic.values.startupCapCredits).toBeNull()
+ expect(logic.values.displayQuota?.credit_limit).toBeNull()
+
+ billingLogic.actions.loadBillingSuccess({ startup_program_label: StartupProgramLabel.YC } as BillingType)
+
+ expect(logic.values.displayQuota?.credit_limit).toBe(STARTUP_CAP_CREDITS)
+ // The guards read `quota`, so the display clamp must not reach it.
+ expect(logic.values.quota?.credit_limit).toBeNull()
+ })
+
+ it('shows the cap line only when it differs from the displayed monthly limit', async () => {
+ await expectLogic(logic).toDispatchActions(['loadQuotaSuccess'])
+ billingLogic.actions.loadBillingSuccess({ startup_program_label: StartupProgramLabel.YC } as BillingType)
+
+ // The fixture's own 1,000 limit sits below the cap, so the cap line adds information.
+ expect(logic.values.showStartupCap).toBe(true)
+ expect(logic.values.showStartupCapLine).toBe(true)
+
+ // With no limit of its own, the displayed limit is the cap itself.
+ logic.actions.loadQuotaSuccess(makeQuota({ credit_limit: null, remaining: null }))
+ expect(logic.values.showStartupCapLine).toBe(false)
+
+ // A limit above the cap is displayed clamped to the cap, so the line would repeat it.
+ logic.actions.loadQuotaSuccess(makeQuota({ credit_limit: STARTUP_CAP_CREDITS + 100_000 }))
+ expect(logic.values.showStartupCapLine).toBe(false)
+
+ // Enrollment alone is not enough for the line: with no quota there is no limit to compare against.
+ logic.actions.loadQuotaSuccess(null)
+ expect(logic.values.showStartupCap).toBe(true)
+ expect(logic.values.showStartupCapLine).toBe(false)
+ })
+
it('loadQuota overwrites any optimistic adjustment with the server value', async () => {
await expectLogic(logic).toDispatchActions(['loadQuotaSuccess'])
logic.actions.adjustProjectedMonthly(250)
diff --git a/products/replay_vision/frontend/logics/visionQuotaLogic.ts b/products/replay_vision/frontend/logics/visionQuotaLogic.ts
index 11ef5fa4d8de..e7732279edfb 100644
--- a/products/replay_vision/frontend/logics/visionQuotaLogic.ts
+++ b/products/replay_vision/frontend/logics/visionQuotaLogic.ts
@@ -1,16 +1,24 @@
-import { MakeLogicType, actions, afterMount, connect, kea, path, reducers } from 'kea'
+import { MakeLogicType, actions, afterMount, connect, kea, path, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
import { billingLogic } from 'scenes/billing/billingLogic'
import { teamLogic } from 'scenes/teamLogic'
+import type { BillingType } from '~/types'
+
import { environmentVisionQuotaRetrieve } from '../generated/api'
import type { VisionQuotaApi } from '../generated/api.schemas'
+import { applyStartupCap, startupCapCredits } from '../utils/startupCap'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface visionQuotaLogicValues {
+ billing: BillingType | null // billingLogic
+ displayQuota: VisionQuotaApi | null
quota: VisionQuotaApi | null
quotaLoading: boolean
+ showStartupCap: boolean
+ showStartupCapLine: boolean
+ startupCapCredits: number | null
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -42,13 +50,29 @@ export interface visionQuotaLogicActions {
}
}
-export type visionQuotaLogicType = MakeLogicType<visionQuotaLogicValues, visionQuotaLogicActions>
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface visionQuotaLogicMeta {
+ __keaTypeGenInternalSelectorTypes: {
+ startupCapCredits: (billing: BillingType | null) => number | null
+ displayQuota: (quota: VisionQuotaApi | null, startupCapCredits: number | null) => VisionQuotaApi | null
+ showStartupCap: (startupCapCredits: number | null) => boolean
+ showStartupCapLine: (startupCapCredits: number | null, displayQuota: VisionQuotaApi | null) => boolean
+ }
+}
+
+export type visionQuotaLogicType = MakeLogicType<
+ visionQuotaLogicValues,
+ visionQuotaLogicActions,
+ Record<string, any>,
+ visionQuotaLogicMeta
+>
export const visionQuotaLogic = kea<visionQuotaLogicType>([
path(['products', 'replay_vision', 'frontend', 'logics', 'visionQuotaLogic']),
connect(() => ({
actions: [billingLogic, ['loadBilling']],
+ values: [billingLogic, ['billing']],
})),
actions({
@@ -92,6 +116,23 @@ export const visionQuotaLogic = kea<visionQuotaLogicType>([
},
}),
+ selectors({
+ startupCapCredits: [(s) => [s.billing], (billing: BillingType | null) => startupCapCredits(billing)],
+ // Spend surfaces render this. Guards stay on `quota` so the display can never block what the backend allows.
+ displayQuota: [
+ (s) => [s.quota, s.startupCapCredits],
+ (quota: VisionQuotaApi | null, capCredits: number | null) => applyStartupCap(quota, capCredits),
+ ],
+ // Single gate for the cap copy so the spend surfaces can't drift on when it shows.
+ showStartupCap: [(s) => [s.startupCapCredits], (capCredits: number | null) => capCredits !== null],
+ // Cost breakdowns already show "Monthly limit"; a cap line only adds information when the two differ.
+ showStartupCapLine: [
+ (s) => [s.startupCapCredits, s.displayQuota],
+ (capCredits: number | null, quota: VisionQuotaApi | null) =>
+ capCredits !== null && quota !== null && quota.credit_limit !== capCredits,
+ ],
+ }),
+
afterMount(({ actions }) => {
actions.loadQuota()
// billingLogic doesn't self-load; the ingestion banner needs billing on cold navigation.
diff --git a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx
index 785ab4a383ab..9b29c05824bf 100644
--- a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx
+++ b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx
@@ -5,8 +5,16 @@ import { App } from 'scenes/App'
import { urls } from 'scenes/urls'
import { mswDecorator } from '~/mocks/browser'
+import { billingJson } from '~/mocks/fixtures/_billing'
+import { StartupProgramLabel } from '~/types'
-import type { ObservationStatsApi, ReplayScannerApi, UserBasicApi, VisionQuotaApi } from '../generated/api.schemas'
+import type {
+ ObservationStatsApi,
+ ReplayScannerApi,
+ ScannerStatsResponseApi,
+ UserBasicApi,
+ VisionQuotaApi,
+} from '../generated/api.schemas'
const alice: UserBasicApi = {
id: 1,
@@ -102,6 +110,17 @@ const quota: VisionQuotaApi = {
period_end: '2026-06-01T00:00:00Z',
}
+const scannerStats: ScannerStatsResponseApi = {
+ total: 4,
+ enabled: 3,
+ by_type: {
+ monitor: { total: 1, enabled: 1 },
+ classifier: { total: 1, enabled: 0 },
+ scorer: { total: 1, enabled: 1 },
+ summarizer: { total: 1, enabled: 1 },
+ },
+}
+
const summarizerScanner = scanners.results[2]
const summarizerStats: ObservationStatsApi = {
@@ -208,3 +227,17 @@ export const SummarizerOverview: StoryObj = {
}),
],
}
+
+// Billing hasn't clamped this org's limit yet, so the API still reports it as uncapped.
+export const StartupProgramCap: StoryObj = {
+ decorators: [
+ mswDecorator({
+ get: {
+ '/api/projects/:team_id/vision/scanners/': scanners,
+ '/api/projects/:team_id/vision/scanners/stats/': scannerStats,
+ '/api/projects/:team_id/vision/quota/': { ...quota, credit_limit: null, remaining: null },
+ '/api/billing/': { ...billingJson, startup_program_label: StartupProgramLabel.YC },
+ },
+ }),
+ ],
+}
diff --git a/products/replay_vision/frontend/replay_scanners/components/QuotaStatusLine.test.tsx b/products/replay_vision/frontend/replay_scanners/components/QuotaStatusLine.test.tsx
new file mode 100644
index 000000000000..d8d3df542474
--- /dev/null
+++ b/products/replay_vision/frontend/replay_scanners/components/QuotaStatusLine.test.tsx
@@ -0,0 +1,47 @@
+import { render } from '@testing-library/react'
+
+import { dayjs } from 'lib/dayjs'
+
+import type { QuotaProjection } from '../../utils/quotaProjection'
+import { QuotaStatusLine } from './QuotaStatusLine'
+
+const base: QuotaProjection = {
+ status: 'safe',
+ exhausted: false,
+ capReachDate: null,
+ percentLabel: 0,
+ resetsOn: null,
+ usedPct: 0,
+ projectedPct: 0,
+}
+
+describe('QuotaStatusLine', () => {
+ it.each([
+ { name: 'renders nothing below danger', projection: { ...base, status: 'warning' as const }, text: null },
+ {
+ name: 'reached when the backend blocks spend',
+ projection: { ...base, exhausted: true, usedPct: 100 },
+ text: 'Spend limit reached',
+ },
+ {
+ // The startup-cap clamp can put spend past the displayed limit while the backend still allows scans;
+ // this must stay a visible red line, not disappear.
+ name: 'exceeded when spend passed the displayed limit without backend exhaustion',
+ projection: { ...base, status: 'danger' as const, usedPct: 104 },
+ text: 'Monthly spend limit exceeded',
+ },
+ {
+ name: 'projected reach date when on track to hit the limit',
+ projection: { ...base, status: 'danger' as const, usedPct: 80, capReachDate: dayjs('2026-07-21') },
+ text: 'July 21',
+ },
+ ])('$name', ({ projection, text }) => {
+ const { container } = render(<QuotaStatusLine projection={projection} />)
+
+ if (text === null) {
+ expect(container.textContent).toBe('')
+ } else {
+ expect(container.textContent).toContain(text)
+ }
+ })
+})
diff --git a/products/replay_vision/frontend/replay_scanners/components/QuotaStatusLine.tsx b/products/replay_vision/frontend/replay_scanners/components/QuotaStatusLine.tsx
index 5b4564324646..4a297f602f21 100644
--- a/products/replay_vision/frontend/replay_scanners/components/QuotaStatusLine.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/QuotaStatusLine.tsx
@@ -1,6 +1,6 @@
import type { QuotaProjection } from '../../utils/quotaProjection'
-/** Red warning when the spend limit is exhausted or projected to overshoot; renders nothing otherwise. */
+/** Red warning when the spend limit is exhausted, exceeded, or projected to overshoot; renders nothing otherwise. */
export function QuotaStatusLine({ projection }: { projection: QuotaProjection }): JSX.Element | null {
if (projection.exhausted) {
return <span className="text-danger">Spend limit reached</span>
@@ -8,6 +8,11 @@ export function QuotaStatusLine({ projection }: { projection: QuotaProjection })
if (projection.status !== 'danger') {
return null
}
+ // Over the displayed limit but not backend-exhausted (the startup cap before billing clamps):
+ // "exceeded" states the spend fact without claiming scanning is paused.
+ if (projection.usedPct >= 100) {
+ return <span className="text-danger">Monthly spend limit exceeded</span>
+ }
return projection.capReachDate ? (
<span className="text-danger">
Spend limit projected to be reached on <strong>{projection.capReachDate.format('MMMM D')}</strong>
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerCalibrationTab.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerCalibrationTab.tsx
index 0cace621c309..44fe2f51c461 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ScannerCalibrationTab.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerCalibrationTab.tsx
@@ -318,7 +318,8 @@ function ConfigRecommendationPanel({ scannerId }: { scannerId: string }): JSX.El
loadSuggestionHistory,
} = useActions(logic)
const { scanner } = useValues(replayScannerLogic({ id: scannerId }))
- const { quota } = useValues(visionQuotaLogic)
+ // `quota` gates the test button (enforcement), `displayQuota` renders spend copy (startup cap applied).
+ const { quota, displayQuota } = useValues(visionQuotaLogic)
const { isDarkModeOn } = useValues(themeLogic)
// Scorer and summarizer have no discrete outcome, so they preview raw before/after instead of a verdict.
const previewEvaluation = scanner?.scanner_type === 'scorer' || scanner?.scanner_type === 'summarizer'
@@ -466,8 +467,8 @@ function ConfigRecommendationPanel({ scannerId }: { scannerId: string }): JSX.El
of your {Math.min(evaluationSessionCap, ratedCount)} rated result
{Math.min(evaluationSessionCap, ratedCount) === 1 ? '' : 's'}, thumbs down first. Costs{' '}
{formatCreditCount(plannedTestCredits)}
- {quota && quota.remaining !== null && quota.credit_limit !== null
- ? `, ${formatCreditsRange(quota.remaining, quota.credit_limit)} left this period`
+ {displayQuota && displayQuota.remaining !== null && displayQuota.credit_limit !== null
+ ? `, ${formatCreditsRange(displayQuota.remaining, displayQuota.credit_limit)} left this period`
: ''}
.
</span>
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerQuotaForecast.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerQuotaForecast.tsx
index 505fbf83883c..749919a23291 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ScannerQuotaForecast.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerQuotaForecast.tsx
@@ -25,7 +25,7 @@ export function ScannerQuotaForecast({ scannerId }: Props): JSX.Element | null {
const { scanner, scannerEstimate, scannerEstimateLoading, scannerEstimateError } = useValues(
replayScannerLogic({ id: scannerId })
)
- const { quota } = useValues(visionQuotaLogic)
+ const { displayQuota: quota, startupCapCredits, showStartupCapLine } = useValues(visionQuotaLogic)
if (!scanner) {
return null
@@ -70,6 +70,11 @@ export function ScannerQuotaForecast({ scannerId }: Props): JSX.Element | null {
Monthly limit: <strong>{formatCreditCount(cap)}</strong>
</div>
)}
+ {showStartupCapLine && (
+ <div>
+ Startup program cap: <strong>{formatCreditCount(startupCapCredits ?? 0)}/month</strong>
+ </div>
+ )}
{resetsOn && <div className="text-muted">Resets {resetsOn}</div>}
</div>
)
diff --git a/products/replay_vision/frontend/replay_scanners/components/VisionMetrics.tsx b/products/replay_vision/frontend/replay_scanners/components/VisionMetrics.tsx
index e6abcc372edc..461a12185f0a 100644
--- a/products/replay_vision/frontend/replay_scanners/components/VisionMetrics.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/VisionMetrics.tsx
@@ -13,6 +13,7 @@ import { ScannerTypeBadge } from '../../components/ScannerTypeBadge'
import { visionQuotaLogic } from '../../logics/visionQuotaLogic'
import { creditsToUsd, formatCreditCount } from '../../utils/credits'
import { QUOTA_STATUS_STYLES, hasCreditLimit, projectQuota } from '../../utils/quotaProjection'
+import { STARTUP_CAP_EXPLANATION } from '../../utils/startupCap'
import { replayScannersLogic } from '../replayScannersLogic'
import { SCANNER_TYPE_OPTIONS } from '../types'
import { QuotaMeterBar, QuotaMeterLegendItem } from './QuotaMeterBar'
@@ -25,7 +26,13 @@ const COLLECTION_ID = 'replay-vision-list-observations'
export function VisionMetrics(): JSX.Element {
const { scannerStats, chartDateFrom, chartDateTo } = useValues(replayScannersLogic)
const { setChartDateRange } = useActions(replayScannersLogic)
- const { quota, quotaLoading } = useValues(visionQuotaLogic)
+ const {
+ displayQuota: quota,
+ quotaLoading,
+ startupCapCredits,
+ showStartupCap,
+ showStartupCapLine,
+ } = useValues(visionQuotaLogic)
const projection = projectQuota(quota)
const { resetsOn, status, percentLabel, usedPct, projectedPct } = projection
@@ -149,6 +156,14 @@ export function VisionMetrics(): JSX.Element {
Monthly limit:{' '}
<strong>{formatCreditCount(quota.credit_limit ?? 0)}</strong>
</div>
+ {showStartupCapLine && (
+ <div>
+ Startup program cap:{' '}
+ <strong>
+ {formatCreditCount(startupCapCredits ?? 0)}/month
+ </strong>
+ </div>
+ )}
{resetsOn && <div className="text-muted">Resets {resetsOn}</div>}
</div>
}
@@ -178,6 +193,9 @@ export function VisionMetrics(): JSX.Element {
spend.
</div>
)}
+ {showStartupCap && (
+ <div className="text-xs text-muted mt-1.5">{STARTUP_CAP_EXPLANATION}</div>
+ )}
<div className="mt-2">
<Link to={`${urls.replayVision()}?tab=usage`} className="text-xs">
View usage by scanner
diff --git a/products/replay_vision/frontend/replay_scanners/components/VisionUsageTab.tsx b/products/replay_vision/frontend/replay_scanners/components/VisionUsageTab.tsx
index bd505168092f..b01a5680541f 100644
--- a/products/replay_vision/frontend/replay_scanners/components/VisionUsageTab.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/VisionUsageTab.tsx
@@ -13,6 +13,7 @@ import { BaseMathType, ChartDisplayType, InsightLogicProps, PropertyFilterType,
import { visionQuotaLogic } from '../../logics/visionQuotaLogic'
import { creditsToUsd, formatCreditCount, formatCredits, formatCreditsRange } from '../../utils/credits'
import { exhaustionForecast, hasCreditLimit, projectQuota } from '../../utils/quotaProjection'
+import { STARTUP_CAP_EXPLANATION } from '../../utils/startupCap'
import { OBSERVATION_CREDITS_BY_MODEL, ReplayScanner, modelName } from '../types'
import { SpendChartInterval, visionUsageLogic } from '../visionUsageLogic'
import { VisionInsightChart } from './VisionInsightChart'
@@ -52,7 +53,7 @@ const SPEND_CHART_FORMULA = `(${SPEND_CHART_MODEL_PRICES.map(
export function VisionUsageTab(): JSX.Element {
const { usageScanners, usageScannersLoading, spendChartInterval } = useValues(visionUsageLogic)
const { setSpendChartInterval } = useActions(visionUsageLogic)
- const { quota } = useValues(visionQuotaLogic)
+ const { displayQuota: quota, showStartupCap } = useValues(visionQuotaLogic)
const projection = projectQuota(quota)
const hasCap = hasCreditLimit(quota)
@@ -171,7 +172,7 @@ export function VisionUsageTab(): JSX.Element {
<Tooltip
title={`≈ ${creditsToUsd(quota.credits_used)}${
hasCap ? ` of ${creditsToUsd(quota.credit_limit ?? 0)}` : ''
- }`}
+ }${showStartupCap ? `. ${STARTUP_CAP_EXPLANATION}` : ''}`}
>
<span className="text-xs text-muted tabular-nums">
{hasCap
diff --git a/products/replay_vision/frontend/utils/quotaProjection.test.ts b/products/replay_vision/frontend/utils/quotaProjection.test.ts
index c8b5057d7009..1ade6fcf1bc7 100644
--- a/products/replay_vision/frontend/utils/quotaProjection.test.ts
+++ b/products/replay_vision/frontend/utils/quotaProjection.test.ts
@@ -45,6 +45,15 @@ describe('projectQuota', () => {
expect(proj.capReachDate).not.toBeNull()
})
+ it('danger when spend has passed the limit even without backend exhaustion', () => {
+ // The startup-cap display clamp can lower credit_limit below credits_used while exhausted stays false;
+ // that state must not read quieter than merely approaching the limit.
+ const proj = projectQuota(makeQuota({ credits_used: 12_000 }))
+ expect(proj.status).toBe('danger')
+ expect(proj.exhausted).toBe(false)
+ expect(proj.usedPct).toBe(120)
+ })
+
it('danger when explicitly exhausted regardless of the fleet rate', () => {
const proj = projectQuota(makeQuota({ credits_used: 10_000, remaining: 0, exhausted: true }))
expect(proj.status).toBe('danger')
diff --git a/products/replay_vision/frontend/utils/quotaProjection.ts b/products/replay_vision/frontend/utils/quotaProjection.ts
index 74008dbf24f0..64bf93739b09 100644
--- a/products/replay_vision/frontend/utils/quotaProjection.ts
+++ b/products/replay_vision/frontend/utils/quotaProjection.ts
@@ -82,8 +82,10 @@ export function projectQuota(
const capReachDate = combinedDailyRate > 0 && used < cap ? now.add((cap - used) / combinedDailyRate, 'day') : null
const capReachInPeriod = !!(capReachDate && periodEnd && capReachDate.isBefore(periodEnd))
+ // `used >= cap` without `exhausted`: a display clamp (startup cap) lowered the limit below spend,
+ // so the backend isn't blocking yet. Being over the limit must not read quieter than approaching it.
const status: QuotaStatus =
- quota.exhausted || capReachInPeriod
+ quota.exhausted || capReachInPeriod || used >= cap
? 'danger'
: projectedPeriodEndRatio >= QUOTA_WARN_THRESHOLD
? 'warning'
diff --git a/products/replay_vision/frontend/utils/startupCap.test.ts b/products/replay_vision/frontend/utils/startupCap.test.ts
new file mode 100644
index 000000000000..086c5f850810
--- /dev/null
+++ b/products/replay_vision/frontend/utils/startupCap.test.ts
@@ -0,0 +1,60 @@
+import { BillingType, StartupProgramLabel } from '~/types'
+
+import { makeQuota } from './quotaTestUtils'
+import { STARTUP_CAP_CREDITS, applyStartupCap, startupCapCredits } from './startupCap'
+
+describe('startupCap', () => {
+ it.each([
+ ['billing has not loaded', null, null],
+ ['the org is not on the startup program', {} as BillingType, null],
+ ['the org is enrolled', { startup_program_label: StartupProgramLabel.YC } as BillingType, STARTUP_CAP_CREDITS],
+ ])('startupCapCredits when %s', (_name, billing: BillingType | null, expected: number | null) => {
+ expect(startupCapCredits(billing)).toBe(expected)
+ })
+
+ it.each([
+ ['fills in the cap when billing reports no limit', null, STARTUP_CAP_CREDITS],
+ ['clamps a limit above the cap', STARTUP_CAP_CREDITS + 100_000, STARTUP_CAP_CREDITS],
+ ['keeps a self-set limit below the cap', 5_000, 5_000],
+ ['keeps a limit equal to the cap', STARTUP_CAP_CREDITS, STARTUP_CAP_CREDITS],
+ ])('%s', (_name, creditLimit: number | null, expected: number) => {
+ const capped = applyStartupCap(makeQuota({ credit_limit: creditLimit }), STARTUP_CAP_CREDITS)
+
+ expect(capped?.credit_limit).toBe(expected)
+ })
+
+ it.each([
+ { name: 'no cap applies', quota: makeQuota(), cap: null },
+ { name: 'there is no quota yet', quota: null, cap: STARTUP_CAP_CREDITS },
+ ])('passes the quota through untouched when $name', ({ quota, cap }) => {
+ expect(applyStartupCap(quota, cap)).toBe(quota)
+ })
+
+ it.each([
+ {
+ name: 'recomputes remaining against the cap when spend is under it',
+ creditLimit: null,
+ creditsUsed: 1_000,
+ remaining: STARTUP_CAP_CREDITS - 1_000,
+ exhausted: false,
+ },
+ {
+ name: 'never exhausts past the cap when billing has no real limit',
+ creditLimit: null,
+ creditsUsed: STARTUP_CAP_CREDITS + 5_000,
+ remaining: 0,
+ exhausted: false,
+ },
+ {
+ name: 'exhausts past the cap when billing has a real limit',
+ creditLimit: STARTUP_CAP_CREDITS + 100_000,
+ creditsUsed: STARTUP_CAP_CREDITS + 5_000,
+ remaining: 0,
+ exhausted: true,
+ },
+ ])('$name', ({ creditLimit, creditsUsed, remaining, exhausted }) => {
+ const quota = makeQuota({ credit_limit: creditLimit, credits_used: creditsUsed, remaining: null })
+
+ expect(applyStartupCap(quota, STARTUP_CAP_CREDITS)).toMatchObject({ remaining, exhausted })
+ })
+})
diff --git a/products/replay_vision/frontend/utils/startupCap.ts b/products/replay_vision/frontend/utils/startupCap.ts
new file mode 100644
index 000000000000..95f5c9d3c75c
--- /dev/null
+++ b/products/replay_vision/frontend/utils/startupCap.ts
@@ -0,0 +1,33 @@
+import { STARTUP_PROGRAM_BILLING_LIMIT_MAX } from 'scenes/billing/billingLimitConfig'
+
+import type { BillingType } from '~/types'
+
+import type { VisionQuotaApi } from '../generated/api.schemas'
+import { CREDITS_PER_DOLLAR } from './credits'
+
+/** Billing enforces this same ceiling server-side, in dollars. */
+export const STARTUP_CAP_CREDITS: number = STARTUP_PROGRAM_BILLING_LIMIT_MAX * CREDITS_PER_DOLLAR
+
+export const STARTUP_CAP_EXPLANATION = `Startup credits are shared across all PostHog products, so the startup program caps Replay vision spend at $${STARTUP_PROGRAM_BILLING_LIMIT_MAX.toLocaleString()} per month.`
+
+export function startupCapCredits(billing: BillingType | null): number | null {
+ return billing?.startup_program_label ? STARTUP_CAP_CREDITS : null
+}
+
+/** Display only: billing clamps the stored limit to the same cap, so this just covers orgs it hasn't reached yet. */
+export function applyStartupCap(quota: VisionQuotaApi | null, capCredits: number | null): VisionQuotaApi | null {
+ if (!quota || capCredits === null) {
+ return quota
+ }
+ const capped = quota.credit_limit === null ? capCredits : Math.min(quota.credit_limit, capCredits)
+ if (capped === quota.credit_limit) {
+ return quota
+ }
+ return {
+ ...quota,
+ credit_limit: capped,
+ remaining: Math.max(capped - quota.credits_used, 0),
+ // Only a real server-side limit can exhaust; the cap is advisory until billing clamps it.
+ exhausted: quota.credit_limit !== null && quota.credits_used >= capped,
+ }
+}