: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(devex): vr approve quarantined changed (#103662)
Julian Bez3a81fee61825
diff --git a/products/visual_review/README.md b/products/visual_review/README.mdindex 067715e0cfc3..06c90f10b704 100644--- a/products/visual_review/README.md+++ b/products/visual_review/README.md@@ -237,9 +237,11 @@ The cap is measured against the committed baseline on every run, so absorbed shi**Quarantine** — known-flaky identifiers can be quarantined per repo and run type.Quarantined snapshots are still captured and diffed but excluded from gating.-A quarantined snapshot is not committed to the baseline, with one exception: a quarantined `new` snapshot that a person approved by identifier.-This is the way to give a story a baseline entry when it has none and the quarantine must stay, because every run without the entry classifies the story `new`, and lifting the quarantine first fails every run until the entry lands.-The procedure is: open a PR that renders the story, approve the `new` snapshot on that run by identifier (the API or the `visual-review-runs-approve-create` MCP tool; "Approve all" skips quarantined snapshots), finalize the run so the entry is committed to the PR branch, then merge the PR.+A quarantined snapshot reaches the baseline only when a person approves it by identifier, because "Approve all" skips quarantined snapshots.+This is how a quarantined story's entry keeps up with the story.+The story still renders on every run, so a code change to it makes the entry stale while the quarantine hides the drift, and every run fails on the day the quarantine is lifted or expires.+It is also how a story gets an entry when it has none and the quarantine must stay, because every run without the entry classifies the story `new`, and lifting the quarantine first fails every run until the entry lands.+The procedure is: open a PR that renders the story, approve the `changed` or `new` snapshot on that run by identifier (the API or the `visual-review-runs-approve-create` MCP tool), finalize the run so the entry is committed to the PR branch, then merge the PR.Keep the quarantine on after the merge.An entry on the default branch does not reach a branch that forked before it, and healing cannot supply it either: healing reads the merge-base, which for such a branch also predates the entry.diff --git a/products/visual_review/backend/logic/approvals.py b/products/visual_review/backend/logic/approvals.pyindex 56b53d56092a..b40ca1e4be44 100644--- a/products/visual_review/backend/logic/approvals.py+++ b/products/visual_review/backend/logic/approvals.py@@ -30,7 +30,7 @@ def finalize_run(derived from DB state — exactly the snapshots with ``review_state == APPROVED``, bytheir approved hash — so a tolerated snapshot keeps its existing baseline and isnever silently overwritten, and the commit always contains the full approved set- regardless of how many calls it took to review them. A quarantined NEW snapshot that+ regardless of how many calls it took to review them. A quarantined snapshot thatwas approved by identifier is committed too (see ``_approved_baseline_updates``).With ``approve_all=True`` every still-pending changed/new snapshot is approved first@@ -95,7 +95,7 @@ def finalize_run(# Commit set is derived from DB state, not a caller-supplied list, so it always reflects# the full approved set however many calls reviewed it. It reads every snapshot, not only- # the actionable ones, so an approved quarantined NEW snapshot reaches the commit.+ # the actionable ones, so an approved quarantined snapshot reaches the commit.approved_updates = baselines._approved_baseline_updates(run.snapshots.using(WRITER_DB).all())has_removed = run.snapshots.using(WRITER_DB).filter(result=SnapshotResult.REMOVED).exists()diff --git a/products/visual_review/backend/logic/baselines.py b/products/visual_review/backend/logic/baselines.pyindex 51550b7f7b11..1011a9b69881 100644--- a/products/visual_review/backend/logic/baselines.py+++ b/products/visual_review/backend/logic/baselines.py@@ -285,17 +285,16 @@ def _approved_baseline_updates(snapshots: Iterable[RunSnapshot]) -> list[dict]:Derived from DB state so the commit always reflects every approval regardless of howmany calls it took. Tolerated snapshots are excluded — toleration never updates the baseline.- Quarantine keeps a flapping hash out of the baseline, so a quarantined CHANGED snapshot is- excluded even when approved. A quarantined NEW snapshot has no baseline entry to protect,- and only a per-identifier approval can mark it (bulk approve skips quarantined rows), so an- approved one is committed. Without this a story that lost its entry while quarantined could- never get one back: lifting the quarantine fails every run until the entry lands.+ Quarantined snapshots are committed when approved, because only a per-identifier approval+ can mark one: bulk approve skips quarantined rows, so a flapping hash never lands by accident.+ A quarantined story still renders on every run. If its baseline cannot move while it is+ quarantined, a code change to the story leaves the entry stale, and the drift fails every+ run on the day the quarantine is lifted or expires."""return [{"identifier": s.identifier, "new_hash": s.approved_hash}for s in snapshots- if s.review_state == ReviewState.APPROVED- and (s.result == SnapshotResult.NEW or (s.result == SnapshotResult.CHANGED and not s.is_quarantined))+ if s.review_state == ReviewState.APPROVED and s.result in (SnapshotResult.NEW, SnapshotResult.CHANGED)]diff --git a/products/visual_review/backend/presentation/views.py b/products/visual_review/backend/presentation/views.pyindex ea73fe0c4f30..50968731833b 100644--- a/products/visual_review/backend/presentation/views.py+++ b/products/visual_review/backend/presentation/views.py@@ -719,8 +719,8 @@ class RunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):Records the per-snapshot "Accept change" decision. Does not commit the baselineor change the GitHub gate — call finalize to ship the run. Works on a quarantined- snapshot too: a quarantined NEW snapshot approved here is committed by finalize,- which gives a quarantined story a baseline entry without lifting the quarantine.+ snapshot too: a quarantined snapshot approved here is committed by finalize, which+ updates a quarantined story's baseline entry without lifting the quarantine."""body = request.validated_datarun_id = _parse_uuid(pk)@@ -750,7 +750,7 @@ class RunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):Commits exactly the snapshots approved in the DB (tolerated ones keep their baseline)and only succeeds once every changed/new snapshot is resolved. With approve_all=true,any still-pending changed/new snapshot is approved first; quarantined snapshots are- skipped, but a quarantined NEW snapshot approved by identifier is still committed.+ skipped, but a quarantined snapshot approved by identifier is still committed.With commit_to_github=false the server returns the signed baseline YAML instead ofcommitting it."""diff --git a/products/visual_review/backend/tests/logic/test_approvals.py b/products/visual_review/backend/tests/logic/test_approvals.pyindex 013f78945d14..d669666b6bc5 100644--- a/products/visual_review/backend/tests/logic/test_approvals.py+++ b/products/visual_review/backend/tests/logic/test_approvals.py@@ -160,15 +160,16 @@ class TestApproveRun:("result", "approve_all", "expect_committed"),[("new", False, True),- ("changed", False, False),+ ("changed", False, True),("new", True, False),+ ("changed", True, False),],)- def test_finalize_commits_quarantined_new_only_when_approved_by_identifier(+ def test_finalize_commits_quarantined_only_when_approved_by_identifier(self, repo, user, mocker, result, approve_all, expect_committed):- # A quarantined NEW snapshot has no entry to protect, so an explicit approval lands in the- # commit. A quarantined CHANGED one keeps its entry, and approve_all never touches quarantine.+ # An explicit approval commits a quarantined snapshot, so its baseline can follow the story.+ # approve_all never touches quarantine, so a flapping hash cannot land in bulk.run = self._completed_quarantined_run(repo, mocker, result)if not approve_all:approvals.approve_snapshots(diff --git a/products/visual_review/frontend/generated/api.ts b/products/visual_review/frontend/generated/api.tsindex 7f25aa750c1d..ac117665ffcb 100644--- a/products/visual_review/frontend/generated/api.ts+++ b/products/visual_review/frontend/generated/api.ts@@ -483,8 +483,8 @@ export const getVisualReviewRunsApproveCreateUrl = (projectId: string, id: strin** Records the per-snapshot "Accept change" decision. Does not commit the baseline* or change the GitHub gate — call finalize to ship the run. Works on a quarantined- * snapshot too: a quarantined NEW snapshot approved here is committed by finalize,- * which gives a quarantined story a baseline entry without lifting the quarantine.+ * snapshot too: a quarantined snapshot approved here is committed by finalize, which+ * updates a quarantined story's baseline entry without lifting the quarantine.*/export const visualReviewRunsApproveCreate = async (projectId: string,@@ -528,7 +528,7 @@ export const getVisualReviewRunsFinalizeCreateUrl = (projectId: string, id: stri* Commits exactly the snapshots approved in the DB (tolerated ones keep their baseline)* and only succeeds once every changed/new snapshot is resolved. With approve_all=true,* any still-pending changed/new snapshot is approved first; quarantined snapshots are- * skipped, but a quarantined NEW snapshot approved by identifier is still committed.+ * skipped, but a quarantined snapshot approved by identifier is still committed.* With commit_to_github=false the server returns the signed baseline YAML instead of* committing it.*/diff --git a/products/visual_review/frontend/generated/api.zod.ts b/products/visual_review/frontend/generated/api.zod.tsindex 8fa29dae8dcf..545077052c90 100644--- a/products/visual_review/frontend/generated/api.zod.ts+++ b/products/visual_review/frontend/generated/api.zod.ts@@ -124,8 +124,8 @@ export const VisualReviewRunsAddSnapshotsCreateBody = /* @__PURE__ */ zod.object** Records the per-snapshot "Accept change" decision. Does not commit the baseline* or change the GitHub gate — call finalize to ship the run. Works on a quarantined- * snapshot too: a quarantined NEW snapshot approved here is committed by finalize,- * which gives a quarantined story a baseline entry without lifting the quarantine.+ * snapshot too: a quarantined snapshot approved here is committed by finalize, which+ * updates a quarantined story's baseline entry without lifting the quarantine.*/export const VisualReviewRunsApproveCreateBody = /* @__PURE__ */ zod.object({snapshots: zod@@ -150,7 +150,7 @@ export const VisualReviewRunsApproveCreateBody = /* @__PURE__ */ zod.object({* Commits exactly the snapshots approved in the DB (tolerated ones keep their baseline)* and only succeeds once every changed/new snapshot is resolved. With approve_all=true,* any still-pending changed/new snapshot is approved first; quarantined snapshots are- * skipped, but a quarantined NEW snapshot approved by identifier is still committed.+ * skipped, but a quarantined snapshot approved by identifier is still committed.* With commit_to_github=false the server returns the signed baseline YAML instead of* committing it.*/diff --git a/services/mcp/src/generated/visual_review/api.ts b/services/mcp/src/generated/visual_review/api.tsindex e5c35292de30..6f81688361c7 100644--- a/services/mcp/src/generated/visual_review/api.ts+++ b/services/mcp/src/generated/visual_review/api.ts@@ -162,8 +162,8 @@ export const VisualReviewRunsRetrieveParams = () => zod.object({** Records the per-snapshot "Accept change" decision. Does not commit the baseline* or change the GitHub gate — call finalize to ship the run. Works on a quarantined- * snapshot too: a quarantined NEW snapshot approved here is committed by finalize,- * which gives a quarantined story a baseline entry without lifting the quarantine.+ * snapshot too: a quarantined snapshot approved here is committed by finalize, which+ * updates a quarantined story's baseline entry without lifting the quarantine.*/export const VisualReviewRunsApproveCreateParams = () => zod.object({id: zod.string(),@@ -197,7 +197,7 @@ export const VisualReviewRunsApproveCreateBody = () => zod.object({* Commits exactly the snapshots approved in the DB (tolerated ones keep their baseline)* and only succeeds once every changed/new snapshot is resolved. With approve_all=true,* any still-pending changed/new snapshot is approved first; quarantined snapshots are- * skipped, but a quarantined NEW snapshot approved by identifier is still committed.+ * skipped, but a quarantined snapshot approved by identifier is still committed.* With commit_to_github=false the server returns the signed baseline YAML instead of* committing it.*/