Skip to content

chore(coderd/provisionerdserver): avoid fk error on invalid ai_task_sidebar_app_id #19253

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 5 commits into from
Aug 8, 2025

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Aug 8, 2025

This is a workaround for #18776

We avoid the foreign key issue by checking the previously inserted workspace applications before calling UpdateWorkspaceAITask. Now, affected workspaces will show as "not running an AI task" on the single task view, which is technically correct.

We also insert a provisioner job log at WARN level to ensure that the user sees some information that they have run into this issue, as well as logging on the server side.

Longer term, we plan to modify how the workspace tasks view is presented. This is a stopgap measure until we solidify that plan.

NOTE: this does not address the fact that stopping a workspace with has_ai_task: true will result in the completed stop build no longer having has_ai_task: true, resulting in tasks "disappearing" on stop.

@johnstcn johnstcn self-assigned this Aug 8, 2025
@johnstcn johnstcn marked this pull request as ready for review August 8, 2025 12:20
Level: []database.LogLevel{database.LogLevelWarn},
Stage: []string{"Cleaning Up"},
Output: []string{
fmt.Sprintf("Unknown ai_task_sidebar_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.", sidebarAppID.UUID.String()),
Copy link
Member

@mafredri mafredri Aug 8, 2025

Choose a reason for hiding this comment

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

Linking to some docs could be beneficial if this is the template author viewing the message. I.e. how will the author know how to resolve this/why it happened?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point. Which documentation should we link to?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, it looks like we don't really have any related docs yet. Perhaps we could give a hint as to what the most common cause of the error is, as well as link to https://registry.terraform.io/providers/coder/coder/latest/docs/resources/ai_task?

Copy link
Member Author

Choose a reason for hiding this comment

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

How does this look?

Screenshot 2025-08-08 at 16 00 56

Copy link
Member

Choose a reason for hiding this comment

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

¡Muy caliente!

if hasAITask {
task := jobType.WorkspaceBuild.AiTasks[0]
if task.SidebarApp == nil {
return xerrors.Errorf("update ai task: sidebar app is nil")
if task.SidebarApp == nil || len(task.SidebarApp.Id) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: Use getters for safer access (fixing all non-getter uses is out of scope though)

@johnstcn johnstcn merged commit 155c7bb into main Aug 8, 2025
31 checks passed
@johnstcn johnstcn deleted the cj/18776/workaround-sidebar-app-id-fk branch August 8, 2025 17:06
@github-actions github-actions bot locked and limited conversation to collaborators Aug 8, 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.

3 participants