: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(visual-review): link quarantine banner to the failing run (#122279)
Raúl Negrón-Oteroba241b4f8358
diff --git a/products/visual_review/frontend/components/SnapshotCard.tsx b/products/visual_review/frontend/components/SnapshotCard.tsxindex 207c5f4d3221..fd7a54498d58 100644--- a/products/visual_review/frontend/components/SnapshotCard.tsx+++ b/products/visual_review/frontend/components/SnapshotCard.tsx@@ -10,6 +10,7 @@ import { urls } from 'scenes/urls'import type { BaselineEntryApi, BaselineQuarantineSummaryApi } from '../generated/api.schemas'import { parseArea, parseTheme } from '../lib/parseIdentifier'import { splitRepoFullName } from '../lib/repoPaths'+import { sourceRunPrNumber } from '../lib/runPredicates'// Drift is shown as a percentage with one decimal — anything less is sub-pixel// noise and not actionable; anything more on a thumbnail-sized card is illegible.@@ -56,7 +57,8 @@ function buildQuarantineTooltip(quarantine: BaselineQuarantineSummaryApi): JSX.Elines.push(`By ${name} · ${dayjs(quarantine.created_at).fromNow()}`)}if (quarantine.source_run) {- const prSuffix = quarantine.source_run.pr_number ? ` · PR #${quarantine.source_run.pr_number}` : ''+ const prNumber = sourceRunPrNumber(quarantine.source_run)+ const prSuffix = prNumber ? ` · PR #${prNumber}` : ''lines.push(`From ${quarantine.source_run.commit_sha.slice(0, 8)} on ${quarantine.source_run.branch}${prSuffix}`)}return (@@ -111,6 +113,7 @@ export function SnapshotCard({const hasMeta = driftVisible || tolerateCount > 0 || variantCount > 0 || entry.baseline_change_count > 0const quarantine = entry.quarantine ?? null+ const quarantinePrNumber = quarantine?.source_run ? sourceRunPrNumber(quarantine.source_run) : null// Yellow ring (not a 1px border) so the card pulls the eye in a grid// of hundreds — quarantine means "system stopped trusting this".const cardClassName = entry.is_quarantined@@ -251,8 +254,8 @@ export function SnapshotCard({</span>{quarantine.source_run && (<span className="font-mono shrink-0" title={`From run ${quarantine.source_run.commit_sha}`}>- {quarantine.source_run.pr_number- ? `PR #${quarantine.source_run.pr_number}`+ {quarantinePrNumber+ ? `PR #${quarantinePrNumber}`: quarantine.source_run.commit_sha.slice(0, 7)}</span>)}diff --git a/products/visual_review/frontend/lib/runPredicates.test.ts b/products/visual_review/frontend/lib/runPredicates.test.tsnew file mode 100644index 000000000000..192afe527434--- /dev/null+++ b/products/visual_review/frontend/lib/runPredicates.test.ts@@ -0,0 +1,23 @@+import type { QuarantineSourceRunApi } from '../generated/api.schemas'+import { sourceRunPrNumber } from './runPredicates'++function sourceRun(branch: string, prNumber: number | null): QuarantineSourceRunApi {+ return { id: 'run', branch, commit_sha: 'abc', created_at: '2026-01-01T00:00:00Z', pr_number: prNumber }+}++describe('sourceRunPrNumber', () => {+ test.each([+ ['merge-queue batch', 'trunk-merge/pr-121142/929572be-e2f5-4d9c-aca3-8ee7b777a173', 122057, 121142],+ [+ 'merge-queue bisection',+ 'trunk-merge/pr-121113/0cab0e58-11f4-4093-b568-b5271275f099-bisection',+ 122001,+ 121113,+ ],+ ['feature branch', 'fix/web-report-runs-newest-first', 120910, 120910],+ ['branch that only starts like a queue branch', 'trunk-merge/pr-abc/x', 120910, 120910],+ ['run without a PR', 'master', null, null],+ ])('%s', (_name, branch, prNumber, expected) => {+ expect(sourceRunPrNumber(sourceRun(branch, prNumber))).toBe(expected)+ })+})diff --git a/products/visual_review/frontend/lib/runPredicates.ts b/products/visual_review/frontend/lib/runPredicates.tsindex b0388147f53f..7a8ff4f8c969 100644--- a/products/visual_review/frontend/lib/runPredicates.ts+++ b/products/visual_review/frontend/lib/runPredicates.ts@@ -1,4 +1,4 @@-import type { RunApi } from '../generated/api.schemas'+import type { QuarantineSourceRunApi, RunApi } from '../generated/api.schemas'// CI submits tracking-only runs with purpose "observe" (default-branch pushes and merge-queue// runs), and the backend rejects approve/finalize on them. A merge-queue run keeps its PR number,@@ -7,3 +7,15 @@ import type { RunApi } from '../generated/api.schemas'export function isReportingOnlyRun(run: RunApi | null): boolean {return !!run && (run.purpose === 'observe' || run.pr_number == null)}++// A merge-queue run's `pr_number` is Trunk's shadow PR, whose body lists every PR it tests.+// The branch names only the first of them. Keep the pattern in sync with `_MERGE_QUEUE_BRANCH_RE` in the backend.+export function mergeQueueBatchLeaderPrNumber(branch: string): number | null {+ const match = /^trunk-merge\/pr-(\d+)\//.exec(branch)+ return match ? Number(match[1]) : null+}++/** The PR a quarantine's source run came from, preferring the batch leader over Trunk's shadow PR. */+export function sourceRunPrNumber(run: QuarantineSourceRunApi): number | null {+ return mergeQueueBatchLeaderPrNumber(run.branch) ?? run.pr_number ?? null+}diff --git a/products/visual_review/frontend/scenes/VisualReviewSnapshotHistoryScene.tsx b/products/visual_review/frontend/scenes/VisualReviewSnapshotHistoryScene.tsxindex 08f655662b0e..5714fe62ae5d 100644--- a/products/visual_review/frontend/scenes/VisualReviewSnapshotHistoryScene.tsx+++ b/products/visual_review/frontend/scenes/VisualReviewSnapshotHistoryScene.tsx@@ -21,6 +21,7 @@ import { VisualReviewTabs } from '../components/VisualReviewTabs'import { VisualReviewTrail } from '../components/VisualReviewTrail'import type { QuarantinedIdentifierEntryApi, SnapshotHistoryEntryApi } from '../generated/api.schemas'import { repoFullNameFromParams, runPath, splitRepoFullName } from '../lib/repoPaths'+import { mergeQueueBatchLeaderPrNumber } from '../lib/runPredicates'import {ThemePair,VisualReviewSnapshotHistorySceneLogicProps,@@ -182,130 +183,150 @@ function HistoryRow({)}-function QuarantineSection({+interface QuarantineVariant {+ identifier: string+ label: string | null+ quarantineEntry: QuarantinedIdentifierEntryApi | null+ onUnquarantine: () => void+}++function QuarantineBanner({identifier,label,quarantineEntry,- isQuarantined,onQuarantine,onUnquarantine,- runType,repoFullName,}: {identifier: string- runType: stringrepoFullName: string- label?: string | null- quarantineEntry: QuarantinedIdentifierEntryApi | null- isQuarantined: boolean+ label: string | null+ quarantineEntry: QuarantinedIdentifierEntryApionQuarantine: OnQuarantineonUnquarantine: () => void}): JSX.Element {- if (isQuarantined && quarantineEntry) {- const expires = quarantineEntry.expires_at ? new Date(quarantineEntry.expires_at) : null- const sourceRun = quarantineEntry.source_run ?? null- const openConfirmation = (): void => {- LemonDialog.open({- title: `Unquarantine ${label ? `(${label})` : 'this identifier'}?`,- description:- 'This identifier will be gated on again in future runs. ' +- "Branches that haven't merged the fix may get blocked.",- primaryButton: {- children: 'Unquarantine',- status: 'danger',- onClick: onUnquarantine,- },- secondaryButton: { children: 'Cancel' },- })- }- return (- <LemonBanner- type="warning"- // No `action` here — extend lives inline below so the user can- // see "what was wrong" first (the source-run link) before- // choosing to extend or unquarantine.- >- <div className="text-sm flex flex-col gap-1">- <div className="flex flex-wrap items-center gap-x-2 gap-y-1">- <span className="font-semibold">Quarantined{label && ` (${label})`}</span>- <span>— {quarantineEntry.reason || 'no reason given'}</span>- {expires && (- <>- <span aria-hidden>·</span>- <span>- until {expires.toLocaleDateString()}{' '}- <span className="text-muted">({dayjs(expires).fromNow()})</span>- </span>- </>- )}- {!expires && (+ const expires = quarantineEntry.expires_at ? new Date(quarantineEntry.expires_at) : null+ const sourceRun = quarantineEntry.source_run ?? null+ const batchLeaderPrNumber = sourceRun ? mergeQueueBatchLeaderPrNumber(sourceRun.branch) : null+ const pullUrl = (prNumber: number): string => `https://github.com/${repoFullName}/pull/${prNumber}`+ const openConfirmation = (): void => {+ LemonDialog.open({+ title: `Unquarantine ${label ? `(${label})` : 'this identifier'}?`,+ description:+ 'This identifier will be gated on again in future runs. ' ++ "Branches that haven't merged the fix may get blocked.",+ primaryButton: {+ children: 'Unquarantine',+ status: 'danger',+ onClick: onUnquarantine,+ },+ secondaryButton: { children: 'Cancel' },+ })+ }+ return (+ <LemonBanner type="warning">+ <div className="text-sm flex flex-col gap-1">+ <div className="flex flex-wrap items-center gap-x-2 gap-y-1">+ <span>+ <span className="font-semibold">Quarantined{label && ` (${label})`}:</span>{' '}+ {quarantineEntry.reason || 'no reason given'}+ </span>+ <span aria-hidden>·</span>+ {expires ? (+ <span>+ until {expires.toLocaleDateString()}{' '}+ <span className="text-muted">({dayjs(expires).fromNow()})</span>+ </span>+ ) : (+ <span className="text-muted">no expiry set</span>+ )}+ {quarantineEntry.created_by && (+ <>+ <span aria-hidden>·</span>+ <ProfilePicture user={quarantineEntry.created_by} size="xs" showName />+ </>+ )}+ </div>+ {sourceRun && (+ <div className="text-xs text-muted flex flex-wrap items-center gap-x-2 gap-y-0.5">+ {batchLeaderPrNumber ? (+ <span>+ Failed in the merge queue with{' '}+ <Link+ to={pullUrl(batchLeaderPrNumber)}+ target="_blank"+ className="font-mono"+ data-attr="visual-review-quarantine-merge-queue-pr"+ >+ #{batchLeaderPrNumber}+ </Link>+ </span>+ ) : (<>- <span aria-hidden>·</span>- <span className="text-muted">no expiry set</span>+ <span>Failed on</span>+ <span className="font-mono">{sourceRun.branch}</span></>)}- {quarantineEntry.created_by && (+ <span aria-hidden>·</span>+ <Link+ to={`https://github.com/${repoFullName}/commit/${sourceRun.commit_sha}`}+ target="_blank"+ className="font-mono"+ >+ {sourceRun.commit_sha.slice(0, 8)}+ </Link>+ {sourceRun.pr_number && (<><span aria-hidden>·</span>- <ProfilePicture user={quarantineEntry.created_by} size="xs" showName />+ <Link+ to={pullUrl(sourceRun.pr_number)}+ target="_blank"+ data-attr="visual-review-quarantine-source-pr"+ >+ {batchLeaderPrNumber ? (+ 'All PRs tested'+ ) : (+ <span className="font-mono">#{sourceRun.pr_number}</span>+ )}+ </Link></>)}+ <span aria-hidden>·</span>+ <TZLabel time={sourceRun.created_at} /></div>+ )}+ <div className="flex flex-wrap items-center gap-2 pt-1">{sourceRun && (- <div className="text-xs text-muted flex flex-wrap items-center gap-x-2 gap-y-0.5">- <span>Originally failed on</span>- <Link- to={runPath(sourceRun.id, repoFullName)}- className="font-mono text-default"- data-attr="visual-review-quarantine-source-run"- >- {sourceRun.commit_sha.slice(0, 8)}- </Link>- <span aria-hidden>·</span>- <span className="font-mono">{sourceRun.branch}</span>- {sourceRun.pr_number && (- <>- <span aria-hidden>·</span>- <span className="font-mono">PR #{sourceRun.pr_number}</span>- </>- )}- <span aria-hidden>·</span>- <TZLabel time={sourceRun.created_at} />- </div>- )}- <div className="flex items-center gap-2 pt-1">- <QuarantineAction- identifier={identifier}- onQuarantine={onQuarantine}- mode="extend"- triggerLabel={label ? `Extend (${label})` : 'Extend quarantine'}- initialReason={quarantineEntry.reason}- initialExpiresAt={quarantineEntry.expires_at}- sourceRunId={sourceRun?.id ?? null}- /><LemonButtontype="secondary"size="small"- status="danger"- onClick={openConfirmation}- data-attr="visual-review-history-unquarantine"+ to={runPath(sourceRun.id, repoFullName)}+ data-attr="visual-review-quarantine-source-run">- Unquarantine+ View run</LemonButton>- </div>+ )}+ <QuarantineAction+ identifier={identifier}+ onQuarantine={onQuarantine}+ mode="extend"+ triggerLabel={label ? `Extend (${label})` : 'Extend quarantine'}+ initialReason={quarantineEntry.reason}+ initialExpiresAt={quarantineEntry.expires_at}+ sourceRunId={sourceRun?.id ?? null}+ />+ <LemonButton+ type="secondary"+ size="small"+ status="danger"+ onClick={openConfirmation}+ data-attr="visual-review-history-unquarantine"+ >+ Unquarantine+ </LemonButton></div>- </LemonBanner>- )- }- return (- <div className="flex items-center justify-end">- <QuarantineAction- identifier={identifier}- onQuarantine={onQuarantine}- triggerLabel={label ? `Quarantine (${label})` : undefined}- runType={runType}- />- </div>+ </div>+ </LemonBanner>)}@@ -343,9 +364,24 @@ export function VisualReviewSnapshotHistoryScene(): JSX.Element {const repoFullName: string = repo?.repo_full_name ?? pathRepoFullNameconst firstSeen = history.length > 0 ? history[history.length - 1].created_at : nullconst baselineUpdates = Math.max(0, history.length - 1)- const isQuarantined = !!quarantineEntry- const isSiblingQuarantined = !!siblingQuarantineEntryconst hasThemePair = primaryTheme !== null && siblingIdentifier !== null+ const loadedVariants: QuarantineVariant[] = []+ if (!quarantineEntryLoading) {+ loadedVariants.push({+ identifier,+ label: hasThemePair ? primaryTheme : null,+ quarantineEntry,+ onUnquarantine: unquarantineIdentifier,+ })+ }+ if (hasThemePair && !siblingQuarantineEntryLoading) {+ loadedVariants.push({+ identifier: siblingIdentifier,+ label: primaryTheme === 'light' ? 'dark' : 'light',+ quarantineEntry: siblingQuarantineEntry,+ onUnquarantine: unquarantineSibling,+ })+ }if (repoNotFound) {return <NotFound object="visual review repo" />@@ -394,47 +430,34 @@ export function VisualReviewSnapshotHistoryScene(): JSX.Element {}label="Repo"/>+ <div className="ml-auto flex flex-wrap items-center gap-2">+ {loadedVariants+ .filter((variant) => !variant.quarantineEntry)+ .map((variant) => (+ <QuarantineAction+ key={variant.identifier}+ identifier={variant.identifier}+ onQuarantine={quarantineIdentifier}+ triggerLabel={variant.label ? `Quarantine (${variant.label})` : undefined}+ runType={runType}+ />+ ))}+ </div></div>- {hasThemePair ? (- <div className="grid grid-cols-2 gap-2">- {!quarantineEntryLoading && (- <QuarantineSection- identifier={identifier}- runType={runType}- repoFullName={repoFullName}- label={primaryTheme}- quarantineEntry={quarantineEntry}- isQuarantined={isQuarantined}- onQuarantine={quarantineIdentifier}- onUnquarantine={unquarantineIdentifier}- />- )}- {!siblingQuarantineEntryLoading && (- <QuarantineSection- identifier={siblingIdentifier}- runType={runType}+ {loadedVariants.map(+ (variant) =>+ variant.quarantineEntry && (+ <QuarantineBanner+ key={variant.identifier}+ identifier={variant.identifier}repoFullName={repoFullName}- label={primaryTheme === 'light' ? 'dark' : 'light'}- quarantineEntry={siblingQuarantineEntry}- isQuarantined={isSiblingQuarantined}+ label={variant.label}+ quarantineEntry={variant.quarantineEntry}onQuarantine={quarantineIdentifier}- onUnquarantine={unquarantineSibling}+ onUnquarantine={variant.onUnquarantine}/>- )}- </div>- ) : (- !quarantineEntryLoading && (- <QuarantineSection- identifier={identifier}- runType={runType}- repoFullName={repoFullName}- quarantineEntry={quarantineEntry}- isQuarantined={isQuarantined}- onQuarantine={quarantineIdentifier}- onUnquarantine={unquarantineIdentifier}- />- )+ ))}{historyLoading || repoLoading ? (