fix(api): count cached open PRs across all in-scope repos on the maintainer dashboard - #399
Merged
JSONbored merged 3 commits intoJun 5, 2026
Conversation
JSONbored
approved these changes
Jun 5, 2026
JSONbored
left a comment
Owner
There was a problem hiding this comment.
@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.
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.
Summary
The
/v1/app/maintainer-dashboard"Open PRs cached" headline metric was computed fromopenPullRequests, a list deliberately limited torepositories.slice(0, 12)(that cap exists to bound thereviewabilitypreview). 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 fromlistRepositoriesis 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 existingPromise.all;RepoSyncStateRecord.openPullRequestsCount, the same sourcebuildRepoDecisionuses), a single query with no extra per-repo fetches. The sparkline now uses a same-unit ratio (reposWithOpenPullRequests / repositories.length). Therepositories.slice(0, 12)PR fetch is unchanged and still feeds only thereviewabilitypreview 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).mcp-clitimeout that passes in isolation).Safety
metricsarray keeps the same labels/fields; only the (now correct, larger-or-equal) "Open PRs cached" value and its sparkline change.repositoriesset, so scoped maintainers still see only their repos.Notes
The sibling metrics remain as-is; only "Open PRs cached" diverged from the global-count convention.