fix: resolve retry logic inconsistencies in github_api_tools#195
Merged
anderdc merged 2 commits intoentrius:testfrom Feb 26, 2026
Merged
fix: resolve retry logic inconsistencies in github_api_tools#195anderdc merged 2 commits intoentrius:testfrom
anderdc merged 2 commits intoentrius:testfrom
Conversation
anderdc
reviewed
Feb 20, 2026
anderdc
reviewed
Feb 20, 2026
anderdc
reviewed
Feb 20, 2026
Contributor
Author
|
Done, reverted all changes except the two you approved:
Kept the corresponding tests for these two changes, reverted everything else including the |
Collaborator
|
sorry took a while to get back to this, resolve conflicts then it'll be good to merge thanks |
6c93938 to
e41a68c
Compare
Contributor
Author
|
Rebased on latest test branch - conflicts resolved. Ready to merge. |
anderdc
requested changes
Feb 26, 2026
Collaborator
|
hmm another conflict, resolve so I can get this in today I was doing reviews on other PRs so that caused a conflict here |
- Fix off-by-one error in get_pull_request_file_changes() that caused an
unnecessary sleep after the final attempt (attempt < max_attempts should
be attempt < max_attempts - 1, consistent with other retry functions)
- Cap exponential backoff at 30s in execute_graphql_query() exception
handler (status code path was already capped, exception path was not)
- Fix docstring in execute_graphql_query() stating default max_attempts
is 6 when the actual default parameter value is 8
- Fix type annotation in load_miners_prs(): prs variable annotated as
Dict but actually receives a List from .get('nodes', [])
- Fix misleading log in should_skip_merged_pr(): message said "merged
within lookback window" but the condition filters PRs merged BEFORE
the lookback window
…pe fix Revert get_pull_request_file_changes retry boundary change and max_attempts docstring change per reviewer request. Keep approved changes: backoff cap in execute_graphql_query and prs type annotation.
e5e90a4 to
8dd03d4
Compare
Contributor
Author
|
Rebased on latest test branch - conflicts resolved. Ready to merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This PR fixes 5 related bugs in
gittensor/utils/github_api_tools.py, all involving retry logic, type annotations, and log message accuracy.Changes
1. Off-by-one in
get_pull_request_file_changes()retry guard (lines 278, 288)Bug: The condition
attempt < max_attemptsis alwaysTrueinside arange(max_attempts)loop, causing an unnecessarytime.sleep()after the last failed attempt before the function returns. This adds up to 20 seconds of wasted delay on total failure.Fix: Changed to
attempt < (max_attempts - 1)to match the pattern used inexecute_graphql_query()andget_github_graphql_query().2. Uncapped exponential backoff in
execute_graphql_query()exception handler (line 352)Bug: The HTTP status code retry path correctly caps backoff at 30s with
min(5 * (2**attempt), 30), but theRequestExceptionhandler computesbackoff_delay = 5 * (2**attempt)without a cap. At attempt 6, this produces a 320-second (5+ minute) sleep.Fix: Added
min(..., 30)cap to match the status code path and other retry functions.3. Incorrect docstring default value in
execute_graphql_query()(line 316)Bug: Docstring says
max_attempts: Maximum retry attempts (default 6)but the actual function signature ismax_attempts: int = 8.Fix: Updated docstring to
(default 8).4. Wrong type annotation in
load_miners_prs()(line 595)Bug:
prs: Dict = pr_data.get('nodes', [])— thenodeskey returns a JSON array (Pythonlist), not adict.Fix: Changed annotation to
prs: List.5. Misleading log message in
should_skip_merged_pr()(line 498)Bug: The condition
merged_dt < lookback_date_filterfilters PRs merged before the lookback window, but the log says"merged within {PR_LOOKBACK_DAYS} day lookback window", implying the opposite.Fix: Changed to
"merged before {PR_LOOKBACK_DAYS}-day lookback window".Test Evidence
Updated and added tests in
tests/utils/test_github_api_tools.py:TestFileChangesRetryLogic.test_gives_up_after_three_attempts: sleep count assertion corrected from 3 to 2 (no sleep on last attempt)TestFileChangesRetryLogic.test_exponential_backoff_timing: expected delays corrected from[5, 10, 20]to[5, 10]TestExecuteGraphQLQueryRetryLogicclass (3 tests):test_exception_backoff_capped_at_30s— verifies backoff cap in exception handlertest_status_code_backoff_capped_at_30s— verifies backoff cap in status code handlertest_successful_request_no_retry— verifies no retry on successTestShouldSkipMergedPrclass (2 tests):test_log_message_says_before_for_old_pr— verifies corrected log wordingtest_recent_pr_not_skipped_by_lookback— verifies recent PRs pass lookback checkAll existing tests continue to pass. Ruff linting passes with no warnings.