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): drop flash follow-up findings on unchanged code (#114316)

Julian Beze869c8db9d0f
diff --git a/products/review_hog/ARCHITECTURE.md b/products/review_hog/ARCHITECTURE.md
index 2b30d3b83fa2..86eb5c971a06 100644
--- a/products/review_hog/ARCHITECTURE.md
+++ b/products/review_hog/ARCHITECTURE.md
@@ -258,7 +258,7 @@ flowchart TD
### Single-agent Flash (the Flash default)
A Flash turn runs one of two designs, picked by the fetch activity (`select_review_design`, `reviewer/constants.py`).
-The **single-agent design** (`reviewhog-flash-2-0`) replaces steps 4, 5, and 8 below with parallel Codex sandbox
+The **single-agent design** (`reviewhog-flash-2-1`) replaces steps 4, 5, and 8 below with parallel Codex sandbox
sessions, all on `SINGLE_AGENT_FLASH_ARM` (`gpt-6.1-sol` @ medium) and all returning `SingleAgentReview`:
- **The main session** (`single_agent_review_activity`) reviews the whole PR. Its system prompt is `core.md` (the
@@ -286,7 +286,10 @@ the prompt tells the session to read those files at the head. There is no team s
DevEx-owned prompts.
Each session persists as one `perspective_result` under a reserved pass (`SINGLE_AGENT_PASS_NUMBER` 2000, lenses 2001
-and 2002) and its part. Step 7 then runs as two dedup calls in parallel (`dedupe_flash_findings`,
+and 2002) and its part. On a follow-up turn, a P2 or P3 finding more than `FLASH_FOLLOW_UP_CHANGE_MARGIN_LINES` (3)
+lines from any code that changed since `completed_head_sha` drops as `old_code` first (`ChangedSinceReview`). The two
+heads' PR snapshots are compared by line content per file, so lines a base merge only moved stay old. P0 and P1
+findings, files whose patch GitHub left out, a first review, and a re-run at the reviewed head skip the check. Step 7 then runs as two dedup calls in parallel (`dedupe_flash_findings`,
`tools/single_agent_review.py`), both one-shot OpenAI calls on `FLASH_DEDUP_MODEL` (`gpt-6-luna` @ medium,
`run_oneshot_openai_review`): the main findings against PR comments and earlier turns, and the lens findings against
the same plus the main findings as anchors, so a lens finding can lose to a main finding but never the reverse.
@@ -313,7 +316,7 @@ optional `suggestion_code` is stored on the finding but never posted. A PR past
Every finding the turn drops after scope cleaning persists as a `dropped_finding` artefact (`DroppedFindingArtefact`,
written by `replace_dropped_findings` beside `replace_deduplicated_findings` in the dedup activity): the full finding
-with its `reported_priority`, the session's pass and part, the `disposition` (`dedup_prior`, `dedup_comment`,
+with its `reported_priority`, the session's pass and part, the `disposition` (`old_code`, `dedup_prior`, `dedup_comment`,
`dedup_anchor`, `dedup_sibling`, or `cap`), `duplicate_of` (an issue key, or `comment:<id>`), the
rank in the composed order for a cut finding, the cap, and the lens part count. A retried turn replaces its rows by
`run_index`. Only analysis reads them: publishing, the status comment, outcome classification, `load_prior_findings`,
@@ -457,7 +460,7 @@ pr_metadata.head_branch` is threaded (as explicit kwargs, alongside `team_id` /
Turn event IDs distinguish Full and Flash, and the single-agent design from the pipeline, while preserving the legacy Full and pipeline Flash IDs across deployments.
Completion-rate calculations match failures and completions by report, turn, and mode; an absent mode means Full for legacy events.
After the skill sync, `record_turn_marker_activity` records the turn's version marker: a version id per review mode
- and design (`reviewhog-flash-2-0`, built by `reviewhog_version_for_mode` from the manual (major, minor) bumps in
+ and design (`reviewhog-flash-2-1`, built by `reviewhog_version_for_mode` from the manual (major, minor) bumps in
`REVIEWHOG_VERSIONS`, `reviewer/constants.py`) plus a 7-character fingerprint (`reviewer/fingerprint.py`).
Full, Flash pipeline, and Flash single agent evolve separately, so each bumps its own version.
The fingerprint hashes the review mode, the review and validator arms, the chunking / dedup / one-shot pins,
diff --git a/products/review_hog/DECISIONS.md b/products/review_hog/DECISIONS.md
index 23d48860de17..a78c689efc07 100644
--- a/products/review_hog/DECISIONS.md
+++ b/products/review_hog/DECISIONS.md
@@ -198,6 +198,22 @@ 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-09 — Flash follow-up turns drop P2 and P3 findings on unchanged code (`reviewhog-flash-2-1`)
+
+- **What.** On a follow-up turn, a P2 or P3 finding that sits more than `FLASH_FOLLOW_UP_CHANGE_MARGIN_LINES` (3)
+ lines from any code that changed since the head the last completed turn reviewed drops as `old_code` before dedup.
+ P0 and P1 findings still post. The two heads' PR diffs are compared by line content per file
+ (`ChangedSinceReview`), so lines that a base merge or a rebase only moved stay old. A first review, a re-run at the
+ reviewed head, a missing snapshot, or a file whose patch GitHub left out skips the check.
+- **Why.** Each follow-up turn re-reviews the whole PR, and a fresh review picks different issues out of the same
+ code, so findings on code from the first commit trickled in push after push. An offline study of 12 PRs found that
+ 51% of later-turn findings sat on code unchanged since the first review (66% on PRs with three or more posting
+ turns). Authors acted on 34% of those, against 70% of first-turn findings and 73% of later findings on new code,
+ which are often bugs in the author's fixes. Performance and security findings on old code: 0 of 8 acted on.
+- **Not chosen yet.** Reviewing only the changes since the last head (a delta prompt) or resuming the earlier session
+ would also save review cost, but neither is tested. The prompt does not mention the rule, so the sessions have no
+ reason to raise a level to get a finding posted.
+
### ✅ BUILT 2026-10-08 — inline finding comments: one P-level heading and one paragraph
- **What.** An inline comment is `**P{n} · {title}**`, then one paragraph with the issue and its fix, then the hidden
diff --git a/products/review_hog/backend/reviewer/constants.py b/products/review_hog/backend/reviewer/constants.py
index 2bb367709bab..dff30ce60fb3 100644
--- a/products/review_hog/backend/reviewer/constants.py
+++ b/products/review_hog/backend/reviewer/constants.py
@@ -114,12 +114,12 @@ def select_review_design(review_mode: str, *, kill_switch_on: bool) -> ReviewDes
REVIEWHOG_VERSIONS: dict[tuple[str, str], tuple[int, int]] = {
(REVIEW_MODE_FULL, REVIEW_DESIGN_PIPELINE): (1, 2),
(REVIEW_MODE_FLASH, REVIEW_DESIGN_PIPELINE): (1, 2),
- (REVIEW_MODE_FLASH, REVIEW_DESIGN_SINGLE_AGENT): (2, 0),
+ (REVIEW_MODE_FLASH, REVIEW_DESIGN_SINGLE_AGENT): (2, 1),
}
def reviewhog_version_for_mode(review_mode: str, review_design: str = REVIEW_DESIGN_PIPELINE) -> str:
- """The version id a turn of this mode and design reports, like a model id: `reviewhog-flash-2-0`."""
+ """The version id a turn of this mode and design reports, like a model id: `reviewhog-flash-2-1`."""
major, minor = REVIEWHOG_VERSIONS[(review_mode, review_design)]
return f"reviewhog-{review_mode}-{major}-{minor}"
@@ -158,6 +158,8 @@ FLASH_MAX_FINDINGS_CEILING = 10
# Must-fix findings post outside the cap. This multiple of the cap still bounds them, so a session that
# marks everything P0 or P1 cannot flood the PR.
FLASH_MUST_FIX_CAP_MULTIPLIER = 2
+# A finding on a line next to a change is often about that change.
+FLASH_FOLLOW_UP_CHANGE_MARGIN_LINES = 3
def flash_max_findings(lens_part_count: int) -> int:
diff --git a/products/review_hog/backend/reviewer/fingerprint.py b/products/review_hog/backend/reviewer/fingerprint.py
index 56da893e72a8..a96cb9a73b87 100644
--- a/products/review_hog/backend/reviewer/fingerprint.py
+++ b/products/review_hog/backend/reviewer/fingerprint.py
@@ -30,6 +30,7 @@ from products.review_hog.backend.reviewer.constants import (
DEDUP_RUNTIME_ADAPTER,
FLASH_DEDUP_MODEL,
FLASH_DEDUP_REASONING_EFFORT,
+ FLASH_FOLLOW_UP_CHANGE_MARGIN_LINES,
FLASH_LENS_CHUNK_MAX_LINES,
FLASH_LENS_MAX_CHUNKS,
FLASH_LENSES,
@@ -256,6 +257,7 @@ class TurnFingerprint:
"max_findings_per_extra_part": FLASH_MAX_FINDINGS_PER_EXTRA_PART,
"max_findings_ceiling": FLASH_MAX_FINDINGS_CEILING,
"must_fix_cap_multiplier": FLASH_MUST_FIX_CAP_MULTIPLIER,
+ "follow_up_change_margin_lines": FLASH_FOLLOW_UP_CHANGE_MARGIN_LINES,
"lens_chunk_max_lines": FLASH_LENS_CHUNK_MAX_LINES,
"lens_max_chunks": FLASH_LENS_MAX_CHUNKS,
"prompt_diff_max_chars": FLASH_PROMPT_DIFF_MAX_CHARS,
diff --git a/products/review_hog/backend/reviewer/models/issues_review.py b/products/review_hog/backend/reviewer/models/issues_review.py
index 6f80a4cafd06..587304c53cdb 100644
--- a/products/review_hog/backend/reviewer/models/issues_review.py
+++ b/products/review_hog/backend/reviewer/models/issues_review.py
@@ -79,8 +79,10 @@ class Issue(BaseModel):
# Why a single-agent turn drops a finding. A `dedup_*` drop repeats an earlier turn's finding, a PR
# comment, a main finding (anchor), or a finding of its own session or lens (sibling). `cap` is the cut
-# in `compose_flash_findings`.
+# in `compose_flash_findings`. `old_code` is a follow-up turn's P2 or P3 finding on code that did not
+# change since the last reviewed head.
DropDisposition = Literal[
+ "old_code",
"dedup_prior",
"dedup_comment",
"dedup_anchor",
diff --git a/products/review_hog/backend/reviewer/tests/test_single_agent_review.py b/products/review_hog/backend/reviewer/tests/test_single_agent_review.py
index 959951d91eac..ce4046f7c4c7 100644
--- a/products/review_hog/backend/reviewer/tests/test_single_agent_review.py
+++ b/products/review_hog/backend/reviewer/tests/test_single_agent_review.py
@@ -20,6 +20,7 @@ from products.review_hog.backend.reviewer.models.issues_review import (
ReportedPriority,
)
from products.review_hog.backend.reviewer.tools.single_agent_review import (
+ ChangedSinceReview,
FlashSelection,
SingleAgentPrompt,
compose_flash_findings,
@@ -43,6 +44,19 @@ def _file(filename: str, code: str) -> PRFile:
)
+def _patched(filename: str, *chunks: tuple[str, int, list[str]]) -> PRFile:
+ return PRFile(
+ filename=filename,
+ status="modified",
+ additions=sum(len(lines) for kind, _, lines in chunks if kind == "addition"),
+ deletions=0,
+ changes=[
+ PRFileUpdate(type=kind, new_start_line=start, new_end_line=start + len(lines) - 1, code="\n".join(lines))
+ for kind, start, lines in chunks
+ ],
+ )
+
+
def _issue(
issue_id: str, priority: IssuePriority, source: str = SINGLE_AGENT_SOURCE, reported: ReportedPriority | None = None
) -> Issue:
@@ -232,6 +246,7 @@ class TestDedupeFlashFindings:
*,
prior_findings: list[ReviewIssueFinding] | None = None,
pr_comments: list[PRComment] | None = None,
+ changed_since: ChangedSinceReview | None = None,
) -> FlashSelection:
with patch(f"{_DEDUP_MODULE}.run_oneshot_openai_review", mock_llm):
return await dedupe_flash_findings(
@@ -244,6 +259,7 @@ class TestDedupeFlashFindings:
branch="feat",
repository="o/r",
lens_part_count=1,
+ changed_since=changed_since,
)
@pytest.mark.asyncio
@@ -446,6 +462,73 @@ class TestDedupeFlashFindings:
for drop in drops
] == expected_drops
+ @pytest.mark.asyncio
+ @pytest.mark.parametrize(
+ "file,lines,priority,posts",
+ [
+ pytest.param(
+ "a.py", LineRange(start=30), IssuePriority.SHOULD_FIX, False, id="p2_on_code_the_first_review_saw"
+ ),
+ pytest.param(
+ "a.py", LineRange(start=16), IssuePriority.CONSIDER, False, id="p3_on_lines_a_base_merge_only_moved"
+ ),
+ pytest.param("a.py", LineRange(start=42), IssuePriority.SHOULD_FIX, True, id="p2_next_to_a_new_line"),
+ pytest.param("a.py", LineRange(start=30), IssuePriority.MUST_FIX, True, id="p1_on_unchanged_code"),
+ pytest.param(
+ "a.py",
+ LineRange(start=100, end=10**9),
+ IssuePriority.SHOULD_FIX,
+ False,
+ id="p2_with_a_huge_range_is_compared_not_scanned",
+ ),
+ pytest.param(
+ "b.py", LineRange(start=30), IssuePriority.SHOULD_FIX, True, id="p2_in_a_file_without_a_patch"
+ ),
+ pytest.param(
+ "c.py", LineRange(start=10), IssuePriority.SHOULD_FIX, True, id="p2_where_a_guard_was_removed"
+ ),
+ pytest.param(
+ "d.py", LineRange(start=10), IssuePriority.SHOULD_FIX, True, id="p2_on_a_copy_above_the_original"
+ ),
+ pytest.param(
+ "e.py", LineRange(start=31), IssuePriority.SHOULD_FIX, True, id="p2_on_a_statement_moved_elsewhere"
+ ),
+ ],
+ )
+ async def test_a_follow_up_drops_p2_and_p3_findings_on_unchanged_code(
+ self, pr_metadata: PRMetadata, file: str, lines: LineRange, priority: IssuePriority, posts: bool
+ ) -> None:
+ # A follow-up turn re-reviews the whole PR, so without this it trickles in findings on code the
+ # first review already covered. Moved lines stay old, while a removed guard or a repeated line in a
+ # new place is new code, and a P1 still posts.
+ earlier = [
+ _patched("a.py", ("addition", 10, ["x = 1", "y = 2", "z = 3"])),
+ _patched("c.py", ("context", 9, ["def delete(request):"]), ("addition", 10, [" check()", " drop()"])),
+ _patched("d.py", ("context", 99, ["def g():"]), ("addition", 100, [" return None"])),
+ _patched("e.py", ("context", 9, ["def save():"]), ("addition", 10, [" notify()"])),
+ ]
+ current = [
+ _patched("a.py", ("addition", 15, ["x = 1", "y = 2", "z = 3"]), ("addition", 40, ["w = 4"])),
+ PRFile(filename="b.py", status="modified", additions=5, deletions=0),
+ _patched("c.py", ("context", 9, ["def delete(request):"]), ("addition", 10, [" drop()"])),
+ _patched(
+ "d.py",
+ ("context", 9, ["def h():"]),
+ ("addition", 10, [" return None"]),
+ ("context", 103, ["def g():"]),
+ ("addition", 104, [" return None"]),
+ ),
+ _patched("e.py", ("context", 30, ["def delete():"]), ("addition", 31, [" notify()"])),
+ ]
+ issue = _issue("2000-1-1", priority).model_copy(update={"file": file, "lines": [lines]})
+
+ selection = await self._dedupe(
+ pr_metadata, [issue], _flash_dedup(), changed_since=ChangedSinceReview.between(earlier, current)
+ )
+
+ assert [kept.id for kept in selection.kept] == (["2000-1-1"] if posts else [])
+ assert [drop.disposition for drop in selection.dropped] == ([] if posts else ["old_code"])
+
def test_turn_stats_count_every_candidate_once_per_session() -> None:
# The completed event's funnel only reads true when every finding that entered dedup is either
diff --git a/products/review_hog/backend/reviewer/tools/single_agent_review.py b/products/review_hog/backend/reviewer/tools/single_agent_review.py
index 157e5faa7d81..b71dbef7979e 100644
--- a/products/review_hog/backend/reviewer/tools/single_agent_review.py
+++ b/products/review_hog/backend/reviewer/tools/single_agent_review.py
@@ -15,12 +15,14 @@ import logging
from collections import Counter
from collections.abc import Mapping
from dataclasses import replace
+from difflib import SequenceMatcher
from pathlib import Path
from posthog.dataclasses import frozen
from products.review_hog.backend.reviewer.artefact_content import ReviewIssueFinding, ValidationVerdict
from products.review_hog.backend.reviewer.constants import (
+ FLASH_FOLLOW_UP_CHANGE_MARGIN_LINES,
FLASH_LENSES,
FLASH_MUST_FIX_CAP_MULTIPLIER,
FLASH_PROMPT_DIFF_MAX_CHARS,
@@ -489,6 +491,106 @@ def _raise_survivors(kept: list[Issue], duplicates: list[Duplicate]) -> dict[str
return group_levels
+def _patch_missing(pr_file: PRFile) -> bool:
+ return not pr_file.changes and bool(pr_file.additions or pr_file.deletions)
+
+
+@frozen
+class _DiffLine:
+ kind: str
+ code: str
+ # The head line it sits on. A removed line has none, so it takes the head line where it used to be.
+ head_line: int
+
+
+def _diff_sequence(pr_file: PRFile) -> list[_DiffLine]:
+ sequence: list[_DiffLine] = []
+ removal_point = 1
+ for change in pr_file.changes:
+ code_lines = change.code.split("\n")
+ if change.type == "deletion":
+ sequence.extend(_DiffLine(kind=change.type, code=code, head_line=removal_point) for code in code_lines)
+ continue
+ start = change.new_start_line
+ if start is None:
+ continue
+ sequence.extend(
+ _DiffLine(kind=change.type, code=code, head_line=start + offset) for offset, code in enumerate(code_lines)
+ )
+ removal_point = start + len(code_lines)
+ return sequence
+
+
+def _lines_new_since(pr_file: PRFile, earlier: PRFile | None) -> set[int]:
+ """The head lines of the file's changes that the earlier diff did not have.
+
+ The two diffs are matched as sequences of lines with their context, so code that a base merge or a rebase
+ only moved stays old, and a repeated line matches the occurrence in the same place.
+ """
+ current = _diff_sequence(pr_file)
+ before = _diff_sequence(earlier) if earlier is not None else []
+ # The default junk heuristic keeps a repetitive patch from making the match quadratic. It can only
+ # leave lines unmatched, which marks them as changed.
+ matcher = SequenceMatcher(
+ None, [(line.kind, line.code) for line in before], [(line.kind, line.code) for line in current]
+ )
+ new_lines: set[int] = set()
+ for tag, before_start, before_end, current_start, current_end in matcher.get_opcodes():
+ if tag == "equal":
+ continue
+ # Context lines count too, so a statement moved into new surroundings is changed code.
+ new_lines.update(line.head_line for line in current[current_start:current_end])
+ # A change the earlier diff had and this one lost, such as a removed guard, changes the code around it.
+ if any(line.kind != "context" for line in before[before_start:before_end]):
+ new_lines.update(line.head_line for line in current[max(current_start - 1, 0) : current_start + 1])
+ return new_lines
+
+
+@frozen
+class ChangedSinceReview:
+ """The lines of the head that changed since an earlier reviewed head, per file."""
+
+ lines: dict[str, set[int]]
+ files_without_patch: set[str]
+
+ @classmethod
+ def between(cls, earlier_files: list[PRFile], current_files: list[PRFile]) -> "ChangedSinceReview":
+ earlier_by_name = {pr_file.filename: pr_file for pr_file in earlier_files}
+ lines: dict[str, set[int]] = {}
+ files_without_patch: set[str] = set()
+ for pr_file in current_files:
+ earlier = earlier_by_name.get(pr_file.filename)
+ if _patch_missing(pr_file) or (earlier is not None and _patch_missing(earlier)):
+ files_without_patch.add(pr_file.filename)
+ else:
+ lines[pr_file.filename] = _lines_new_since(pr_file, earlier)
+ return cls(lines=lines, files_without_patch=files_without_patch)
+
+ def touches(self, issue: Issue) -> bool:
+ """Whether the finding sits on or near a changed line, or in a file whose lines cannot be compared."""
+ if not issue.lines or issue.file in self.files_without_patch:
+ return True
+ changed = self.lines.get(issue.file, set())
+ margin = FLASH_FOLLOW_UP_CHANGE_MARGIN_LINES
+ # The range comes from the model, so it is compared, never expanded line by line.
+ return any(
+ line_range.start - margin <= line <= (line_range.end or line_range.start) + margin
+ for line_range in issue.lines
+ for line in changed
+ )
+
+
+def _old_code_findings(issues: list[Issue], changed_since: ChangedSinceReview | None) -> list[Issue]:
+ """A follow-up turn's P2 and P3 findings on code that did not change since the last reviewed head.
+
+ Authors act on these about half as often as on first-turn findings, because the first review already
+ covered that code. A P0 or P1 still posts, since a new commit can break code it did not touch.
+ """
+ if changed_since is None:
+ return []
+ return [issue for issue in issues if issue.priority != IssuePriority.MUST_FIX and not changed_since.touches(issue)]
+
+
async def dedupe_flash_findings(
*,
team_id: int,
@@ -502,6 +604,7 @@ async def dedupe_flash_findings(
lens_part_count: int,
workflow_id_prefix: str | None = None,
fall_back_on_any_error: bool = False,
+ changed_since: ChangedSinceReview | None = None,
) -> FlashSelection:
"""Deduplicate a single-agent turn's main and lens findings, then keep the few it posts.
@@ -511,9 +614,13 @@ async def dedupe_flash_findings(
it repeats survives (`_resolve_duplicates`). A finding that survives takes the priority of the most
severe duplicate removed in its favor. `fall_back_on_any_error` lets a dedup
call fall back to the positional pre-filter on any failure, for the activity's last attempt.
+ On a follow-up turn, `changed_since` drops the P2 and P3 findings on unchanged code before dedup.
"""
- main = [issue for issue in issues if issue.source_perspective == SINGLE_AGENT_SOURCE]
- lens = [issue for issue in issues if issue.source_perspective != SINGLE_AGENT_SOURCE]
+ old_code = _old_code_findings(issues, changed_since)
+ old_code_ids = {issue.id for issue in old_code}
+ reviewed = [issue for issue in issues if issue.id not in old_code_ids]
+ main = [issue for issue in reviewed if issue.source_perspective == SINGLE_AGENT_SOURCE]
+ lens = [issue for issue in reviewed if issue.source_perspective != SINGLE_AGENT_SOURCE]
main_outcome, lens_outcome = await asyncio.gather(
deduplicate_issues(
team_id=team_id,
@@ -559,13 +666,15 @@ async def dedupe_flash_findings(
for removal in held
]
logger.info(
- "Flash keeps %s of %s main and %s lens finding(s) left after dedup",
+ "Flash keeps %s of %s main and %s lens finding(s) left after dedup, after %s on unchanged code",
len(composed.kept),
len(kept_main),
len(kept_lens),
+ len(old_code),
)
+ old_code_drops = [DroppedIssue(issue=issue, disposition="old_code") for issue in old_code]
return replace(
composed,
- dropped=[*dedup_drops, *composed.dropped],
+ dropped=[*old_code_drops, *dedup_drops, *composed.dropped],
dedup_fell_back=main_outcome.fell_back or lens_outcome.fell_back,
)
diff --git a/products/review_hog/backend/temporal/activities.py b/products/review_hog/backend/temporal/activities.py
index 406b8303662b..e9bea4c0db67 100644
--- a/products/review_hog/backend/temporal/activities.py
+++ b/products/review_hog/backend/temporal/activities.py
@@ -146,6 +146,7 @@ from products.review_hog.backend.reviewer.tools.select_perspectives import (
prunable_perspectives,
)
from products.review_hog.backend.reviewer.tools.single_agent_review import (
+ ChangedSinceReview,
FlashSelection,
FlashTurnStats,
SingleAgentPrompt,
@@ -1407,6 +1408,27 @@ def _combine_and_clean(
return clean_issues(raw_issues, pr_files)
+def _changed_since_last_review(
+ team_id: int, report_id: str, head_sha: str, current_files: list[PRFile]
+) -> ChangedSinceReview | None:
+ """What changed since the head the last completed turn reviewed, or None for a first review or a re-run at that head.
+
+ Only a single-agent snapshot is a baseline: a Full turn at that head fetched a different file set, so the check
+ then does not run.
+ """
+ reviewed_head = (
+ ReviewReport.objects.for_team(team_id).filter(id=report_id).values_list("completed_head_sha", flat=True).first()
+ )
+ if reviewed_head is None or reviewed_head == head_sha:
+ return None
+ reviewed = load_pr_snapshot(
+ team_id=team_id, report_id=report_id, head_sha=reviewed_head, review_design=REVIEW_DESIGN_SINGLE_AGENT
+ )
+ if reviewed is None:
+ return None
+ return ChangedSinceReview.between(reviewed.pr_files, current_files)
+
+
@activity.defn
@scoped_temporal()
@close_db_connections
@@ -1448,6 +1470,9 @@ async def dedup_activity(input: SandboxStageInput) -> DedupResult:
async with ReviewActivityHeartbeater(team_id=input.team_id, report_id=input.report_id, head_sha=input.head_sha):
if single_agent:
lens_plan = plan_lens_chunks(snapshot.pr_files)
+ changed_since = await database_sync_to_async(_changed_since_last_review, thread_sensitive=False)(
+ input.team_id, input.report_id, input.head_sha, snapshot.pr_files
+ )
flash_selection = await dedupe_flash_findings(
team_id=input.team_id,
user_id=input.user_id,
@@ -1460,6 +1485,7 @@ async def dedup_activity(input: SandboxStageInput) -> DedupResult:
lens_part_count=len(lens_plan.chunks),
workflow_id_prefix=_sandbox_workflow_id_prefix("dedup"),
fall_back_on_any_error=_is_final_attempt(),
+ changed_since=changed_since,
)
survivors = flash_selection.kept
flash_stats = flash_turn_stats(issues, flash_selection, reviewable_lines=lens_plan.reviewable_lines)
diff --git a/products/review_hog/backend/tests/test_constants.py b/products/review_hog/backend/tests/test_constants.py
index 317adb31acf9..2d2bf3a782b0 100644
--- a/products/review_hog/backend/tests/test_constants.py
+++ b/products/review_hog/backend/tests/test_constants.py
@@ -71,7 +71,7 @@ class TestSelectReviewDesign:
@parameterized.expand(
[
# Dashboards split Flash by version, so a v2 turn must never report the v1 id or the reverse.
- ("flash_single_agent", REVIEW_MODE_FLASH, REVIEW_DESIGN_SINGLE_AGENT, "reviewhog-flash-2-0"),
+ ("flash_single_agent", REVIEW_MODE_FLASH, REVIEW_DESIGN_SINGLE_AGENT, "reviewhog-flash-2-1"),
("flash_pipeline", REVIEW_MODE_FLASH, REVIEW_DESIGN_PIPELINE, "reviewhog-flash-1-2"),
("full_pipeline", REVIEW_MODE_FULL, REVIEW_DESIGN_PIPELINE, "reviewhog-full-1-2"),
]
diff --git a/products/review_hog/backend/tests/test_fingerprint.py b/products/review_hog/backend/tests/test_fingerprint.py
index 26ccdff94b2a..8fc2efafa44d 100644
--- a/products/review_hog/backend/tests/test_fingerprint.py
+++ b/products/review_hog/backend/tests/test_fingerprint.py
@@ -100,7 +100,7 @@ class TestRecordTurnMarker(BaseTest):
self._edit_single_agent_prompt(f"{prompt_name}.md")
changed = self._record_single_agent(run_index=2)
- assert original.version == "reviewhog-flash-2-0"
+ assert original.version == "reviewhog-flash-2-1"
assert changed.fingerprint != original.fingerprint
@parameterized.expand(