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.

feat(review-hog): skip automatic follow-ups that rarely surface anything (#118427)

Julian Bez53f877d065b3
diff --git a/products/review_hog/ARCHITECTURE.md b/products/review_hog/ARCHITECTURE.md
index 5c4964ef6e6f..c4ce280e6dc3 100644
--- a/products/review_hog/ARCHITECTURE.md
+++ b/products/review_hog/ARCHITECTURE.md
@@ -963,13 +963,13 @@ An explicit Full request remains pending during an active Flash turn and runs if
Automatic pushes coalesce to the latest head; a rule change that stops the author's automatic review prevents pending automatic reviews from starting without canceling a running turn.
`automatic_reviewed_head_sha` advances only after publication succeeds or finds nothing to publish, so a failed publication can retry and an empty review does not repeat.
An automatic follow-up turn (one with an `automatic_reviewed_head_sha`) first runs the push gate (`reviewer/push_gate.py`) on the PR's own commits since that head.
-Its rules, in order: `no_new_commits` (the PR gained no commit and its full diff is unchanged; a force-push that drops commits runs the review), `reviewhog_commits_only` (the ReviewHog app authored every new commit, such as resolution fixes; this includes the PostHog app's commits on self-driving PRs, which share the app identity), `merge_only` (the PR's full diff against its base is unchanged, as after a base merge or a rebase), `docs_only` (the new own commits touch only docs, lockfiles, snapshots, images, or generated files), `small_change` (the compare of the last reviewed head and the push head changes 1 to `SMALL_CHANGE_MAX_NET_CODE_LINES` code lines; a per-PR Redis counter allows `SMALL_CHANGE_MAX_DEFERRALS` deferrals in a row, then the next small push runs the review), `system_one_below_threshold` (System One rates the own code patches below `SYSTEM_ONE_SKIP_BELOW`), `draft` (the PR is a draft and no earlier rule skips the push), `next_push_likely` (the PR is not a draft, no earlier rule matched, and the chance of another automatic follow-up is at least `NEXT_PUSH_SKIP_AT`), and `throttled` (the PR spent its review budget).
+Its rules, in order: `no_new_commits` (the PR gained no commit and its full diff is unchanged; a force-push that drops commits runs the review), `reviewhog_commits_only` (the ReviewHog app authored every new commit, such as resolution fixes; this includes the PostHog app's commits on self-driving PRs, which share the app identity), `merge_only` (the PR's full diff against its base is unchanged, as after a base merge or a rebase), `docs_only` (the new own commits touch only docs, lockfiles, snapshots, images, or generated files), `small_change` (the compare of the last reviewed head and the push head changes 1 to `SMALL_CHANGE_MAX_NET_CODE_LINES` code lines; a per-PR Redis counter allows `SMALL_CHANGE_MAX_DEFERRALS` deferrals in a row, then the next small push runs the review), `system_one_below_threshold` (System One rates the own code patches below `SYSTEM_ONE_SKIP_BELOW`), `draft` (the PR is a draft and no earlier rule skips the push), `late_follow_up` (the push would start review number `LATE_FOLLOW_UP_RUN_INDEX` or a later one), `small_pr` (the PR has fewer than `SMALL_PR_REVIEWABLE_LINES_BELOW` reviewable lines, the size the lens parts use), `quiet_small_push` (the last review kept no finding and the push changes at most `QUIET_PUSH_MAX_OWN_CODE_LINES` own code lines; skipped pushes add up until one crosses the limit), `next_push_likely` (the PR is not a draft, no earlier rule matched, and the chance of another automatic follow-up is at least `NEXT_PUSH_SKIP_AT`), and `throttled` (the PR spent its review budget).
The `draft` rule reads the draft state from the turn's own PR snapshot: every turn fetches the PR before the gate and the snapshot load is latest-wins, so a PR marked ready at an unchanged head reads as ready. A draft skip reads the PR from GitHub again after the gate's other reads: a PR marked ready while the turn runs sends a ready request that the queue drops, because it asks for the head the running turn gates. If the PR is ready by then, the gate uses the decision of the rules before `draft`. A failed read reviews the push. Only a PR marked ready between that read and the end of the turn keeps its changes unreviewed until the next trigger. A draft decision keeps the System One answer and `own_code_lines` of the rules that ran before it.
The `throttled` rule keeps a token bucket per PR in Redis (`PUSH_BUDGET`): it holds two reviews and gets one back every 30 minutes. Only a push that every earlier rule lets through takes a token, so a draft push or a merge from the base costs nothing. A push that finds the bucket empty waits for the next trigger like any other skip. A Redis failure reviews the push. A head pays once: a turn that runs again at the same head, as an activity retry or a retried `review-pr` child, does not take a second token. A retry after a denial asks the bucket again, so it cannot get past the budget. The first review and human triggers never reach the gate, so they neither take nor need a token.
The `next_push_likely` chance comes from a table fitted offline on closed PRs and refitted by hand. Its key is the follow-up number, capped at 8, and the PR size band (additions plus deletions: up to 200, up to 1000, more). A size cell with fewer than 10 PRs falls back to the chance for the follow-up number alone. The follow-up number is `run_index - 1`, so it also counts label and UI turns, which the fit left out.
-Each rule has a `SKIP_*` switch. `no_new_commits`, `reviewhog_commits_only`, `merge_only`, `draft`, and `throttled` skip; `docs_only`, `small_change`, System One, and `next_push_likely` (`SKIP_NEXT_PUSH`) only record a shadow decision until production data confirms them.
+Each rule has a `SKIP_*` switch. `no_new_commits`, `reviewhog_commits_only`, `merge_only`, `draft`, `late_follow_up`, `small_pr`, `quiet_small_push`, and `throttled` skip; the three value rules also take over a shadow match of an earlier rule, but never a gate failure, and they do not run on a retry of a turn that already finalized its head; `docs_only`, `small_change`, System One, and `next_push_likely` (`SKIP_NEXT_PUSH`) only record a shadow decision until production data confirms them.
A skipped turn posts no status comment and leaves `automatic_reviewed_head_sha` in place, so the next push is judged against the last reviewed head.
-Any gate failure reviews the push. Each decision emits `reviewhog_push_gate_decided` with `skipped`, `would_skip`, the reason, the System One probability and model, `own_code_lines`, the lines the new own commits change in code files (empty when GitHub could not list every file of a commit), `net_code_lines` and `small_change_deferrals` (empty when the gate did not read them), `pr_draft`, the draft state the gate used (null when the snapshot is unavailable), and `next_push_probability` (null on a draft and when the snapshot is unavailable; set on every other decision, also when another rule decided); the event key includes it and the reason, so a draft or throttle skip and a later review at the same head stay two events, so skip rules that weigh push size can be calibrated offline.
+Any gate failure reviews the push. Each decision emits `reviewhog_push_gate_decided` with `skipped`, `would_skip`, the reason, the System One probability and model, `own_code_lines`, the lines the new own commits change in code files (empty when GitHub could not list every file of a commit), `net_code_lines` and `small_change_deferrals` (empty when the gate did not read them), `pr_draft`, the draft state the gate used (null when the snapshot is unavailable), `reviewable_lines` and `previous_findings`, the inputs of the value rules (null when the gate could not read them), and `next_push_probability` (null on a draft and when the snapshot is unavailable; set on every other decision, also when another rule decided); the event key includes it and the reason, so a draft or throttle skip and a later review at the same head stay two events, so skip rules that weigh push size can be calibrated offline.
The first automatic review and every label, UI, inbox, and manual trigger never reach the gate.
An automatic review of a draft that posts findings ends with a note: it is the only automatic review while the PR is a draft, `@posthog review` (or the `posthog-review` label when `github-commands` is off) reviews new changes sooner, and marking the PR ready reviews them otherwise. Label and UI reviews leave the note out, because they also run for authors without automatic reviews.
Reviews start only from a trigger (a push, the label, the UI, the inbox, or a manual run) and run right away.
diff --git a/products/review_hog/DECISIONS.md b/products/review_hog/DECISIONS.md
index fb66be718376..185d3ace756b 100644
--- a/products/review_hog/DECISIONS.md
+++ b/products/review_hog/DECISIONS.md
@@ -198,6 +198,29 @@ read `FINAL_REPORT.md` there first (config glossary + coverage matrix + ranking)
rate drops materially (toward ≤50%) on frozen-PR evals with the valid-finding set intact (item 5's
coverage matrix as the guard); kill if valid findings drop with the noise.
+### ✅ BUILT 2026-10-16 — push gate skips follow-ups that rarely surface anything (live)
+
+- **What.** Three live push gate rules run after `draft`: `late_follow_up` (the push would start review 9 or a later
+ one), `small_pr` (the PR has fewer than 150 reviewable lines, the size the lens parts use), and `quiet_small_push`
+ (the last review kept no finding and the push changes at most 30 own code lines). They take over a shadow match of an
+ earlier rule. A skipped push leaves the baseline in place, so the next review covers its changes, and skipped small
+ pushes add up until one crosses 30 lines. Every gate decision now carries `reviewable_lines` and `previous_findings`.
+- **Why.** Automatic follow-ups make up most of the Standard spend, and most of them surface nothing. The findings of
+ the previous review predict what a follow-up surfaces better than the PR size does: inside each PR size band, a
+ follow-up after a review with two or more findings surfaced three to five times the must-fix findings of a follow-up
+ after a review that kept none.
+- **Evidence.** A replay of automatic follow-ups under the current posting rules, with model cost joined per turn
+ (review-eval `experiments/2026-10-16-follow-up-value`):
+ - The three rules match about two in five of those follow-ups and about a third of their cost.
+ - They hold back about one in six follow-up must-fix labels and follow-up findings. The labels are the model's own,
+ and a skipped push stays in the next review's scope, so both shares are upper bounds.
+ - Follow-ups after a push the gate expects another push for surfaced the most per review, so `next_push_likely`
+ stays a shadow rule.
+- **Not chosen.**
+ - Skipping first reviews of small PRs: a first review of a 30 to 99 line PR still surfaces must-fix findings.
+ - System One below 0.7: it saves less per must-fix label held back than the push-size rule.
+ - A cap from review 5: it saves about half as much and holds back almost as many must-fix labels.
+
### ✅ BUILT 2026-10-15 — push gate: small-change deferral (shadow)
- **What.** A new push gate rule, `small_change`, sits after `docs_only` and before `system_one_below_threshold`. It
diff --git a/products/review_hog/backend/reviewer/push_gate.py b/products/review_hog/backend/reviewer/push_gate.py
index 04b59548d039..734a755eb2fe 100644
--- a/products/review_hog/backend/reviewer/push_gate.py
+++ b/products/review_hog/backend/reviewer/push_gate.py
@@ -25,11 +25,21 @@ The rules, in order. The first rule that matches gives the reason:
7. `draft`: the PR is a draft and no rule above skips the push. A draft cannot merge, and marking it
ready starts a turn that reviews everything since the last reviewed head. The rules above still run,
so a draft decision keeps the System One answer and the push size for calibration.
-8. `next_push_likely`: on a PR that is not a draft, when no rule above matched, another automatic
+8. `late_follow_up`: the push would start review number `LATE_FOLLOW_UP_RUN_INDEX` of the PR or a later one.
+9. `small_pr`: the PR has fewer than `SMALL_PR_REVIEWABLE_LINES_BELOW` reviewable lines, the changed lines
+ without generated and vendored files that the lens parts are sized by.
+10. `quiet_small_push`: the last review kept no finding and the push changes at most
+ `QUIET_PUSH_MAX_OWN_CODE_LINES` own code lines. Skipped pushes add up, so a later push that brings the
+ own code lines over the limit runs the review.
+ Rules 8 to 10 match the follow-ups that surfaced the least per review in production. A skipped push
+ does not move the baseline, so the next review covers its changes. These rules take over a shadow
+ match of the rules above, so a push that only a shadow rule matched can still skip. They never take
+ over a gate failure, and they do not run on a retry of a turn that already finalized its head.
+11. `next_push_likely`: on a PR that is not a draft, when no rule above matched, another automatic
follow-up is likely to come. Skipped changes add up and the next review covers them. The chance
comes from a table fitted offline on the follow-up number and the PR size. Every decision on a
PR that is not a draft records the chance, also when another rule decided.
-9. `throttled`: the PR spent its review budget. Each PR has a token bucket (Turner 1986) that holds
+12. `throttled`: the PR spent its review budget. Each PR has a token bucket (Turner 1986) that holds
`PUSH_BUDGET.burst` reviews and gets one back every `3600 / PUSH_BUDGET.per_hour` seconds. A push
that every rule above lets through takes a token, and a push that finds the bucket empty waits:
the next turn that runs reviews everything since the last reviewed head. This caps bursts of
@@ -72,6 +82,9 @@ SKIP_DOCS_ONLY = False
SKIP_SMALL_CHANGE = False
SKIP_SYSTEM_ONE = False
SKIP_DRAFT = True
+SKIP_LATE_FOLLOW_UP = True
+SKIP_SMALL_PR = True
+SKIP_QUIET_SMALL_PUSH = True
# Before this goes on, `next_push_likely` must defer only once per reviewed head. A skip does not
# advance run_index, so the same chance would match every later push and no review would run.
SKIP_NEXT_PUSH = False
@@ -91,6 +104,10 @@ end
redis.call('SET', KEYS[1], ARGV[2], 'EX', ARGV[3])
return 1
"""
+# Picked by a replay of production follow-ups in `review-eval/experiments/2026-10-16-follow-up-value`.
+LATE_FOLLOW_UP_RUN_INDEX = 9
+SMALL_PR_REVIEWABLE_LINES_BELOW = 150
+QUIET_PUSH_MAX_OWN_CODE_LINES = 30
# Picked by the replay in `review-eval/experiments/2026-10-14-review-throttle`.
PUSH_BUDGET = Budget(burst=2, per_hour=2)
# Longer than a turn and its retry take, so a retried turn finds that its head paid already.
@@ -198,6 +215,9 @@ SkipReason = Literal[
"small_change",
"system_one_below_threshold",
"draft",
+ "late_follow_up",
+ "small_pr",
+ "quiet_small_push",
"next_push_likely",
"throttled",
]
@@ -228,6 +248,9 @@ class PushGateDecision:
net_code_lines: int | None = None
# Small-change deferrals in a row after this decision. None when the gate did not read the counter.
small_change_deferrals: int | None = None
+ # Inputs of rules 8 to 10. None when the gate could not read them.
+ reviewable_lines: int | None = None
+ previous_findings: int | None = None
@frozen
@@ -273,6 +296,12 @@ def _rule_enabled(reason: SkipReason) -> bool:
return SKIP_SMALL_CHANGE
if reason == "draft":
return SKIP_DRAFT
+ if reason == "late_follow_up":
+ return SKIP_LATE_FOLLOW_UP
+ if reason == "small_pr":
+ return SKIP_SMALL_PR
+ if reason == "quiet_small_push":
+ return SKIP_QUIET_SMALL_PUSH
if reason == "next_push_likely":
return SKIP_NEXT_PUSH
if reason == "throttled":
@@ -633,10 +662,48 @@ def apply_draft_rule(decision: PushGateDecision, *, draft: bool) -> PushGateDeci
)
+# A decision that runs the review because the gate could not judge the push. Rules 8 to 10 keep it.
+_FAIL_OPEN_REASONS: frozenset[RunReason] = frozenset(
+ {"commits_removed", "system_one_unavailable", "interdiff_too_large", "compare_unavailable", "snapshot_unavailable"}
+)
+
+
+def _low_value_reason(
+ decision: PushGateDecision, *, run_index: int, reviewable_lines: int | None, previous_findings: int | None
+) -> SkipReason | None:
+ if run_index >= LATE_FOLLOW_UP_RUN_INDEX:
+ return "late_follow_up"
+ if reviewable_lines is not None and reviewable_lines < SMALL_PR_REVIEWABLE_LINES_BELOW:
+ return "small_pr"
+ own_code_lines = decision.own_code_lines
+ if previous_findings == 0 and own_code_lines is not None and own_code_lines <= QUIET_PUSH_MAX_OWN_CODE_LINES:
+ return "quiet_small_push"
+ return None
+
+
+def apply_follow_up_value_rules(
+ decision: PushGateDecision, *, run_index: int, reviewable_lines: int | None, previous_findings: int | None
+) -> PushGateDecision:
+ """Rules 8 to 10, on top of the draft rule. An input that is None matches no rule, so the push runs.
+
+ `run_index` is the turn this push would start. `previous_findings` is the number of findings the last
+ turn kept.
+ """
+ decision = replace(decision, reviewable_lines=reviewable_lines, previous_findings=previous_findings)
+ if decision.skip or decision.reason in _FAIL_OPEN_REASONS:
+ return decision
+ reason = _low_value_reason(
+ decision, run_index=run_index, reviewable_lines=reviewable_lines, previous_findings=previous_findings
+ )
+ if reason is None:
+ return decision
+ return replace(decision, skip=_rule_enabled(reason), would_skip=True, reason=reason)
+
+
def apply_next_push_rule(
decision: PushGateDecision, *, follow_up: int | None, pr_lines: int | None
) -> PushGateDecision:
- """Rule 8, only for a PR that is not a draft. It records the chance also when another rule decided.
+ """Rule 11, only for a PR that is not a draft. It records the chance also when another rule decided.
`follow_up` is the number of this automatic follow-up (1-based) and `pr_lines` is the PR's
additions plus deletions. Both are None when they are unknown.
@@ -645,20 +712,12 @@ def apply_next_push_rule(
if follow_up is not None and pr_lines is not None:
probability = next_push_probability(follow_up=follow_up, pr_lines=pr_lines)
if probability is not None and probability >= NEXT_PUSH_SKIP_AT and not decision.would_skip:
- decision = _matched(
- "next_push_likely",
- own_commits=decision.own_commits,
- probability=decision.probability,
- model=decision.model,
- own_code_lines=decision.own_code_lines,
- net_code_lines=decision.net_code_lines,
- small_change_deferrals=decision.small_change_deferrals,
- )
+ decision = replace(decision, skip=_rule_enabled("next_push_likely"), would_skip=True, reason="next_push_likely")
return replace(decision, next_push_probability=probability)
def apply_throttle(decision: PushGateDecision, *, report_id: str, head_sha: str) -> PushGateDecision:
- """Rule 9, last: a push that the rules before it skip takes no token. Without Redis the push runs.
+ """Rule 12, last: a push that the rules before it skip takes no token. Without Redis the push runs.
A head pays once. A failed turn runs again as a new activity or a new child workflow, and a
retry that charged again could find the bucket empty and drop a review that passed the budget.
diff --git a/products/review_hog/backend/temporal/activities.py b/products/review_hog/backend/temporal/activities.py
index 664d79e0fd8a..98c7e0fdf21e 100644
--- a/products/review_hog/backend/temporal/activities.py
+++ b/products/review_hog/backend/temporal/activities.py
@@ -127,6 +127,7 @@ from products.review_hog.backend.reviewer.push_gate import (
PushGate,
PushGateDecision,
apply_draft_rule,
+ apply_follow_up_value_rules,
apply_next_push_rule,
apply_throttle,
)
@@ -2326,6 +2327,8 @@ def _track_push_gate_decided(input: GatePushInput, decision: PushGateDecision, d
"small_change_deferrals": decision.small_change_deferrals,
"pr_draft": draft,
"next_push_probability": decision.next_push_probability,
+ "reviewable_lines": decision.reviewable_lines,
+ "previous_findings": decision.previous_findings,
},
groups=groups(team=report.team),
)
@@ -2347,6 +2350,26 @@ def _pr_is_draft_now(repository: str, pr_number: int, *, token: str, installatio
return response.json().get("draft") is True
+def _previous_turn_findings(input: GatePushInput) -> int | None:
+ """The findings the last counted turn kept. A turn that failed before publishing does not count."""
+ try:
+ return len(load_valid_findings(team_id=input.team_id, report_id=input.report_id, run_index=input.run_index - 1))
+ except Exception:
+ logger.exception("Could not read the previous turn's findings for report %s", input.report_id)
+ return None
+
+
+def _head_already_finalized(input: GatePushInput) -> bool:
+ """Whether a finished turn already reviewed this head, as on a retry after a failed publish."""
+ completed_head_sha = (
+ ReviewReport.objects.for_team(input.team_id)
+ .filter(id=input.report_id)
+ .values_list("completed_head_sha", flat=True)
+ .first()
+ )
+ return completed_head_sha == input.head_sha
+
+
def _gate_push(input: GatePushInput) -> PushGateDecision:
current = load_pr_snapshot(team_id=input.team_id, report_id=input.report_id, head_sha=input.head_sha)
draft = _pr_draft(current)
@@ -2374,6 +2397,15 @@ def _gate_push(input: GatePushInput) -> PushGateDecision:
):
draft = False
decision = push_decision
+ # A retry of a finalized turn has a run_index one higher than the turn it retries, and its own
+ # findings count as the previous turn's, so rules 8 to 10 would drop findings nobody saw yet.
+ if not _head_already_finalized(input):
+ decision = apply_follow_up_value_rules(
+ decision,
+ run_index=input.run_index,
+ reviewable_lines=plan_lens_chunks(current.pr_files).reviewable_lines if current.pr_files else None,
+ previous_findings=_previous_turn_findings(input),
+ )
if not draft:
# The offline fit counted only automatic follow-ups. No turn stores its trigger, so this
# count is the completed turns after the first review, which also includes label, UI,
diff --git a/products/review_hog/backend/tests/test_push_gate.py b/products/review_hog/backend/tests/test_push_gate.py
index e09b95860d67..d2f6708f884e 100644
--- a/products/review_hog/backend/tests/test_push_gate.py
+++ b/products/review_hog/backend/tests/test_push_gate.py
@@ -1,4 +1,5 @@
from collections.abc import Iterator
+from dataclasses import replace
from datetime import UTC, datetime, timedelta
from typing import Any
@@ -19,6 +20,7 @@ from products.review_hog.backend.reviewer.push_gate import (
PushGateDecision,
_NextPushCell,
apply_draft_rule,
+ apply_follow_up_value_rules,
apply_next_push_rule,
apply_throttle,
next_push_probability,
@@ -659,3 +661,70 @@ def test_push_gate_small_change_streak_after_a_push_another_rule_decides(
outcomes.append((decision.reason, decision.small_change_deferrals))
assert outcomes == [("small_change", 1), ("small_change", 2), *expected_tail]
+
+
+def _running(own_code_lines: int | None) -> PushGateDecision:
+ return PushGateDecision(
+ skip=False,
+ would_skip=False,
+ reason="system_one_above_threshold",
+ probability=0.8,
+ own_code_lines=own_code_lines,
+ )
+
+
+ [
+ ("ninth_review", _running(200), 9, 2000, 3, (True, True, "late_follow_up")),
+ ("eighth_review_runs", _running(200), 8, 2000, 3, (False, False, "system_one_above_threshold")),
+ ("pr_under_150_lines", _running(200), 3, 149, 3, (True, True, "small_pr")),
+ ("pr_of_150_lines_runs", _running(200), 3, 150, 3, (False, False, "system_one_above_threshold")),
+ ("quiet_review_and_small_push", _running(30), 3, 400, 0, (True, True, "quiet_small_push")),
+ ("quiet_review_and_larger_push_runs", _running(31), 3, 400, 0, (False, False, "system_one_above_threshold")),
+ ("review_with_a_finding_runs", _running(5), 3, 400, 1, (False, False, "system_one_above_threshold")),
+ ("unknown_inputs_run", _running(None), 3, None, None, (False, False, "system_one_above_threshold")),
+ (
+ "shadow_match_skips",
+ PushGateDecision(skip=False, would_skip=True, reason="docs_only", own_code_lines=0),
+ 3,
+ 400,
+ 0,
+ (True, True, "quiet_small_push"),
+ ),
+ (
+ "gate_failure_keeps_running",
+ PushGateDecision(skip=False, would_skip=False, reason="compare_unavailable"),
+ 12,
+ 50,
+ 0,
+ (False, False, "compare_unavailable"),
+ ),
+ (
+ "earlier_skip_keeps_its_reason",
+ PushGateDecision(skip=True, would_skip=True, reason="merge_only"),
+ 12,
+ 50,
+ 0,
+ (True, True, "merge_only"),
+ ),
+ ]
+)
+def test_push_gate_skips_follow_ups_that_rarely_surface_anything(
+ _name: str,
+ decision: PushGateDecision,
+ run_index: int,
+ reviewable_lines: int | None,
+ previous_findings: int | None,
+ expected: tuple[bool, bool, str],
+) -> None:
+ result = apply_follow_up_value_rules(
+ decision, run_index=run_index, reviewable_lines=reviewable_lines, previous_findings=previous_findings
+ )
+ assert (result.skip, result.would_skip, result.reason) == expected
+
+
+def test_next_push_rule_keeps_the_value_rule_inputs() -> None:
+ decision = replace(_running(200), reviewable_lines=400, previous_findings=2)
+ with patch(f"{_MODULE}.NEXT_PUSH_SKIP_AT", 0.0):
+ result = apply_next_push_rule(decision, follow_up=4, pr_lines=400)
+ assert (result.reason, result.reviewable_lines, result.previous_findings) == ("next_push_likely", 400, 2)
diff --git a/products/review_hog/backend/tests/test_review_completed_tracking.py b/products/review_hog/backend/tests/test_review_completed_tracking.py
index faa414f3297c..8cf8c1c6fdcd 100644
--- a/products/review_hog/backend/tests/test_review_completed_tracking.py
+++ b/products/review_hog/backend/tests/test_review_completed_tracking.py
@@ -25,6 +25,7 @@ from products.review_hog.backend.reviewer.models.github_meta import PRFile, PRMe
from products.review_hog.backend.reviewer.models.issue_validation import IssueValidation
from products.review_hog.backend.reviewer.models.issues_review import Issue, IssuePriority, LineRange
from products.review_hog.backend.reviewer.persistence import (
+ finalize_review_report,
persist_findings,
persist_pr_snapshot,
persist_verdicts,
@@ -400,6 +401,74 @@ class TestTrackReviewCompleted(BaseTest):
assert (props["pr_draft"], second.kwargs["properties"]["pr_draft"]) == (True, False)
assert (props["next_push_probability"], second.kwargs["properties"]["next_push_probability"]) == (None, 0.559)
+ @parameterized.expand(
+ [
+ ("quiet_previous_review", False, False, (True, "quiet_small_push", 0, 400)),
+ ("previous_review_found_a_bug", True, False, (False, "system_one_above_threshold", 1, 400)),
+ # A retry after a failed publish runs one run_index higher at the head its first attempt finalized.
+ ("retry_of_a_finalized_head", False, True, (False, "system_one_above_threshold", None, None)),
+ ]
+ )
+ def test_the_gate_reads_the_previous_turns_findings_and_the_pr_size(
+ self,
+ _name: str,
+ previous_finding: bool,
+ head_finalized: bool,
+ expected: tuple[bool, str, int | None, int | None],
+ ) -> None:
+ report_id = self._review_report()
+ persist_pr_snapshot(
+ team_id=self.team.id,
+ report_id=report_id,
+ head_sha="sha1",
+ pr_metadata=_pr_metadata(),
+ pr_comments=[],
+ pr_files=[
+ PRFile(filename="a.py", status="modified", additions=300, deletions=100),
+ PRFile(filename="pnpm-lock.yaml", status="modified", additions=900, deletions=0),
+ ],
+ )
+ if previous_finding:
+ issues = [_issue("1-1-1")]
+ persist_findings(team_id=self.team.id, report_id=report_id, issues=issues, run_index=1)
+ persist_verdicts(
+ team_id=self.team.id,
+ report_id=report_id,
+ issues=issues,
+ run_index=1,
+ validations={"1-1-1": IssueValidation(is_valid=True, argumentation="real")},
+ )
+ if head_finalized:
+ finalize_review_report(
+ team_id=self.team.id, report_id=report_id, body_markdown="# r", run_index=1, head_sha="sha1"
+ )
+ decision = PushGateDecision(
+ skip=False, would_skip=False, reason="system_one_above_threshold", probability=0.8, own_code_lines=12
+ )
+
+ with (
+ patch("products.review_hog.backend.temporal.activities._installation_auth", return_value=("tok", None)),
+ patch("products.review_hog.backend.temporal.activities.PushGate") as gate,
+ patch("products.review_hog.backend.temporal.activities.apply_throttle", side_effect=lambda d, **_: d),
+ patch("products.review_hog.backend.temporal.activities.posthoganalytics.capture") as capture,
+ ):
+ gate.return_value.decide.return_value = decision
+ gate.return_value.record_small_change_streak.side_effect = lambda decision, **_: decision
+ result = _gate_push(
+ GatePushInput(
+ team_id=self.team.id,
+ report_id=report_id,
+ repository="o/r",
+ previous_head_sha="sha0",
+ head_sha="sha1",
+ run_index=2,
+ review_mode=REVIEW_MODE_FLASH,
+ )
+ )
+
+ props = capture.call_args.kwargs["properties"]
+ assert (result.skip, result.reason, props["previous_findings"], props["reviewable_lines"]) == expected
+
def _gate_draft_push(self, report_id: str, live_pr: dict[str, object] | Exception) -> tuple[PushGateDecision, Any]:
live = MagicMock(side_effect=live_pr) if isinstance(live_pr, Exception) else MagicMock()
live.return_value.json.return_value = live_pr