Skip to content

Conversation

@leonace924
Copy link
Contributor

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 synchronous requests.
This can block the asyncio event loop, preventing other coroutines (and future timeout/cancellation logic) from making progress.

What was changed

  • We implemented the fastest retrofit: run synchronous GitHub HTTP calls in a background thread via asyncio.to_thread().
  • Added validation check before caching GitHub user data to ensure only complete user objects with essential fields are stored in the cache.

Updated call sites

  • gittensor/validator/evaluation/reward.py:reward()
    • validate_response_and_initialize_miner_evaluation() is executed via asyncio.to_thread() (it calls GitHub /user under the hood).
    • get_user_merged_prs_graphql() (GraphQL POSTs) is executed via asyncio.to_thread().
    • PR file diff retrieval is now done through an async scoring function (below).
  • gittensor/validator/evaluation/scoring.py
    • Added score_pull_requests_async(), which calls get_pull_request_file_changes() (REST GETs) via asyncio.to_thread().
    • Kept the existing synchronous score_pull_requests() for compatibility with scripts/tests.

Safety fix included

  • gittensor/validator/evaluation/inspections.py:validate_response_and_initialize_miner_evaluation() no longer dereferences response.axon.hotkey before checking whether response is 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 both id and created_at fields before caching:

Why to_thread() and not aiohttp

aiohttp is 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 by requests calls.

@leonace924
Copy link
Contributor Author

@anderdc would you review my PR, please?

@leonace924 leonace924 marked this pull request as draft December 22, 2025 01:59
@LandynDev LandynDev closed this Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants