feat: remove native chat usage limits in favor of AI Gateway budgets by ibetitsmike · Pull Request #27329 · coder/coder · GitHub
Skip to content

feat: remove native chat usage limits in favor of AI Gateway budgets - #27329

Merged
ibetitsmike merged 8 commits into
mainfrom
mike/chat-cost/remove-usage-limits
Aug 4, 2026
Merged

feat: remove native chat usage limits in favor of AI Gateway budgets#27329
ibetitsmike merged 8 commits into
mainfrom
mike/chat-cost/remove-usage-limits

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Stack Context

This stack makes AI Gateway data and budgets the source of truth for AI spend controls.

  1. Re-back the per-chat cost endpoint with AI Gateway data (feat: back the per-chat cost endpoint with AI Gateway data #27328, merged).
  2. This PR: remove native chat usage limits.
  3. Remove native chat cost tracking and its dedicated admin UI (feat: remove native chat cost tracking in favor of AI Gateway cost data #27330).

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.

Mux prepared this PR on Mike's behalf.

@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread coderd/database/migrations/000556_drop_chat_usage_limits.up.sql Outdated
Comment thread site/src/pages/AISettingsPage/SpendPage/SpendPageView.tsx
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review


P2 Badge Gate Spend queries on cost-control availability

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".

Comment thread site/src/pages/AgentsPage/components/UsageIndicator.tsx Outdated
@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-usage-limits branch from 06b6764 to 6620edc Compare July 18, 2026 23:23
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread site/src/pages/AgentsPage/components/UsageIndicator.tsx Outdated
Comment thread coderd/database/migrations/000556_drop_chat_usage_limits.up.sql Outdated
@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-usage-limits branch from 6620edc to 5f65130 Compare July 18, 2026 23:38
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread coderd/database/migrations/000556_drop_chat_usage_limits.up.sql Outdated
@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-usage-limits branch from 5f65130 to e583a77 Compare July 18, 2026 23:55
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-usage-limits branch from 3c0d3de to 6ee9b84 Compare July 19, 2026 00:07
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread coderd/database/migrations/000556_drop_chat_usage_limits.up.sql Outdated
Comment thread site/src/pages/AISettingsPage/SpendPage/SpendPage.tsx
Comment thread site/src/pages/AgentsPage/components/UsageIndicator.stories.tsx
@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-usage-limits branch from 6ee9b84 to 92f968a Compare July 19, 2026 00:22
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread coderd/coderd.go
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

2 similar comments
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-usage-limits branch from 1c3875d to 8b533ce Compare July 19, 2026 00:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread site/src/pages/AISettingsPage/SpendPage/SpendPage.tsx Outdated
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread site/src/pages/AISettingsPage/SpendPage/SpendPage.tsx Outdated
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-usage-limits branch from 680697b to 6b52f14 Compare July 29, 2026 17:36
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Force-pushed after rebasing the stack onto main. New head: 6b52f14803e.

Upstream #27579 removed the ai-gateway-cost-control experiment, which this stack still gated on. Git merged cleanly but the result did not compile, so CI on #27328 failed lint, check-build, test-e2e, and Storybook with Type '"ai-gateway-cost-control"' is not assignable to type 'Experiment'. The descendant PRs passed only because their bases are stack branches rather than main.

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 providerErrorResponseMessage from upstream #27597; the usage-limit admission checks #27429 added under the transaction lock were removed with checkUsageLimit; UsageIndicator and UserDropdown adapted to the effective_budget shape from #27611; and the Spend page is documented as a live surface here (the "no dashboard" claim moved to #27330).

Validated per branch: go build ./..., go vet ./... (no new findings), pnpm run lint:types, make lint, make gen clean, TestGetChatCost, and the affected Storybook and unit tests. Earlier review approvals were given on the pre-rebase heads.

Mux is acting on Mike's behalf.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Mux is acting on Mike's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 6b52f14803

ℹ️ 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".

@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-usage-limits branch 4 times, most recently from 26926a7 to ed20f70 Compare July 30, 2026 10:14
Base automatically changed from mike/chat-cost/gateway-cost-api to main July 30, 2026 11:01
@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-usage-limits branch 3 times, most recently from 11a5a39 to 2f7337a Compare July 31, 2026 22:03

@nickvigilante nickvigilante 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.

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.

Comment thread docs/ai-coder/agents/platform-controls/usage-insights.md Outdated
Comment thread docs/ai-coder/agents/platform-controls/usage-insights.md Outdated
Comment thread docs/ai-coder/agents/platform-controls/usage-insights.md Outdated
Comment thread docs/ai-coder/agents/platform-controls/usage-insights.md Outdated
Comment thread docs/ai-coder/agents/platform-controls/usage-insights.md Outdated
Comment thread docs/manifest.json Outdated
Comment thread docs/ai-coder/agents/platform-controls/advisor.md Outdated
Comment thread docs/ai-coder/agents/platform-controls/index.md Outdated
Comment thread docs/ai-coder/agents/platform-controls/index.md Outdated
Comment thread docs/ai-coder/agents/platform-controls/index.md Outdated
Comment thread enterprise/audit/table.go Outdated
Comment thread enterprise/audit/table.go Outdated
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.
@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-usage-limits branch from a676bbe to 1346e13 Compare August 4, 2026 09:00
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Mux requested this review on Mike's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

@ibetitsmike
ibetitsmike merged commit f0e6ac6 into main Aug 4, 2026
33 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chat-cost/remove-usage-limits branch August 4, 2026 09:36
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release/breaking This label is applied to PRs to detect breaking changes as part of the release process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants