Populate AIC panel from ai-credits rows in current exports - #236
Merged
Merged
Conversation
Current GitHub AI usage exports emit aic_quantity and aic_gross_amount as a literal 0 on every row, while the real consumption is carried in quantity (unit_type ai-credits) and gross_amount/net_amount. The AIC cost panel only read the aic_* columns, so it permanently rendered the "no non-zero values" empty state for these exports. Derive effective AIC values for rows identified as AI credits by sku (copilot_ai_credit) or unit_type (ai-credits), falling back to quantity and gross_amount (then net_amount). Explicit non-zero aic_* values still win, so older exports are unaffected, and rows with genuinely zero consumption keep the empty state. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging Rob Bos (@rajbos) for notifications |
Rob Bos (rajbos)
requested a deployment
to
github-pages
September 17, 2026 12:02 — with
GitHub Actions
Waiting
Rob Bos (rajbos)
requested a deployment
to
github-pages
September 17, 2026 12:02 — with
GitHub Actions
Waiting
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.
Problem
The "Estimated Cost & AI Credits Usage" panel was permanently empty for current GitHub AI usage exports, showing:
Those exports (header
date,username,product,sku,model,quantity,unit_type,...,aic_quantity,aic_gross_amount,...) emitaic_quantityandaic_gross_amountas a literal0on every row. The actual AI credit consumption is carried inquantity(withunit_type=ai-credits) and the cost ingross_amount/net_amount:getAICDataStatus/getAICDataonly read theaic_*columns, so the panel always concluded there was no data.Fix
src/lib/utils.tsnow derives effective AIC values:isAICreditRecord()— identifies AI credit rows viasku=copilot_ai_creditorunit_type=ai-credits.getEffectiveAICQuantity()— usesaic_quantitywhen it is non-zero, otherwise falls back toquantityfor AI credit rows.getEffectiveAICGrossAmount()— usesaic_gross_amountwhen non-zero, otherwise falls back togross_amount, thennet_amount.getAICDataStatusandgetAICDatause these helpers. No changes were needed inAICCostChart.tsx.Behaviour preserved:
aic_quantity/aic_gross_amountstill use those values (explicit non-zero values win).copilot_premium_request/premium_requests) never derive AIC values, so exports without credits still show the "no AIC fields" state.Tests
New
src/test/aic-credit-fallback.test.tscovers both export shapes: derivation from the current format (day + month aggregation,net_amountfallback), backwards compatibility with explicitaic_*values, the genuine empty state, and non AI-credit rows.npx vitest run→ 252 passed, 1 failed (src/test/smoke-test-validation.test.ts— known pre-existing cold-run timeout flake; passes standalone).npm run buildsucceeds.Screenshots
Run against a representative export of the new shape (21 days, 4 users, 3 models, all
aic_*columns zero).Before
After