Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

refactor: use AI budget period from deployment config - #27117

#27117
Merged
ssncferreira merged 1 commit into
maincoder/coder:mainfrom
ssncf/aibridge-budget-periodcoder/coder:ssncf/aibridge-budget-periodCopy head branch name to clipboard
Jul 13, 2026
Merged

refactor: use AI budget period from deployment config#27117
ssncferreira merged 1 commit into
maincoder/coder:mainfrom
ssncf/aibridge-budget-periodcoder/coder:ssncf/aibridge-budget-periodCopy head branch name to clipboard

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

Read the AI budget period from the deployment config on both the RPC server and the /users/{user}/ai/spend endpoint, instead of hardcoding month. Drops the period_start RPC parameter that was incorrectly introduced in #26915: the period should have been derived from the deployment config from the start.

Changes

  • Add codersdk.NewAIBudgetPeriodFromString, mirroring NewAIBudgetPolicyFromString.
  • aibridgedserver.Server takes a quartz.Clock, reads BudgetPeriod from the deployment config at construction, and computes the period window inside IsBudgetExceeded.
  • Remove period_start from IsBudgetExceededRequest and stop sending it from the daemon.
  • The userAISpendStatus endpoint reads the period from AIBridgeConfig.BudgetPeriod instead of hardcoding month.

Note

Initially generated by Claude Opus 4.7, modified and reviewed by @ssncferreira

ssncferreira commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@ssncferreira
ssncferreira force-pushed the ssncf/aibridge-budget-period branch 3 times, most recently from 28e3a8d to db14366 Compare July 9, 2026 08:39
@ssncferreira
ssncferreira force-pushed the ssncf/aibridge-budget-period branch from db14366 to a06d471 Compare July 13, 2026 12:05
message IsBudgetExceededRequest {
string user_id = 1; // UUID
// The spend aggregation window is [period_start, now].
google.protobuf.Timestamp period_start = 2;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This parameter was incorrectly introduced in #26915: the period should have been derived from the deployment config from the beginning. Since this change was not part of any release, my understanding is that we can safely remove the field without marking it as deprecated. This would only be a problem if we had a server and a client running with different proto versions: an old server that still requires period_start receiving a request from a new client (which no longer sends it) would reject the request. Let me know if that is not the case.

@ssncferreira
ssncferreira force-pushed the ssncf/aibridge-budget-period branch from a06d471 to a35ad30 Compare July 13, 2026 12:21
@ssncferreira
ssncferreira marked this pull request as ready for review July 13, 2026 12:22
Comment thread codersdk/deployment.go
if slices.Contains(AIBudgetPeriods, s) {
return AIBudgetPeriod(s)
}
return AIBudgetPeriodMonth

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.

Shouldn't we error when an unrecognised period is defined? It'd be unfortunate if an operator mispelled daily as daly but silently got monthly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is handled by serpent.EnumOf at config load time:

Value: serpent.EnumOf(&c.AI.BridgeConfig.BudgetPeriod, AIBudgetPeriods...),

Any typo in the CLI, env var, or YAML is rejected before this function runs. This matches other usages of Enum in configuration values.

clock quartz.Clock
}

func NewServer(lifecycleCtx context.Context, store store, ps pubsub.Pubsub, logger slog.Logger, accessURL string,

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.

Nit: the number of args is starting to get unwieldy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point 👍 This is a bigger change and touches a lot of files, including tests, so will address this in a follow-up PR.

@ssncferreira
ssncferreira merged commit 6580cdc into main Jul 13, 2026
34 of 35 checks passed
@ssncferreira
ssncferreira deleted the ssncf/aibridge-budget-period branch July 13, 2026 16:52
ssncferreira added a commit that referenced this pull request Jul 16, 2026
Refactor `aibridgedserver.NewServer` to take an `Options` struct instead
of a long list of positional arguments. Follow-up to review feedback in
#27117 (comment)
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.