Skip to content

[bug] miners API: CLOSED pull requests sorted by created_at instead of closed_at, causing recent closures to appear stale #151

@Tet-9

Description

@Tet-9

Duplicate check

Item Relation
#139 (open) Fixes CLOSED filter to use closed_at — does not fix sort order
No open/closed issue ORDER BY p.created_at DESC for CLOSED PRs

Description

GET /api/v1/miners/:githubId/pulls and POST .../pulls (per-repo variant) both sort all results by p.created_at DESC. After #139 fixes the window filter for CLOSED PRs to use closed_at >= since, the sort order remains anchored to created_at.

This means a PR opened 60 days ago but closed 2 days ago will appear near the bottom of results behind PRs opened more recently, even though it is the most recently resolved. Validators consuming the miner API see an ordering that does not reflect actual activity recency for closed PRs.

Steps to Reproduce

  1. Mirror a repo with a miner-authored PR: created_at = 60 days ago, closed_at = 2 days ago, state = CLOSED.
  2. Call GET /api/v1/miners/{authorId}/pulls?since= (ISO timestamp 30 days ago).
  3. Observe the PR appears correctly in results (after [bug] miners API: CLOSED pull requests filtered by created_at instead of closed_at #139 fix).
  4. Observe it appears near the bottom of the list sorted behind PRs opened more recently.

Expected Behavior

Results should reflect recency by the timestamp most meaningful to each state:

  • OPEN -> created_at
  • MERGED -> merged_at
  • CLOSED -> closed_at

A unified sort could use COALESCE(p.merged_at, p.closed_at, p.created_at) DESC.

Actual Behavior

Both getPullRequests and getPullRequestsByRepo use ORDER BY p.created_at DESC for all states regardless of PR state.

Files

packages/das/src/api/miners/miners.service.tsORDER BY clause in both query variants (~line 198 and ~line 247).

Environment

  • Runtime/Node version: Node 20
  • OS: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions