Skip to content

fix(billing): stop raising Enterprise's AI budget to 1% of its contract - #1577

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/enterprise-ai-budget
Oct 27, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/enterprise-ai-budget

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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:

  • Starter: $5.
  • Growth: $25.
  • Enterprise (custom): $50 by default, or the customer's own amount, set by Ansvisor.
  • The free trial: $1.

Until now, an Enterprise org with plan_overrides.contractMonthlyUsd got 1% of its monthly contract as its AI budget, never below $50. This PR removes that rule.

Server:

  • applyPlanOverrides (plan-guard.js) no longer derives improveMonthlyBudgetUsd from contractMonthlyUsd.
    • The plan's $50 stays the default.
    • Only an explicit plan_overrides.improveMonthlyBudgetUsd sets a customer's own. That already worked and is unchanged.
  • IMPROVE_BUDGET_SHARE (improve-cost.js) had no other use, so it's removed.
  • The relevance allowance's 0.1% of the contract (VIS-011) is an internal budget and is untouched.
  • Comments in server/src/config/plans.js, web/src/config/plans.ts, plan-guard.js and web/src/lib/prompt-improve.ts say the new rule. Old migration comments (00120, 00138) are left as they are.

Billing (Settings › Billing):

  • The plan cards show only Starter and Growth (SUBSCRIBABLE_PLANS). Enterprise appears in the Need a custom plan? box, which had no AI usage line.
  • That box now starts with Custom AI usage, over 10x, with the same hover text as the plan cards' AI usage line.
    • The new key is settings.billing.planCards.aiUsageCustom.
    • The "10x" is computed from the budgets (Enterprise's $50 over Starter's $5), as the cards' "Nx" is.

@gkhngyk, before merging: please check on production whether any Enterprise org's AI budget comes from contractMonthlyUsd. That would be an org with contractMonthlyUsd above $5,000 a month and no improveMonthlyBudgetUsd in plan_overrides. If there is one, set its amount explicitly in improveMonthlyBudgetUsd first, 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 feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd server && npx vitest run src/lib/plan-guard.test.js src/lib/plan-guard-ai-usage.test.js:
    • An Enterprise org with a $100,000 contract keeps the $50 default (4.99 in the test's fixture).
    • An explicit improveMonthlyBudgetUsd still sets its own.
    • The relevance allowance still follows 0.1% of the contract.
  2. 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.
  3. In the app, as an admin, open Settings › Billing. The Need a custom plan? box lists Custom AI usage, over 10x first.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • server/: npm run format, npm run lint and npm test (2,933 tests);
  • web/: yarn format, yarn lint (0 errors), yarn typecheck, yarn test (4,126 tests) and yarn build (with CI's placeholder env).

A pre-push review found no other copy of the rule (the web's getOrgPlan only reads what's entered; nothing in docs/). 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

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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 sets improveMonthlyBudgetUsd from contractMonthlyUsd.
    • { ...plan.limits, ...overrides } still lets an explicit plan_overrides.improveMonthlyBudgetUsd win, and the relevance allowance keeps its 0.1% of the contract.
    • IMPROVE_BUDGET_SHARE had no other reader.
    • Nothing left in server/, web/, docs/ or web/messages computes or states 1% of the contract. The only mentions are the 00120 and 00138 migration comments, and their copies in schema.sql.
  • Every plan, server and web.
    • Both server/src/config/plans.js and web/src/config/plans.ts have 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, getAiUsage and getDraftAiUsage all read plan.limits.improveMonthlyBudgetUsd through resolveOrgPlanByOrgId and applyPlanOverrides.
    • The web's planFromOrgRow merges 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.
  • 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" follows PLANS.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.js and improve-cost.js under 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.tsx and en.json, the custom box test fails.
    • On the head they all pass: on the server, plan-guard, plan-guard-ai-usage, prompt-improve, relevance-allowance and improve-cost; on the web, plan-switcher. CI passes.
  • 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 improveMonthlyBudgetUsd drops 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.

Follow-ups:

  1. "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:41 says "over $50", while plans.js:147 and plans.ts:267 say "$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.
  2. 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 null makes the budget unlimited (?? -1);
      • a string such as "80" works only by coercion;
      • a typo such as "80$" makes every AI call fail at reserve_ai_usage.
    • 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 null and for "80".

On prod: no organization has contractMonthlyUsd or improveMonthlyBudgetUsd in its plan_overrides today, so no budget moves at the API deploy.

@gkhngyk
gkhngyk merged commit 36e5cef into ansvisor:main Oct 27, 2026
6 checks passed
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]>
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.

2 participants