Skip to content

fix(validator): filter stale closed mirror PRs#1361

Open
JSONbored wants to merge 1 commit into
entrius:testfrom
JSONbored:codex/stale-closed-pr-local-proof
Open

fix(validator): filter stale closed mirror PRs#1361
JSONbored wants to merge 1 commit into
entrius:testfrom
JSONbored:codex/stale-closed-pr-local-proof

Conversation

@JSONbored
Copy link
Copy Markdown
Contributor

Summary

Defensively re-apply the repo lookback cutoff for CLOSED PRs returned by the mirror before they enter current credibility accounting.

What changed

  • Pass the same per-repo since_by_repo cutoff map used for the mirror request into _maybe_add_pr.
  • Drop returned CLOSED PRs whose created_at is older than that repo's cutoff.
  • Add a regression test covering mixed stale/fresh CLOSED PRs from a mirror response.

Why

load_miner_prs() already computes per-repo lookback cutoffs and sends them to the mirror, but the loader currently assumes every returned PR is in-window. Since CLOSED PRs feed current credibility accounting, keeping the local cutoff preserves the existing invariant that out-of-window CLOSED PRs do not count as current attempts.

Proof

The new regression test builds a fake mirror response with:

  • one stale CLOSED PR created 120 days ago
  • one fresh CLOSED PR created 5 days ago
  • a repo lookback of 30 days

Before this patch, the test fails because both CLOSED PRs are loaded:

assert [pr.pr.pr_number for pr in eval_.closed_prs] == [2]
E       assert [1, 2] == [2]

With this patch, the stale PR is filtered and only the fresh CLOSED PR remains in eval_.closed_prs.

I also checked the end-to-end loader/finalizer behavior locally with one current merged PR and one stale CLOSED PR returned by the mirror:

control:     closed_prs_loaded=0, credibility=1.0, eligible=true,  repo_score=100.0
before fix:  closed_prs_loaded=1, credibility=0.5, eligible=false, repo_score=0.0
after fix:   closed_prs_loaded=0, credibility=1.0, eligible=true,  repo_score=100.0

Validation

  • uv run --extra dev pytest tests/validator/oss_contributions/mirror/test_load.py::TestLookbackWindow::test_stale_closed_pr_before_repo_lookback_is_dropped_defensively -q
  • uv run --extra dev pytest tests/validator/oss_contributions/mirror tests/validator/test_blend_emission_pools.py tests/validator/test_scoring_classes.py tests/validator/test_scoring_resolver.py -q
  • uv run --extra dev pytest -q
  • uv run --extra dev ruff check gittensor/validator/oss_contributions/mirror/load.py tests/validator/oss_contributions/mirror/test_load.py
  • git diff --check

@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label May 25, 2026
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.

1 participant