: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
feat(reviewhog): Allow reviewing drafts + don't stop review if the branch is merged (#70977)
Alex Lebedev006b9660ca77
diff --git a/.github/workflows/review-hog.yml b/.github/workflows/review-hog.ymlindex d2c3513c42e1..b48c4b611d9a 100644--- a/.github/workflows/review-hog.yml+++ b/.github/workflows/review-hog.yml@@ -1,21 +1,21 @@# ReviewHog label trigger.#-# When a maintainer adds the `reviewhog` label to a non-fork PR (or marks an already-labeled draft as-# ready for review), this makes ONE authenticated call to the PostHog `review_hog` trigger endpoint,-# which starts the review Temporal workflow server-side and publishes the review back to the PR.-# Pushes deliberately do NOT re-trigger — re-reviewing is an explicit gesture (remove and re-add the-# label), so a labeled PR can keep evolving without burning a review per push. Unlike Stamphog, the-# agent does NOT run in CI: there is no checkout, no app token, no Anthropic key here — the only secret-# is the shared trigger token. Publishing happens server-side via the PostHog GitHub App installation-# token.+# When a maintainer adds the `reviewhog` label to a non-fork PR (drafts included), this makes ONE+# authenticated call to the PostHog `review_hog` trigger endpoint, which starts the review Temporal+# workflow server-side and publishes the review back to the PR. One label add = one review: pushes+# and ready-for-review deliberately do NOT re-trigger — re-reviewing is an explicit gesture (remove+# and re-add the label), so a labeled PR can keep evolving without burning a review per event.+# Unlike Stamphog, the agent does NOT run in CI: there is no checkout, no app token, no Anthropic key+# here — the only secret is the shared trigger token. Publishing happens server-side via the PostHog+# GitHub App installation token.## Safety: `pull_request` (not `pull_request_target`) means fork PRs receive no secrets, so they cannot-# trigger; the `if:` also hard-gates forks, drafts, and bots; and applying the label needs write access.+# trigger; the `if:` also hard-gates forks and bots; and applying the label needs write access.name: ReviewHogon:pull_request:- types: [labeled, ready_for_review]+ types: [labeled]# No GitHub permissions needed — the job only makes an outbound authenticated request; the review is# fetched and published server-side via the PostHog GitHub App installation token.@@ -30,18 +30,13 @@ jobs:name: Trigger ReviewHog reviewruns-on: ubuntu-latesttimeout-minutes: 5- # Run only for the `reviewhog` label on a non-fork, non-draft, human-authored PR. On `labeled`- # the label name is on the event; on `ready_for_review` it must already be present.+ # Run only for the `reviewhog` label on a non-fork, human-authored PR (drafts included).if: >-- !github.event.pull_request.draft- && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name+ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name&& github.event.pull_request.user.type != 'Bot'&& !contains(github.event.pull_request.user.login, '[bot]')&& github.event.pull_request.user.login != 'posthog-bot'- && (- github.event.label.name == 'reviewhog'- || (github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'reviewhog'))- )+ && github.event.label.name == 'reviewhog'steps:- name: Trigger ReviewHog reviewenv:diff --git a/products/review_hog/ARCHITECTURE.md b/products/review_hog/ARCHITECTURE.mdindex b7d4021bc663..ac8fc3469c8b 100644--- a/products/review_hog/ARCHITECTURE.md+++ b/products/review_hog/ARCHITECTURE.md@@ -2053,7 +2053,7 @@ pipeline just built + hardened).```textreviewhog label on a non-fork PostHog/posthog PR- └─ .github/workflows/review-hog.yml (gates: label==reviewhog, head.repo==base.repo, non-bot, non-draft, concurrency)+ └─ .github/workflows/review-hog.yml (gates: label==reviewhog, head.repo==base.repo, non-bot, concurrency; drafts allowed)└─ one authenticated curl → POST /api/review_hog/trigger {repo, pr_number} (Authorization: Bearer <secret>)└─ endpoint: verify shared secret · validate repo allowlist (forks blocked upstream by the Action+ downstream by the fetch activity) · resolve team-2 integration + run user@@ -2118,8 +2118,8 @@ github-actions[bot] trick), and its Action carries **one** secret (no Anthropicthe review is **pinned to the reviewed `head_sha`** via `commit=repo_obj.get_commit(head_sha)`. Fork rejection isauthoritative in the **fetch activity** (`PRMetadata.is_fork`, non-retryable `ApplicationError` before the reportrow is created).-4. ✅ **The Action:** `.github/workflows/review-hog.yml` — `on: pull_request [labeled, ready_for_review, synchronize]`,- `permissions: {}`, per-PR concurrency, `if:` gates (label + non-fork + non-bot + non-draft), one `curl` with the+4. ✅ **The Action:** `.github/workflows/review-hog.yml` — `on: pull_request [labeled]`,+ `permissions: {}`, per-PR concurrency, `if:` gates (label + non-fork + non-bot; drafts allowed), one `curl` with thebearer secret. `pull_request` (not `pull_request_target`) ⇒ forks get no secret ⇒ can't trigger.**2026-07-14 update:** `synchronize` dropped (ADR 0002) — pushes no longer re-trigger; re-review = re-add thelabel (or mark an already-labeled draft ready).diff --git a/products/review_hog/backend/temporal/activities.py b/products/review_hog/backend/temporal/activities.pyindex 491e0f0075f5..b58b6694330e 100644--- a/products/review_hog/backend/temporal/activities.py+++ b/products/review_hog/backend/temporal/activities.py@@ -530,7 +530,9 @@ def _fetch_and_persist(input: FetchPRDataInput) -> ReviewMeta:return ReviewMeta(report_id=report_id,head_sha=head_sha,- branch=pr_metadata.head_branch,+ # 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,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 435da599cfda..bb3cbbd3ae9d 100644--- a/products/review_hog/backend/tests/test_branch_targets.py+++ b/products/review_hog/backend/tests/test_branch_targets.py@@ -107,6 +107,8 @@ class TestFetchBranchTarget(BaseTest):assert meta.pr_number is Noneassert meta.pr_url is Noneassert meta.empty_diff is True+ # Branch targets have no pull ref — sandboxes must check out the branch itself.+ assert meta.branch == "feat"# The resolved installation id must reach the compare fetch — dropping it silently turns the# calls identity-blind (no egress budget accounting).mock_compare.assert_called_once_with(@@ -135,6 +137,8 @@ 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"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