Skip to content

fix: prevent scoring data loss and fix fragile test in stale PR refresh - #992

Merged
anderdc merged 2 commits into
entrius:testfrom
wdeveloper16:fix/stale-pr-gaps
May 9, 2026
Merged

fix: prevent scoring data loss and fix fragile test in stale PR refresh #992
anderdc merged 2 commits into
entrius:testfrom
wdeveloper16:fix/stale-pr-gaps

Conversation

@wdeveloper16

Copy link
Copy Markdown
Contributor

Description

Two gaps left unaddressed by #769.

Gap 1 — Stale UPSERT silently zeroes previously-scored rows

store_pull_requests_bulk in gittensor/validator/utils/storage.py:74-76 routes stale PRs through BULK_UPSERT_PULL_REQUESTS, which uses ON CONFLICT DO UPDATE SET with EXCLUDED.* — overwriting every column on conflict. PullRequest.from_graphql_response() leaves all scoring fields at dataclass defaults (base_score = 0.0, earned_score = 0.0, credibility_multiplier = 1.0, etc.). Any PR that was previously scored — for example, one that was OPEN with collateral before the window shifted — has those computed values silently replaced with zeros on every subsequent scan.

Gap 2 — Fragile positional assertion in test_stale_closed_prs_are_stored_separately

tests/validator/utils/test_storage_mirror.py:176 asserts stale storage correctness via call_args_list[3]. If the call order inside store_evaluation ever changes, the assertion silently targets the wrong call and the test continues to pass.

Changes

  • Add REFRESH_STALE_PR_STATES to queries.py — a targeted UPDATE that touches only pr_state and updated_at, leaving all scoring columns on existing rows untouched
  • Add Repository.refresh_stale_pr_states() backed by the new query
  • Wire store_evaluation to call refresh_stale_pr_states instead of store_pull_requests_bulk for the stale bucket
  • Replace call_args_list[3] with refresh_stale_pr_states.assert_called_once() and add a leak guard asserting stale PRs do not reach store_pull_requests_bulk

No schema changes required.

Closes #991

@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label May 5, 2026
@wdeveloper16
wdeveloper16 force-pushed the fix/stale-pr-gaps branch 2 times, most recently from 0ace2e9 to 5ffc817 Compare May 5, 2026 19:01
@wdeveloper16

Copy link
Copy Markdown
Contributor Author

Hi, @anderdc
Can you review the PR, please?

@wdeveloper16

Copy link
Copy Markdown
Contributor Author
  • store_evaluation routes stale_closed_pull_requests through store_pull_requests_bulk, which runs BULK_UPSERT_PULL_REQUESTS — an ON CONFLICT DO UPDATE SET that overwrites every column including earned_score, base_score, credibility_multiplier, pioneer_rank, and pioneer_dividend.
  • PullRequest.from_graphql_response() never computes scoring fields for stale PRs, so those columns arrive as dataclass defaults (0.0 / 1.0).
  • The overwrite is deterministic: any PR scored in epoch N becomes stale in epoch N+35 as the lookback window shifts, and the next scan silently zeroes its stored scores — destroying audit-accurate scoring history every cycle for any miner with aged-out PRs.

This PR replaces the full UPSERT for the stale bucket with a dedicated REFRESH_STALE_PR_STATES query that touches only pr_state and updated_at, leaving all scoring columns untouched. No schema changes, no new tables, no behavioural change to the scoring pipeline.

@wdeveloper16
wdeveloper16 force-pushed the fix/stale-pr-gaps branch 11 times, most recently from a8946ba to bccaf29 Compare May 9, 2026 00:17
@anderdc anderdc added refactor Code restructuring without behavior change and removed bug Something isn't working labels May 9, 2026
@anderdc
anderdc merged commit 0e5e531 into entrius:test May 9, 2026
3 checks passed
alpurkan17 pushed a commit to alpurkan17/gittensor that referenced this pull request May 10, 2026
…sh (entrius#992)

Co-authored-by: Ander <61125407+anderdc@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Three gaps in #769 stale-closed PR fix: scoring data loss, silent drop path, and fragile test

2 participants