Skip to content

feat(stamphog): route PR review through the ai-gateway#3354

Merged
brandonleung merged 1 commit into
mainfrom
brandon/stamphog-ai-gateway-cutover
Jul 10, 2026
Merged

feat(stamphog): route PR review through the ai-gateway#3354
brandonleung merged 1 commit into
mainfrom
brandon/stamphog-ai-gateway-cutover

Conversation

@brandonleung

Copy link
Copy Markdown
Contributor

Problem

Stamphog (the vendored PR-approval agent) calls Anthropic directly, so its LLM usage bypasses PostHog's ai-gateway and shows up as pre-gateway stamphog traffic on the cutover dashboards. This routes it through the gateway, matching the other migrated products.

Changes

  • Add gateway.py: resolves AI_GATEWAY_URL/AI_GATEWAY_API_KEY, points the Claude Agent SDK at the gateway via ANTHROPIC_* env, tags aio_stamphog. Verbatim copy from the posthog monorepo tools/pr-approval-agent.
  • reviewer.py uses the plain SDK query in gateway mode so the gateway's own $ai_generation is not double-counted; falls back to the traced query (then the plain query) when the gateway is not configured.
  • Workflow passes AI_GATEWAY_URL/AI_GATEWAY_API_KEY from STAMPHOG_AI_GATEWAY_* secrets to the review step.

Env-gated: both secrets set and valid routes through the gateway; unset or malformed falls back to direct Anthropic.

Not in this PR

  • Populating the two GitHub secrets (needs the gateway URL and a phs_ project secret).
  • The other stamphog surfaces (MLHog, the monorepo) and summarization; those are tracked separately.

Rollout

Set repo/org secrets STAMPHOG_AI_GATEWAY_URL (gateway URL ending in /v1) and STAMPHOG_AI_GATEWAY_API_KEY (phs_ project secret) to arm the cutover; until then it stays on direct Anthropic. Rollback: clear either secret.

How did you test this?

pytest test_gateway.py test_reviewer_gateway.py (16 tests): gateway config validation and fallback, /v1 stripping, the X-PostHog-Properties attribution blob, and the routing guard that selects the plain query in gateway mode so the gateway and traced paths never both emit. The live path (a real PR review through the gateway) needs the secrets populated in CI and has not run yet.

Authored by Claude (Opus 4.8); requires human review.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

@trunk-io

trunk-io Bot commented Jul 10, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@brandonleung brandonleung marked this pull request as ready for review July 10, 2026 20:58
@brandonleung brandonleung requested a review from a team July 10, 2026 20:59
@charlesvien

Copy link
Copy Markdown
Member

exciting!

@greptile-apps

greptile-apps Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "feat(stamphog): route PR review through ..." | Re-trigger Greptile

@brandonleung brandonleung merged commit e687cf6 into main Jul 10, 2026
25 checks passed
@brandonleung brandonleung deleted the brandon/stamphog-ai-gateway-cutover branch July 10, 2026 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants