Skip to content

fix: clean up stale PR state when repo removed or PR merged to non-acceptable branch#399

Closed
jamesrayammons wants to merge 1 commit intoentrius:testfrom
jamesrayammons:fix/stale-pr-state-cleanup
Closed

fix: clean up stale PR state when repo removed or PR merged to non-acceptable branch#399
jamesrayammons wants to merge 1 commit intoentrius:testfrom
jamesrayammons:fix/stale-pr-state-cleanup

Conversation

@jamesrayammons
Copy link
Copy Markdown

When a repository is removed from master_repositories.json, existing PR records in the database kept their old pr_state indefinitely. Similarly, PRs merged to non-acceptable branches were skipped during evaluation, leaving stale OPEN state in the DB.

Two cleanup mechanisms added:

  • Scenario 1 (repo removed): DELETE PR records for repos no longer in master_repositories
  • Scenario 2 (non-acceptable branch): UPDATE pr_state for skipped merged PRs to reflect actual GitHub state

Related Issues

Fixes #398

Type of Change

  • Bug fix

Testing

  • Tests added/updated
  • Manually tested

10 tests added in tests/validator/test_stale_pr_cleanup.py:

  • 6 SQL logic tests (SQLite in-memory) covering both scenarios
  • 4 Python unit tests (mocked DB) for Repository methods

Checklist

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

@jamesrayammons jamesrayammons force-pushed the fix/stale-pr-state-cleanup branch from fa7eb6c to ccf0cad Compare April 13, 2026 19:25
@anderdc anderdc force-pushed the fix/stale-pr-state-cleanup branch from ccf0cad to 618cf36 Compare April 14, 2026 04:19
…ceptable branch

When a repository is removed from master_repositories.json, existing PR
records in the database kept their old pr_state indefinitely. Similarly,
PRs merged to non-acceptable branches were skipped during evaluation,
leaving stale OPEN state in the DB.

Two cleanup mechanisms added:
- DELETE PR records for repos no longer in master_repositories
- UPDATE pr_state for skipped merged PRs to reflect actual GitHub state

Fixes entrius#398
@jamesrayammons jamesrayammons force-pushed the fix/stale-pr-state-cleanup branch from 618cf36 to ecfbea7 Compare April 14, 2026 05:14
@jamesrayammons
Copy link
Copy Markdown
Author

@anderdc @LandynDev could you review this PR?

@anderdc anderdc closed this Apr 14, 2026
anderdc added a commit that referenced this pull request Apr 25, 2026
End-of-phase cache stats give operators a single-line view of how the
solving-PR cache performed during a scoring round:

  Solving-PR cache: 47 hits | 5 misses (4 fetched OK, 1 fetch failures)

Hits = cache lookup (no HTTP). Misses = get_pr_files invocation. Fetch
failures = MirrorRequestError raised; issue counts toward credibility but
no discovery_earned_score awarded. Useful for tuning expectations
(maintainer-solved miner-issues are guaranteed cache misses since
maintainer PRs are dropped at OSS load time and never enter
mirror_merged_prs) and for spotting mirror flakiness without scraping the
warning lines.

Per-issue debug logs explain every classification + scoring decision so
operators can debug "why didn't UID X get credit for issue Y?" by setting
the log level to debug. Each gate logs its specific reason:

  issue #553 (entrius/gittensor): closed-not-solved (state_reason=NOT_PLANNED, need COMPLETED)
  issue #480 (entrius/gittensor-ui): same-account (discoverer == solver 218712309) — credibility only
  issue #621 (entrius/allways): one-issue-per-PR (PR #527 already scored an earlier issue) — credibility only
  issue #410 (entrius/gittensor): solving PR #399 token_score 2.50 < 5 — credibility only

All at debug level so they don't clutter normal info-level logs.

_score_miner_mirror_issues + _resolve_solving_pr_score gain a _CacheStats
parameter; callers updated. New TestCacheStats covers all three counter
paths (hit / fetch-success / fetch-failure).

Full suite: 618 passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale PR state in database when repository is removed from tracking

2 participants