Skip to content

fix(miners): use closed_at for CLOSED PRs in pull request window filter#149

Closed
Tet-9 wants to merge 14 commits into
entrius:testfrom
Tet-9:fix/139-closed-prs-use-closed-at
Closed

fix(miners): use closed_at for CLOSED PRs in pull request window filter#149
Tet-9 wants to merge 14 commits into
entrius:testfrom
Tet-9:fix/139-closed-prs-use-closed-at

Conversation

@Tet-9
Copy link
Copy Markdown
Contributor

@Tet-9 Tet-9 commented May 30, 2026

Summary

getPullRequests and getPullRequestsByRepo in miners.service.ts were filtering CLOSED pull requests using created_at >= since, causing PRs that were closed within the scoring window but opened before since to be silently omitted from miner results.

Root Cause

Both query branches had an inconsistent condition for the CLOSED state:

-- Before (incorrect)
OR (p.state = 'CLOSED' AND p.created_at >= $2)

-- After (correct)
OR (p.state = 'CLOSED' AND p.closed_at >= $2)

This is inconsistent with:

  • MERGED PRs, which correctly use merged_at >= since
  • The sibling /issues endpoint, which correctly uses closed_at >= since for closed issues

Changes

  • packages/das/src/api/miners/miners.service.ts: fixed the CLOSED branch in both getPullRequests (GET path) and getPullRequestsByRepo (POST path) to use closed_at

Testing

Lint and build confirmed pre-existing failures in cache.module.ts are unrelated to this change. Only miners.service.ts was modified.

Fixes #139

DragunovX16 and others added 14 commits May 20, 2026 10:57
Move issue backfill ahead of PR metadata and file job enqueueing so metadata jobs can resolve solved_by_pr links during backfill.

Fixes entrius#28
Clear solved_by_pr links that still point to a refreshed PR when its closing references change or it is no longer merged, then reapply current merged links.

Fixes entrius#59
A `fetch-pr-metadata` job uses a stable custom jobId per PR
(`meta-<repo>-<pr>`). BullMQ ignores `add()` when a job with that id
already exists in any state, including the failed-retention set. With
`removeOnFail: 50`, a metadata job that exhausts its 3 retries during a
transient GitHub outage sat in the failed set and blocked every later
`edited`/`closed`/`reopened`/`synchronize` webhook for the same PR until
the global 50-slot cap evicted it — leaving `body`,
`last_edited_at`, `closing_issue_numbers`, and downstream
`issues.solved_by_pr` stale.

Drop retention for these enqueues to `true` so failed jobs evict
immediately and the next webhook gets a fresh fetch. Failure detail
remains in service logs. Fixes entrius#75.

Co-authored-by: anderdc <me@alexanderdc.com>
Co-authored-by: anderdc <me@alexanderdc.com>
Solver attribution previously rode the cross-reference reconcile path:
on every PR metadata fetch, the mirror wrote issue.solved_by_pr from
the PR's closingIssueNumbers array. That's a record of "PR text
declared it would close #N," not "GitHub determined PR-N caused the
issue's current closure," so reopen-then-reclose cycles, late body
edits, and stray "Closes #N" mentions could attribute to the wrong PR.

Switches the source of truth to ClosedEvent.closer anchored to the
issue's current closedAt:

- Add fetchIssueClosingPr / selectClosingPrFromTimeline on the
  GitHub fetcher. Returns the closer PR number when the close event
  matches the current closedAt and the closer is a merged same-repo PR;
  null for manual closes, non-PR closers, or NOT_PLANNED closures.
- Add an ISSUE_CLOSURE BullMQ job. Webhook handler enqueues on the
  closed action; the processor writes solved_by_pr from the fetcher.
- Extend backfillIssues to query the closure timeline alongside the
  label timeline so each issue's solver is resolved in the same pass.
- Drop reconcileSolvedIssueLinks. PR metadata still refreshes the
  PR-side closing_issue_numbers column; it no longer writes to
  issues.solved_by_pr.

The downstream effect: gittensor's issue discovery (reads
MirrorIssue.solved_by_pr) and the issue-bounty solver lookup
(entrius/gittensor#1305, also moved to ClosedEvent.closer) now share
one primitive and stay 1:1.

Schema unchanged. After deploy, re-running BACKFILL_REPO with a
long window reconciles existing solved_by_pr values.

Co-authored-by: anderdc <me@alexanderdc.com>
…ntrius#87)

* fix: allowing unknown solvers through mirror solved-issue pipeline

* fix: code change after review
…ntrius#62) (entrius#115)

* fix(webhook): refresh PR files on pull_request.edited base retarget (entrius#62)

The handler enqueues PR_FILES on opened / synchronize / merged-closed but
not on pull_request.edited with a base-ref change. The PR row updates
its baseSha, but the stored pr_files and scoringDataStored stay pinned
to the old base — leaving scoring inputs stale.

Detect a base retarget via payload.changes.base, clear scoringDataStored,
and enqueue PR_FILES with the new base/head SHAs through the existing
prFilesJobId path.

Closes entrius#62

* chore: prettier --write on pull-request.handler.ts (entrius#62)

The lint CI run failed Prettier formatting on f830e3d. Prettier wanted
the isBaseRetarget assignment on a single line. Single-line fit, no
behaviour change.

---------

Co-authored-by: jeffrey701 <jeffrey701@users.noreply.github.com>
Both getPullRequests and getPullRequestsByRepo were filtering CLOSED
pull requests by created_at >= since, causing PRs closed within the
scoring window but opened before it to be omitted from miner results.

Fix both query branches to use closed_at >= since for CLOSED state,
consistent with how merged_at is used for MERGED and how the sibling
issues endpoint already handles closed issues.

Fixes entrius#139
@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label May 30, 2026
@Tet-9
Copy link
Copy Markdown
Contributor Author

Tet-9 commented May 30, 2026

@anderdc , if you could please check this out

@anderdc
Copy link
Copy Markdown
Collaborator

anderdc commented Jun 2, 2026

CLOSED PRs are windowed by created_at on purpose. They feed only the merged/(merged+closed) credibility ratio in scoring, and the original GitHub-direct scoring path gated this exact way with a comment: "This allows users to close old PRs without receiving a fresh credibility penalty." A PR created before the window is deliberately excluded so that closing a stale PR doesn't drag down current-window credibility — switching to closed_at reintroduces precisely that penalty. The merged_at branch is special because a merge is the reward event that also drives time-decay; a close is not. Closing.

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] miners API: CLOSED pull requests filtered by created_at instead of closed_at

8 participants