fix: ai cost control cap configurable AI spend limit (#27640)

## Problem

A configured AI spend limit was only validated as `gte=0`, with no upper
bound. The group spend query multiplies the per-member limit by the
number of attributed members, so a large enough limit overflows `bigint`
and fails the whole query, returning an error for every group in the
request rather than just the misconfigured one.

## Changes

- Add `MaxAISpendLimitMicros`, $1,000,000 per member per budget period.
- Reject group budgets and per-user overrides above the maximum with a
400 naming the limit.
- Bound both budget forms in the UI so they show the valid range before
submitting.

Follow-up
https://github.com/coder/coder/pull/27589#discussion_r3668956350
Depends on https://github.com/coder/coder/pull/27589

> [!NOTE]
> Initially generated by Claude Opus 5, modified and reviewed by
@ssncferreira
This commit is contained in:
Susana Ferreira
2026-07-29 14:00:13 +01:00
committed by GitHub
parent 4987afada7
commit e71249a821
12 changed files with 218 additions and 30 deletions
+2
View File
@@ -26320,6 +26320,7 @@ const docTemplate = `{
"type": "object",
"properties": {
"spend_limit_micros": {
"description": "SpendLimitMicros must not exceed MaxAISpendLimitMicros.",
"type": "integer",
"minimum": 0
}
@@ -26337,6 +26338,7 @@ const docTemplate = `{
"format": "uuid"
},
"spend_limit_micros": {
"description": "SpendLimitMicros must not exceed MaxAISpendLimitMicros.",
"type": "integer",
"minimum": 0
}
+2
View File
@@ -24200,6 +24200,7 @@
"type": "object",
"properties": {
"spend_limit_micros": {
"description": "SpendLimitMicros must not exceed MaxAISpendLimitMicros.",
"type": "integer",
"minimum": 0
}
@@ -24215,6 +24216,7 @@
"format": "uuid"
},
"spend_limit_micros": {
"description": "SpendLimitMicros must not exceed MaxAISpendLimitMicros.",
"type": "integer",
"minimum": 0
}