fix(miners): sort pull requests by state-relevant timestamp instead of created_at#155
Closed
Tet-9 wants to merge 14 commits into
Closed
fix(miners): sort pull requests by state-relevant timestamp instead of created_at#155Tet-9 wants to merge 14 commits into
Tet-9 wants to merge 14 commits into
Conversation
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>
…f created_at Both getPullRequests and getPullRequestsByRepo sorted all results by p.created_at DESC regardless of PR state. A PR opened 60 days ago but closed 2 days ago would appear below PRs opened more recently, making CLOSED results appear stale to validators. Fix both ORDER BY clauses to use COALESCE(p.merged_at, p.closed_at, p.created_at) DESC so each PR floats by the timestamp most relevant to its state. Also fixes the CLOSED filter to use closed_at >= since consistent with entrius#139. Fixes entrius#151
Collaborator
|
Built on #149/#139, now closed: CLOSED PRs are windowed by created_at deliberately (they feed only the credibility ratio, and the original scoring code gated this way to avoid a fresh credibility penalty when old PRs are closed), so the filter half here duplicates a rejected change. The ORDER BY half only reorders rows in the API response; the validator buckets PRs by state regardless of order, so it has no scoring effect. Closing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(miners): sort pull requests by state-relevant timestamp instead of created_at
Summary
getPullRequestsandgetPullRequestsByRepoinminers.service.tssorted all pull request results byp.created_at DESCregardless of PR state. A PR opened 60 days ago but closed 2 days ago would appear near the bottom of results behind PRs opened more recently, making recently-resolved CLOSED PRs appear stale to validators.Root Cause
Both query variants used a single fixed sort key for all states:
-- Before (incorrect)
ORDER BY p.created_at DESC
-- After (correct)
ORDER BY COALESCE(p.merged_at, p.closed_at, p.created_at) DESC
This is inconsistent with how the filter already distinguishes between states (merged_at for MERGED, closed_at for CLOSED after #139). The sort should reflect the same timestamp hierarchy.
Changes
Testing
Lint confirmed only pre-existing errors in cache.module.ts, unrelated to this change. Verified ORDER BY on issue query variants (lines 278, 321) were not affected.
Fixes #151