Skip to content

Add proofline stats: review turnaround and outcomes per repository - #133

Open
SahibYar wants to merge 3 commits into
prooflinedev:mainfrom
SahibYar:feat/review-turnaround-stats
Open

SahibYar wants to merge 3 commits into
prooflinedev:mainfrom
SahibYar:feat/review-turnaround-stats

Conversation

@SahibYar

@SahibYar SahibYar commented Nov 30, 2026 •

Copy link
Copy Markdown

Who this helps

An engineering lead or platform owner who has rolled Proofline out across many repositories, and needs answers to two questions: how long do authors wait for a review, and how often does a review fail to give them a usable result? Today the CLI can only answer that with a shell loop. You would run proofline export reviews page by page, carry --cursor along by hand, check that the settled horizon stays the same, strip repeated headers, and then compute percentiles with jq or a spreadsheet. The README itself warns against treating partial output from several invocations as a complete export.

proofline stats does that whole job in one command. This is the real output against the synthetic 200,000-review export described under verification:

$ proofline stats --from 2026-10-01T00:00:00Z --to 2026-10-25T00:00:00Z
repository   reviews  completed  incomplete  failed  unfinished  other     p50     p90     p99     max
acme/svc-0      4114       2690         352     352         384    336   4m01s  10m49s  24m37s  58m49s
acme/svc-1      4091       2709         376     320         340    346   4m06s  11m14s  24m41s  52m52s
…
all           200000     133173       16962   16527       16650  16688   4m04s  11m22s  26m11s   2h03m
settled-until: 2026-10-25T00:00:00Z (40 pages); counted PULL_REQUEST reviews, left out 0 reviews of other kinds   ← stderr

--json prints the same report with times in seconds, for dashboards and CI checks such as "fail if p90 turnaround goes above 15 minutes".

What it does

  • Reads every page of the reviews export for the window. It needs analytics:read and the server's 31-day window limit, and adds no new API.
  • Counts pull-request reviews by default. Repeat --kind to choose others: pull_request, deployment, patch, commit, files, merge_group or revision_scan. Stderr and the JSON report say which kinds were counted and how many reviews were left out.
  • Prints one row per repository (grouped by repository ID, shown by current name) and an all row. Each row shows reviews by status: completed, incomplete, failed, unfinished (pending or running) and other. It also shows the nearest-rank p50 / p90 / p99 / max time from created_at to completed_at.
  • Prints nothing until the last page has been read. A failed page, a settled horizon that changes between pages, a continuation cursor that repeats, or an unknown row version all exit 1 with no partial report.

Decisions

Decision Why
Count pull-request reviews unless --kind says otherwise The export mixes pull requests, deployments, local patches, commits, named files, merge groups and revision scans. Their wait times mean different things, and the README says revision scans currently end FAILED or INCOMPLETE. Mixing them in would inflate the failed count and skew "how long authors wait". The default answers the pull-request question, and --kind opts others in.
Group by repository_id, show repository_full_name The contract calls names display data and the ID the stable key. A review whose repository the organization no longer owns keeps its ID and appears under it. A review with no ID groups by name, then (no repository).
Turnaround counts only COMPLETED reviews An incomplete, failed or stopped review gave the author no usable result. Mixing those times in would make a failing pipeline look fast. Those reviews still show up in the status counts.
Nearest-rank percentiles over exact durations Every reported value is a turnaround that actually happened, with no interpolation. Holding one u64 per completed review is about 8 MB for a million reviews, so a sketch isn't needed yet.
Report only after the last page The export's contract is one frozen horizon per window. A report built from pages with different horizons, or from a cursor that loops, would be wrong without anything showing it, so the command refuses it instead. The walk is also bounded at 10,000 pages, which is 50M rows.
Unknown statuses count as other, unreadable times are refused New statuses from the server don't break older CLIs. A time the CLI can't parse fails loudly instead of being guessed.
Shared export_page helper (separate refactor commit) stats reuses exactly the media-type, row-version, horizon and cursor checks that proofline export already applies, instead of a second copy. export prints byte-for-byte what it did before. The only difference is that an unreadable next-cursor header is now refused before the page is printed, instead of after.
Reuses github_actions::unix_seconds No new date-time dependency, so cargo deny is unaffected.

