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): link the review ui and deep review from the first review (#118836)

posthog[bot]5c963c57f3a8
diff --git a/products/review_hog/ARCHITECTURE.md b/products/review_hog/ARCHITECTURE.md
index 5b652aca0e10..59980d7e8fb3 100644
--- a/products/review_hog/ARCHITECTURE.md
+++ b/products/review_hog/ARCHITECTURE.md
@@ -371,6 +371,11 @@ time loop, and most of what a late round flags was already there in the first. A
`reviewhog_review_completed` event carries `review_round`, so convergence (how many rounds a pull request takes before
a clean turn) reads from the events.
+The first review that posts findings on a pull request ends with one more note (`first_review_note` in
+`backend/label_reviews.py`). It links the report in the PostHog Review UI (`report_deep_link`). On a Standard review,
+where comment commands run, it also offers `@posthog review --deep`. A label review leaves the command out, because
+its own footer already names it. Later reviews do not repeat the note: the published watermark is set after the first post.
+
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` (`old_code`, `dedup_prior`, `dedup_comment`,
diff --git a/products/review_hog/backend/label_reviews.py b/products/review_hog/backend/label_reviews.py
index 1ed457f1c40c..aefac5380629 100644
--- a/products/review_hog/backend/label_reviews.py
+++ b/products/review_hog/backend/label_reviews.py
@@ -84,6 +84,17 @@ def draft_review_notice(comment_commands_on: bool) -> str:
)
+def first_review_note(review_link: str, deep_command: bool) -> str:
+ """The note the first review on a pull request ends with: where to see the review, and how to ask for Deep."""
+ note = f"See this review and its findings in [PostHog Review]({review_link})."
+ if deep_command:
+ note = (
+ f"{note} Comment `@posthog review --deep` for a Deep review. "
+ "A Deep review takes longer and looks deeper than a Standard review."
+ )
+ return note
+
+
LabelReviewOutcome = Literal[
"repository_not_added",
"installation_mismatch",
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 5348f8c78e87..0d2b4d56d84f 100644
--- a/products/review_hog/backend/reviewer/tests/test_publish_review.py
+++ b/products/review_hog/backend/reviewer/tests/test_publish_review.py
@@ -565,6 +565,47 @@ class TestPublishReviewGate:
assert comments == []
assert mock_post.call_args.kwargs["marker"] == expected_marker
+ @parameterized.expand(
+ [
+ ("first_review", None, True),
+ ("later_review", "old", False),
+ ]
+ )
+ @patch(_POST)
+ @patch(_LOAD_FINDINGS)
+ @patch(_REPORT)
+ def test_only_the_first_review_with_findings_carries_the_first_review_note(
+ self,
+ _name: str,
+ published_head_sha: str | None,
+ expects_note: bool,
+ mock_report_cls: MagicMock,
+ mock_load: MagicMock,
+ mock_post: MagicMock,
+ ) -> None:
+ self._wire_report(mock_report_cls, published_head_sha)
+ mock_load.return_value = [(_finding(), _verdict())]
+
+ publish_review(
+ owner="o",
+ repo="r",
+ pr_number=1,
+ team_id=1,
+ report_id="rep",
+ run_index=1,
+ pr_files=[],
+ token="t",
+ head_sha="sha",
+ published_priorities=_SHOULD_FIX_PUBLISHED,
+ review_mode="flash",
+ footer="Footer.",
+ first_review_note="First review note.",
+ )
+
+ marker = mock_post.call_args.kwargs["marker"]
+ closing = "Footer.\n\nFirst review note.\n\n" if expects_note else "Footer.\n\n"
+ assert mock_post.call_args.args[3].endswith(f"{closing}{marker}")
+
@parameterized.expand(
[
("keeps_nothing_stays_silent", IssuePriority.CONSIDER, False),
diff --git a/products/review_hog/backend/reviewer/tools/publish_review.py b/products/review_hog/backend/reviewer/tools/publish_review.py
index eb6f5ac297bf..8eccf0d5ed3c 100644
--- a/products/review_hog/backend/reviewer/tools/publish_review.py
+++ b/products/review_hog/backend/reviewer/tools/publish_review.py
@@ -97,6 +97,7 @@ def publish_persisted_review(
capped_lens_parts: int | None = None,
footer: str = "",
draft_notice: str = "",
+ first_review_note: str = "",
comment_commands_on: bool = False,
answers_request: bool = False,
) -> PublishOutcome:
@@ -114,6 +115,7 @@ def publish_persisted_review(
event loop.
`draft_notice` closes a review with findings when the turn's snapshot shows the PR as a draft.
+ `first_review_note` closes the first review that posts findings on the pull request (see `publish_review`).
`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`).
"""
@@ -148,6 +150,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 "",
+ first_review_note=first_review_note,
answers_request=answers_request,
budget_note=budget_note(over_budget, comment_commands_on) if over_budget else "",
round_note=round_note(review_round) if review_round.asks_for_a_rethink else "",
@@ -254,6 +257,7 @@ def publish_review(
capped_lens_parts: int | None = None,
footer: str = "",
findings_footer: str = "",
+ first_review_note: str = "",
budget_note: str = "",
round_note: str = "",
answers_request: bool = False,
@@ -275,6 +279,9 @@ def publish_review(
`findings_footer` follows `footer` only on a review that posts findings, never on the clean-turn note.
+ `first_review_note` follows them only on the first review that posts findings on the pull request. It tells
+ people new to PostHog Review where the review is in PostHog and how to ask for a Deep review.
+
`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.
@@ -339,6 +346,8 @@ def publish_review(
remove_own_pr_reactions(repository, pr_number, "+1", token=token, installation_id=installation_id)
if findings_footer:
footer_block = f"{footer_block}{findings_footer}\n\n"
+ if first_review_note and report.published_head_sha is None:
+ footer_block = f"{footer_block}{first_review_note}\n\n"
footer_block = f"{budget_block}{footer_block}"
body = f"{report.report_markdown}\n\n{note_block}{footer_block}{marker}"
diff --git a/products/review_hog/backend/temporal/activities.py b/products/review_hog/backend/temporal/activities.py
index c6f3daade3d7..8635c10f57e1 100644
--- a/products/review_hog/backend/temporal/activities.py
+++ b/products/review_hog/backend/temporal/activities.py
@@ -40,7 +40,12 @@ from products.review_hog.backend.app_identity import posthog_app_login
from products.review_hog.backend.automatic_reviews import automatic_flash_allowed, observe_dispatch
from products.review_hog.backend.facade.enums import ReviewRequestRefusal
from products.review_hog.backend.facade.finished_review_hooks import FinishedReview, get_finished_review_hooks
-from products.review_hog.backend.label_reviews import comment_commands_enabled, draft_review_notice, label_commands_hint
+from products.review_hog.backend.label_reviews import (
+ comment_commands_enabled,
+ draft_review_notice,
+ first_review_note,
+ label_commands_hint,
+)
from products.review_hog.backend.models import ReviewProjectSettings, ReviewReport, ReviewUserSettings
from products.review_hog.backend.pr_owner import PullRequestOwnerResolver
from products.review_hog.backend.preferences import ReviewPreferences
@@ -2074,16 +2079,22 @@ async def build_body_activity(input: BuildBodyInput) -> None:
def _publish(input: PublishInput) -> PublishResult:
token, installation_id = _installation_auth(input.team_id, f"{input.owner}/{input.repo}")
+ commands_on = comment_commands_enabled(input.team_id)
footer = ""
- if input.trigger_source == TRIGGER_LABEL and comment_commands_enabled(input.team_id):
+ if input.trigger_source == TRIGGER_LABEL and commands_on:
footer = label_commands_hint(input.review_mode)
# Only an automatic turn can promise the review on ready: a label or UI review runs for authors
# without automatic reviews too. Only an automatic turn is held to the finding budget, too.
draft_notice = ""
comment_commands_on = False
if input.trigger_source == TRIGGER_AUTOMATIC:
- comment_commands_on = comment_commands_enabled(input.team_id)
+ comment_commands_on = commands_on
draft_notice = draft_review_notice(comment_commands_on)
+ # The label footer already names the Deep command.
+ intro_note = first_review_note(
+ report_deep_link(input.team_id, input.report_id),
+ deep_command=commands_on and input.review_mode == REVIEW_MODE_FLASH and not footer,
+ )
outcome = publish_persisted_review(
team_id=input.team_id,
report_id=input.report_id,
@@ -2099,6 +2110,7 @@ def _publish(input: PublishInput) -> PublishResult:
capped_lens_parts=input.capped_lens_parts,
footer=footer,
draft_notice=draft_notice,
+ first_review_note=intro_note,
answers_request=input.trigger_source in REQUESTED_TRIGGERS,
comment_commands_on=comment_commands_on,
)
diff --git a/products/review_hog/backend/tests/test_review_activity.py b/products/review_hog/backend/tests/test_review_activity.py
index a7a5f1d986b3..a8e0d235caab 100644
--- a/products/review_hog/backend/tests/test_review_activity.py
+++ b/products/review_hog/backend/tests/test_review_activity.py
@@ -793,15 +793,18 @@ async def test_a_standard_turn_scope_follows_its_trigger_and_run(
@pytest.mark.parametrize(
- "trigger_source,commands_on,expected_hint",
+ "trigger_source,commands_on,review_mode,expected_hint,note_names_deep",
[
- pytest.param("label", True, "@posthog review --deep", id="label_with_commands"),
- pytest.param("label", False, None, id="label_without_commands"),
- pytest.param("automatic", True, None, id="other_trigger"),
+ # The label footer names the Deep command, so the first review note does not repeat it.
+ pytest.param("label", True, REVIEW_MODE_FLASH, "@posthog review --deep", False, id="label_with_commands"),
+ pytest.param("label", False, REVIEW_MODE_FLASH, None, False, id="label_without_commands"),
+ pytest.param("automatic", True, REVIEW_MODE_FLASH, None, True, id="automatic_standard"),
+ pytest.param("automatic", False, REVIEW_MODE_FLASH, None, False, id="automatic_without_commands"),
+ pytest.param("comment", True, REVIEW_MODE_FULL, None, False, id="deep_review"),
],
)
-def test_a_label_review_points_to_the_comment_commands(
- trigger_source: str, commands_on: bool, expected_hint: str | None
+def test_a_review_points_to_the_review_ui_and_the_comment_commands(
+ trigger_source: str, commands_on: bool, review_mode: str, expected_hint: str | None, note_names_deep: bool
) -> None:
# The hint advertises `@posthog` commands, so it must not appear where they do not run or where nobody used the label.
publish = MagicMock(return_value=PublishOutcome(posted=True))
@@ -820,10 +823,13 @@ def test_a_label_review_points_to_the_comment_commands(
owner="o",
repo="r",
pr_number=1,
- review_mode=REVIEW_MODE_FLASH,
+ review_mode=review_mode,
trigger_source=trigger_source,
)
)
footer = publish.call_args.kwargs["footer"]
assert (expected_hint in footer) if expected_hint else footer == ""
+ note = publish.call_args.kwargs["first_review_note"]
+ assert "/project/1/code-review?review=rep-1" in note
+ assert ("@posthog review --deep" in note) is note_names_deep