Skip to content

fix: parse summarized usage reports and AI-credit billed Copilot rows - #105

Merged
austenstone merged 2 commits into
mainfrom
fix/billing-format-drift
Aug 20, 2026
Merged

fix: parse summarized usage reports and AI-credit billed Copilot rows#105
austenstone merged 2 commits into
mainfrom
fix/billing-format-drift

Conversation

@austenstone

Copy link
Copy Markdown
Owner

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:

detailed summarized
max range 31 days 1 year
username
workflow_path

Detection required workflow_path, so every summarized export threw Unknown 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.

date, product, sku, quantity, unit_type, applied_cost_per_quantity,
gross_amount, discount_amount, net_amount, organization, repository,
cost_center_name
→ Error: Unknown report type

Fixed by keying detection off repository instead — 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_SIGNATURES was an object being iterated with Object.entries(), i.e. detection order depended on JS key insertion order. Now an explicit ordered array, which also drops a as ReportType cast.

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-credits unit type and the copilot_ai_credit / coding_agent_ai_credit / spark_ai_credit SKUs.

PRODUCT_METRIC_OPTIONS.copilot filtered usage on unitType === '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 onto model/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 no Organization column — confirmed against GitHub's own export source), plus end-to-end parses of a summarized report and an ai-credits row.

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.

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>
@austenstone
austenstone merged commit d77fbf6 into main Aug 20, 2026
3 checks passed
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