Skip to content

Copilot: usage missing when modelMetrics doesn't cover the whole session #1823

Closed

Description

@erwindamsma

What happened?

ccusage copilot daily shows about 38% of what GitHub bills me for Oct 1–3 (UTC), comparing its cost with the AI credits on my Copilot usage page at $0.01 each.

The adapter only reads modelMetrics from session.shutdown. That breakdown only covers the running Copilot process, while the session-wide totalNanoAiu on every shutdown and on session.usage_checkpoint events has the whole session:

  • A session resumed after the app or its process died shuts down with an empty or partial modelMetrics, for example a non-zero totalNanoAiu next to "modelMetrics": {}.
  • Sessions that are still open, or were killed without a shutdown, only have checkpoints, so they don't show up at all.

Summing the session totals from my local logs gives about 97% of the billed credits.

Steps to reproduce

  1. Use Copilot CLI 1.0.90 or the Copilot app and resume a session after the app restarted, or keep a session open.
  2. On a session.shutdown event, compare data.totalNanoAiu with the sum of data.modelMetrics[*].totalNanoAiu.
  3. Compare ccusage copilot daily --since <date> with the Copilot usage page.

Expected behavior

Credits in totalNanoAiu that modelMetrics doesn't account for still count toward cost. The tokens behind them can't be recovered, but the cost can (1 AIU = 1 AI credit = $0.01).

Version

20.0.26

I have a fix with tests on https://github.com/erwindamsma/ccusage/tree/fix/copilot-session-credit-gaps. It adds the unexplained credits as cost-only unknown rows and leaves sessions from older Copilot versions (no checkpoints, counters restart on resume) alone. With it, ccusage reports about 97% of my billed credits with identical token totals. Opening PRs is limited to collaborators, so I'd like to submit it as a PR.

Activity

  1. pullfrog commented on Oct 3, 2026

    @pullfrog
    Contributor
  2. added
    priority:highHigh user impact or an important regression.
    triage:maintainableFits the repository's maintainable scope and needs review.
    on Oct 3, 2026
  3. github-actions commented on Oct 3, 2026

    @github-actions
    Contributor

    Pullfrog triage: priority:high
    Kind: bug
    Maintenance fit: maintainable
    Confidence: high

    Copilot adapter reports only part of billed credits because modelMetrics can be empty or partial while totalNanoAiu holds the session total, plus checkpoints are ignored. This is a material cost undercount with quantified evidence, squarely within core usage reporting.

    Decision: kept open; Pullfrog will attempt a focused implementation PR.

  4. erwindamsma commented on Oct 3, 2026

    @erwindamsma
    ContributorAuthor

    Two things I ran into while testing the fix against my own logs, in case the implementation doesn't take them over from the branch:

    1. Sessions without session.usage_checkpoint events come from older Copilot versions that restart both totalNanoAiu and the per-model metrics on every resume. In my logs, 22 of 32 such sessions have per-model counters that go down between shutdowns, against 0 of 24 sessions with checkpoints. Applying the gap logic to them overcounted June by more than the raw totals add up to, so the branch skips sessions without checkpoints.

    2. A shutdown can carry a breakdown that lags behind the session total, and the next shutdown catches up. One session went from totalNanoAiu 452.1 AIU with modelMetrics at 249.2 AIU to 452.1 / 452.1 twenty minutes later. Taking the gap per shutdown counts those ~203 credits twice: once as unexplained, and again as tokens at the next shutdown. The branch only reports what stays unexplained at every later snapshot.

    Both have a test on the branch: leaves_sessions_without_checkpoints_unchanged and does_not_count_credits_that_a_later_shutdown_attributes.

  5. added a commit that references this issue on Oct 10, 2026
    c788127
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:highHigh user impact or an important regression.triage:maintainableFits the repository's maintainable scope and needs review.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions