: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(stamphog): hide bot 👀 that aged out of the in-flight window (#104925)
Julian Bez5e4b199890ab
diff --git a/.stamphog/review-guidance.md b/.stamphog/review-guidance.mdindex f22682cd7dd5..e94affbaef44 100644--- a/.stamphog/review-guidance.md+++ b/.stamphog/review-guidance.md@@ -71,7 +71,7 @@ Reviews, comments, and reactions:- Each top-level review shows its state (APPROVED / COMMENTED / CHANGES_REQUESTED) and whether it landed on the current head or an older commit. Treat current-head reviews as active signals; treat older-commit reviews as historical context, acting on them only if the current diff still shows the same unresolved issue.- Inline comments are tagged [resolved], [outdated], or unmarked (unresolved). Resolution status is a signal, not gospel — use judgment. A resolved or outdated comment that raised a serious concern (security, data loss) the diff clearly did NOT address → flag it anyway. For unresolved comments, check whether a later commit already addressed the concern before flagging; substantive ones still unaddressed → REFUSE.- Reactions (👍, 👎, 👀, etc.) on the PR and on individual review comments are provided — already filtered to trusted org members and bot reviewers, never the PR author. A 👍 from an agent reviewer or teammate is how a bot often signals "no concerns" — a mild positive; a 👎 or 😕 is a mild negative. These two are weak evidence: never approve on a 👍 alone or refuse on a 👎 alone — corroborate against the diff.-- An 👀 (eyes) reaction means a review is in flight — someone is actively looking at the PR right now. Do NOT approve over an in-progress review: REFUSE and tell the author to wait for that reviewer to finish and re-request. This overrides any 👍 present. (Reviewer bots clear their 👀 within minutes and the pipeline waits those out before invoking you, so any 👀 you see — bot or human — is a genuine in-flight review.)+- An 👀 (eyes) reaction means a review is in flight — someone is actively looking at the PR right now. Do NOT approve over an in-progress review: REFUSE and tell the author to wait for that reviewer to finish and re-request. This overrides any 👍 present. (Reviewer bots clear their 👀 within minutes, and the pipeline both waits that race out and hides a bot 👀 that has aged past the in-flight window, so every bot 👀 that reaches you is genuinely fresh.) A human 👀 is never aged out. You get no reaction or comment times, so a review or a comment from that person is not proof that their look is over — keep the 👀 blocking.- Discussion comments (the PR's general comment timeline, separate from inline review comments) are included. A maintainer's explicit hold — "don't merge yet", "wait for X", "hold off" — that has not been withdrawn later in the thread means do NOT approve: REFUSE and point at that comment. The PR author's own comments are claims about the change, not assurance — never treat them as an independent sign-off.- Bot/agent comments with valid concerns that were ignored → ESCALATE.- Your own prior reviews (posted as stamphog[bot] or github-actions[bot]) are excluded from this context — each run judges the PR's current state fresh. If a review or inline comment quotes or restates an earlier stamphog verdict, treat it as history — never as an independent signal, as tampering, or as someone impersonating you.diff --git a/products/stamphog/packages/pr-approval-agent/github.py b/products/stamphog/packages/pr-approval-agent/github.pyindex dcda6609e906..941aed4a7474 100644--- a/products/stamphog/packages/pr-approval-agent/github.py+++ b/products/stamphog/packages/pr-approval-agent/github.py@@ -12,6 +12,7 @@ import tempfileimport subprocessfrom collections.abc import Callablefrom dataclasses import dataclass, field+from datetime import UTC, datetimefrom pathlib import Path@@ -86,6 +87,43 @@ TRUSTED_REACTOR_BOTS = {"veria-ai[bot]",}+# A reviewer bot's 👀 outlives the review it announced when the bot fails+# mid-run: reactions never expire, and no one can remove another app's+# reaction. Past this age the 👀 is treated as abandoned instead of in flight,+# so a wedged bot cannot block a PR forever. A reaction with no timestamp+# counts as fresh, which fails toward waiting.+BOT_EYES_MAX_AGE_SECONDS = 45 * 60+++def _reaction_age_seconds(created_at: str | None) -> float:+ if not created_at:+ return 0.0+ try:+ created = datetime.fromisoformat(created_at)+ except ValueError:+ return 0.0+ return (datetime.now(UTC) - created).total_seconds()+++def _is_bot_eyes(reaction: dict) -> bool:+ return reaction.get("emoji") == "👀" and (reaction.get("user") or "").lower() in TRUSTED_REACTOR_BOTS+++def is_in_flight_bot_eyes(reaction: dict) -> bool:+ """True for a 👀 from an allowlisted reviewer bot that has not aged out."""+ return _is_bot_eyes(reaction) and _reaction_age_seconds(reaction.get("created_at")) <= BOT_EYES_MAX_AGE_SECONDS+++def drop_abandoned_bot_eyes(reactions: list[dict] | None) -> list[dict]:+ """Drop reviewer-bot 👀 that aged past the in-flight cutoff.++ The wait gate stops waiting on these, so every reader of a reaction list+ must hide them too. A stale 👀 left in the reviewer prompt makes the LLM+ refuse over a review that finished days ago, and the author cannot clear+ the reaction because it belongs to the bot.+ """+ return [r for r in reactions or [] if not _is_bot_eyes(r) or is_in_flight_bot_eyes(r)]+def is_bot_author(user: dict) -> bool:"""True when the PR author is a bot or machine account.diff --git a/products/stamphog/packages/pr-approval-agent/review_pr.py b/products/stamphog/packages/pr-approval-agent/review_pr.pyindex 75b98c27d446..6ed179fd034d 100644--- a/products/stamphog/packages/pr-approval-agent/review_pr.py+++ b/products/stamphog/packages/pr-approval-agent/review_pr.py@@ -31,7 +31,6 @@ import subprocessfrom collections.abc import Iteratorfrom contextlib import contextmanagerfrom dataclasses import dataclass, field-from datetime import UTC, datetimefrom pathlib import Pathfrom familiarity import AuthorFamiliarity, compute_familiarity, familiarity_evidence@@ -59,11 +58,11 @@ from gates import ()from gateway import analytics_extra_propertiesfrom github import (- TRUSTED_REACTOR_BOTS,CommitProvenance,PRData,check_team_membership,fetch_pr,+ is_in_flight_bot_eyes,pr_provenance,provenance_evidence,write_pr_diff,@@ -166,23 +165,6 @@ def _is_retryable_error(err_msg: str) -> bool:BOT_REVIEW_WAIT_BUDGET_SECONDS = 300BOT_REVIEW_POLL_SECONDS = 30-# A bot 👀 much older than any real review is a crashed reviewer, not an-# in-flight one — reactions never expire and a human can't remove another-# app's reaction, so without this cutoff a wedged bot would make every run-# WAIT forever. Reactions missing a timestamp count as fresh (fail toward-# waiting).-BOT_EYES_MAX_AGE_SECONDS = 45 * 60---def _reaction_age_seconds(created_at: str | None) -> float:- if not created_at:- return 0.0- try:- created = datetime.fromisoformat(created_at)- except ValueError:- return 0.0- return (datetime.now(UTC) - created).total_seconds()-# ── Gate result ──────────────────────────────────────────────────@@ -320,15 +302,7 @@ class Pipeline:def _in_flight_bot_reviewers(self) -> list[str]:"""Allowlisted reviewer bots with a fresh 👀 reaction on the PR."""- return sorted(- {- r["user"]- for r in self.pr.pr_reactions- if r["emoji"] == "👀"- and r["user"].lower() in TRUSTED_REACTOR_BOTS- and _reaction_age_seconds(r.get("created_at")) <= BOT_EYES_MAX_AGE_SECONDS- }- )+ return sorted({r["user"] for r in self.pr.pr_reactions if is_in_flight_bot_eyes(r)})def _handle_in_flight_bot_reviews(self) -> str | None:"""Wait out the reviewer-bot 👀 race; WAIT if a bot is still reviewing.diff --git a/products/stamphog/packages/pr-approval-agent/reviewer.py b/products/stamphog/packages/pr-approval-agent/reviewer.pyindex bd7397364fed..9387091fee9e 100644--- a/products/stamphog/packages/pr-approval-agent/reviewer.py+++ b/products/stamphog/packages/pr-approval-agent/reviewer.py@@ -18,7 +18,7 @@ from claude_agent_sdk import ClaudeAgentOptions, ResultMessage, queryfrom claude_agent_sdk.types import AssistantMessage, ToolUseBlockfrom gates import manifest_basenamesfrom gateway import analytics_extra_properties, gateway_env, resolve_gateway_config-from github import PRData, new_diff_file, write_pr_diff+from github import PRData, drop_abandoned_bot_eyes, new_diff_file, write_pr_difffrom policy import _sanitize_untrusted, review_guidance_path, steering_pathfrom version import STAMPHOG_VERSION@@ -599,7 +599,7 @@ class Reviewer:lines.extend(self._discussion_line(c) for c in tail_items)discussion_text = "\n".join(lines)- pr_reactions = "\n".join(f" - {_reaction_token(r)}" for r in pr.pr_reactions)+ pr_reactions = "\n".join(f" - {_reaction_token(r)}" for r in drop_abandoned_bot_eyes(pr.pr_reactions))ownership = self._format_ownership(cl)assurance_block = self._format_assurance(cl)@@ -743,9 +743,10 @@ class Reviewer:def _format_reactions(self, reactions: list[dict] | None) -> str:"""Render a compact reaction annotation like ` {👍 @greptile-apps}`."""- if not reactions:+ shown = drop_abandoned_bot_eyes(reactions)+ if not shown:return ""- return " {" + ", ".join(_reaction_token(r) for r in reactions) + "}"+ return " {" + ", ".join(_reaction_token(r) for r in shown) + "}"def _format_familiarity(self, cl: dict) -> str:"""Render the TRUSTED author-familiarity block, or "" when the signal is absent.diff --git a/products/stamphog/packages/pr-approval-agent/test_reviewer.py b/products/stamphog/packages/pr-approval-agent/test_reviewer.pyindex 31edb14900b7..7cbdaff43097 100644--- a/products/stamphog/packages/pr-approval-agent/test_reviewer.py+++ b/products/stamphog/packages/pr-approval-agent/test_reviewer.py@@ -4,6 +4,7 @@ import sysfrom pathlib import Pathimport pytest+import time_machinefrom unittest.mock import MagicMock# reviewer.py is imported by a uv-script; its `claude_agent_sdk` dep is@@ -379,3 +380,37 @@ def test_prompt_provenance_renders_only_for_self_driving_runs() -> None:# untrusted PR content. rindex: the anti-injection notice at the top of the prompt also quotes# the marker text, so the real delimiter is the last occurrence.assert self_driving_prompt.index("Provenance:") < self_driving_prompt.rindex("--- BEGIN UNTRUSTED CONTENT ---")+++@time_machine.travel("2026-01-01T12:00:00Z", tick=False)+def test_prompt_hides_bot_eyes_that_aged_past_the_in_flight_window() -> None:+ # The guidance tells the reviewer that every 👀 it sees is an in-flight review, so a reviewer+ # bot that fails without clearing its 👀 would make the reviewer refuse that PR forever. Nobody+ # can remove another app's reaction, so the prompt must hide the abandoned one, exactly as the+ # wait gate does.+ stale = "2025-12-30T12:00:00Z"+ fresh = "2026-01-01T11:58:00Z"+ pr = _pr(+ pr_reactions=[+ {"user": "greptile-apps[bot]", "emoji": "👀", "created_at": stale},+ {"user": "veria-ai[bot]", "emoji": "👀", "created_at": fresh},+ {"user": "greptile-apps[bot]", "emoji": "👍", "created_at": stale},+ {"user": "alice", "emoji": "👀", "created_at": stale},+ ],+ review_comments=[+ {+ "user": "bob",+ "body": "b",+ "path": "p.py",+ "reactions": [{"user": "greptile-apps[bot]", "emoji": "👀", "created_at": stale}],+ }+ ],+ )++ prompt = _prompt(pr)++ assert "👀 @greptile-apps[bot]" not in prompt+ assert "👀 @veria-ai[bot]" in prompt+ assert "👍 @greptile-apps[bot]" in prompt+ # A human can clear their own reaction, so age tells us nothing about whether they are done.+ assert "👀 @alice" in prompt