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(github): match GitHub's actual GraphQL rate-limit error spelling (#106208)

Tom Owerse9013ac9c450
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py
index 596b03619c3a..9d6f646eab57 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py
@@ -1376,18 +1376,26 @@ def _has_only_graphql_access_errors(errors: Any) -> bool:
)
+# GitHub's GraphQL API has been observed using both spellings for this condition: the documented
+# "RATE_LIMITED" and, for the primary rate limit specifically, "RATE_LIMIT" (with code
+# "graphql_rate_limit"). Match both so neither shape falls through to the generic retryable path,
+# whose plain backoff is capped at 30 seconds and cannot outlast the hourly window this resets on.
+_GRAPHQL_RATE_LIMIT_ERROR_TYPES = frozenset({"RATE_LIMITED", "RATE_LIMIT"})
+
+
def _raise_if_graphql_rate_limited(response: requests.Response, body: dict[str, Any]) -> None:
"""Map GraphQL's own primary rate limit onto the error the REST path raises.
- GraphQL reports that limit as a 200 whose `errors` carry type RATE_LIMITED. `raise_if_github_rate_limited`
- cannot see that shape, because it only inspects 429 and 403 responses. Without this mapping the retry
- falls back to the plain backoff, which is capped at 30 seconds and so cannot outlast the hourly window
- the GraphQL limit resets on.
+ GraphQL reports that limit as a 200 whose `errors` carry a rate-limit type (see
+ `_GRAPHQL_RATE_LIMIT_ERROR_TYPES`). `raise_if_github_rate_limited` cannot see that shape, because
+ it only inspects 429 and 403 responses. Without this mapping the retry falls back to the plain
+ backoff, which is capped at 30 seconds and so cannot outlast the hourly window the GraphQL limit
+ resets on.
"""
errors = body.get("errors")
if not isinstance(errors, list):
return
- if not any(isinstance(error, dict) and error.get("type") == "RATE_LIMITED" for error in errors):
+ if not any(_graphql_error_type(error) in _GRAPHQL_RATE_LIMIT_ERROR_TYPES for error in errors):
return
try:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py
index 0126e93814f1..80f1308d1357 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py
@@ -555,9 +555,22 @@ class TestMergeCommitSha:
assert github_request.call_count == 5
- @parameterized.expand([("advertised reset", 900, 900), ("no reset header", None, 60)])
+ @parameterized.expand(
+ [
+ ("advertised reset", 900, 900, {"type": "RATE_LIMITED", "message": "API rate limit exceeded"}),
+ ("no reset header", None, 60, {"type": "RATE_LIMITED", "message": "API rate limit exceeded"}),
+ # GitHub has also been observed reporting the primary rate limit under this spelling,
+ # with the reason nested under "code" rather than "type".
+ (
+ "RATE_LIMIT spelling",
+ 900,
+ 900,
+ {"type": "RATE_LIMIT", "code": "graphql_rate_limit", "message": "API rate limit already exceeded"},
+ ),
+ ]
+ )
def test_graphql_rate_limit_carries_a_wait_that_outlasts_the_window(
- self, _name: str, reset_in: int | None, expected_retry_after: int
+ self, _name: str, reset_in: int | None, expected_retry_after: int, error: dict[str, Any]
) -> None:
now = datetime(2026, 9, 1, 10, 0, 0, tzinfo=UTC)
rate_limited = mock.Mock()
@@ -567,10 +580,7 @@ class TestMergeCommitSha:
if reset_in is not None
else {}
)
- rate_limited.json.return_value = {
- "data": None,
- "errors": [{"type": "RATE_LIMITED", "message": "API rate limit exceeded"}],
- }
+ rate_limited.json.return_value = {"data": None, "errors": [error]}
with (
time_machine.travel(now, tick=False),