fix: parse summarized usage reports and AI-credit billed Copilot rows - #105
Merged
Conversation
GitHub emits the metered usage report in two shapes: detailed (max 31 days, includes username + workflow_path) and summarized (up to a year, omits both). Detection required workflow_path, so every summarized export — arguably the more commonly downloaded of the two — failed with "Unknown report type". Detection is now an explicit ordered list rather than an object relying on key insertion order, and keys off `repository`, which no Copilot report has. Premium request detection moves off the aic_* columns onto model/exceeds_quota/total_monthly_quota so it survives the PRU to AI credits transition. That same transition (June 2026) introduced the `ai-credits` unit type and the *_ai_credit SKUs. The Copilot "Usage (PRUs)" metric filtered on unitType === 'requests', so it silently rendered zero for anyone on the new billing model. It now matches anything not billed per seat. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.
Stacked on #104. This is the one that matters.
The task was to check whether the parser still matches what GitHub emits today. It doesn't. Two real drifts, both silent-ish, both confirmed against current GitHub docs and real export samples.
1. Summarized usage reports were rejected outright
GitHub emits the metered usage report in two shapes:
usernameworkflow_pathDetection required
workflow_path, so every summarized export threwUnknown report type. For a tool whose entire job is "drop your usage CSV here", and where summarized is the export you reach for when you want more than a month of history, that's a big hole.Fixed by keying detection off
repositoryinstead — no Copilot report has that column, so it's a clean discriminator. The mappers already default missing columns to'', so summarized files need no separate report type.While in there:
HEADER_SIGNATURESwas an object being iterated withObject.entries(), i.e. detection order depended on JS key insertion order. Now an explicit ordered array, which also drops aas ReportTypecast.2. AI credits billing rendered zero usage
Copilot moved from per-user PRU quota to token-metered AI Credits on 2026-06-01. That shipped two months ago. It introduced the
ai-creditsunit type and thecopilot_ai_credit/coding_agent_ai_credit/spark_ai_creditSKUs.PRODUCT_METRIC_OPTIONS.copilotfiltered usage onunitType === 'requests'. Under the new billing model that matches nothing, so the "Usage (PRUs)" card silently rendered 0 — no error, no empty state, just a wrong number. Worst kind of bug.Now filters on "not billed per seat" (
!== 'user-months') rather than an allow-list, so the next unit type GitHub invents doesn't break it again. Relabeled to just "Usage" since it's no longer PRUs.Premium-request detection also moved off the
aic_*columns ontomodel/exceeds_quota/total_monthly_quota— same reason, those are stable across the billing transition.Tests
7 new regression tests: summarized detection, premium-request without
aic_*columns, token-usage still winning over premium-request, org-level seat activity (which genuinely has noOrganizationcolumn — confirmed against GitHub's own export source), plus end-to-end parses of a summarized report and anai-creditsrow.Checked and found clean
Detailed metered usage, token usage (19 cols), GHAS active committers, dormant users, and enterprise members all match the app exactly. The legacy pre-enhanced-billing Actions CSV was retired in Nov 2025, so no back-compat needed there.
Verified: 254 tests pass, 0 lint errors, 0 type errors, build succeeds.