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.

fix(review-hog): stop counting reviewhog's own reactions as engagement (#114661)

Julian Bez5c2ac297b92b
diff --git a/products/review_hog/ARCHITECTURE.md b/products/review_hog/ARCHITECTURE.md
index e802c420f3d8..c73a9225ec92 100644
--- a/products/review_hog/ARCHITECTURE.md
+++ b/products/review_hog/ARCHITECTURE.md
@@ -454,6 +454,7 @@ pr_metadata.head_branch` is threaded (as explicit kwargs, alongside `team_id` /
A single-agent finding shows its `reported_priority` while that level still folds into the effective priority; otherwise `must_fix` shows P1, `should_fix` P2, and `consider` P3 (`display_level`).
The body's Other-findings section uses the same heading, then the file and lines, then the same paragraph.
The outcome sweep (`find_finding_comment`) matches a finding to its comment by the whole first line, for any P level and for the older `### {title}` heading.
+ A reply or reaction counts as engagement unless ReviewHog's own app left it (`engagement_method`), so the resolution stage's 👀 queue marker never marks a finding `reacted`.
The validator's argumentation stays out of GitHub; the reviews API returns it as `validator_note`.
When every publishable finding posts inline, the review body is only the hidden publish marker, because the tally repeats the comments.
The body-only fallback always posts the full body.
diff --git a/products/review_hog/backend/reviewer/constants.py b/products/review_hog/backend/reviewer/constants.py
index f28d4c7d0bd6..3ead8e6cbfd3 100644
--- a/products/review_hog/backend/reviewer/constants.py
+++ b/products/review_hog/backend/reviewer/constants.py
@@ -597,6 +597,11 @@ OUTCOME_MAX_REPORTS_PER_SWEEP = 50
# whole report is decided, the retry and every later sweep would replay the same calls and never
# finish it. Candidates past this ceiling settle without a judge call so the report always completes.
OUTCOME_MAX_JUDGE_CALLS_PER_REPORT = 30
+# Ceiling on reaction reads for one report: each finding comment with a reaction costs one GitHub read
+# to see who left it. Outcomes persist only once the whole report is decided, so a report that spends
+# the installation's budget stops the team's sweep and replays the same reads on every retry. Comments
+# past the ceiling go to the line check and judge, which under-counts `reacted` rather than inventing it.
+OUTCOME_MAX_REACTION_READS_PER_REPORT = 30
# A judge call that fails settles its finding as `judge_failed` rather than throwing away the whole
# report's completed judgments and replaying them next sweep. These two bound that tolerance, because
# an outcome is written once and never re-decided: recording a report's worth of `judge_failed` during
diff --git a/products/review_hog/backend/reviewer/outcomes/classify.py b/products/review_hog/backend/reviewer/outcomes/classify.py
index 6cddf1c7d308..92fc0c0344e2 100644
--- a/products/review_hog/backend/reviewer/outcomes/classify.py
+++ b/products/review_hog/backend/reviewer/outcomes/classify.py
@@ -50,6 +50,7 @@ from products.review_hog.backend.reviewer.constants import (
OUTCOME_LINE_PROXIMITY_WINDOW,
OUTCOME_MAX_EXTRA_COMPARE_BASES,
OUTCOME_MAX_JUDGE_CALLS_PER_REPORT,
+ OUTCOME_MAX_REACTION_READS_PER_REPORT,
OUTCOME_MAX_REPORTS_PER_SWEEP,
effective_priority,
priority_rank,
@@ -58,7 +59,11 @@ from products.review_hog.backend.reviewer.constants import (
from products.review_hog.backend.reviewer.models.issues_review import IssuePriority
from products.review_hog.backend.reviewer.outcomes.comment_signal import engagement_method, find_finding_comment
from products.review_hog.backend.reviewer.outcomes.discovery import unclassified_published_reports
-from products.review_hog.backend.reviewer.outcomes.github_fetch import fetch_compare_files, fetch_review_comments
+from products.review_hog.backend.reviewer.outcomes.github_fetch import (
+ fetch_comment_reactions,
+ fetch_compare_files,
+ fetch_review_comments,
+)
from products.review_hog.backend.reviewer.outcomes.judge import judge_finding
from products.review_hog.backend.reviewer.outcomes.line_proximity import parse_compare_files, touched_near
from products.review_hog.backend.reviewer.persistence import load_findings_bundle
@@ -110,6 +115,7 @@ class _ReportInputs:
# inside the diff it is judged on.
compares: dict[str, list[dict[str, Any]]]
review_comments: list[dict[str, Any]]
+ reactions_by_comment: dict[int, list[dict[str, Any]]]
published: list[_PublishedFinding]
distinct_id: str
judge_user_id: int
@@ -153,7 +159,7 @@ def _touching_diff(file: str, compare_files: list[dict[str, Any]]) -> str:
def _gather_report_inputs(*, team_id: int, report: ReviewReport, final_head: str) -> _ReportInputs:
- """All the blocking IO for one report: auth, compare, comments, and its published findings.
+ """All the blocking IO for one report: auth, compare, comments, reactions, and its published findings.
Returns the findings publishing gated on (validated + at/above the acting user's urgency
threshold), each paired with its inline comment when one is on the PR. Raises when auth is
@@ -239,18 +245,43 @@ def _gather_report_inputs(*, team_id: int, report: ReviewReport, final_head: str
for base in [reviewed_head, *extra_bases]
}
+ published_findings = [
+ _PublishedFinding(
+ finding=finding,
+ verdict=verdict,
+ comment=find_finding_comment(finding=finding, review_comments=review_comments),
+ reviewed_head=(base if (base := base_by_run[finding.run_index]) in compares else reviewed_head),
+ )
+ for finding, verdict in to_classify
+ ]
+ reacted_comment_ids = list(
+ dict.fromkeys(
+ pf.comment["id"]
+ for pf in published_findings
+ if pf.comment is not None and (pf.comment.get("reactions") or {}).get("total_count", 0) > 0
+ )
+ )
+ if len(reacted_comment_ids) > OUTCOME_MAX_REACTION_READS_PER_REPORT:
+ logger.warning(
+ "Report %s has %d reacted finding comments; reading the reactions of the first %d, so the rest "
+ "may read as addressed or ignored instead of reacted",
+ report.id,
+ len(reacted_comment_ids),
+ OUTCOME_MAX_REACTION_READS_PER_REPORT,
+ )
+ reacted_comment_ids = reacted_comment_ids[:OUTCOME_MAX_REACTION_READS_PER_REPORT]
+ reactions_by_comment = {
+ comment_id: fetch_comment_reactions(
+ owner=owner, repo=repo, comment_id=comment_id, token=token, installation_id=installation_id
+ )
+ for comment_id in reacted_comment_ids
+ }
+
return _ReportInputs(
compares=compares,
review_comments=review_comments,
- published=[
- _PublishedFinding(
- finding=finding,
- verdict=verdict,
- comment=find_finding_comment(finding=finding, review_comments=review_comments),
- reviewed_head=(base if (base := base_by_run[finding.run_index]) in compares else reviewed_head),
- )
- for finding, verdict in to_classify
- ],
+ reactions_by_comment=reactions_by_comment,
+ published=published_findings,
distinct_id=_finding_distinct_id(report, repository),
judge_user_id=report.acting_user_id or 0,
)
@@ -446,7 +477,15 @@ async def classify_report(
# judge compete for its budget.
candidates: list[_PublishedFinding] = []
for pf in inputs.published:
- method = engagement_method(comment=pf.comment, review_comments=inputs.review_comments) if pf.comment else None
+ method = (
+ engagement_method(
+ comment=pf.comment,
+ review_comments=inputs.review_comments,
+ reactions=inputs.reactions_by_comment.get(pf.comment["id"], []),
+ )
+ if pf.comment
+ else None
+ )
if method is not None:
outcomes.append(_decided(pf, "reacted", method))
elif touched_near(
diff --git a/products/review_hog/backend/reviewer/outcomes/comment_signal.py b/products/review_hog/backend/reviewer/outcomes/comment_signal.py
index e9e2193ccb17..995894913a05 100644
--- a/products/review_hog/backend/reviewer/outcomes/comment_signal.py
+++ b/products/review_hog/backend/reviewer/outcomes/comment_signal.py
@@ -3,8 +3,9 @@
ReviewHog's published comments lead with a heading that holds ``finding.title`` and anchor to the
finding's file, so a finding maps to its posted comment exactly by (path, title) — no stored comment id, and robust to
line drift after review (the match is on body content, not position). The one
-``GET /pulls/{n}/comments`` list carries both an ``in_reply_to_id`` per comment and a ``reactions``
-summary, so replies and reactions are read without any extra call or GraphQL.
+``GET /pulls/{n}/comments`` list carries an ``in_reply_to_id`` per comment, so replies need no extra
+call. Its ``reactions`` summary counts reactions but names nobody, so a comment with a reaction costs
+one more read to see who left it (``fetch_comment_reactions``).
"""
from typing import Any
@@ -47,7 +48,9 @@ def find_finding_comment(
return None
-def engagement_method(*, comment: dict[str, Any], review_comments: list[dict[str, Any]]) -> str | None:
+def engagement_method(
+ *, comment: dict[str, Any], review_comments: list[dict[str, Any]], reactions: list[dict[str, Any]]
+) -> str | None:
"""How the finding's thread was engaged, or None if it wasn't. All results map to `reacted`.
Engagement means *someone responded*, not specifically a human: a reply from another agent (a
@@ -64,10 +67,12 @@ def engagement_method(*, comment: dict[str, Any], review_comments: list[dict[str
old behavior of ignoring every bot reply.
A human reply beats an agent one when both are present, and a reaction beats both: it is the
- cheaper, unambiguous signal. The ``reactions`` summary carries no actor, so a bot reaction counts
- as a reaction — accepted, and now consistent with replies rather than at odds with them.
+ cheaper, unambiguous signal. ``reactions`` are the comment's reactions with their actors, and the
+ same rule applies to them: ReviewHog's own never count. The resolution stage puts a 👀 on every
+ thread it queues, so counting it would mark each of those findings ``reacted`` and keep the judge
+ from ruling on the fix that followed.
"""
- if (comment.get("reactions") or {}).get("total_count", 0) > 0:
+ if any(not is_app_bot_author(reaction.get("user")) for reaction in reactions):
return "comment_reaction"
comment_id = comment.get("id")
if comment_id is None:
diff --git a/products/review_hog/backend/reviewer/outcomes/github_fetch.py b/products/review_hog/backend/reviewer/outcomes/github_fetch.py
index ed2e538e74a6..e8c7b0d3c810 100644
--- a/products/review_hog/backend/reviewer/outcomes/github_fetch.py
+++ b/products/review_hog/backend/reviewer/outcomes/github_fetch.py
@@ -1,6 +1,6 @@
-"""The two GitHub reads outcome classification needs, through the gated egress client.
+"""The GitHub reads outcome classification needs, through the gated egress client.
-Both are read-only and metered against the installation's budget like every other ReviewHog call.
+All are read-only and metered against the installation's budget like every other ReviewHog call.
"""
import logging
@@ -88,3 +88,24 @@ def fetch_review_comments(
)
return comments[:_MAX_REVIEW_COMMENTS]
return comments
+
+
+def fetch_comment_reactions(
+ *, owner: str, repo: str, comment_id: int, token: str, installation_id: str | None = None
+) -> list[dict[str, Any]]:
+ """The reactions on one review comment, each with the ``user`` who left it.
+
+ The ``reactions`` summary on a review comment counts reactions but names nobody, and the resolution
+ stage puts its own 👀 on every thread it queues. Only the actors tell that marker apart from
+ someone else's reaction. One page is enough: ReviewHog leaves at most one reaction on a comment, so
+ a full page always holds someone else's.
+ """
+ response = github_api_request(
+ "GET",
+ f"/repos/{owner}/{repo}/pulls/comments/{comment_id}/reactions",
+ token=token,
+ installation_id=installation_id,
+ endpoint="/repos/{owner}/{repo}/pulls/comments/{comment_id}/reactions",
+ params={"per_page": 100},
+ )
+ return response.json()
diff --git a/products/review_hog/backend/reviewer/tests/test_outcome_comment_signal.py b/products/review_hog/backend/reviewer/tests/test_outcome_comment_signal.py
index 984b0e152433..cbfbe6cb2d47 100644
--- a/products/review_hog/backend/reviewer/tests/test_outcome_comment_signal.py
+++ b/products/review_hog/backend/reviewer/tests/test_outcome_comment_signal.py
@@ -60,53 +60,70 @@ _OTHER_BOT: dict[str, Any] = {"login": "greptile-apps[bot]", "type": "Bot"}
class TestEngagementMethod:
- def test_reaction_counts_as_engagement(self):
- comment: dict[str, Any] = {"id": 1, "reactions": {"total_count": 2}}
- assert engagement_method(comment=comment, review_comments=[comment]) == "comment_reaction"
+ @parameterized.expand(
+ [
+ ("human", {"login": "alice", "type": "User"}, "comment_reaction"),
+ ("another_agent", _OTHER_BOT, "comment_reaction"),
+ ("our_own_queue_marker", _OUR_BOT, None),
+ ]
+ )
+ @override_settings(REVIEWHOG_GITHUB_BOT_LOGIN=_OUR_BOT["login"])
+ def test_a_reaction_counts_unless_it_is_ours(self, _name: str, user: dict[str, Any], expected: str | None):
+ comment: dict[str, Any] = {"id": 1}
+ reactions = [{"user": user, "content": "eyes"}]
+ assert engagement_method(comment=comment, review_comments=[comment], reactions=reactions) == expected
def test_reply_counts_as_engagement(self):
- comment: dict[str, Any] = {"id": 1, "reactions": {"total_count": 0}}
+ comment: dict[str, Any] = {"id": 1}
reply: dict[str, Any] = {"id": 2, "in_reply_to_id": 1, "user": {"login": "alice", "type": "User"}}
- assert engagement_method(comment=comment, review_comments=[comment, reply]) == "comment_reply"
+ assert engagement_method(comment=comment, review_comments=[comment, reply], reactions=[]) == "comment_reply"
@override_settings(REVIEWHOG_GITHUB_BOT_LOGIN=_OUR_BOT["login"])
def test_our_own_reply_is_never_engagement(self):
# ReviewHog posts the finding comment itself, so counting its own follow-up would let the
# feature grade its own homework. A fix it lands is captured as a commit the judge rules on.
- comment: dict[str, Any] = {"id": 1, "reactions": {"total_count": 0}}
+ comment: dict[str, Any] = {"id": 1}
reply: dict[str, Any] = {"id": 2, "in_reply_to_id": 1, "user": _OUR_BOT}
- assert engagement_method(comment=comment, review_comments=[comment, reply]) is None
+ assert engagement_method(comment=comment, review_comments=[comment, reply], reactions=[]) is None
@override_settings(REVIEWHOG_GITHUB_BOT_LOGIN=_OUR_BOT["login"])
def test_another_agents_reply_is_engagement_tagged_as_agent(self):
# A reviewer's own bot answering on their behalf is a real response to the finding. Dropping
# it under-reports engagement, so the actor rides in the method instead of being filtered out.
- comment: dict[str, Any] = {"id": 1, "reactions": {"total_count": 0}}
+ comment: dict[str, Any] = {"id": 1}
reply: dict[str, Any] = {"id": 2, "in_reply_to_id": 1, "user": _OTHER_BOT}
- assert engagement_method(comment=comment, review_comments=[comment, reply]) == "comment_reply_agent"
+ assert (
+ engagement_method(comment=comment, review_comments=[comment, reply], reactions=[]) == "comment_reply_agent"
+ )
@override_settings(REVIEWHOG_GITHUB_BOT_LOGIN=_OUR_BOT["login"])
def test_human_reply_wins_over_an_agent_reply(self):
# Both are engagement, but "a human responded" has to stay answerable once agents do more of
# the replying, so the human actor takes the thread.
- comment: dict[str, Any] = {"id": 1, "reactions": {"total_count": 0}}
+ comment: dict[str, Any] = {"id": 1}
agent: dict[str, Any] = {"id": 2, "in_reply_to_id": 1, "user": _OTHER_BOT}
human: dict[str, Any] = {"id": 3, "in_reply_to_id": 1, "user": {"login": "alice", "type": "User"}}
- assert engagement_method(comment=comment, review_comments=[comment, agent, human]) == "comment_reply"
+ assert (
+ engagement_method(comment=comment, review_comments=[comment, agent, human], reactions=[]) == "comment_reply"
+ )
def test_agent_replies_are_ignored_when_our_bot_login_is_unconfigured(self):
# `is_app_bot_author` fails open to "any bot" without REVIEWHOG_GITHUB_BOT_LOGIN, so a
# stranger's bot is never credited as engagement on a deployment that cannot tell it from
# ours — the signal degrades to the old ignore-every-bot behaviour rather than misattributing.
- comment: dict[str, Any] = {"id": 1, "reactions": {"total_count": 0}}
+ comment: dict[str, Any] = {"id": 1}
reply: dict[str, Any] = {"id": 2, "in_reply_to_id": 1, "user": _OTHER_BOT}
- assert engagement_method(comment=comment, review_comments=[comment, reply]) is None
+ assert engagement_method(comment=comment, review_comments=[comment, reply], reactions=[]) is None
def test_reaction_wins_over_reply(self):
- comment: dict[str, Any] = {"id": 1, "reactions": {"total_count": 1}}
+ comment: dict[str, Any] = {"id": 1}
reply: dict[str, Any] = {"id": 2, "in_reply_to_id": 1}
- assert engagement_method(comment=comment, review_comments=[comment, reply]) == "comment_reaction"
+ reactions = [{"user": {"login": "alice", "type": "User"}, "content": "+1"}]
+ assert (
+ engagement_method(comment=comment, review_comments=[comment, reply], reactions=reactions)
+ == "comment_reaction"
+ )
def test_no_reaction_no_reply_is_none(self):
- comment: dict[str, Any] = {"id": 1, "reactions": {"total_count": 0}}
- assert engagement_method(comment=comment, review_comments=[comment]) is None
+ comment: dict[str, Any] = {"id": 1}
+ assert engagement_method(comment=comment, review_comments=[comment], reactions=[]) is None
diff --git a/products/review_hog/backend/tests/test_outcome_classify.py b/products/review_hog/backend/tests/test_outcome_classify.py
index 97ec5b46de44..6be2e2b97a93 100644
--- a/products/review_hog/backend/tests/test_outcome_classify.py
+++ b/products/review_hog/backend/tests/test_outcome_classify.py
@@ -10,6 +10,7 @@ import pytest
from posthog.test.base import BaseTest
from unittest.mock import AsyncMock, patch
+from django.test import override_settings
from django.utils import timezone
from asgiref.sync import async_to_sync
@@ -92,10 +93,17 @@ def _verdict(issue_key: str = _ISSUE_KEY) -> ValidationVerdict:
class TestClassifyReportDecision:
"""The precedence + emit logic, with the DB helpers mocked so no database or thread is involved."""
- def _inputs(self, *, comment: dict[str, Any] | None, compare_files: list[dict[str, Any]]) -> _ReportInputs:
+ def _inputs(
+ self,
+ *,
+ comment: dict[str, Any] | None,
+ compare_files: list[dict[str, Any]],
+ reactions: list[dict[str, Any]] | None = None,
+ ) -> _ReportInputs:
return _ReportInputs(
compares={"base_sha": compare_files},
review_comments=[comment] if comment else [],
+ reactions_by_comment={comment["id"]: reactions} if comment and reactions else {},
published=[
_PublishedFinding(finding=_finding(), verdict=_verdict(), comment=comment, reviewed_head="base_sha")
],
@@ -117,14 +125,23 @@ class TestClassifyReportDecision:
)
return captured, judge
- def test_reacted_takes_precedence_and_skips_the_judge(self):
- # A reaction settles the finding as `reacted` before we spend a judge call — even though the
- # diff also touched its lines. Precedence inversion here would waste tokens and mislabel.
+ @parameterized.expand(
+ [
+ # A reaction settles the finding as `reacted` before we spend a judge call — even though the
+ # diff also touched its lines. Precedence inversion here would waste tokens and mislabel.
+ ("someone_reacted", {"login": "alice", "type": "User"}, "reacted", "comment_reaction"),
+ ("only_our_queue_marker", {"login": "reviewhog[bot]", "type": "Bot"}, "addressed", "judge_confirmed"),
+ ]
+ )
+ @override_settings(REVIEWHOG_GITHUB_BOT_LOGIN="reviewhog[bot]")
+ def test_a_reaction_takes_precedence_unless_it_is_ours(
+ self, _name: str, reactor: dict[str, Any], outcome: str, method: str
+ ):
comment = {"id": 1, "path": "f.py", "body": "### Off-by-one\n\nbody", "reactions": {"total_count": 1}}
- captured, judge = self._run(inputs=self._inputs(comment=comment, compare_files=_TOUCHING))
- judge.assert_not_awaited()
- assert captured[0]["properties"]["outcome"] == "reacted"
- assert captured[0]["properties"]["classification_method"] == "comment_reaction"
+ reactions = [{"user": reactor, "content": "eyes"}]
+ captured, _judge = self._run(inputs=self._inputs(comment=comment, compare_files=_TOUCHING, reactions=reactions))
+ assert captured[0]["properties"]["outcome"] == outcome
+ assert captured[0]["properties"]["classification_method"] == method
def test_addressed_when_touched_and_judge_confirms(self):
captured, judge = self._run(inputs=self._inputs(comment=None, compare_files=_TOUCHING), judge_return=True)
@@ -347,6 +364,7 @@ class TestClassifyReportDecision:
inputs = _ReportInputs(
compares={"base_sha": _TOUCHING},
review_comments=[],
+ reactions_by_comment={},
published=published,
distinct_id="user-distinct",
judge_user_id=0,
@@ -368,6 +386,7 @@ class TestClassifyReportDecision:
return _ReportInputs(
compares={"base_sha": _TOUCHING},
review_comments=[],
+ reactions_by_comment={},
published=[
_PublishedFinding(
finding=_finding(issue_key=f"r1:f.py:{i}:logic"),
@@ -524,11 +543,13 @@ class TestGatherAndIdempotency(BaseTest):
def test_gather_selects_published_finding_pairs_its_comment_and_resolves_distinct_id(self):
report = self._report()
- comment = {"id": 1, "path": "f.py", "body": "### Off-by-one\n\nbody", "reactions": {"total_count": 0}}
+ comment = {"id": 1, "path": "f.py", "body": "### Off-by-one\n\nbody", "reactions": {"total_count": 1}}
+ reactions = [{"user": {"login": "alice", "type": "User"}, "content": "+1"}]
with (
patch(f"{_CLASSIFY}._installation_auth", return_value=("tok", "inst")),
patch(f"{_CLASSIFY}.fetch_compare_files", return_value=_FAR),
patch(f"{_CLASSIFY}.fetch_review_comments", return_value=[comment]),
+ patch(f"{_CLASSIFY}.fetch_comment_reactions", return_value=reactions),
):
inputs = _gather_report_inputs(team_id=self.team.id, report=report, final_head="head_sha")
@@ -536,6 +557,7 @@ class TestGatherAndIdempotency(BaseTest):
assert inputs.published[0].reviewed_head == "base_sha"
assert [pf.finding.issue_key for pf in inputs.published] == [_ISSUE_KEY]
assert inputs.published[0].comment == comment # the finding was paired with its posted comment
+ assert inputs.reactions_by_comment == {1: reactions}
assert inputs.distinct_id == self.user.distinct_id
def test_each_turn_is_compared_from_the_head_it_published_at(self):