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): reply when a requested standard review finds nothing (#117033)

Julian Beze1f1e98db04b
diff --git a/products/review_hog/ARCHITECTURE.md b/products/review_hog/ARCHITECTURE.md
index 5e5aad94fd13..1fa3a087e9cc 100644
--- a/products/review_hog/ARCHITECTURE.md
+++ b/products/review_hog/ARCHITECTURE.md
@@ -488,6 +488,7 @@ pr_metadata.head_branch` is threaded (as explicit kwargs, alongside `team_id` /
When a publishing turn ends, after publish or after the failure is recorded, `nudge_stamphog_activity` calls stamphog's `request_rereview_after_external_review` (behind the `reviewhog-nudge-stamphog-2026-10` patch, fail-open). Stamphog decides whether a WAIT at that head runs again.
**Standard turns post no status comment** (the same patch): the 👀 shows the turn runs, and the outcome is the review, a 👍 on the PR when nothing is publishable, or one failure comment per head (`post_failure_comment`, hidden `reviewhog:failed` marker) posted by `fail_status_comment_activity`.
A later publish with findings, in either mode, first removes the app's own 👍 (`remove_own_pr_reactions`, matched with `is_app_bot_author`). The 👍 does not come back: a clean turn adds it only while no turn of the PR published findings (`published_head_sha` unset).
+ A clean Standard turn that a person asked for (`REQUESTED_TRIGGERS`: the label, a comment, the UI, or the CLI) also posts a one-line review that says it found nothing, because the 👍 is easy to miss next to other bots' reactions. It has a hidden `reviewhog:clean-reply:<report>:<head>` marker, so each head gets one reply, also when a workflow retry starts a new turn. A second request on the same head reuses the findings stored for that head (`load_perspective_results`), runs no sandbox and posts nothing new, because the first reply already answers it. Automatic and inbox turns keep only the 👍.
Status comments that earlier turns left on the PR stay as they are, and a Standard turn never refreshes them.
On the publish path of a **Deep** turn a live **status comment**
(`reviewer/status_comment.py`) is posted at kickoff as one table with a row per step of the turn's review design,
diff --git a/products/review_hog/backend/reviewer/tests/test_publish_review.py b/products/review_hog/backend/reviewer/tests/test_publish_review.py
index 83c43bf38e62..cb77c774a78f 100644
--- a/products/review_hog/backend/reviewer/tests/test_publish_review.py
+++ b/products/review_hog/backend/reviewer/tests/test_publish_review.py
@@ -30,6 +30,11 @@ _LOAD_FINDINGS = "products.review_hog.backend.reviewer.tools.publish_review.load
_POST = "products.review_hog.backend.reviewer.tools.publish_review._post_github_review"
_ADD_REACTION = "products.review_hog.backend.reviewer.tools.publish_review.add_pr_reaction"
_REMOVE_REACTIONS = "products.review_hog.backend.reviewer.tools.publish_review.remove_own_pr_reactions"
+_CLEAN = "**PostHog Review · Standard · reviewed `sha`**: no findings."
+_LARGE_NOTE = (
+ "**PostHog Review · Standard · reviewed `sha`**: no findings. This pull request is large, so the"
+ " review ran in 3 parts with less depth than usual."
+)
# The should_fix threshold: publishes should_fix and must_fix, drops consider. These tests use it to
# exercise the publish gate, not the default (consider), which publishes everything.
@@ -457,19 +462,53 @@ class TestPublishReviewGate:
@parameterized.expand(
[
- ("deep", "full", None, None, [], None),
- ("deep_large", "full", 3, None, [], None),
- ("standard_reacts", "flash", None, None, [("o/r", 1, "+1")], None),
+ ("deep", "full", None, None, False, [], None, None),
+ ("deep_large", "full", 3, None, False, [], None, None),
+ ("deep_requested", "full", None, None, True, [], None, None),
+ ("standard_reacts", "flash", None, None, False, [("o/r", 1, "+1")], None, None),
# An earlier turn published findings, so a clean turn must not bring the 👍 back.
- ("standard_after_published_findings_does_not_react", "flash", None, "old", [], None),
+ ("standard_after_published_findings_does_not_react", "flash", None, "old", False, [], None, None),
(
"standard_large_reacts_and_posts_the_note",
"flash",
3,
None,
+ False,
+ [("o/r", 1, "+1")],
+ f"{_LARGE_NOTE}\n\n<!-- reviewhog:large-pr-note:rep:sha -->",
+ # The skip check matches a note from any earlier head, so re-reviews do not repeat it.
+ "<!-- reviewhog:large-pr-note:rep:",
+ ),
+ (
+ "standard_requested_replies",
+ "flash",
+ None,
+ None,
+ True,
+ [("o/r", 1, "+1")],
+ f"{_CLEAN}\n\n<!-- reviewhog:clean-reply:rep:sha -->",
+ "<!-- reviewhog:clean-reply:rep:sha -->",
+ ),
+ (
+ "standard_requested_after_published_findings_replies",
+ "flash",
+ None,
+ "old",
+ True,
+ [],
+ f"{_CLEAN}\n\n<!-- reviewhog:clean-reply:rep:sha -->",
+ "<!-- reviewhog:clean-reply:rep:sha -->",
+ ),
+ # The reply carries the note's marker too, so a later automatic turn does not repeat the note.
+ (
+ "standard_large_requested_replies_with_the_note",
+ "flash",
+ 3,
+ None,
+ True,
[("o/r", 1, "+1")],
- "**PostHog Review · Standard · reviewed `sha`**: no findings. This pull request is large, so the"
- " review ran in 3 parts with less depth than usual.",
+ f"{_LARGE_NOTE}\n\n<!-- reviewhog:clean-reply:rep:sha --><!-- reviewhog:large-pr-note:rep:sha -->",
+ "<!-- reviewhog:clean-reply:rep:sha -->",
),
]
)
@@ -482,16 +521,18 @@ class TestPublishReviewGate:
review_mode: str,
capped_lens_parts: int | None,
published_head_sha: str | None,
+ answers_request: bool,
expected_reactions: list[tuple[str, int, str]],
- expected_note: str | None,
+ expected_body: str | None,
+ expected_marker: str | None,
mock_report_cls: MagicMock,
mock_load: MagicMock,
mock_post: MagicMock,
) -> None:
# Below the should_fix threshold: a run whose only valid finding is `consider` has
# nothing publishable, so it posts no findings (guards the off-diff fix against over-surfacing).
- # A clean Standard turn has no status comment, so its 👍 and its large pull request note
- # are the only signs that it ran.
+ # A clean Standard turn has no status comment, so its 👍, its large pull request note and its
+ # reply to a request are the only signs that it ran.
self._wire_report(mock_report_cls, published_head_sha)
mock_load.return_value = [(_finding(priority=IssuePriority.CONSIDER), _verdict())]
@@ -501,7 +542,7 @@ class TestPublishReviewGate:
pr_number=1,
team_id=1,
report_id="rep",
- run_index=1,
+ run_index=2,
pr_files=[],
token="t",
head_sha="sha",
@@ -510,19 +551,19 @@ class TestPublishReviewGate:
capped_lens_parts=capped_lens_parts,
# A clean turn posts no findings, so the note below must leave this out.
findings_footer="Draft notice.",
+ answers_request=answers_request,
)
assert outcome.posted is False
assert [c.args for c in self.add_reaction.call_args_list] == expected_reactions
- if expected_note is None:
+ if expected_body is None:
mock_post.assert_not_called()
return
mock_post.assert_called_once()
body, comments = mock_post.call_args.args[3:5]
- assert body == f"{expected_note}\n\n<!-- reviewhog:large-pr-note:rep:sha -->"
+ assert body == expected_body
assert comments == []
- # The skip check matches a note from any earlier head, so re-reviews do not repeat it.
- assert mock_post.call_args.kwargs["marker"] == "<!-- reviewhog:large-pr-note:rep:"
+ assert mock_post.call_args.kwargs["marker"] == expected_marker
@parameterized.expand(
[
diff --git a/products/review_hog/backend/reviewer/tools/publish_review.py b/products/review_hog/backend/reviewer/tools/publish_review.py
index 994aab2d1504..2ba13e33ae75 100644
--- a/products/review_hog/backend/reviewer/tools/publish_review.py
+++ b/products/review_hog/backend/reviewer/tools/publish_review.py
@@ -98,6 +98,7 @@ def publish_persisted_review(
footer: str = "",
draft_notice: str = "",
comment_commands_on: bool = False,
+ answers_request: bool = False,
) -> PublishOutcome:
"""Publish an already-computed review for `report_id` at `head_sha`, idempotently.
@@ -114,6 +115,7 @@ def publish_persisted_review(
`draft_notice` closes a review with findings when the turn's snapshot shows the PR as a draft.
`comment_commands_on` picks the trigger the finding budget note points to.
+ `answers_request` is set when a person asked for this turn (see `publish_review`).
"""
report = ReviewReport.objects.for_team(team_id).get(id=report_id)
if review_already_published(report, head_sha, review_mode):
@@ -145,6 +147,7 @@ def publish_persisted_review(
capped_lens_parts=capped_lens_parts,
footer=footer,
findings_footer=draft_notice if snapshot is not None and snapshot.pr_metadata.draft else "",
+ answers_request=answers_request,
budget_note=budget_note(over_budget, comment_commands_on) if over_budget else "",
)
if outcome.posted:
@@ -222,6 +225,16 @@ def _large_pr_note_marker(report_id: str, head_sha: str) -> str:
return f"{_large_pr_note_prefix(report_id)}{head_sha} -->"
+def _clean_reply_marker(report_id: str, head_sha: str) -> str:
+ """The hidden marker of the reply to a requested Standard turn that found nothing.
+
+ It is per head, not per turn: a workflow retry starts a new turn after the old one counted, so a turn
+ index would post the reply again. A later request on the same head also adds nothing, because the
+ first reply already answers it.
+ """
+ return f"<!-- reviewhog:clean-reply:{report_id}:{head_sha} -->"
+
+
def publish_review(
*,
owner: str,
@@ -240,6 +253,7 @@ def publish_review(
footer: str = "",
findings_footer: str = "",
budget_note: str = "",
+ answers_request: bool = False,
) -> PublishOutcome:
"""Publish the review to GitHub: the stored body plus inline comments from the durable rows.
@@ -258,8 +272,11 @@ def publish_review(
`findings_footer` follows `footer` only on a review that posts findings, never on the clean-turn note.
- `budget_note` says the finding budget left findings out. A turn that keeps nothing stays silent: once
+ `budget_note` says the finding budget left findings out. An automatic turn that keeps nothing stays silent: once
the budget is spent an automatic review only looks for must-fix findings.
+
+ `answers_request` is set when a person asked for the turn, with the label, a comment, or the UI. A clean
+ Standard turn then posts a short review that says it found nothing. A Deep turn has its status comment for that.
"""
logger.info(f"Publishing review for {owner}/{repo}#{pr_number}")
@@ -291,18 +308,23 @@ def publish_review(
# published findings, the 👍 stays off, because a later clean turn does not clear those findings.
if standard and report.published_head_sha is None:
add_pr_reaction(repository, pr_number, "+1", token=token, installation_id=installation_id)
- if large_pr_parts is not None:
+ replies = standard and answers_request
+ if replies or large_pr_parts is not None:
# Not a published turn: the watermark stays unset, so a later turn on this head can still publish.
summary = render_review_summary(review_mode, head_sha, Counter(), large_pr_parts)
+ hidden = _clean_reply_marker(report_id, head_sha) if replies else ""
+ if large_pr_parts is not None:
+ hidden = f"{hidden}{_large_pr_note_marker(report_id, head_sha)}"
_post_github_review(
owner,
repo,
pr_number,
- f"{summary}\n\n{footer_block}{_large_pr_note_marker(report_id, head_sha)}",
+ f"{summary}\n\n{footer_block}{hidden}",
[],
token=token,
head_sha=head_sha,
- marker=_large_pr_note_prefix(report_id),
+ # A reply posts once per head. The large pull request note alone posts once per pull request.
+ marker=_clean_reply_marker(report_id, head_sha) if replies else _large_pr_note_prefix(report_id),
installation_id=installation_id,
review_mode=review_mode,
)
diff --git a/products/review_hog/backend/temporal/activities.py b/products/review_hog/backend/temporal/activities.py
index c22d753f019e..04e8b8ab73cf 100644
--- a/products/review_hog/backend/temporal/activities.py
+++ b/products/review_hog/backend/temporal/activities.py
@@ -211,7 +211,12 @@ from products.review_hog.backend.reviewer.tools.split_pr_into_chunks import (
reconcile_chunks,
)
from products.review_hog.backend.temporal.heartbeat import ReviewActivityHeartbeater
-from products.review_hog.backend.temporal.types import TRIGGER_AUTOMATIC, TRIGGER_LABEL, TRIGGER_MANUAL
+from products.review_hog.backend.temporal.types import (
+ REQUESTED_TRIGGERS,
+ TRIGGER_AUTOMATIC,
+ TRIGGER_LABEL,
+ TRIGGER_MANUAL,
+)
from products.signals.backend.artefact_attribution import ArtefactAttribution
from products.signals.backend.artefact_schemas import CodeReview, CodeReviewCounts
from products.signals.backend.enums import ReportPriority
@@ -2085,6 +2090,7 @@ def _publish(input: PublishInput) -> PublishResult:
capped_lens_parts=input.capped_lens_parts,
footer=footer,
draft_notice=draft_notice,
+ answers_request=input.trigger_source in REQUESTED_TRIGGERS,
comment_commands_on=comment_commands_on,
)
if input.trigger_source == TRIGGER_AUTOMATIC:
diff --git a/products/review_hog/backend/temporal/types.py b/products/review_hog/backend/temporal/types.py
index 2237f3f80a09..11a277d6eb94 100644
--- a/products/review_hog/backend/temporal/types.py
+++ b/products/review_hog/backend/temporal/types.py
@@ -18,6 +18,9 @@ TRIGGER_MANUAL = "manual"
TRIGGER_UI = "ui"
TRIGGER_COMMENT = "comment"
TRIGGER_AUTOMATIC = "automatic"
+# The triggers a person starts and then waits on for an answer. An inbox review comes from the signals
+# agent, so it is not one of them.
+REQUESTED_TRIGGERS = frozenset({TRIGGER_LABEL, TRIGGER_MANUAL, TRIGGER_UI, TRIGGER_COMMENT})
@frozen
diff --git a/products/review_hog/backend/tests/test_publish_idempotency.py b/products/review_hog/backend/tests/test_publish_idempotency.py
index 43ea3e8a172a..0274d7a2abbb 100644
--- a/products/review_hog/backend/tests/test_publish_idempotency.py
+++ b/products/review_hog/backend/tests/test_publish_idempotency.py
@@ -282,22 +282,26 @@ class TestPublishIdempotency(BaseTest):
@parameterized.expand(
[
- ("automatic_draft_with_commands", "automatic", True, True, "Comment `@posthog review` to review"),
- ("automatic_draft_without_commands", "automatic", True, False, "Add the `posthog-review` label to"),
- ("automatic_ready", "automatic", False, True, None),
+ ("automatic_draft_with_commands", "automatic", True, True, "Comment `@posthog review` to review", False),
+ ("automatic_draft_without_commands", "automatic", True, False, "Add the `posthog-review` label to", False),
+ ("automatic_ready", "automatic", False, True, None, False),
# A label review also runs for authors without automatic reviews, so it cannot promise one on ready.
- ("label_draft", "label", True, True, None),
+ ("label_draft", "label", True, True, None, True),
+ ("comment_ready", "comment", False, True, None, True),
+ ("ui_ready", "ui", False, True, None, True),
+ ("inbox_ready", "inbox", False, True, None, False),
]
)
@patch(_PUBLISH)
@patch(_AUTH, return_value=("tok", None))
- def test_an_automatic_review_of_a_draft_says_when_the_next_review_runs(
+ def test_the_publish_notes_follow_the_trigger(
self,
_name: str,
trigger_source: str,
draft: bool,
commands_on: bool,
expected_trigger: str | None,
+ expects_reply: bool,
_auth,
mock_publish,
) -> None:
@@ -315,6 +319,7 @@ class TestPublishIdempotency(BaseTest):
):
_publish(replace(_publish_input(self.team.id, report_id, "sha1"), trigger_source=trigger_source))
+ assert mock_publish.call_args.kwargs["answers_request"] is expects_reply
findings_footer = mock_publish.call_args.kwargs["findings_footer"]
if expected_trigger is None:
assert findings_footer == ""