Skip to content

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

Merged
johnstcn merged 5 commits into
mainfrom
cj/18776/workaround-sidebar-app-id-fk
Aug 8, 2025
Merged

johnstcn merged 5 commits into
mainfrom
cj/18776/workaround-sidebar-app-id-fk

Conversation

@johnstcn

@johnstcn johnstcn commented Aug 8, 2025 •

Copy link
Copy Markdown
Member

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()),

@mafredri mafredri Aug 8, 2025 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

¡Muy caliente!

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
Copy Markdown
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
@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