Skip to content

fix(api): count cached open PRs across all in-scope repos on the maintainer dashboard - #399

Merged
JSONbored merged 3 commits into
JSONbored:mainfrom
philluiz2323:fix/dashboard-open-prs-global-count
Jun 5, 2026
Merged

fix(api): count cached open PRs across all in-scope repos on the maintainer dashboard#399
JSONbored merged 3 commits into
JSONbored:mainfrom
philluiz2323:fix/dashboard-open-prs-global-count

Conversation

@philluiz2323

Copy link
Copy Markdown
Contributor

Summary

The /v1/app/maintainer-dashboard "Open PRs cached" headline metric was computed from openPullRequests, a list deliberately limited to repositories.slice(0, 12) (that cap exists to bound the reviewability preview). Its three sibling metrics (Installations, Install issues, Rate-limit events) are global counts across the full scoped set, so "Open PRs cached" silently undercounted whenever more than 12 in-scope repos held open PRs. Because repo ordering from listRepositories is arbitrary, which 12 repos contributed was effectively non-deterministic. The metric's sparkline was also dimensionally inconsistent -- a PR-count numerator (openPullRequests.length) over a repo-count denominator (repositories.length). Closes #398.

Reachable for operators (no scope -> all repos) and any maintainer/owner scoped to >12 repos. Example: 30 repos with 8 open PRs in the first 12 and 25 in the rest reported 8 instead of 33.

Scope

  • src/api/routes.ts -- the cached open-PR count is now summed across all in-scope repos from sync state (listRepoSyncStates, added to the existing Promise.all; RepoSyncStateRecord.openPullRequestsCount, the same source buildRepoDecision uses), a single query with no extra per-repo fetches. The sparkline now uses a same-unit ratio (reposWithOpenPullRequests / repositories.length). The repositories.slice(0, 12) PR fetch is unchanged and still feeds only the reviewability preview list, where the cap is intended.
  • test/integration/api.test.ts -- fail-on-revert: two repos carry cached open-PR counts in sync state (5 + 3) but have no open PR records, so the old per-repo-fetch metric reported 0 while the global count reports 8.

Validation

  • npx tsc --noEmit -- clean.
  • npx vitest run test/integration/api.test.ts -- 26/26 pass (including the new test).
  • Full suite -- 1029 pass, 1 skipped (excluding the two unparseable upstream test files and one unrelated mcp-cli timeout that passes in isolation).
  • Branch coverage 97.15% (above the 97% gate).

Safety

  • No response-shape change: the metrics array keeps the same labels/fields; only the (now correct, larger-or-equal) "Open PRs cached" value and its sparkline change.
  • Scope handling is unchanged -- the new sum reuses the existing scoped repositories set, so scoped maintainers still see only their repos.
  • Uses already-cached sync-state counts; no additional GitHub or per-repo PR queries.

Notes

The sibling metrics remain as-is; only "Open PRs cached" diverged from the global-count convention.

@JSONbored JSONbored left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philluiz2323 this looks ready from my side.

A few notes:

  • The stale readiness count is wired into the maintainer dashboard path instead of living as an isolated helper.
  • The integration test covers the behavior that matters for the API consumer.
  • No code changes requested from me; merge after required review clears.

Validation expected:

  • Current green CI is sufficient.

@dosubot dosubot Bot added the lgtm label Jun 5, 2026
@JSONbored
JSONbored merged commit dc7c375 into JSONbored:main Jun 5, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in gittensory - v1 roadmap Jun 5, 2026
@JSONbored JSONbored added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

No open projects
Status: Done

2 participants