Skip to content

feat: add coderd_ai_user_budget_override resource - #454

Open
ssncferreira wants to merge 1 commit into
ssncf/ai-group-budgetfrom
ssncf/ai-user-budget-override
Open

ssncferreira wants to merge 1 commit into
ssncf/ai-group-budgetfrom
ssncf/ai-user-budget-override

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Oct 12, 2026 •

Copy link
Copy Markdown

Description

Adds the coderd_ai_user_budget_override resource, which manages an AI spend limit for a single user and the group their spend is attributed to (/api/v2/users/{user}/ai/budget/override). Stacked on #453.

Changes

  • Add coderd_ai_user_budget_override with user_id, group_id, and spend_limit, registered under the "AI Governance" docs subcategory.
  • Reuse the spend_limit validators and conventions from coderd_ai_group_budget, and link the two resources in the docs.
  • Import by user ID or username, like coderd_user.
  • Add an example, import docs, mock-server plan tests, and an acceptance test.

Closes AIGOV-682

Note

Generated by Coder Agents on behalf of @ssncferreira.

@linear-code

linear-code Bot commented Oct 12, 2026

Copy link
Copy Markdown

AIGOV-682

@ssncferreira
ssncferreira force-pushed the ssncf/ai-user-budget-override branch 2 times, most recently from 4a53442 to e557846 Compare October 15, 2026 16:23
@ssncferreira
ssncferreira force-pushed the ssncf/ai-user-budget-override branch from e557846 to ed6f583 Compare October 15, 2026 16:26
@ssncferreira
ssncferreira force-pushed the ssncf/ai-user-budget-override branch from ed6f583 to 439b34c Compare October 15, 2026 16:27
@ssncferreira
ssncferreira force-pushed the ssncf/ai-user-budget-override branch from 439b34c to 2751b02 Compare October 15, 2026 16:43
@ssncferreira
ssncferreira force-pushed the ssncf/ai-user-budget-override branch from 2751b02 to 65dbcd2 Compare October 15, 2026 16:49
@ssncferreira
ssncferreira marked this pull request as ready for review October 15, 2026 16:52
@ssncferreira
ssncferreira requested a review from SasSwart October 15, 2026 16:52
Comment on lines +1 to +4
resource "coderd_user" "alice" {
username = "alice"
email = "alice@example.com"
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we update integration/agents-model-test to cover this resource and coderd_ai_group_budget, like #445 and #448 did for the other AI resources? Something like:

  • create a user, add it to the existing agents-users group, and give the group a coderd_ai_group_budget and the user a coderd_ai_user_budget_override, all in the same apply
  • assert that UserAISpendStatus for that user returns the override's limit with limit_source set to user_override

The acceptance tests for both resources create the users and groups through the SDK, so nothing applies this example shape end to end or checks that Coder enforces the override over the group budget.

Generated by an agent on behalf of the user

Comment on lines +44 to +54
// aiUserBudgetOverrideDiag converts an error from the user AI budget override
// API into a diagnostic. The upsert call returns 404 only when the group does
// not exist, or when the deployment has no user AI budget override API.
func aiUserBudgetOverrideDiag(action string, userID uuid.UUID, err error) diag.Diagnostics {
var diags diag.Diagnostics
if isHTTPNotFound(err) {
diags.AddError("Group Not Found or Unsupported Coder Version", fmt.Sprintf(
"Unable to %s AI budget override for user %s: the deployment returned 404 for /api/v2/users/%s/ai/budget/override. "+
"Either the group does not exist, or the deployment is older than Coder version %s, which this resource requires. "+
"Original error: %s",
action, userID, userID, aiUserBudgetOverrideMinVersion, err))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A 404 here doesn't only mean a missing group or an old Coder. Coder also returns 404 when the user_id doesn't exist, or when the token can't update the user or the group: UpsertUserAIBudgetOverride checks update on both, and the handler maps the denial to 404 through httpapi.Is404Error.

An Organization Admin or Organization User Admin token hits this. Those roles can read users site-wide but can't update them, so the plan-time conflict check passes, then the apply fails with "Group Not Found or Unsupported Coder Version" while the group exists and Coder is new enough. #453 documents those roles as enough for coderd_ai_group_budget, so the same token can apply the group budget and then hit this.

Could the comment and the message cover the missing user and missing permission cases too, similar to the 404 message in agentsSystemPromptDiag?

Generated by an agent on behalf of the user

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