fix(api): adaptive GraphQL page size on 5xx + file changes retry #185
+257
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
get_pull_request_file_changes(3 attempts with exponential backoff) — previously a single transient failure silently returned an empty list, causing the PR to score 0Problem
The GraphQL PR query (
get_github_graphql_query) fetches ~20+ fields per PR including nested relations (closingIssuesReferences,reviews,repository,headRepository). At 100 PRs per page, this can exceed GitHub's server-side processing timeout for miners with many PRs, returning a 502. The existing retry loop retried 8 times at the same page size — all failing identically.Separately,
get_pull_request_file_changeshad zero retry logic. A single transient 502/timeout on this REST endpoint would silently return[], causing the entire PR to score 0 with no warning.Changes
gittensor/utils/github_api_tools.pyget_github_graphql_query(page size reduction):variablesdict inside the retry loop solimitcan update between attemptslimitbefore retrying (floor of 10)get_pull_request_file_changes(retry logic):RequestException(connection errors, timeouts)tests/utils/test_github_api_tools.pyAPI usage impact
These changes are budget-neutral in the happy path and net-positive under failures:
The per-PR scoring calls (
file_changes+file_contents) are the dominant API cost (~97% of calls), but at ~0.6% per validator per miner they are well within the ~5% target needed for 20-validator redundancy.Verified
Observed in production-like run — the 502 warning fires and self-heals:
Miner scored 1122.47 at Silver tier after recovery.
Test plan
pytest tests/utils/test_github_api_tools.py -v— 23 passedpytest tests/ -v— 210 passedcheck_miner_status.py— 502 recovery confirmed