Skip to content

Log the account's snapshot quota utilization after verifying a build - #1513

Closed
CameronHall wants to merge 1 commit into
chromaui:mainfrom
CameronHall:account-quota-utilisation
Closed

CameronHall wants to merge 1 commit into
chromaui:mainfrom
CameronHall:account-quota-utilisation

Conversation

@CameronHall

Copy link
Copy Markdown

What

After a build is verified, the CLI now logs the account's billed snapshot usage for the current billing period against the plan's included snapshots:

ℹ Snapshot usage: 42,317 / 85,000 (50%)
  Billing period: 2026-09-04 → 2026-10-04

The figures are also kept on ctx.accountUsage, so they show up in the --diagnostics-file output.

Why

Today you can only see quota usage in the web app's billing page. Accounts that run over their included snapshots often only find out when the invoice arrives. Showing usage in every CI log makes overage trends visible to the engineers who cause them, at the point where they can do something about it.

How

A new AccountUsageQuery (node-src/tasks/verify/getAccountUsage.ts) reads the same fields the billing page uses:

  • account.currentUsage { totalFinalBillableCount from to }
  • account.subscription { monthlyUsageLimit bonusUsage }

Utilization is totalFinalBillableCount / (monthlyUsageLimit + bonusUsage). When the plan has no monthly limit, only the count is shown.

This is a separate, fail-soft query rather than new fields on VerifyBuildQuery. These fields may not be exposed to project-token auth yet (see the authorizedBuildFieldsViaAppCode note on VerifyBuildQuery). Adding them there would turn a GraphQL authorization error into a failed build. Here, any error, including an unauthorized field, is logged at debug level, nothing is printed, and the build carries on. It runs with retries: 0, so it never adds retry delay to a build.

⚠️ Needs confirmation from the Chromatic team

I could only check the field shapes against the web app's session-authenticated billing query. Please confirm whether app.account.currentUsage and app.account.subscription { monthlyUsageLimit bonusUsage } can be read with a project/app token. If they can't, this PR stays harmlessly silent until they're allow-listed server-side.

Testing

  • New unit tests for getAccountUsage:
    • limit plus bonus
    • a plan with no limit
    • no usage data
    • a failed query returns undefined and logs at debug
  • New applyVerifyOutput test for ctx.accountUsage.
  • New stories under CLI/Messages/Info: within limit, over limit, no limit.
  • yarn tsc --noEmit and eslint are clean; the verify suites pass.

🤖 Generated with Claude Code

Query the account's current billed snapshot usage and plan limit (monthly limit plus bonus
usage), log it after the build is verified, and keep it on ctx so it lands in the diagnostics
file. The query is fail-soft: if the API doesn't expose these fields to the project token, or
the request fails for any reason, it is logged at debug level and the build is unaffected.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@CameronHall CameronHall closed this Oct 1, 2026
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