mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: restore block to Managed Agents on Enterprise (#22210)
#21998 accidentally allowed `Managed Agents` usages whilst being on an `Enterprise` license. This was incorrect, it should work as the following (same as prior to #21998). | Scenario | Before your PRs | After your PRs (bug) | After this fix | |---|---|---|---| | Unlicensed (AGPL) | Permitted | Permitted | Permitted | | Licensed, no entitlement | **Blocked** | Permitted | **Blocked** | | Licensed, explicitly disabled (limit=0) | **Blocked** | Permitted | **Blocked** | | Licensed, entitled, under limit | Permitted | Permitted | Permitted | | Licensed, entitled, over limit | Blocked | Permitted (advisory) | Permitted (advisory) | | Any license, stop/delete | Permitted | Permitted | Permitted | | Any license, non-AI build | Permitted | Permitted | Permitted |
This commit is contained in:
@@ -987,8 +987,8 @@ func (api *API) CheckBuildUsage(
|
||||
_ context.Context,
|
||||
_ database.Store,
|
||||
templateVersion *database.TemplateVersion,
|
||||
_ *database.Task,
|
||||
_ database.WorkspaceTransition,
|
||||
task *database.Task,
|
||||
transition database.WorkspaceTransition,
|
||||
) (wsbuilder.UsageCheckResponse, error) {
|
||||
// If the template version has an external agent, we need to check that the
|
||||
// license is entitled to this feature.
|
||||
@@ -1002,6 +1002,25 @@ func (api *API) CheckBuildUsage(
|
||||
}
|
||||
}
|
||||
|
||||
// Verify managed agent entitlement for AI task builds.
|
||||
// The count/limit check is intentionally omitted — breaching the
|
||||
// limit is advisory only and surfaced as a warning via entitlements.
|
||||
if transition != database.WorkspaceTransitionStart || task == nil {
|
||||
return wsbuilder.UsageCheckResponse{Permitted: true}, nil
|
||||
}
|
||||
|
||||
if !api.Entitlements.HasLicense() {
|
||||
return wsbuilder.UsageCheckResponse{Permitted: true}, nil
|
||||
}
|
||||
|
||||
managedAgentLimit, ok := api.Entitlements.Feature(codersdk.FeatureManagedAgentLimit)
|
||||
if !ok || !managedAgentLimit.Enabled {
|
||||
return wsbuilder.UsageCheckResponse{
|
||||
Permitted: false,
|
||||
Message: "Your license is not entitled to managed agents. Please contact sales to continue using managed agents.",
|
||||
}, nil
|
||||
}
|
||||
|
||||
return wsbuilder.UsageCheckResponse{Permitted: true}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user