Skip to content

fix: sync pr_state for stale-merged PRs excluded from scoring - #1071

Closed
Crystora wants to merge 2 commits into
entrius:testfrom
Crystora:fix/sync-stale-merged-pr-state
Closed

fix: sync pr_state for stale-merged PRs excluded from scoring#1071
Crystora wants to merge 2 commits into
entrius:testfrom
Crystora:fix/sync-stale-merged-pr-state

Conversation

@Crystora

@Crystora Crystora commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

A PR stored as OPEN stays stuck as OPEN in pull_requests if it gets merged on GitHub after the 35-day lookback window has already passed. The miner API and dashboard then keep showing it as open with a stale collateral_score.

Close: #1070

Root cause

should_skip_merged_pr returns True once merged_at is older than the lookback window, and the loop just continues. The PR never enters any bucket, so the old OPEN row never gets refreshed.

#769 fixed the same shape for stale-CLOSED PRs. This adds the MERGED counterpart.

Fix

New stale_merged_pull_requests bucket on MinerEvaluation, paired with a targeted UPDATE (not the bulk upsert) so existing rows get their status synced without touching scoring fields.

File Change
gittensor/classes.py Add stale_merged_pull_requests + add_stale_merged_pull_request.
gittensor/utils/github_api_tools.py Add _maybe_add_stale_merged_pr, called from the merged-PR skip branch.
gittensor/validator/storage/queries.py Add REFRESH_STALE_MERGED_PR_STATE — UPDATE-only, status fields only, guarded by pr_state != 'MERGED'.
gittensor/validator/storage/repository.py Add refresh_stale_merged_pr_states.
gittensor/validator/utils/storage.py Wire the refresh into the existing transaction.

Why UPDATE instead of the bulk upsert #769 used

A stale-MERGED row may already have real scoring fields from an earlier round. The bulk upsert would overwrite them with dataclass defaults. The targeted UPDATE only touches pr_state, merged_at, collateral_score, updated_at, never inserts, and skips rows already at pr_state = 'MERGED'.

No scoring impact

Stale-merged PRs never enter merged_pull_requests, so totals, eligibility, credibility, token score, pioneer math, and emissions are all unchanged.

Test plan

  • uv run python -m pytest tests/ — 1418 passed (7 new)
  • uv run python -m pyright — 0 errors
  • uv run pre-commit run — all hooks pass

New tests:

  • tests/validator/test_unscored_stale_prs.py — stale-merged routes to the storage-only bucket, doesn't inflate totals; fresh merged PR is not captured; missing mergedAt is skipped safely.
  • tests/validator/utils/test_storage_mirror.py — stale-merged list goes through refresh_stale_merged_pr_states, not the bulk upsert path.

Related

Follow-up to #769.

@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label May 7, 2026
@Crystora
Crystora force-pushed the fix/sync-stale-merged-pr-state branch from f0ef0d6 to f9617bb Compare May 7, 2026 18:03
@Crystora
Crystora force-pushed the fix/sync-stale-merged-pr-state branch from 96ba694 to c6d61ee Compare May 10, 2026 00:07
@anderdc

anderdc commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Stale-merged only fires when a single miner's scanning has a >35-day gap (PAT lapse, identity change, etc.) and the impact is dashboard-only — no scoring effect. The stale-CLOSED variant in #769 covered the substantially more common case where any user can close a PR at any time. Not pursuing this edge case. Closing.

@anderdc anderdc closed this May 11, 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] Out-of-window merged PRs can remain stuck as OPEN in miner PR lists

2 participants