feat: remove native chat usage limits in favor of AI Gateway budgets - #27329
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06b67640e7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
When AI Governance is licensed but the ai-gateway-cost-control experiment is not enabled, enabled: isEntitled still fetches the AI Gateway cost endpoints even though the backend routes are also guarded by RequireExperiment in enterprise/coderd/coderd.go lines 319 and 662. In that deployment context the Spend page renders the usage UI with failing queries instead of hiding/paywalling the cost-control surface, so this should use the same feature-visibility plus experiment gate used by the group budget and navbar code.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
06b6764 to
6620edc
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6620edc8fe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
6620edc to
5f65130
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5f65130fd6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
5f65130 to
e583a77
Compare
|
@codex review |
1 similar comment
|
@codex review |
3c0d3de to
6ee9b84
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ee9b848d3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
6ee9b84 to
92f968a
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 759b726660
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
1c3875d to
8b533ce
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c3875d4fc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3ca60f837c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
680697b to
6b52f14
Compare
|
Force-pushed after rebasing the stack onto Upstream #27579 removed the Changes here: remaining experiment gates dropped; docs rewritten to describe entitlement-only gating; the plain-text budget-error extraction this PR added now defers to Validated per branch:
|
|
@codex review
|
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
26926a7 to
ed20f70
Compare
11a5a39 to
2f7337a
Compare
nickvigilante
left a comment
There was a problem hiding this comment.
A few changes, but otherwise looks solid! The biggest thing I'm concerned about is the lack of docs on /api/v2/groups/{group}/ai/budget.
Chats enforced their own spend limits (a deployment-wide chat_usage_limit_config plus per-user and per-group overrides) alongside AI Gateway budgets, so two independent limits governed the same spend. Remove the native implementation and leave AI Gateway budgets as the only enforcement path. Backend: delete the usage-limit endpoints, codersdk types, chatd enforcement, and SQL. No schema is dropped here. A replica on the previous release still serves the usage-limit status handler, which reads chat_usage_limit_config and runs the spend query behind idx_chat_messages_owner_spend, so removing either during a mixed-version rolling upgrade would make that handler fail or scan chat_messages unindexed. users.chat_spend_limit_micros and groups.chat_spend_limit_micros stay for the same reason, with the added constraint that sqlc bakes them into the generated column lists for the SELECT * user and group queries, so an old replica would fail broad authorization and audit reads. Their audit table entries stay too. The whole contract phase is tracked in #27600. ChatErrorKindUsageLimit survives, since provider quota errors and gateway budget 403s both classify to it. Two gaps in that path are fixed here: the gateway's plain-text budget 403 body is now read when the SDK message reduces to a bare status line, and a budget rejection during synchronous title generation returns 409 rather than 500. Frontend: the sidebar usage indicator now reports AI Gateway spend against budget, gated on a licensed gateway. The Spend page loses its limits editor, since gateway budgets are managed under /ai/budget. Period labels are derived from period_start and period_end through one shared helper, replacing the dropdown's hardcoded month label. Docs record that the replacement requires the ai-gateway-cost-control experiment and an AI Gateway license, resets monthly, and has no deployment-wide budget amount.
…nd spend surfaces The replacement docs claimed budgets always require the cost-control experiment and described a deployment-wide spend dashboard that this stack removes. Correct both: the experiment gates the UI controls and the spend status endpoints, while group budget CRUD needs only the AI Gateway entitlement, and gateway enforcement is unaffected by the experiment. Document the supported --ai-budget-policy and --ai-budget-period values, state that native limit values are not migrated, and describe the spend surfaces that actually ship: the Agents usage indicator, the user menu, group settings, and the per-chat cost row. Drop the experiment-gate TODOs and the stale LiveStreamTail docblock that referenced the removed 'View usage' CTA.
The ai-gateway-cost-control experiment was removed upstream, so drop the remaining gates and document entitlement gating instead. Provider plain-text error extraction now lives in providerErrorResponseMessage, and the usage-limit admission checks added for lifecycle hooks go with the removed checkUsageLimit.
a676bbe to
1346e13
Compare
|
@codex review
|

Stack Context
This stack makes AI Gateway data and budgets the source of truth for AI spend controls.
Summary
Removes the native usage-limit API, SDK types, SQL, and chat enforcement for deployment, user, and group chat limits. Compact AI Gateway budget indicators remain in the Agents sidebar, user menu, and group settings. Gateway budget rejections and provider quota failures continue to classify as usage-limit errors, including a 409 response for synchronous title generation.
Budget-period labels now use the API's UTC boundaries, so users see the same dates in every browser timezone. The documentation explains the AI Gateway replacement, its licensing requirements, and the differences from native limits.
No schema is dropped in this release. The usage-limit table, index, user and group columns, constraints, audit mappings, and generated scan fields remain for mixed-version rolling upgrades. #27600 tracks their removal after the compatibility window.
Breaking change
Native day, week, and month chat spend limits are removed and are not migrated. AI Gateway budgets are month-based, group-scoped with per-user overrides, and require the AI Gateway entitlement. Deployments without that entitlement no longer have chat spend enforcement.