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(visual-review): stop offering approval that cannot succeed (#106955)

posthog[bot]92a36cb701cc
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 0a2f353f4766..9b51ade5979d 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -13030,14 +13030,22 @@ snapshots:
hash: v1.k794b7964.879549ba86b942a0497ef5b08bb0172ac58c62fe8da41a21584c82bea231db20.lG7LsOxr5tzXDBwFMJwt3c7IgoQuIH6h8qlUZnPNJVw
scenes-app-visual-review-run--ready-to-finalize--light:
hash: v1.k794b7964.197e6fe1cc9dba0da720ef1e1cfc94b3601d775aa389e49230465a2b65797d47.Tqyss84UbEfq4Gra3v9eMtLs4zfONfl5fSfff9FlmZA
+ scenes-app-visual-review-run--removed-snapshot--dark:
+ hash: v1.k794b7964.cf6e85f2cd90ce4e409779ef1bfbee5d10393bc479f41d3e50d03cba33693312.NmmpL2GTe2k2F-HE9fFlM5VWtpfPt8EZ5VuE3-JLE9c
+ scenes-app-visual-review-run--removed-snapshot--light:
+ hash: v1.k794b7964.0a560a35b82eb383220ef16017363f6aed5f6fc9b376517753dc7de6bd80a0f5.EdWHF5M5586Q6V9-hmDTM_OfZHDiZiJ2Si2DtO3ijf8
scenes-app-visual-review-run--tolerate-suggests-quarantine--dark:
hash: v1.k794b7964.01b906bdb8448973bb5a655f0ea96dbf42ba0def73d179ce3f1c2779d603d1cd.ZVbpVkiu1tofZS8NcQ8DpGM57DqjoiC5vDWQnPKEscw
scenes-app-visual-review-run--tolerate-suggests-quarantine--light:
hash: v1.k794b7964.423d5d2ad0d7ef00ba976f5455835ba0c518c8d7c86a7a2a359c8af4b1eab648.V47tBu61Pg3UnMCcefNn1D4VzvUXv5-qQU8_qkyk3_k
scenes-app-visual-review-run--tracking-only-master-run--dark:
- hash: v1.k794b7964.12ad60f78c9ac28eac9811dfe25cef1900c2887af2d940c357cc4c0741be912a.nXTRF_gA3j8NrvRhkrth4eGcISgQgW4LrgOd5-Pl2x8
+ hash: v1.k794b7964.e59e3231d8f3819b93e106857cf4facc9f1b0869ab5e811ac34e426d71231122.U_WoHysJq5Ejuf0w4Y3p2DvGbfug2wbN4bpwLRRmoRY
scenes-app-visual-review-run--tracking-only-master-run--light:
- hash: v1.k794b7964.671a38949e4cde3777432b0348bfc3db9dec13dbf98d8e0a4095a7e9c212d635.gFNG2t8UNO3MXMn7Di9NVVO9Ws_7PvMQEUBB_tTXn_c
+ hash: v1.k794b7964.9df045cf6656b4a3368311725e6a2ebe7bc219a623f2261c4d413a1de46dfe46.VisEM7d1gjJ-3JYkN8dDNK0_aerTjYCZz0q6x9DA0KE
+ scenes-app-visual-review-run--tracking-only-merge-queue-run--dark:
+ hash: v1.k794b7964.263baaa86027f58e5dc7a282d2142703e8761e4a5048d0438aeea7f36c2a13cb.mhocFfJnwA7n9J-yj1jIvCVUZPHlXw5dxn-mRhHnDY8
+ scenes-app-visual-review-run--tracking-only-merge-queue-run--light:
+ hash: v1.k794b7964.e43050321d087de05b71ba56cc2324af5fb9e593b2cc47e43dd7028b6a8333b9.cU1JJMaO53XDwKdykPxvEAiRWiyJloyITpU5-Ctg4N8
scenes-app-web-analytics--web-analytics-dashboard--dark:
hash: v1.k794b7964.d633e702e43e79c58f10610a823818f7d79717d49a670e6c85c6410d894b7d58.cegK9GTI0OfzEn0BkTrnAKcM5Q6u1KpT53hyljMVPBU
scenes-app-web-analytics--web-analytics-dashboard--light:
diff --git a/products/visual_review/backend/facade/api.py b/products/visual_review/backend/facade/api.py
index de79fec78ef2..88fa5c484186 100644
--- a/products/visual_review/backend/facade/api.py
+++ b/products/visual_review/backend/facade/api.py
@@ -248,6 +248,7 @@ def _to_run(
error_message=run.error_message or None,
created_at=run.created_at,
completed_at=run.completed_at,
+ purpose=run.purpose,
is_stale=run_queries.is_run_stale(run),
superseded_by_id=run.superseded_by_id,
approved_by=approved_by,
diff --git a/products/visual_review/backend/facade/contracts.py b/products/visual_review/backend/facade/contracts.py
index 04d4d054f1b3..d93862bf4762 100644
--- a/products/visual_review/backend/facade/contracts.py
+++ b/products/visual_review/backend/facade/contracts.py
@@ -352,6 +352,7 @@ class Run:
error_message: str | None
created_at: datetime
completed_at: datetime | None
+ purpose: str = "review"
is_stale: bool = False
superseded_by_id: UUID | None = None
approved_by: UserBasicInfo | None = None
diff --git a/products/visual_review/backend/presentation/serializers.py b/products/visual_review/backend/presentation/serializers.py
index 8eee6fff758c..e583eb3d1674 100644
--- a/products/visual_review/backend/presentation/serializers.py
+++ b/products/visual_review/backend/presentation/serializers.py
@@ -51,7 +51,7 @@ from ..facade.contracts import (
UploadTarget,
UserBasicInfo,
)
-from ..facade.enums import FlakinessState, ShiftBandKind
+from ..facade.enums import FlakinessState, RunPurpose, ShiftBandKind
# --- Output Serializers ---
@@ -143,6 +143,14 @@ class SnapshotSerializer(DataclassSerializer):
class RunSerializer(DataclassSerializer):
approved_by = UserBasicInfoSerializer(allow_null=True, required=False)
+ purpose = serializers.ChoiceField(
+ choices=[p.value for p in RunPurpose],
+ read_only=True,
+ help_text=(
+ "Why CI submitted the run. `review` runs gate the PR and need approval. `observe` runs are "
+ "tracking-only, for example default-branch pushes and merge-queue runs, and can never be approved."
+ ),
+ )
search_match_type = serializers.ChoiceField(
choices=["exact", "similar"],
allow_null=True,
diff --git a/products/visual_review/backend/tests/test_presentation.py b/products/visual_review/backend/tests/test_presentation.py
index 871b28d3f96e..21ce9a48d05a 100644
--- a/products/visual_review/backend/tests/test_presentation.py
+++ b/products/visual_review/backend/tests/test_presentation.py
@@ -13,7 +13,7 @@ from posthog.helpers.trigram_search import MAX_SEARCH_LENGTH
from products.visual_review.backend.facade import api
from products.visual_review.backend.facade.contracts import CreateRunInput, SnapshotManifestItem
-from products.visual_review.backend.facade.enums import RunStatus, RunType, SnapshotResult
+from products.visual_review.backend.facade.enums import RunPurpose, RunStatus, RunType, SnapshotResult
from products.visual_review.backend.logic import artifact_store, quarantine, runs
from products.visual_review.backend.models import Run, RunSnapshot
from products.visual_review.backend.tests.conftest import PRODUCT_DATABASES, VisualReviewTeamScopedTestMixin
@@ -185,7 +185,9 @@ class TestRunViewSet(VisualReviewTeamScopedTestMixin, APIBaseTest):
repo_id=self.vr_project.id,
run_type=RunType.STORYBOOK,
commit_sha="abc123",
- branch="main",
+ branch="trunk-merge/pr-42",
+ pr_number=42,
+ purpose=RunPurpose.OBSERVE,
snapshots=[],
),
team_id=self.team.id,
@@ -197,6 +199,7 @@ class TestRunViewSet(VisualReviewTeamScopedTestMixin, APIBaseTest):
data = response.json()
self.assertEqual(data["commit_sha"], "abc123")
self.assertEqual(data["status"], "pending")
+ self.assertEqual(data["purpose"], "observe")
def test_get_run_snapshots(self):
create_result = api.create_run(
diff --git a/products/visual_review/frontend/components/SnapshotDiffViewer.tsx b/products/visual_review/frontend/components/SnapshotDiffViewer.tsx
index dad9aaf08f5f..f086b6f7bd4c 100644
--- a/products/visual_review/frontend/components/SnapshotDiffViewer.tsx
+++ b/products/visual_review/frontend/components/SnapshotDiffViewer.tsx
@@ -248,6 +248,11 @@ export function SnapshotDiffViewer({
size="small"
onClick={onApprove}
loading={isApproving}
+ disabledReason={
+ snapshot.result === 'removed'
+ ? 'A removed snapshot has no new image to accept. Finalize the run to remove it from the baseline.'
+ : undefined
+ }
data-attr="visual-review-snapshot-accept"
>
Accept change
diff --git a/products/visual_review/frontend/generated/api.schemas.ts b/products/visual_review/frontend/generated/api.schemas.ts
index f7a037643fc3..49f3172a1f93 100644
--- a/products/visual_review/frontend/generated/api.schemas.ts
+++ b/products/visual_review/frontend/generated/api.schemas.ts
@@ -336,6 +336,17 @@ export interface TolerationPileupsApi {
generated_at: string
}
+/**
+ * * `review` - review
+ * * `observe` - observe
+ */
+export type PurposeEnumApi = (typeof PurposeEnumApi)[keyof typeof PurposeEnumApi]
+
+export const PurposeEnumApi = {
+ Review: 'review',
+ Observe: 'observe',
+} as const
+
export type SearchMatchTypeEnumApi = (typeof SearchMatchTypeEnumApi)[keyof typeof SearchMatchTypeEnumApi]
export const SearchMatchTypeEnumApi = {
@@ -357,6 +368,11 @@ export type RunApiMetadata = { [key: string]: unknown }
export interface RunApi {
approved_by?: UserBasicInfoApi | null
+ /** Why CI submitted the run. `review` runs gate the PR and need approval. `observe` runs are tracking-only, for example default-branch pushes and merge-queue runs, and can never be approved.
+ *
+ * * `review` - review
+ * * `observe` - observe */
+ readonly purpose: PurposeEnumApi
/** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of branch/run type, a commit SHA prefix, or an exact PR number) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`.
*
* * `exact` - exact
diff --git a/products/visual_review/frontend/lib/runPredicates.ts b/products/visual_review/frontend/lib/runPredicates.ts
index 0bc419adcb98..b0388147f53f 100644
--- a/products/visual_review/frontend/lib/runPredicates.ts
+++ b/products/visual_review/frontend/lib/runPredicates.ts
@@ -1,9 +1,9 @@
import type { RunApi } from '../generated/api.schemas'
-// A run with no PR is a default-branch (master/main) push: tracking-only, never approvable.
-// CI submits these with purpose "observe", and the backend rejects approve/finalize on them,
-// so the UI must never offer an approval that can't apply. The run API doesn't expose `purpose`
-// yet, so PR presence is the proxy — it matches the backend's needs_review filter.
+// 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,
+// so PR presence alone is not enough. A run with no PR also stays tracking-only, which matches
+// the backend's needs_review filter.
export function isReportingOnlyRun(run: RunApi | null): boolean {
- return !!run && run.pr_number == null
+ return !!run && (run.purpose === 'observe' || run.pr_number == null)
}
diff --git a/products/visual_review/frontend/scenes/VisualReviewRunScene.stories.tsx b/products/visual_review/frontend/scenes/VisualReviewRunScene.stories.tsx
index 38a0a0f851e9..3b9750442bdb 100644
--- a/products/visual_review/frontend/scenes/VisualReviewRunScene.stories.tsx
+++ b/products/visual_review/frontend/scenes/VisualReviewRunScene.stories.tsx
@@ -48,6 +48,7 @@ const run: RunApi = {
error_message: null,
created_at: '2026-06-10T00:00:00Z',
completed_at: '2026-06-10T00:01:00Z',
+ purpose: 'review',
is_stale: false,
metadata: {},
search_match_type: null,
@@ -138,6 +139,14 @@ const masterRun: RunApi = {
...run,
branch: 'master',
pr_number: null,
+ purpose: 'observe',
+}
+
+// A merge-queue run keeps its PR number but is tracking-only, so it must not offer approval either.
+const mergeQueueRun: RunApi = {
+ ...run,
+ branch: 'trunk-merge/pr-42',
+ purpose: 'observe',
}
const emptyList = { count: 0, next: null, previous: null, results: [] }
@@ -184,6 +193,52 @@ export const TrackingOnlyMasterRun: StoryObj = {
],
}
+export const TrackingOnlyMergeQueueRun: StoryObj = {
+ parameters: {
+ testOptions: { waitForSelector: '[data-attr="visual-review-snapshot-thumbnail"]' },
+ },
+ decorators: [
+ mswDecorator({
+ get: {
+ [`/api/projects/:team_id/visual_review/runs/${RUN_ID}/`]: mergeQueueRun,
+ },
+ }),
+ ],
+}
+
+// A removed snapshot has no current image, so "Accept change" is disabled and finalize prunes it.
+export const RemovedSnapshot: StoryObj = {
+ parameters: {
+ testOptions: { waitForSelector: '[data-attr="visual-review-snapshot-accept"]' },
+ },
+ decorators: [
+ mswDecorator({
+ get: {
+ [`/api/projects/:team_id/visual_review/runs/${RUN_ID}/`]: {
+ ...run,
+ summary: { total: 1, changed: 0, new: 0, removed: 1, unchanged: 0 },
+ },
+ [`/api/projects/:team_id/visual_review/runs/${RUN_ID}/snapshots/`]: {
+ count: 1,
+ next: null,
+ previous: null,
+ quarantined_count: 0,
+ results: [
+ snapshot({
+ id: 'snapshot-removed',
+ identifier: 'Components/Legacy--card',
+ result: 'removed',
+ diff_percentage: null,
+ diff_pixel_count: null,
+ baseline_artifact: artifact('base_removed'),
+ }),
+ ],
+ },
+ },
+ }),
+ ],
+}
+
const repeatedTolerations = {
count: 3,
next: null,
diff --git a/products/visual_review/frontend/scenes/VisualReviewRunScene.tsx b/products/visual_review/frontend/scenes/VisualReviewRunScene.tsx
index 6e6daeaca801..7873c9d32575 100644
--- a/products/visual_review/frontend/scenes/VisualReviewRunScene.tsx
+++ b/products/visual_review/frontend/scenes/VisualReviewRunScene.tsx
@@ -420,8 +420,8 @@ export function VisualReviewRunScene(): JSX.Element {
{isReportingOnly && (
<LemonBanner type="info" className="mb-4">
- Tracking-only run — this is a push to the default branch, so there's nothing to approve. Visual
- changes are recorded for history and reported to GitHub as a non-blocking status.
+ Tracking-only run, so there's nothing to approve. Default-branch pushes and merge-queue runs record
+ visual changes for history and report them to GitHub as a non-blocking status.
</LemonBanner>
)}
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 9cf3c3815ef4..7f41a1e66c70 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -49358,6 +49358,18 @@ export namespace Schemas {
size_bytes: number;
}
+ /**
+ * * `review` - review
+ * * `observe` - observe
+ */
+ export type PurposeEnum = typeof PurposeEnum[keyof typeof PurposeEnum];
+
+
+ export const PurposeEnum = {
+ Review: 'review',
+ Observe: 'observe',
+ } as const;
+
export interface RunSummary {
total: number;
changed: number;
@@ -49372,6 +49384,11 @@ export namespace Schemas {
export interface Run {
approved_by?: UserBasicInfo | null;
+ /** Why CI submitted the run. `review` runs gate the PR and need approval. `observe` runs are tracking-only, for example default-branch pushes and merge-queue runs, and can never be approved.
+ *
+ * * `review` - review
+ * * `observe` - observe */
+ readonly purpose: PurposeEnum;
/** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of branch/run type, a commit SHA prefix, or an exact PR number) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`.
*
* * `exact` - exact