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(stamphog): single app approval and app token for all actions (#70133)

Julian Bez655e81716619
diff --git a/.github/workflows/pr-approval-agent.yml b/.github/workflows/pr-approval-agent.yml
index 88f42e6e3188..2afe8528d35f 100644
--- a/.github/workflows/pr-approval-agent.yml
+++ b/.github/workflows/pr-approval-agent.yml
@@ -90,15 +90,11 @@ jobs:
- name: Post review
if: always()
env:
- # Approvals are posted twice, on purpose. The Stamphog app
- # (GH_TOKEN) posts the review body as an approval so the
- # human-facing feedback carries the bot's own identity;
- # github-actions[bot] (GH_TOKEN_APPROVE) posts a second,
- # bodyless approval. We keep both while we confirm which
- # identity's approval actually counts toward branch protection
- # — GitHub App bot approvals have shown author_association NONE.
- # If the github-actions[bot] one proves redundant, drop it.
- GH_TOKEN_APPROVE: ${{ github.token }}
+ # Everything stamphog does — the approval, the sticky comment,
+ # the label strip — posts as the Stamphog app (GH_TOKEN) so it
+ # all carries the bot's own identity. The app approval was
+ # confirmed to unblock PRs, so the earlier bodyless
+ # github-actions[bot] fallback approval has been dropped.
GH_TOKEN: ${{ steps.app-token.outputs.token }}
# Derived from the token step so the sticky-comment author
# filter tracks an app rename instead of failing silent.
@@ -122,24 +118,15 @@ jobs:
fi
if [ "$VERDICT" = "APPROVED" ]; then
- # Stamphog app approval, carrying the review body. Best-effort:
- # the step runs under `set -e`, so a failure here (e.g. the App
- # install missing Pull-requests write, or a transient error)
- # would otherwise abort before the github-actions[bot] approval
- # below — the identity currently known to unblock PRs. Keep it
- # non-fatal and surface the failure as a warning instead.
+ # Single Stamphog app approval, carrying the review body.
+ # Fatal on failure (the step runs under `set -e`): this is
+ # now the only approval, so if it doesn't post the PR stays
+ # blocked and that must surface as a red run, not a warning.
gh api \
-X POST "repos/$REPO/pulls/$PR/reviews" \
"${SHA_ARGS[@]}" \
-f event=APPROVE \
- -f body="$REASONING" \
- || echo "::warning::stamphog app approval failed to post; continuing with the github-actions[bot] approval"
- # Bodyless github-actions[bot] approval — kept alongside the
- # app approval until we've confirmed which one unblocks PRs.
- GH_TOKEN="$GH_TOKEN_APPROVE" gh api \
- -X POST "repos/$REPO/pulls/$PR/reviews" \
- "${SHA_ARGS[@]}" \
- -f event=APPROVE
+ -f body="$REASONING"
else
# Non-approve verdicts share ONE sticky comment, updated in
# place, instead of a fresh COMMENT review per run. Review
@@ -349,10 +336,16 @@ jobs:
# is skipped for bots, which routes here via the 'skipped' fail-closed
# path. This only ever touches github-actions[bot] approvals, so it's a
# no-op when there's nothing to dismiss.
+ # Same-repo only: forked / Dependabot PRs don't receive the app secrets,
+ # so the app-token step below would fail on every such synchronize. There
+ # is nothing to dismiss there anyway, since stamphog can never have
+ # approved a fork PR (the review job's app-token step is equally starved
+ # of secrets on forks), so gate the whole job to head branches in this repo.
if: >-
always()
&& github.event.action == 'synchronize'
&& !github.event.pull_request.draft
+ && github.event.pull_request.head.repo.full_name == github.repository
&& (
needs.decide-delta.outputs.dismiss_approval == 'true'
|| needs.decide-delta.result == 'failure'
@@ -362,10 +355,20 @@ jobs:
timeout-minutes: 5
steps:
+ - name: Get app token
+ id: app-token
+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
+ with:
+ client-id: ${{ secrets.GH_APP_PR_APPROVAL_AGENT_APP_ID }}
+ private-key: ${{ secrets.GH_APP_PR_APPROVAL_AGENT_PRIVATE_KEY }}
+
- name: Dismiss stale bot approvals
env:
- # github.token can dismiss both bot identities' approvals.
- GH_TOKEN: ${{ github.token }}
+ # Act as the Stamphog app for consistency with every other
+ # write. pull-requests:write can dismiss any review regardless
+ # of its author, so the app dismisses both its own approvals
+ # and any legacy github-actions[bot] ones.
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
PR: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
REASON: ${{ needs.decide-delta.outputs.reason || (needs.decide-delta.result == 'skipped' && 'label_absent') || 'decide_delta_failed' }}
diff --git a/tools/pr-approval-agent/README.md b/tools/pr-approval-agent/README.md
index 921a2e7f383e..7995815dfb1a 100644
--- a/tools/pr-approval-agent/README.md
+++ b/tools/pr-approval-agent/README.md
@@ -139,9 +139,8 @@ Final verdict → GitHub review (approve) or sticky comment (everything else)
The bot never posts request-changes.
Approvals are posted as real PR reviews (they must count toward branch protection).
-An approval is posted twice on purpose: the Stamphog app (`stamphog[bot]`) posts the review body as an approval, and `github-actions[bot]` posts a second, bodyless approval.
-We keep both while confirming which identity's approval actually satisfies branch protection — GitHub App bot approvals have shown `author_association: NONE`.
-If the `github-actions[bot]` one proves redundant, it can be dropped.
+An approval is posted once, as the Stamphog app (`stamphog[bot]`), carrying the review body.
+This identity was confirmed to satisfy branch protection, so the earlier bodyless `github-actions[bot]` fallback approval has been dropped and every stamphog action now runs under the app token.
Every other verdict (REFUSED, ESCALATE, WAIT, ERROR) goes into a single sticky comment that is updated in place on each run, with a counter of how many verdicts the comment has carried (failure notes append without bumping it) — repeated refusals don't stack up as separate review comments on the PR.
## Tiers
diff --git a/tools/pr-approval-agent/dismiss_check.py b/tools/pr-approval-agent/dismiss_check.py
index 1416300a80ff..28436e33d75d 100644
--- a/tools/pr-approval-agent/dismiss_check.py
+++ b/tools/pr-approval-agent/dismiss_check.py
@@ -36,9 +36,9 @@ from pathlib import Path
from gates import is_trivial_at_dismiss_time
-# Both identities Stamphog approves under: github-actions[bot] posts a
-# bodyless approval, stamphog[bot] (the app) posts the approval carrying the
-# review body. Either counts as a prior bot approval for the delta check.
+# Stamphog now approves only as stamphog[bot] (the app), carrying the review
+# body. github-actions[bot] is kept here so legacy bodyless approvals from
+# before that change still count as a prior bot approval for the delta check.
BOT_LOGINS = {"github-actions[bot]", "stamphog[bot]"}
diff --git a/tools/pr-approval-agent/review_pr.py b/tools/pr-approval-agent/review_pr.py
index c1e34a10772c..af9c793310c8 100644
--- a/tools/pr-approval-agent/review_pr.py
+++ b/tools/pr-approval-agent/review_pr.py
@@ -448,11 +448,24 @@ class Pipeline:
summary of who has actually vouched for the current head.
"""
pr = self.pr
+ # Exclude the author's own reviews: an author commenting on or replying
+ # within their own PR records a COMMENTED review at head, which would
+ # otherwise surface as "<author> reviewed the current head." Self-review
+ # is never independent assurance, so it must not read as a vouch — to the
+ # human in the review body or to the LLM in the trusted prompt block.
head_approvals = sorted(
- {r["user"] for r in pr.reviews if r.get("is_current_head") and r.get("state") == "APPROVED"}
+ {
+ r["user"]
+ for r in pr.reviews
+ if r.get("is_current_head") and r.get("state") == "APPROVED" and r["user"] != pr.author
+ }
)
head_commented_users = sorted(
- {r["user"] for r in pr.reviews if r.get("is_current_head") and r.get("state") == "COMMENTED"}
+ {
+ r["user"]
+ for r in pr.reviews
+ if r.get("is_current_head") and r.get("state") == "COMMENTED" and r["user"] != pr.author
+ }
)
# Count unresolved conversations, not flattened comments: replies inherit
# the thread's resolution state, so a single 4-reply thread must read as
diff --git a/tools/pr-approval-agent/test_review_pr.py b/tools/pr-approval-agent/test_review_pr.py
index 93e05d8507cf..7298c5cf268b 100644
--- a/tools/pr-approval-agent/test_review_pr.py
+++ b/tools/pr-approval-agent/test_review_pr.py
@@ -61,6 +61,22 @@ def test_summarize_assurance_counts_threads_not_flattened_replies() -> None:
assert pipeline._summarize_assurance()["unresolved_threads"] == 1
+def test_summarize_assurance_excludes_author_self_review() -> None:
+ # An author replying within their own PR records a COMMENTED review at head.
+ # That self-review must not read as a vouch — otherwise the review body and
+ # the trusted assurance block both claim "<author> reviewed the current head."
+ pipeline = Pipeline(pr_number=1, repo="PostHog/posthog")
+ pr = _fake_pr(head_sha="abc123") # _fake_pr author is "alice"
+ pr.reviews = [
+ {"user": "alice", "state": "COMMENTED", "is_current_head": True, "commit_id": "abc123"},
+ {"user": "bob", "state": "COMMENTED", "is_current_head": True, "commit_id": "abc123"},
+ ]
+ pipeline.pr = pr
+
+ assurance = pipeline._summarize_assurance()
+ assert assurance["head_commented_users"] == ["bob"]
+
+
def test_to_dict_includes_head_sha() -> None:
"""The post-review workflow step reads head_sha from the JSON output to
lock the resulting GitHub review to the sha the LLM actually saw — see