Skip to content

[pull] main from coder:main #142

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 4 commits into from
Aug 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 58 additions & 9 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1925,12 +1925,16 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
return xerrors.Errorf("update workspace build deadline: %w", err)
}

appIDs := make([]string, 0)
agentTimeouts := make(map[time.Duration]bool) // A set of agent timeouts.
// This could be a bulk insert to improve performance.
for _, protoResource := range jobType.WorkspaceBuild.Resources {
for _, protoAgent := range protoResource.Agents {
dur := time.Duration(protoAgent.GetConnectionTimeoutSeconds()) * time.Second
agentTimeouts[dur] = true
for _, app := range protoAgent.GetApps() {
appIDs = append(appIDs, app.GetId())
}
}

err = InsertWorkspaceResource(ctx, db, job.ID, workspaceBuild.Transition, protoResource, telemetrySnapshot)
Expand All @@ -1945,33 +1949,78 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
}

var sidebarAppID uuid.NullUUID
hasAITask := len(jobType.WorkspaceBuild.AiTasks) == 1
if hasAITask {
task := jobType.WorkspaceBuild.AiTasks[0]
if task.SidebarApp == nil {
return xerrors.Errorf("update ai task: sidebar app is nil")
var hasAITask bool
var warnUnknownSidebarAppID bool
if tasks := jobType.WorkspaceBuild.GetAiTasks(); len(tasks) > 0 {
hasAITask = true
task := tasks[0]
if task == nil || task.GetSidebarApp() == nil || len(task.GetSidebarApp().GetId()) == 0 {
return xerrors.Errorf("update ai task: sidebar app is nil or empty")
}

sidebarTaskID := task.GetSidebarApp().GetId()
if !slices.Contains(appIDs, sidebarTaskID) {
warnUnknownSidebarAppID = true
}

id, err := uuid.Parse(task.SidebarApp.Id)
id, err := uuid.Parse(task.GetSidebarApp().GetId())
if err != nil {
return xerrors.Errorf("parse sidebar app id: %w", err)
}

sidebarAppID = uuid.NullUUID{UUID: id, Valid: true}
}

if warnUnknownSidebarAppID {
// 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_sidebar_app_id",
slog.F("ai_task_sidebar_app_id", sidebarAppID.UUID.String()),
slog.F("job_id", job.ID.String()),
slog.F("workspace_id", workspace.ID),
slog.F("workspace_build_id", workspaceBuild.ID),
slog.F("transition", string(workspaceBuild.Transition)),
)
// In order to surface this to the user, we will also insert a warning into the build logs.
if _, err := db.InsertProvisionerJobLogs(ctx, database.InsertProvisionerJobLogsParams{
JobID: jobID,
CreatedAt: []time.Time{now, now, now, now},
Source: []database.LogSource{database.LogSourceProvisionerDaemon, database.LogSourceProvisionerDaemon, database.LogSourceProvisionerDaemon, database.LogSourceProvisionerDaemon},
Level: []database.LogLevel{database.LogLevelWarn, database.LogLevelWarn, database.LogLevelWarn, database.LogLevelWarn},
Stage: []string{"Cleaning Up", "Cleaning Up", "Cleaning Up", "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()),
"Template author: double-check the following:",
" - You have associated the coder_ai_task with a valid coder_app in your template (ref: https://registry.terraform.io/providers/coder/coder/latest/docs/resources/ai_task).",
" - You have associated the coder_agent with at least one other compute resource. Agents with no other associated resources are not inserted into the database.",
},
}); err != nil {
s.Logger.Error(ctx, "insert provisioner job log for ai task sidebar app id warning",
slog.F("job_id", jobID),
slog.F("workspace_id", workspace.ID),
slog.F("workspace_build_id", workspaceBuild.ID),
slog.F("transition", string(workspaceBuild.Transition)),
)
}
// Important: reset hasAITask and sidebarAppID so that we don't run into a fk constraint violation.
hasAITask = false
sidebarAppID = uuid.NullUUID{}
}

// Regardless of whether there is an AI task or not, update the field to indicate one way or the other since it
// always defaults to nil. ONLY if has_ai_task=true MUST ai_task_sidebar_app_id be set.
err = db.UpdateWorkspaceBuildAITaskByID(ctx, database.UpdateWorkspaceBuildAITaskByIDParams{
if err := db.UpdateWorkspaceBuildAITaskByID(ctx, database.UpdateWorkspaceBuildAITaskByIDParams{
ID: workspaceBuild.ID,
HasAITask: sql.NullBool{
Bool: hasAITask,
Valid: true,
},
SidebarAppID: sidebarAppID,
UpdatedAt: now,
})
if err != nil {
}); err != nil {
return xerrors.Errorf("update workspace build ai tasks flag: %w", err)
}

Expand Down
16 changes: 16 additions & 0 deletions coderd/provisionerdserver/provisionerdserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2794,6 +2794,22 @@ func TestCompleteJob(t *testing.T) {
},
expected: true,
},
// Checks regression for https://github.com/coder/coder/issues/18776
{
name: "non-existing app",
input: &proto.CompletedJob_WorkspaceBuild{
AiTasks: []*sdkproto.AITask{
{
Id: uuid.NewString(),
SidebarApp: &sdkproto.AITaskSidebarApp{
// Non-existing app ID would previously trigger a FK violation.
Id: uuid.NewString(),
},
},
},
},
expected: false,
},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
Expand Down
9 changes: 6 additions & 3 deletions docs/install/cloud/compute-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ Google Cloud Platform project.

## Launch a Coder instance from the Google Cloud Marketplace

We publish an Ubuntu 22.04 VM image with Coder and Docker pre-installed. Search
for `Coder v2` in the GCP Marketplace or
[use direct link](https://console.cloud.google.com/marketplace/product/coder-enterprise-market-public/coder-v2).
We publish an Ubuntu 22.04 VM image with Coder and Docker pre-installed.

Two SKU's are available via the Google Cloud Marketplace:

1. [License purchase via Google Cloud Marketplace](https://console.cloud.google.com/marketplace/product/coder-enterprise-market-public/coder-gcmp?inv=1&invt=Ab45rg&project=secret-beacon-468405-p5)
2. [A solution to deploy VM's on GCP (Bring Your Own License)](https://console.cloud.google.com/marketplace/product/workspan-public-422119/coder?inv=1&invt=Ab45rg&project=secret-beacon-468405-p5)

![Coder on GCP Marketplace](../../images/platforms/gcp/marketplace.png)

Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy