fix: async correctness to avoid blocking event loop and user cache saving update #102
+28
−8
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.
Validator async: avoid blocking the event loop
The validator scoring pipeline is async (e.g.
gittensor/validator/evaluation/reward.py:get_rewards()), but several underlying GitHub API helpers use synchronousrequests.This can block the asyncio event loop, preventing other coroutines (and future timeout/cancellation logic) from making progress.
What was changed
asyncio.to_thread().Updated call sites
gittensor/validator/evaluation/reward.py:reward()validate_response_and_initialize_miner_evaluation()is executed viaasyncio.to_thread()(it calls GitHub/userunder the hood).get_user_merged_prs_graphql()(GraphQL POSTs) is executed viaasyncio.to_thread().gittensor/validator/evaluation/scoring.pyscore_pull_requests_async(), which callsget_pull_request_file_changes()(REST GETs) viaasyncio.to_thread().score_pull_requests()for compatibility with scripts/tests.Safety fix included
gittensor/validator/evaluation/inspections.py:validate_response_and_initialize_miner_evaluation()no longer dereferencesresponse.axon.hotkeybefore checking whetherresponseis present.This prevents crashes when a miner does not respond.
Validation check for user data
In
gittensor/utils/github_api_tools.py(lines 155-156), the code now validates that user data contains bothidandcreated_atfields before caching:Why
to_thread()and notaiohttpaiohttpis the cleaner long-term approach, but switching requires rewriting the GitHub API layer and retry/rate-limit logic.asyncio.to_thread()is low-risk and immediately prevents the event loop from being blocked byrequestscalls.