Skip to content

fix: handle malformed mirror JSON responses - #894

Merged
anderdc merged 3 commits into
entrius:testfrom
bitloi:fix/issue-893-mirror-client-malformed-json
May 5, 2026
Merged

fix: handle malformed mirror JSON responses#894
anderdc merged 3 commits into
entrius:testfrom
bitloi:fix/issue-893-mirror-client-malformed-json

Conversation

@bitloi

@bitloi bitloi commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix MirrorClient so malformed HTTP 2xx mirror responses are treated as mirror request failures instead of escaping as raw JSON parse exceptions.

Previously, _get() returned response.json() directly for any 2xx response. If the mirror, CDN, or proxy returned HTTP 200 with truncated JSON or an HTML/plaintext error body, ValueError could bypass retry handling and the MirrorRequestError path used by validator mirror callers.

This PR:

  • retries invalid 2xx JSON with the existing mirror backoff policy
  • raises MirrorRequestError after max_attempts
  • wraps top-level mirror response schema parse failures as MirrorRequestError
  • preserves existing validator fallback behavior for failed mirror fetches

Related Issues

Closes #893

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other (describe below)

Testing

  • Tests added/updated
  • Manually tested

Commands run:

  • uv run pytest tests/utils/test_mirror_client.py -q
  • uv run pytest tests/validator/oss_contributions/mirror/test_load.py -q
  • uv run pytest tests/validator/issue_discovery/test_mirror_scan.py::TestRunMirrorIssueDiscovery::test_mirror_request_error_does_not_abort_other_miners tests/validator/issue_discovery/test_mirror_scan.py::TestSolvingPrCache::test_fetch_failure_skips_scoring_for_that_issue -q
  • uv run pytest tests/ -q --ignore=tests/validator/issue_discovery/test_one_issue_per_pr_cross_miner.py --ignore=tests/validator/issue_discovery/test_post_merge_issue_edit.py
  • uv run pyright
  • uv run pre-commit run --files gittensor/utils/mirror/client.py tests/utils/test_mirror_client.py tests/validator/oss_contributions/mirror/test_load.py

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Changes are documented (if applicable)

@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label Apr 30, 2026

@anderdc anderdc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gittensor/utils/mirror/client.py:134 — use backoff_seconds(attempt) instead of inline min(5 * (2**attempt), 30). It's already imported and used by the other two retry tails in this same function; the inline copy drifts.

@bitloi

bitloi commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

gittensor/utils/mirror/client.py:134 — use backoff_seconds(attempt) instead of inline min(5 * (2**attempt), 30). It's already imported and used by the other two retry tails in this same function; the inline copy drifts.

@anderdc I just pushed the update. Would you please check it again?

@bitloi
bitloi requested a review from anderdc May 5, 2026 20:38
@anderdc
anderdc merged commit dec61ca into entrius:test May 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] MirrorClient malformed 2xx JSON bypasses mirror failure handling and can stop validator rounds

2 participants