- Notifications
You must be signed in to change notification settings - Fork1.1k
refactor(coderd): drop sidebar app constraint and simplify provisionerdserver for tasks#20591
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| -- WARNING: Restoring this constraint after running a newer version of coderd | ||
| -- and using tasks is bound to break this constraint. | ||
| ALTER TABLE workspace_builds | ||
| ADD CONSTRAINT workspace_builds_ai_task_sidebar_app_id_required CHECK (((((has_ai_task IS NULL) OR (has_ai_task = false)) AND (ai_task_sidebar_app_id IS NULL)) OR ((has_ai_task = true) AND (ai_task_sidebar_app_id IS NOT NULL)))); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| -- We no longer need to enforce this constraint as tasks have their own data | ||
| -- model. | ||
| ALTER TABLE workspace_builds | ||
| DROP CONSTRAINT workspace_builds_ai_task_sidebar_app_id_required; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2006,10 +2006,12 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro | ||
| } | ||
| } | ||
| var ( | ||
| hasAITask bool | ||
| unknownAppID string | ||
| taskAppID uuid.NullUUID | ||
| taskAgentID uuid.NullUUID | ||
| ) | ||
| if tasks := jobType.WorkspaceBuild.GetAiTasks(); len(tasks) > 0 { | ||
| hasAITask = true | ||
| task := tasks[0] | ||
| @@ -2026,59 +2028,29 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro | ||
| } | ||
| if !slices.Contains(appIDs, appID) { | ||
Comment on lines -2029 to -2062 Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. ❤️ | ||
| unknownAppID = appID | ||
| hasAITask = false | ||
| } else { | ||
| // Only parse for valid app and agent to avoid fk violation. | ||
| id, err := uuid.Parse(appID) | ||
| if err != nil { | ||
| return xerrors.Errorf("parse app id: %w", err) | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| taskAppID = uuid.NullUUID{UUID: id, Valid: true} | ||
| agentID, ok := agentIDByAppID[appID] | ||
| taskAgentID = uuid.NullUUID{UUID: agentID, Valid: ok} | ||
| } | ||
| } | ||
| ifunknownAppID != "" && workspaceBuild.Transition == database.WorkspaceTransitionStart { | ||
| // Ref: https://github.com/coder/coder/issues/18776 | ||
| // This can happen for a number of reasons: | ||
| // 1. Misconfigured template | ||
| // 2. Count=0 on the agent due to stop transition, meaning the associated coder_app was not inserted. | ||
| // Failing the build at this point is not ideal, so log a warning instead. | ||
| s.Logger.Warn(ctx, "unknown ai_task_app_id", | ||
| slog.F("ai_task_app_id",unknownAppID), | ||
| slog.F("job_id", job.ID.String()), | ||
| slog.F("workspace_id", workspace.ID), | ||
| slog.F("workspace_build_id", workspaceBuild.ID), | ||
| @@ -2105,9 +2077,6 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro | ||
| slog.F("transition", string(workspaceBuild.Transition)), | ||
| ) | ||
| } | ||
| } | ||
| if hasAITask && workspaceBuild.Transition == database.WorkspaceTransitionStart { | ||
| @@ -2124,14 +2093,6 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro | ||
| } | ||
| } | ||
| if task, err := db.GetTaskByWorkspaceID(ctx, workspace.ID); err == nil { | ||
| // Irrespective of whether the agent or sidebar app is present, | ||
| // perform the upsert to ensure a link between the task and | ||
| @@ -2153,20 +2114,21 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro | ||
| return xerrors.Errorf("get task by workspace id: %w", err) | ||
| } | ||
| _, hasExternalAgent := slice.Find(jobType.WorkspaceBuild.Resources, func(resource *sdkproto.Resource) bool { | ||
| return resource.Type == "coder_external_agent" | ||
| }) | ||
| if err := db.UpdateWorkspaceBuildFlagsByID(ctx, database.UpdateWorkspaceBuildFlagsByIDParams{ | ||
| ID: workspaceBuild.ID, | ||
| HasAITask: sql.NullBool{ | ||
| Bool: hasAITask, | ||
| Valid: true, | ||
| }, | ||
| SidebarAppID: taskAppID, // SidebarAppID is not required, but kept for API backwards compatibility. | ||
| HasExternalAgent: sql.NullBool{ | ||
| Bool: hasExternalAgent, | ||
| Valid: true, | ||
| }, | ||
| UpdatedAt: now, | ||
| }); err != nil { | ||
| return xerrors.Errorf("update workspace build ai tasks and external agent flag: %w", err) | ||
| } | ||
Uh oh!
There was an error while loading.Please reload this page.