Skip to content

Populate AIC panel from ai-credits rows in current exports - #236

Merged
Rob Bos (rajbos) merged 1 commit into
mainfrom
local-empty-aic-panel
Sep 17, 2026
Merged

Rob Bos (rajbos) merged 1 commit into
mainfrom
local-empty-aic-panel

Conversation

@rajbos

@rajbos Rob Bos (rajbos) commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Problem

The "Estimated Cost & AI Credits Usage" panel was permanently empty for current GitHub AI usage exports, showing:

The AIC fields are present in the data but contain no non-zero values for the selected period.

Those exports (header date,username,product,sku,model,quantity,unit_type,...,aic_quantity,aic_gross_amount,...) emit aic_quantity and aic_gross_amount as a literal 0 on every row. The actual AI credit consumption is carried in quantity (with unit_type = ai-credits) and the cost in gross_amount / net_amount:

2026-09-01,nemo-chen_Barco,copilot,copilot_ai_credit,"Auto: Claude Haiku 4.5",4.212603,ai-credits,0.01,0.04212603,0.04212603,0,1900,...,0,0,16,475,32507,32932

getAICDataStatus / getAICData only read the aic_* columns, so the panel always concluded there was no data.

Fix

src/lib/utils.ts now derives effective AIC values:

  • isAICreditRecord() — identifies AI credit rows via sku = copilot_ai_credit or unit_type = ai-credits.
  • getEffectiveAICQuantity() — uses aic_quantity when it is non-zero, otherwise falls back to quantity for AI credit rows.
  • getEffectiveAICGrossAmount() — uses aic_gross_amount when non-zero, otherwise falls back to gross_amount, then net_amount.

getAICDataStatus and getAICData use these helpers. No changes were needed in AICCostChart.tsx.

Behaviour preserved:

  • Older exports that populate aic_quantity / aic_gross_amount still use those values (explicit non-zero values win).
  • Rows that are AI credits but have zero consumption still render the empty state.
  • Non AI-credit rows (e.g. 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.ts covers both export shapes: derivation from the current format (day + month aggregation, net_amount fallback), backwards compatibility with explicit aic_* 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 build succeeds.

Screenshots

Run against a representative export of the new shape (21 days, 4 users, 3 models, all aic_* columns zero).

Before

AIC panel before the fix - empty state

After

AIC panel after the fix - populated chart

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>
@github-actions

Copy link
Copy Markdown
Contributor

Tagging Rob Bos (@rajbos) for notifications

@rajbos
Rob Bos (rajbos) merged commit b9005ae into main Sep 17, 2026
9 of 11 checks passed
@rajbos
Rob Bos (rajbos) deleted the local-empty-aic-panel branch September 17, 2026 12:11
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