Skip to content

fix: prefer maintainer-authored issue in calculate_issue_multiplier#673

Merged
anderdc merged 4 commits intoentrius:testfrom
plind-junior:fix/issue-multiplier-prefer-maintainer
Apr 22, 2026
Merged

fix: prefer maintainer-authored issue in calculate_issue_multiplier#673
anderdc merged 4 commits intoentrius:testfrom
plind-junior:fix/issue-multiplier-prefer-maintainer

Conversation

@plind-junior
Copy link
Copy Markdown
Contributor

Picking valid_issues[0] made the multiplier depend on GraphQL closingIssuesReferences response ordering, which isn't documented as stable. A PR closing both a maintainer and a regular-author issue could flip between 1.66x and 1.33x run-to-run, and closing more valid issues could lower the multiplier.

Fixes #671

Picking valid_issues[0] made the multiplier depend on GraphQL
closingIssuesReferences response ordering, which isn't documented as
stable. A PR closing both a maintainer and a regular-author issue could
flip between 1.66x and 1.33x run-to-run, and closing more valid issues
could lower the multiplier.

Now the maintainer-authored valid issue wins deterministically when one
exists. Same-class determinism fix as entrius#633 / PR entrius#636 (label ordering).
@plind-junior
Copy link
Copy Markdown
Contributor Author

Open to suggestions and feedback from @e35ventura and @anderdc.

@anderdc anderdc added the enhancement New feature or request label Apr 21, 2026
anderdc and others added 3 commits April 22, 2026 09:31
…us#680

Tests set closed_at before merged_at, which entrius#680 now treats as invalid.
Flipping the hour offset matches GitHub's real behavior (closing-keyword
PRs close linked issues at or after merge time).
@anderdc anderdc merged commit bc04ad9 into entrius:test Apr 22, 2026
3 checks passed
anderdc added a commit that referenced this pull request Apr 24, 2026
Audit found five real behavioral differences beyond the edited_after_merge
gate scope. Each fix and why it matters:

1. calculate_open_pr_collateral_score crashes on ScoredMirrorPR (runtime bug)
   Legacy reads pr.number; ScoredMirrorPR exposes it only at pr.pr_number. Every
   miner with an OPEN mirror PR would crash at finalize time. Add .number and
   .repository_full_name property proxies to ScoredMirrorPR so the function
   accepts either type via duck-typing.

2. Eligibility gate runs at SCORE time in mirror, LOAD time in legacy
   Rejected merged PRs (self-merge w/o approval, base_ref mismatch, etc.)
   stayed in mirror_merged_prs with token_score=0, inflating len(merged_prs)
   inside check_eligibility and boosting credibility artificially. Moved
   _should_skip_merged_mirror_pr from score_mirror_pr to load's _maybe_add_pr,
   matching legacy's should_skip_merged_pr flow. Rejected PRs never enter the
   list now.

3. _is_valid_linked_issue used abs() for days_diff
   Legacy: `if days_diff > MAX or days_diff < 0: return False` — rejects issues
   closed BEFORE the PR merged (impossible for the PR to be the solver).
   Mirror's abs() made a -1 day diff look like +1 day and pass the MAX check.
   Replaced with signed days_diff and the < 0 check.

4. state_reason check was scoped to MERGED PRs only in mirror
   Legacy's _is_completed_when_closed applies regardless of PR state — a CLOSED
   issue with state_reason=NOT_PLANNED should never grant the issue multiplier,
   even for OPEN PR collateral. Pulled the state_reason gate out of the
   is_merged block.

5. _calculate_issue_multiplier took valid[0] without maintainer preference
   Legacy PR #673 (bc04ad9) updated calculate_issue_multiplier to prefer a
   maintainer-authored valid issue over response ordering. Mirror lagged.
   Applied the same next((m for ...), valid[0]) pattern.

Also found gap #6 (not fixed in this commit, mirror-side change needed):
The mirror API filters by p.created_at >= since, whereas legacy effectively
uses merged_at >= lookback for MERGED PRs. A PR created >35d ago but merged
within the lookback window is missed by mirror. Needs mirror SQL to
`p.created_at >= since OR p.merged_at >= since`. Will draft as a separate
plan for the mirror repo.

Tests (+11 new):
- TestEligibilityGateAtLoadTime: 3 tests (self-merge, base_ref mismatch,
  missing merged_at) all verifying rejected PRs never enter merged_prs
- TestLinkedIssueValidity.test_issue_closed_before_pr_merged_blocks (abs fix)
- TestLinkedIssueValidity.test_closed_issue_not_planned_blocks_open_pr_too
  (state_reason scope fix)
- TestLinkedIssueValidity.test_open_issue_on_open_pr_still_valid (regression
  guard — OPEN issues on OPEN PRs should still pass)
- TestIssueMultiplierPreference: 2 tests (prefer-maintainer + fallback)
- TestCollateralScoreAcceptsScoredMirrorPR: 3 tests (no-crash, .number
  property, .repository_full_name property)

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] calculate_issue_multiplier picks valid_issues[0] — GraphQL ordering decides maintainer vs standard multiplier

2 participants