Repository navigation
feat(billing): read a Content Editor page's share of the month's AI usage (AI usage display, part 3a) - #1432
Merged
Conversation
…sage (AI usage display, part 3a) Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
approved these changes
Oct 24, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good. The route reads only the member's own organization's rows, so another workspace's draft id reads 0 and shows nothing about it. Only percents leave the server.
One low item, fine as a follow-up:
server/src/lib/plan-guard.js:570: the page's share isn't capped at the month's figure, so rounding can put the page above the month. Example: $4.998 of a $5 budget spent, all on one page. The month reads 99.9, becausegetAiUsageholds an unspent budget at 99.9, but the page readstenths(99.96)= 100. The popover then shows "This page this month 100%" under a "99%" meter. Fix: cap the page the same way, e.g.Math.min(percent, spentAll >= budget ? 100 : 99.9).
cihan-gyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Oct 24, 2026
ansvisor#1432 is on main (squash-merged), with ansvisor#1429–ansvisor#1436 around it; this branch's own changes (part 5 and its follow-up) are applied on top. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Summary
AI usage display, part 3a (server): a Content Editor page's share of the month's AI usage, for the editor meter's "This page this month" line (Drive › AI Usage ›
AI-USAGE-spec.md§3.1). Server only, additive, no migration.getDraftAiUsage(orgId, draftId)inlib/plan-guard.js, next togetAiUsage:prompt_improve_usage(its brief, Content Agent and writer chargecontent_draft_id; holds included, as the month's figure counts them).getAiUsage, so the page is a part of the month's figure.getAiUsagescales its features, so a page never reads more than the month.{ unlimited: true, percent: null }.GET /api/billing/ai-usage/draft/:draftId(routes/billing.js):z.guid()check, 400 otherwise, asroutes/content-drafts.js;/ai-usage;PlanLimitErrorstatus witherror: 'plan_limit';Read cost:
(organization_id, used_at)index from 00120 serves. They are a few hundred at most, since the budget caps them.ai_usage_by_featureRPC.Deploy order: this one first; the web part (the editor meter, stacked on #1429 and #1431) reads it.
Pre-push review: no high findings. Fixed:
Noted outside this PR:
content_draft_id(00212) has no index, so deleting a draft scans the ledger forON DELETE SET NULL;improveSpendThisPeriodasks for 5000 rows, but PostgREST's max_rows caps that at 1000.Related issue
Drive spec AI Usage (approved 2026-10-23). No GitHub issue.
Type of change
How to test
IS_CLOUD=trueand a workspace on a cloud plan, callGET /api/billing/ai-usage/draft/<draftId>as a member. It reads{ unlimited: false, percent }: the page's share of the month's budget.percent: 0; a bad id answers 400; self-hosted reads{ unlimited: true, percent: null }.Checklist
server/:npm run format,npm run lint,npm test(190 files, 2,314 tests) passplan-guard-ai-usage.test.js:plan_limitwithout an active plan;billing.test.js: the route reads for the member's organization, turns away a bad id, has no share without an organization, and mapsplan_limitand failures.npm run version:checkfails onmainalready (compose images 0.2.0 vs 0.3.0); not touched here🤖 Generated with Claude Code