Skip to content

fix: sync pr_state for stale-closed PRs excluded from scoring - #769

Merged
anderdc merged 2 commits into
entrius:testfrom
ai-mountain:fix/unscored-stale-closed-prs
May 4, 2026
Merged

fix: sync pr_state for stale-closed PRs excluded from scoring#769
anderdc merged 2 commits into
entrius:testfrom
ai-mountain:fix/unscored-stale-closed-prs

Conversation

@ai-mountain

@ai-mountain ai-mountain commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes phantom OPEN rows on miner dashboards caused by the 35-day creation cliff introduced in #406. Stale-closed PRs now have their pr_state persisted while remaining excluded from credibility scoring — #406's intent (no fresh credibility penalty when miners close old backlog PRs) is preserved.

  • Add stale_closed_pull_requests bucket on MinerEvaluation for CLOSED PRs that are observed by the scanner but excluded from scoring.
  • Route the created_dt < lookback_date_filter skip in try_add_open_or_closed_pr into the new bucket instead of dropping the PR entirely.
  • Persist the new bucket through the existing store_pull_requests_bulk / BULK_UPSERT_PULL_REQUESTS path — no schema change, no migration.
    Previously frozen pr_state='OPEN' rows now UPSERT to their real GitHub state.
  • total_{merged,open,closed}_prs properties are intentionally unchanged — the new bucket is storage-only and does not inflate counts. This keeps calculate_credibility inputs and all scoring buckets identical to test. The dashboard mismatch (e.g. 7 Open in the table vs 3 in the header tile) resolves because the table now reads the refreshed pr_state='CLOSED', not because totals changed.

UPSERT semantics

BULK_UPSERT_PULL_REQUESTS zeroes scoring columns (earned_score, token_score, collateral_score, multipliers) on conflict. For a PR that was previously OPEN with collateral and is now CLOSED-not-merged and out-of-window, zero is the correct value — the PR no longer provides collateral. No partial-update query needed.

Related Issues

Fixes #768

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other

Testing

  • tests/validator/test_unscored_stale_prs.py — 5 tests covering: stale routing to the storage-only bucket, totals NOT inflated, fresh-PR regression guard, mixed fresh/stale, multi-stale totals invariant.
  • tests/validator/utils/test_storage_mirror.py — 1 test confirming store_evaluation calls store_pull_requests_bulk with the new bucket as a separate (4th) call.
  • Full validator test suite passes locally (708/708).
  • Ruff lint + format clean.
  • Pyright: 0 errors.

Checklist

  • Code follows project style guidelines (ruff + pyright clean).
  • Self-review completed.
  • No schema change — reuses pull_requests table and BULK_UPSERT_PULL_REQUESTS query as-is.
  • calculate_credibility inputs unchanged; fix: ignore stale closed PRs in lookback window #406's no-fresh-credibility-penalty guarantee holds.
  • No change to total_*_prs properties; totals on /miners/{id} remain consistent with scoring buckets.

@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label Apr 24, 2026
@ai-mountain
ai-mountain force-pushed the fix/unscored-stale-closed-prs branch 6 times, most recently from c160076 to 7a21b62 Compare April 29, 2026 18:29
@ai-mountain
ai-mountain force-pushed the fix/unscored-stale-closed-prs branch from a11a992 to 28ad3e4 Compare April 30, 2026 19:07
@ai-mountain
ai-mountain force-pushed the fix/unscored-stale-closed-prs branch from 2c89e76 to 28646e6 Compare May 4, 2026 13:55
@ai-mountain

Copy link
Copy Markdown
Contributor Author

@anderdc can you review this PR?

@anderdc
anderdc merged commit 86390ad into entrius:test May 4, 2026
3 checks passed
@ai-mountain
ai-mountain deleted the fix/unscored-stale-closed-prs branch May 4, 2026 18:36
@ai-mountain

Copy link
Copy Markdown
Contributor Author

@anderdc Thanks for merging this PR.

wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 5, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 5, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 5, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 5, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 5, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 5, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 6, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 6, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 6, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 6, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 7, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 7, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 8, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 8, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 9, 2026
wdeveloper16 added a commit to wdeveloper16/gittensor that referenced this pull request May 9, 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.

[Bug] Stale-closed PRs skip pull_requests UPSERT, leaving phantom OPEN rows on miner dashboards

2 participants