Skip to content

feat: add managed agent license limit checks #18937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 22, 2025

Conversation

deansheather
Copy link
Member

  • Adds a query for counting managed agent workspace builds between two timestamps
  • The "Actual" field in the feature entitlement for managed agents is now populated with the value read from the database
  • The wsbuilder package now validates AI agent usage against the limit when a license is installed

Most of the code is new tests and updating old ones.

Closes coder/internal#777

- Adds a query for counting managed agent workspace builds between two
  timestamps
- The "Actual" field in the feature entitlement for managed agents is
  now populated with the value read from the database
- The wsbuilder package now validates AI agent usage against the limit
  when a license is installed
@deansheather deansheather changed the title feat: managed agent license limit checks feat: add managed agent license limit checks Jul 21, 2025
Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

LGTM, couple minor points; I don't need to re-review.

@@ -279,7 +281,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
}

if nextTransition != "" {
builder := wsbuilder.New(ws, nextTransition).
builder := wsbuilder.New(ws, nextTransition, *e.buildUsageChecker.Load()).
Copy link
Contributor

Choose a reason for hiding this comment

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

This could panic; can you add some protection for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

The atomic pointer is preloaded with a value before the AGPL API gets constructed, so there's no opportunity for it to be misused or ever hold nil. We also have many other atomic pointers that get dereferenced like this, such as *api.Auditor.Load() which is used in every auditable API endpoint.

@@ -335,7 +335,7 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
return
}

builder := wsbuilder.New(workspace, database.WorkspaceTransition(createBuild.Transition)).
builder := wsbuilder.New(workspace, database.WorkspaceTransition(createBuild.Transition), *api.BuildUsageChecker.Load()).
Copy link
Contributor

Choose a reason for hiding this comment

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

Can panic

This comment was marked as spam.

@deansheather deansheather merged commit 9a6dd73 into main Jul 22, 2025
31 checks passed
@deansheather deansheather deleted the dean/ai-usage-enforcement-2 branch July 22, 2025 03:39
@github-actions github-actions bot locked and limited conversation to collaborators Jul 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Count managed agent usage and enforce limits in wsbuilder
2 participants