Repository navigation
fix(billing): stop raising Enterprise's AI budget to 1% of its contract - #1577
Merged
Merged
Conversation
User decision 2026-10-27: Enterprise's AI budget is $50, or more as Ansvisor sets it per customer in plan_overrides.improveMonthlyBudgetUsd; contractMonthlyUsd no longer raises it (the relevance allowance's 0.1% of the contract stays). IMPROVE_BUDGET_SHARE goes. Settings › Billing's custom plan box now says "Custom AI usage, over 10x", worked out from the budgets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
approved these changes
Oct 27, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good, with follow-ups.
What I checked:
- Own change.
origin/main..origin/pr/1577, one commit on 55b49e7 (main). - The rule.
applyPlanOverrides(plan-guard.js:48-67) no longer setsimproveMonthlyBudgetUsdfromcontractMonthlyUsd.{ ...plan.limits, ...overrides }still lets an explicitplan_overrides.improveMonthlyBudgetUsdwin, and the relevance allowance keeps its 0.1% of the contract.IMPROVE_BUDGET_SHAREhad no other reader.- Nothing left in
server/,web/,docs/orweb/messagescomputes or states 1% of the contract. The only mentions are the 00120 and 00138 migration comments, and their copies inschema.sql.
- Every plan, server and web.
- Both
server/src/config/plans.jsandweb/src/config/plans.tshave Starter $5, Growth $25, Enterprise $50 and self-hosted -1. - The trial's $1 (
TRIAL_AI_BUDGET_USD) lives only on the server. Enterprise keeps its own budget in a trial (applyTrialAiBudget). - An explicit override reaches every reader on the server.
getImproveQuotaStatus,reserveAiBudget,getAiUsageandgetDraftAiUsageall readplan.limits.improveMonthlyBudgetUsdthroughresolveOrgPlanByOrgIdandapplyPlanOverrides. - The web's
planFromOrgRowmerges the overrides the same way and never had the 1%, so it now agrees with the server. - The web doesn't read an org's budget anyway. The meter shows the API's percent, and the cards and the custom box read the static
PLANS.
- Both
- Who sets it. No code writes
plan_overrides: not the Stripe webhook, and there's no admin screen. The 00062 trigger refuses it from a client. A customer's amount is a JSON key set by hand with the service role. - The custom box.
customPlanPoints()(plan-switcher.tsx:216) puts the AI line first, with the cards' hover text and dotted underline.aiMultiple(:178) is the cards' old sum, so the "10x" followsPLANS.enterprise, and the line is hidden when the budget is unlimited.- The list keys are the texts, which are all different.
- Tests.
- With main's
plan-guard.jsandimprove-cost.jsunder the PR's tests, two fail with "expected 10 to be 4.99": "stays at the plan default whatever the contract is worth" and "leaves the AI budget at the plan default". - With main's
plan-switcher.tsxanden.json, the custom box test fails. - On the head they all pass: on the server,
plan-guard,plan-guard-ai-usage,prompt-improve,relevance-allowanceandimprove-cost; on the web,plan-switcher. CI passes.
- With main's
- Merge.
- Before and after the API deploy.
- On merge, only the custom box on the Billing page changes. No budget moves. The API alone holds and refuses AI calls (
reserve_ai_usage), and the web shows the percent it sends. So the web never blocks anyone ahead of the API, and the old API keeps the 1% until the new one is deployed. - Once the API is deployed, an Enterprise org with a contract above $5,000 a month and no
improveMonthlyBudgetUsddrops to $50 in the middle of its period. If it has already spent $50 this period, its meter reads 100%, and Improve, the Content Editor's AI and agent, task writing and Quality checks are refused until the period renews. - So the check on production in the description is needed before the API deploy. The web merge alone changes no budget.
- On merge, only the custom box on the Billing page changes. No budget moves. The API alone holds and refuses AI calls (
Follow-ups:
- "over 10x" (
web/messages/en.json:7764).- Enterprise's default is $50, exactly 10x Starter's $5, so "over 10x" is wrong for an Enterprise customer on the default. The comments disagree too:
plan-guard.js:41says "over $50", whileplans.js:147andplans.ts:267say "$50 at the least". - "Custom AI usage, from {count}x" fits both cases, and so does "{count}x AI usage or more".
- The hover text's last sentence, "The free trial comes with a smaller allowance", isn't true of Enterprise, whose trial keeps its own budget. Give the box its own hint without that sentence, e.g.
aiUsageCustomHint.
- Enterprise's default is $50, exactly 10x Starter's $5, so "over 10x" is wrong for an Enterprise customer on the default. The comments disagree too:
- Use a hand-set budget only when it's a number (
plan-guard.js:56).- That key is now the only way to give a customer more, and it's typed by hand. The merge takes any value:
- a JSON
nullmakes the budget unlimited (?? -1); - a string such as
"80"works only by coercion; - a typo such as
"80$"makes every AI call fail atreserve_ai_usage.
- a JSON
- If it isn't a finite number, keep the plan's budget:
const own = overrides.improveMonthlyBudgetUsd; if (own !== undefined && !(typeof own === 'number' && Number.isFinite(own))) { limits.improveMonthlyBudgetUsd = plan.limits.improveMonthlyBudgetUsd; }
- Add a test for
nulland for"80".
- That key is now the only way to give a customer more, and it's typed by hand. The merge takes any value:
On prod: no organization has contractMonthlyUsd or improveMonthlyBudgetUsd in its plan_overrides today, so no budget moves at the API deploy.
7 of 12 tasks
gkhngyk
pushed a commit
that referenced
this pull request
Oct 27, 2026
…mber, and word the custom line "from 10x" (#1598) Two follow-ups from #1577. - applyPlanOverrides keeps the plan's AI budget when plan_overrides.improveMonthlyBudgetUsd isn't a finite number. Before, null read as unlimited and "80$" failed every AI call. - The custom plan's line says "Custom AI usage, from {count}x": the default $50 is exactly 10x Starter's, so "over" was wrong. - The line has its own hint, without the free trial's smaller allowance, which isn't Enterprise's. Co-authored-by: Cihan <[email protected]> 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
The user decided on 2026-10-27 that Enterprise's AI budget is over $50, with the amount set by Ansvisor for each customer. The contract's value no longer raises it.
The tiers:
Until now, an Enterprise org with
plan_overrides.contractMonthlyUsdgot 1% of its monthly contract as its AI budget, never below $50. This PR removes that rule.Server:
applyPlanOverrides(plan-guard.js) no longer derivesimproveMonthlyBudgetUsdfromcontractMonthlyUsd.plan_overrides.improveMonthlyBudgetUsdsets a customer's own. That already worked and is unchanged.IMPROVE_BUDGET_SHARE(improve-cost.js) had no other use, so it's removed.server/src/config/plans.js,web/src/config/plans.ts,plan-guard.jsandweb/src/lib/prompt-improve.tssay the new rule. Old migration comments (00120, 00138) are left as they are.Billing (Settings › Billing):
SUBSCRIBABLE_PLANS). Enterprise appears in the Need a custom plan? box, which had no AI usage line.settings.billing.planCards.aiUsageCustom.@gkhngyk, before merging: please check on production whether any Enterprise org's AI budget comes from
contractMonthlyUsd. That would be an org withcontractMonthlyUsdabove $5,000 a month and noimproveMonthlyBudgetUsdinplan_overrides. If there is one, set its amount explicitly inimproveMonthlyBudgetUsdfirst, so nobody's budget drops. We run nothing on production.The user updates www.ansvisor.com/pricing separately.
Related issue
None. User decision (2026-10-27), recorded with the Chat specs in Drive.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/lib/plan-guard.test.js src/lib/plan-guard-ai-usage.test.js:improveMonthlyBudgetUsdstill sets its own.cd web && yarn vitest run src/components/settings/plan-switcher.test.tsx: the custom plan box says "Custom AI usage, over 10x", with the hover text.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
server/:npm run format,npm run lintandnpm test(2,933 tests);web/:yarn format,yarn lint(0 errors),yarn typecheck,yarn test(4,126 tests) andyarn build(with CI's placeholder env).A pre-push review found no other copy of the rule (the web's
getOrgPlanonly reads what's entered; nothing indocs/). Its small points are folded in: two stale comments, and the cards' and the custom box's "Nx" from one helper. Putting the old rule back fails two tests.Checked in the browser at 1024 px, light and dark: Settings › Billing in cloud mode, with this branch's web and the dev DB. The custom plan box lists Custom AI usage, over 10x first, underlined dotted, with the hover text.
🤖 Generated with Claude Code