: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(review_hog): check out the PR head branch by name in review sandboxes (#88775)
Alex Lebedeve2e11a96c6e4
diff --git a/products/review_hog/DECISIONS.md b/products/review_hog/DECISIONS.mdindex 4b4b28aaa994..12e8a07e018f 100644--- a/products/review_hog/DECISIONS.md+++ b/products/review_hog/DECISIONS.md@@ -3908,3 +3908,18 @@ resolution died silently at sandbox checkout. Decisions, in one PR:Vocabulary added to CONTEXT.md: **Review cycle**, **Busy-guard**. ADR: `adr/0001-resolution-is-a-separate-workflow.md`(kept resolution a separate workflow after challenging it — standalone mode, failure isolation, independentversioning outweigh the manual seam).++## Sandbox checkout ref: head branch by name (2026-08-25, maintainer decision)++Review sandboxes check out the PR's **head branch by name** again. The 2026-07-15 switch to `pull/N/head` (meant to+survive a mid-review merge, which deletes the head branch) never worked: the Tasks checkout resolves only+`refs/heads/<name>`, so the pull ref fell through to a fresh local branch on the base tip and every review+sandbox investigated the base branch instead of the PR. Invisible while base ≈ PR; loud once the base carried+later fixes — validators dismissed real findings as "already fixed" because the tree they examined was master.+The reviewer's findings still came from the diff pasted into its prompt, so review volume never dropped.+Residual gap (not a loud failure): if a mid-review merge deletes the head branch, the Tasks checkout does not+raise — `git ls-remote --exit-code --heads origin refs/heads/<name>` returns exit 2 and `checkout_branch_in_sandbox`+falls back to a fresh branch on the base tip. A later checkout can then still land on the base tree, but only for+checkouts after the branch is gone, not the whole review as the 2026-07-15 regression did. Closing that window —+a strict checkout that fails on a missing head branch, or a proper `refs/pull/N/head` fetch — belongs in the Tasks+checkout, out of scope here.diff --git a/products/review_hog/backend/temporal/activities.py b/products/review_hog/backend/temporal/activities.pyindex 7c64e49f5bc1..ff1887e9ddbd 100644--- a/products/review_hog/backend/temporal/activities.py+++ b/products/review_hog/backend/temporal/activities.py@@ -588,9 +588,10 @@ def _fetch_and_persist(input: FetchPRDataInput) -> ReviewMeta:return ReviewMeta(report_id=report_id,head_sha=head_sha,- # Sandboxes check out this ref. For PRs use the pinned pull ref: refs/pull/N/head outlives the- # head branch (merging mid-review deletes it, killing every later sandbox checkout).- branch=f"pull/{pr_number}/head" if pr_number is not None else pr_metadata.head_branch,+ # Sandboxes check out this branch by name. The Tasks checkout only resolves refs/heads/<name>;+ # a pull ref like `pull/N/head` falls through to a fresh branch on the base tip, so every+ # sandbox would review the base branch instead of the PR.+ branch=pr_metadata.head_branch,repository=input.repository,run_index=run_index,snapshotted=snapshotted,diff --git a/products/review_hog/backend/tests/test_branch_targets.py b/products/review_hog/backend/tests/test_branch_targets.pyindex bb3cbbd3ae9d..c4a8203eacca 100644--- a/products/review_hog/backend/tests/test_branch_targets.py+++ b/products/review_hog/backend/tests/test_branch_targets.py@@ -137,8 +137,9 @@ class TestFetchBranchTarget(BaseTest):assert meta.pr_number == 9assert meta.pr_url == "https://github.com/o/r/pull/9"assert meta.empty_diff is False- # PR reviews check out the pinned pull ref, which survives head-branch deletion on merge.- assert meta.branch == "pull/9/head"+ # PR reviews check out the head branch by name: the sandbox cannot resolve a `pull/N/head`+ # ref and would silently land on the base tip.+ assert meta.branch == "feat"mock_fetcher.assert_called_once_with(owner="o", repo="r", pr_number=9, token="tok", installation_id="9876543")row = ReviewReport.objects.for_team(self.team.id).get(id=stored_id)assert row.pr_number == 9