Skip to content

GLOOK-26: fix PR undercount in get_metric_timeseries (per-repo PR numbers) - #60

Merged
msogin merged 1 commit into
mainfrom
fix/glook-26-pr-number-per-repo
Jul 23, 2026
Merged

msogin merged 1 commit into
mainfrom
fix/glook-26-pr-number-per-repo

Conversation

@msogin

@msogin msogin commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a significant undercount in the get_metric_timeseries MCP tool's prs metric.

Root cause: GitHub PR numbers restart at #1 in every repo, so pr_number is only unique within a repo — the true key is (repo, pr_number). The metric grouped by bare pr_number, collapsing PR #42 in repo A with PR #42 in repo B. Cross-report over the default 180-day window this compounded badly: with ~600 repos, low PR numbers (1–~100) each absorbed hundreds of distinct PRs, all bucketed at the earliest date that number ever appeared. Result: recent weeks were starved (their low-numbered PRs were "already counted" months earlier) and the series capped near the range of PR numbers — a ~5× undercount.

Fix: key the prs metric on (repo, pr_number) in both aggregation paths:

  • group_by=report: COUNT(DISTINCT ca.repo, ca.pr_number)
  • week/month/dimension dedup: GROUP BY ca.repo, ca.pr_number

commit_sha and issue_key are globally unique, so the commits/jira_resolved paths are unchanged.

Verification

  • 810 tests pass, tsc --noEmit clean; 2 tests updated/added asserting the (repo, pr_number) keying.
  • Real-data replay (latest report): COUNT(DISTINCT pr_number)=354 vs COUNT(DISTINCT repo, pr_number)=452, matching sum(developer_stats.total_prs)=467. PR #99 alone appeared in 4 repos.
  • Deployed to dev and verified live through the MCP connector — weekly PRs corrected ~4–5×:
Week Before After
2026-06-22 49 221
2026-07-06 46 261
2026-07-13 36 184

Notes

The same per-repo-number pattern exists in GLOOK-25's project-insights drill-down (commitsByPr keyed by pr_number within a single report) — much smaller impact (single report, display not counting), left out to keep this focused. Worth a follow-up.

🤖 Generated with Claude Code

…OOK-26)

GitHub PR numbers restart at #1 per repo, so grouping the prs metric by
pr_number alone collapsed PR #42 in repo A with PR #42 in repo B. Cross-report
over the default 180-day window this compounded badly: every repo has low PR
numbers, so pr_number 1..~100 each absorbed hundreds of distinct PRs bucketed
at their earliest appearance — starving recent weeks and capping the series at
roughly the range of PR numbers (~5x undercount).

Key the prs metric on (repo, pr_number) in both the report-grouped
COUNT(DISTINCT ...) and the week/month/dimension dedup GROUP BY. commit_sha and
issue_key are globally unique and unchanged.

Verified on real data: recent weekly PR counts corrected ~4-5x (e.g. 2026-06-08
34 -> 197), matching sum(developer_stats.total_prs).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@msogin
msogin merged commit c13e089 into main Jul 23, 2026
1 check passed
@msogin
msogin deleted the fix/glook-26-pr-number-per-repo branch July 23, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant