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(ci): post stamphog non-approve verdicts as one sticky comment (#68371)

Paul D'Ambradaa3693befbb
diff --git a/.github/workflows/pr-approval-agent.yml b/.github/workflows/pr-approval-agent.yml
index a52f16ade8ae..86d55f2f5fc9 100644
--- a/.github/workflows/pr-approval-agent.yml
+++ b/.github/workflows/pr-approval-agent.yml
@@ -90,6 +90,9 @@ jobs:
# unlike GitHub App bot approvals which show author_association NONE.
GH_TOKEN_APPROVE: ${{ github.token }}
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.
+ BOT_LOGIN: ${{ steps.app-token.outputs.app-slug }}[bot]
run: |
PR=${{ github.event.pull_request.number }}
REPO=${{ github.repository }}
@@ -111,16 +114,90 @@ jobs:
"${SHA_ARGS[@]}" \
-f event=APPROVE \
-f body="$REASONING"
- elif [ -n "$REASONING" ]; then
- gh api \
- -X POST "repos/$REPO/pulls/$PR/reviews" \
- "${SHA_ARGS[@]}" \
- -f event=COMMENT \
- -f body="$REASONING"
else
- gh pr comment "$PR" \
- --body "Review agent failed — check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) and re-apply the label to retry." \
- --repo "$REPO"
+ # Non-approve verdicts share ONE sticky comment, updated in
+ # place, instead of a fresh COMMENT review per run. Review
+ # bodies can't be minimized or deleted, so when an automation
+ # loop keeps re-applying the label against a deterministic
+ # denial (e.g. the size gate) the refusals pile up — one PR
+ # collected 60+ near-identical stamphog reviews.
+ MARKER='<!-- stamphog-sticky-review -->'
+ RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
+
+ # Author + leading-marker filter: on a public repo anyone can
+ # post a comment containing the marker; without the filter the
+ # bot would PATCH (clobber) a third-party comment. Slurp so the
+ # jq runs once over all pages — per-page --jq could emit one
+ # object per page. The || guard keeps a transient lookup
+ # failure from aborting the step before the label strip below
+ # (it degrades to posting a fresh comment instead).
+ EXISTING=$(gh api "repos/$REPO/issues/$PR/comments" --paginate --slurp \
+ --jq "[.[][] | select(.user.login == \"$BOT_LOGIN\" and (.body | startswith(\"$MARKER\")))][0] // empty" \
+ || echo "")
+ COMMENT_ID=""
+ EXISTING_BODY=""
+ PREV_COUNT=0
+ if [ -n "$EXISTING" ]; then
+ COMMENT_ID=$(jq -r '.id' <<<"$EXISTING")
+ EXISTING_BODY=$(jq -r '.body' <<<"$EXISTING")
+ PREV_COUNT=$(jq -r '.body | (match("stamphog-review-count:([0-9]+)").captures[0].string // "0")' <<<"$EXISTING")
+ fi
+
+ # The append path requires an actual verdict in the prior body —
+ # a crash-only prior comment goes through the rebuild branch so
+ # it can't end up claiming "the verdict above" over no verdict.
+ if [ -z "$REASONING" ] && [ -n "$COMMENT_ID" ] \
+ && grep -q 'verdict: \*\*' <<<"$EXISTING_BODY"; then
+ # Verdictless crash with a prior verdict on record: append the
+ # failure note below it rather than clobbering the reasoning
+ # the author still needs to act on. The anchored grep dedups
+ # only the note itself, never verdict reasoning that happens
+ # to mention review failures.
+ { grep -v '^> ⚠️ A later review run failed' <<<"$EXISTING_BODY" || true; } > /tmp/stamphog-comment.md
+ {
+ echo
+ echo "> ⚠️ A later review run failed before producing a verdict — check the [workflow run]($RUN_URL). The verdict above is from an earlier run."
+ } >> /tmp/stamphog-comment.md
+ else
+ # The counter tracks verdicts only — a crash rebuild keeps
+ # the previous count so repeated failures don't inflate it.
+ if [ -n "$REASONING" ]; then
+ COUNT=$((PREV_COUNT + 1))
+ HEADLINE="stamphog reviewed \`${REVIEWED_SHA:-unknown}\` — verdict: **${VERDICT:-unknown}**"
+ DETAIL="$REASONING"
+ else
+ COUNT=$PREV_COUNT
+ HEADLINE="stamphog review failed before producing a verdict"
+ DETAIL="Check the [workflow run]($RUN_URL) and re-apply the label to retry."
+ fi
+ {
+ echo "$MARKER"
+ echo "<!-- stamphog-review-count:$COUNT -->"
+ echo "> [!NOTE]"
+ echo "> 🤖 $HEADLINE"
+ echo
+ echo "$DETAIL"
+ if [ -n "$COMMENT_ID" ]; then
+ echo
+ [ "$PREV_COUNT" -gt 0 ] \
+ && echo "_Updated in place — this replaces $PREV_COUNT earlier stamphog review(s) on this PR._" \
+ || echo "_Updated in place from an earlier stamphog review._"
+ fi
+ } > /tmp/stamphog-comment.md
+ fi
+
+ # A failed PATCH (comment deleted, transient API error) falls
+ # back to posting fresh, so the only unguarded API call left
+ # ahead of the label strip is the same single POST the old
+ # COMMENT-review path had.
+ if [ -n "$COMMENT_ID" ]; then
+ gh api -X PATCH "repos/$REPO/issues/comments/$COMMENT_ID" \
+ -F "body=@/tmp/stamphog-comment.md" || COMMENT_ID=""
+ fi
+ if [ -z "$COMMENT_ID" ]; then
+ gh api -X POST "repos/$REPO/issues/$PR/comments" \
+ -F "body=@/tmp/stamphog-comment.md"
+ fi
fi
# Only the two substantive verdicts strip the label — a
diff --git a/tools/pr-approval-agent/README.md b/tools/pr-approval-agent/README.md
index d2aac75a2ae5..d15eadfbdf95 100644
--- a/tools/pr-approval-agent/README.md
+++ b/tools/pr-approval-agent/README.md
@@ -120,10 +120,12 @@ LLM Review
- Gates are authoritative — LLM can tighten but never loosen
│
▼
-Final verdict → GitHub review (approve or comment)
+Final verdict → GitHub review (approve) or sticky comment (everything else)
```
-The bot never posts request-changes — only approves or comments.
+The bot never posts request-changes.
+Approvals are posted as real PR reviews (they must count toward branch protection).
+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