: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(ci): keep stamphog review-threads query under github node limit (#67520)
Andrew Maguire0d0e1c806ce7
diff --git a/tools/pr-approval-agent/github.py b/tools/pr-approval-agent/github.pyindex 118778572b68..883ac48cfeb7 100644--- a/tools/pr-approval-agent/github.py+++ b/tools/pr-approval-agent/github.py@@ -211,6 +211,8 @@ def _gh_api(endpoint: str, *, paginate: bool = False) -> dict | list:return json.loads(result.stdout)+# GitHub rejects GraphQL queries whose worst-case node count — the product of+# nested `first:` sizes — exceeds 500,000, before executing anything._REVIEW_THREADS_QUERY = """query($owner: String!, $name: String!, $pr: Int!, $threadCursor: String) {repository(owner: $owner, name: $name) {@@ -236,7 +238,7 @@ query($owner: String!, $name: String!, $pr: Int!, $threadCursor: String) {bodydatabaseIdreplyTo { databaseId }- reactions(first: 100) {+ reactions(first: 20) {nodes {contentuser { login }diff --git a/tools/pr-approval-agent/test_github.py b/tools/pr-approval-agent/test_github.pyindex 7b464cffd068..bbd680c282aa 100644--- a/tools/pr-approval-agent/test_github.py+++ b/tools/pr-approval-agent/test_github.py@@ -1,5 +1,7 @@"""Tests for GitHub review normalization used by the PR approval agent."""+import re+import pytestimport github@@ -126,3 +128,27 @@ def test_trusted_reactor_predicate_gates_untrusted_and_author()def test_is_bot_author(user: dict, expected: bool) -> None:assert is_bot_author(user) is expected+++def _worst_case_node_count(query: str) -> int:+ # Mirrors GitHub's pre-execution node-limit check: each connection requests+ # `first` nodes multiplied by the `first` of every ancestor connection.+ total = 0+ multipliers = [1]+ pending = 1+ for match in re.finditer(r"first:\s*(\d+)|[{}]", query):+ if match.group(1):+ pending = int(match.group(1))+ total += multipliers[-1] * pending+ elif match.group(0) == "{":+ multipliers.append(multipliers[-1] * pending)+ pending = 1+ else:+ multipliers.pop()+ return total+++def test_review_threads_query_stays_under_github_node_limit() -> None:+ # GitHub rejects any GraphQL query whose worst-case node count exceeds+ # 500,000 before executing it, which hard-fails the review on every PR.+ assert _worst_case_node_count(github._REVIEW_THREADS_QUERY) < 500_000