Skip to content

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Aug 26, 2025

Quick fix for following issue in CLI:

$ go run ./cmd/coder exp task list
Encountered an error running "coder exp task list", see "coder exp task list --help" for more information
error: Trace=[list tasks: ]
Internal error fetching task prompts and states.
workspace 14d548f4-aaad-40dd-833b-6ffe9c9d31bc is not an AI task workspace
exit status 1

This occurs in a short time window directly after creating a new task.

I took a stab at writing a test for this, but ran out of time. I'm not entirely sure what causes non-AI-task workspaces to be returned in the query but I suspect it's when a workspace build is pending or running.

@johnstcn johnstcn self-assigned this Aug 26, 2025
filtered = append(filtered, ws)
}
}
tasks, err := api.tasksFromWorkspaces(ctx, filtered)
Copy link
Member

Choose a reason for hiding this comment

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

I think it’s worth finding a proper fix for this as filtering here breaks pagination.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we could always add the filter has-ai-task:true?

Copy link
Member

Choose a reason for hiding this comment

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

We already do that 🤔

@DanielleMaywood
Copy link
Contributor

I suspect this is the root cause

If the build has no AI task, it means that the provisioner job is in progress
and we don't know if it has an AI task yet. In this case, we optimistically
assume that it has an AI task if the AI Prompt parameter is not empty.
lets the AI Task frontend spawn a task and see it immediately after instead of
having to wait for the build to complete.

https://github.com/coder/coder/blob/8083d9d5c87fbb7d7d8f018706a8d0769480378a/coderd/database/queries/workspaces.sql#L357C1-L372C46

So we're potentially returning workspaces that do not yet have has_ai_task set

@mafredri
Copy link
Member

I suspect this is the root cause

If the build has no AI task, it means that the provisioner job is in progress
and we don't know if it has an AI task yet. In this case, we optimistically
assume that it has an AI task if the AI Prompt parameter is not empty.
lets the AI Task frontend spawn a task and see it immediately after instead of
having to wait for the build to complete.

8083d9d/coderd/database/queries/workspaces.sql#L357C1-L372C46

So we're potentially returning workspaces that do not yet have has_ai_task set

@DanielleMaywood that does indeed look like it would be the culprit. We definitely need to improve how tasks are detected so there can't be any flip-flopping between states.

@johnstcn
Copy link
Member Author

We definitely need to improve how tasks are detected so there can't be any flip-flopping between states.

Honestly I think the 'correct' fix here is to have tasks defined separately to workspaces.

@mafredri
Copy link
Member

Honestly I think the 'correct' fix here is to have tasks defined separately to workspaces.

I definitely agree. I don't think that excludes an interim fix, though. For now we could relax the "ai task" constraint to match that of the query.

I.e. in tasksFromWorkspaces remove:

	for _, ws := range apiWorkspaces {
		if ws.LatestBuild.HasAITask == nil || !*ws.LatestBuild.HasAITask {
			return nil, xerrors.Errorf("workspace %s is not an AI task workspace", ws.ID)
		}
	}

@johnstcn johnstcn force-pushed the cj/exp-task-list-filter branch from 83eb368 to 81fb1d5 Compare August 27, 2025 11:16
@johnstcn
Copy link
Member Author

Honestly I think the 'correct' fix here is to have tasks defined separately to workspaces.

I definitely agree. I don't think that excludes an interim fix, though. For now we could relax the "ai task" constraint to match that of the query.

I.e. in tasksFromWorkspaces remove:

	for _, ws := range apiWorkspaces {
		if ws.LatestBuild.HasAITask == nil || !*ws.LatestBuild.HasAITask {
			return nil, xerrors.Errorf("workspace %s is not an AI task workspace", ws.ID)
		}
	}

Sounds good to me, it appears to work locally also:

cdr-mbp-jmqxfj0746:coder cian$ ./scripts/coder-dev.sh exp tasks create --input hello tasks && ./scripts/coder-dev.sh exp tasks list
The task task-crazy-williamson-34b8 has been created at Aug 27 12:19:37!
ID                                    NAME                        STATUS    STATE  STATE CHANGED  MESSAGE
5bdfa8ee-55fd-4d9c-bd63-212176d6a5b3  task-crazy-williamson-34b8  starting  <nil>                 <nil>
69a7e749-37ea-48c7-88a4-6ed78e737459  task-youthful-pare-6c73     running   <nil>                 <nil>

@johnstcn johnstcn merged commit dbc6c98 into main Aug 27, 2025
31 checks passed
@johnstcn johnstcn deleted the cj/exp-task-list-filter branch August 27, 2025 14:32
@github-actions github-actions bot locked and limited conversation to collaborators Aug 27, 2025
@johnstcn johnstcn added the cherry-pick/v2.26 Needs to be cherry-picked to the 2.26 release branch label Aug 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cherry-pick/v2.26 Needs to be cherry-picked to the 2.26 release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants