Skip to content

feat: Copilot AI Credit plan math from total_nano_aiu - #1123

Merged
iamtoruk merged 4 commits into
getagentseal:mainfrom
avs-io:local/943-copilot-credits
Aug 24, 2026
Merged

iamtoruk merged 4 commits into
getagentseal:mainfrom
avs-io:local/943-copilot-credits

Conversation

@avs-io

@avs-io avs-io commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Fixes #943

Plan math against real total_nano_aiu. Not #890. Not #1114 live quota. No app/.

Behavior

  • copilot is a plan provider. Presets use official allotments (fetched 2026-08-23), not sticker prices:
    • copilot-pro — 1500 credits / $15 equivalent
    • copilot-pro-plus — 7000 / $70
    • copilot-max — 20000 / $200
  • codeburn plan set custom --credits N --provider copilot is the org path. Mixed units (--monthly-usd + copilot) are rejected.
  • Copilot spend is sum(finite nanoAiu) / 1e9. Missing nanoAiu → spentCredits = 0 + creditsIncomplete. Token-priced costUSD does not fill the bar.
  • Claude / cursor / grok / custom-USD plans stay on costUSD.
  • TUI headline is N / B AI Credits. Status still says “Not a live provider window.” No GitHub UTC-1st claim.

Serve hole

cachedCallToApiCall now threads nanoAiu onto ParsedApiCall. Same field on the fresh-parse twin. CACHE_VERSION stays 9 — reconstruction from already-cached CachedCall.nanoAiu works.

Proofs

  1. plan set copilot-pro writes { id: copilot-pro, monthlyCredits: 1500, monthlyUsd: 15, provider: copilot, resetDay: 1 }
  2. custom --credits 20000 --provider copilot writes monthlyCredits: 20000, monthlyUsd: 200
  3. custom --monthly-usd 200 --provider copilot exits non-zero
  4. nanoAiu = 1_500_000_000 → spentCredits === 1.5, budgetCredits === 1500, percentUsed === 0.1
  5. Same tokens, no nanoAiu → spentCredits === 0, creditsIncomplete === true
  6. Claude plan on the same fixture still sums costUSD. JSONL / rollup siblings without nanoAiu do not change the 1.5

Spent credits are finite nanoAiu / 1e9. Token-priced costUSD does not
fill the Copilot bar. Thread nanoAiu through cachedCallToApiCall with
no cache-version bump.
@avs-io
avs-io marked this pull request as ready for review August 23, 2026 14:21
@iamtoruk

Copy link
Copy Markdown
Member

Reviewed (MiniMax draft; findings verified against the diff by maintainer). Preset math, nanoAiu threading through the cache, no-app/no-quota scope claims: all confirmed (including CACHE_VERSION staying 9 with warm reconstruction asserted in tests).

Two changes requested:

  1. Add a supplementaryAccounting guard in copilotCreditSpend (src/plan-usage.ts). Verified: the loop sums every copilot call's nanoAiu with no supplementary filter. Today's fixtures pass only because supplementary siblings happen to carry no nanoAiu — the moment a store attaches it to a paired rollup row, credits double-count. One line (if (call.supplementaryAccounting) return) closes the class.

  2. Retention predicate widened for every plan provider (src/plan-usage.ts: totalApiCalls > 0 || totalCostUSD > 0 → sessions.length > 0). Verified unconditional — Claude/cursor/grok plans now retain zero-spend sessions they previously dropped. Zero dollar impact, but it's an unannounced behavior change on providers this PR isn't about: gate it on isCopilotCreditsPlan(plan) or call it out in the description.

avs-io added 3 commits August 23, 2026 20:54
Store-row nanoAiu is still the bill when the JSONL twin has none.
USD plans keep the cost-or-calls retain predicate.
Keep both cachedCallToApiCall spreads: nanoAiu from this PR and
supplementaryAccounting / Hermes observation keys from #1121.
foldCopilotSupplementaryTurns will not fold a supplementary twin across
a local-day boundary, so the pair can occupy separate turns. Credit
spend now groups at session scope.
@iamtoruk
iamtoruk merged commit 1936f69 into getagentseal:main Aug 24, 2026
15 checks passed
@iamtoruk

Copy link
Copy Markdown
Member

Merged. For the record on the retention-predicate change (totalApiCalls > 0 || totalCostUSD > 0 → sessions.length > 0 in plan views): this now retains zero-spend sessions for every plan provider, not only copilot. Zero dollar impact — arguably more correct, since behavioral-only sessions were silently dropped from plan views before. Documented here so the behavior change has a paper trail.

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.

Request: Github Copilot AI Credit tracking

2 participants