How I verified it

  • TDD: I wrote tests/stats.rs first and watched it fail, because the subcommand didn't exist yet. The tests run the real binary against a loopback stand-in for the console:
    • two pages, checking that the second request keeps the window and format and adds only the cursor
    • a revision scan and a local patch left out by default and counted with --kind pull_request --kind patch
    • a repository with an ID and no name grouped and shown by its ID
    • exact JSON for three repository groups plus all
    • the text table and its duration formatting
    • refusal of a moving horizon, a repeating cursor and an unknown row version, with nothing printed to stdout and the token never echoed
  • Unit tests in src/stats.rs: percentile ranks (1..100 gives 50/90/99/100, a single value, empty input), duration formatting at every scale, turnaround only for COMPLETED, clock skew clamped to 0, an unreadable time refused, the repository name fallback, and unknown statuses counted as other, grouping by ID and never by name when an ID exists, and every --kind value mapping to the export's spelling.
  • Scale check (release build, local fake server): 40 pages × 5,000 rows = 200,000 reviews in about 0.15 s with 26 MB peak RSS. I recomputed the percentiles independently in Python from the same seeded data, and they match exactly (4m04s / 11m22s / 26m11s / 2h03m).
  • cargo fmt --check and cargo clippy --locked --all-targets -- -D warnings are clean, and cargo test --locked --no-fail-fast passes. The one failure, agent_install's unattended_registration_…, is the existing macOS /var vs /private/var issue unattended_registration_preserves_settings_and_uses_the_installed_binary fails on macOS (/var vs /private/var) #112. It fails the same way on main.
  • I checked that each commit is green on its own.

Out of scope

  • Windows longer than 31 days. Export every page and window into one file #42 adds multi-window export, and stats can build on it once that lands.
  • A --trigger-origin filter or breakdown, for example automatic runs vs RERUN, to see how much of the wait is reruns. It fits in the same row filter as --kind.
  • Cost per review, from the spend dataset.

Move the export request, media-type and row-version checks and the
horizon and cursor headers out of `proofline export` into export_page,
so another command can follow the continuation with the same checks.
`proofline export` prints exactly what it printed before.
`proofline stats --from FROM --to TO` reads every page of the reviews
export for one window and prints, per repository and in total, the
reviews by status and the nearest-rank p50, p90, p99 and longest time
from creation to completion of the completed reviews. --json prints the
same report with times in seconds.

The report is printed only after the last page. A page that fails, a
settled horizon that changes between pages or a continuation cursor that
repeats exits 1 with no partial report, and the walk is bounded at
10,000 pages.
@SahibYar

Copy link
Copy Markdown
Author

The Checks workflow is waiting for maintainer approval because this PR comes from a fork, so I ran the same workflow on the PR branch in my fork. Both jobs pass: check (fmt, clippy -D warnings, cargo test, cargo deny) and windows. Run: https://github.com/SahibYar/cli/actions/runs/46494462638

The reviews export mixes pull-request, deployment, local patch, commit,
named-file, merge-group and revision-scan reviews. Mixing them skews the
turnaround authors wait for, and revision scans currently end FAILED or
INCOMPLETE, so they inflate the failed count. stats now counts
pull_request reviews unless a repeatable --kind selects others, and
reports the kinds it counted and how many reviews it left out.

Repository names are display data, so reviews now group by the stable
repository ID and show its current name, falling back to the name and
then '(no repository)' when the review records no ID.
@SahibYar

Copy link
Copy Markdown
Author

I pushed 439686b. stats now counts pull-request reviews by default (--kind selects other kinds) and groups by repository ID. The same Checks workflow passes on that commit in my fork: https://github.com/SahibYar/cli/actions/runs/46507382160

This branch has not been deployed

No deployments
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