Skip to content

fix(coderd/provisionerdserver): correct managed agent tracking#21696

Merged
johnstcn merged 4 commits intomainfrom
fix-aitask-usage-tracking
Jan 27, 2026
Merged

fix(coderd/provisionerdserver): correct managed agent tracking#21696
johnstcn merged 4 commits intomainfrom
fix-aitask-usage-tracking

Conversation

@johnstcn
Copy link
Member

@johnstcn johnstcn commented Jan 27, 2026

Relates to coder/internal#1282

Updates tracking of managed agents to be predicated instead on the presence of a related task_id instead of the presence of a coder_ai_task resource.

@johnstcn johnstcn self-assigned this Jan 27, 2026
return nil
}

func seedPreviousWorkspaceStartWithAITask(ctx context.Context, t testing.TB, db database.Store) error {
Copy link
Member Author

Choose a reason for hiding this comment

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

review: unused now

Comment on lines -3007 to -3019
{
name: "current build does not have ai task but previous build did",
seedFunc: seedPreviousWorkspaceStartWithAITask,
transition: database.WorkspaceTransitionStop,
input: &proto.CompletedJob_WorkspaceBuild{
AiTasks: []*sdkproto.AITask{},
Resources: []*sdkproto.Resource{},
},
isTask: true,
expectTaskStatus: database.TaskStatusPaused,
expectHasAiTask: false, // We no longer inherit this from the previous build.
expectUsageEvent: false,
},
Copy link
Member Author

Choose a reason for hiding this comment

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

review: this test case is no longer valid

Stage: []string{"Cleaning Up", "Cleaning Up", "Cleaning Up", "Cleaning Up"},
Output: []string{
fmt.Sprintf("Unknown ai_task_app_id %q. This workspace will be unable to run AI tasks. This may be due to a template configuration issue, please check with the template author.", taskAppID.UUID.String()),
fmt.Sprintf("Unknown ai_task_app_id %q. This workspace will be unable to run AI tasks. This may be due to a template configuration issue, please check with the template author.", unknownAppID),
Copy link
Member Author

Choose a reason for hiding this comment

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

review: drive-by fix to avoid getting a uuid.Nil in the log which isn't really useful here

@github-actions
Copy link

github-actions bot commented Jan 27, 2026

Copy link
Member

@deansheather deansheather left a comment

Choose a reason for hiding this comment

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

The usage code looks correct, I don't know enough about tasks to comment on the other changes, though.

@coder-tasks
Copy link
Contributor

coder-tasks bot commented Jan 27, 2026

Documentation Check

No Changes Needed

This PR corrects internal tracking logic for managed agents in the provisioner server. The change affects how has_ai_task is determined (now based on the presence of a task_id rather than a coder_ai_task resource), but this is an internal implementation detail.

Reasoning:

  • The has_ai_task field is already documented as deprecated in API docs ("Deprecated: This field has been deprecated in favor of Task WorkspaceID")
  • User-facing documentation in docs/ai-coder/tasks.md focuses on the coder_ai_task resource for template configuration, which remains unchanged
  • The managed agent limit feature is an internal billing/licensing concern, not user-facing functionality
  • Test changes demonstrate the new behavior but don't expose new user-facing features

Automated review via Coder Tasks

Comment on lines +3002 to +3005
// You can still "sort of" use a task in this state, but as we don't have
// the correct app ID you won't be able to communicate with it via Coder.
expectHasAiTask: true,
expectUsageEvent: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

review: We decided to count "misconfigured but otherwise working".

@johnstcn johnstcn merged commit 7b44976 into main Jan 27, 2026
31 checks passed
@johnstcn johnstcn deleted the fix-aitask-usage-tracking branch January 27, 2026 12:14
@github-actions github-actions bot locked and limited conversation to collaborators Jan 27, 2026
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.

3 participants