@@ -597,6 +597,14 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
597
597
return nil ,failJob (fmt .Sprintf ("get workspace build parameters: %s" ,err ))
598
598
}
599
599
600
+ // TODO(DanielleMaywood):
601
+ // Plumb a task prompt into this when we have the new data-model ready
602
+ var taskPrompt string
603
+
604
+ // TODO(DanielleMaywood):
605
+ // Plumb a task ID into this when we have the new data-model ready
606
+ var taskID string
607
+
600
608
dbExternalAuthProviders := []database.ExternalAuthProvider {}
601
609
err = json .Unmarshal (templateVersion .ExternalAuthProviders ,& dbExternalAuthProviders )
602
610
if err != nil {
@@ -721,6 +729,8 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
721
729
WorkspaceOwnerRbacRoles :ownerRbacRoles ,
722
730
RunningAgentAuthTokens :runningAgentAuthTokens ,
723
731
PrebuiltWorkspaceBuildStage :input .PrebuiltWorkspaceBuildStage ,
732
+ TaskId :taskID ,
733
+ TaskPrompt :taskPrompt ,
724
734
},
725
735
LogLevel :input .LogLevel ,
726
736
},
@@ -1976,27 +1986,34 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
1976
1986
}
1977
1987
}
1978
1988
1979
- var sidebarAppID uuid.NullUUID
1989
+ var taskAppID uuid.NullUUID
1980
1990
var hasAITask bool
1981
- var warnUnknownSidebarAppID bool
1991
+ var warnUnknownTaskAppID bool
1982
1992
if tasks := jobType .WorkspaceBuild .GetAiTasks ();len (tasks )> 0 {
1983
1993
hasAITask = true
1984
1994
task := tasks [0 ]
1985
- if task == nil || task .GetSidebarApp ()== nil || len (task .GetSidebarApp ().GetId ())== 0 {
1986
- return xerrors .Errorf ("update ai task: sidebar app is nil or empty" )
1995
+ if task == nil {
1996
+ return xerrors .Errorf ("update ai task: task is nil" )
1997
+ }
1998
+
1999
+ appID := task .GetAppId ()
2000
+ if appID == "" && task .GetSidebarApp ()!= nil {
2001
+ appID = task .GetSidebarApp ().GetId ()
2002
+ }
2003
+ if appID == "" {
2004
+ return xerrors .Errorf ("update ai task: app id is empty" )
1987
2005
}
1988
2006
1989
- sidebarTaskID := task .GetSidebarApp ().GetId ()
1990
- if ! slices .Contains (appIDs ,sidebarTaskID ) {
1991
- warnUnknownSidebarAppID = true
2007
+ if ! slices .Contains (appIDs ,appID ) {
2008
+ warnUnknownTaskAppID = true
1992
2009
}
1993
2010
1994
- id ,err := uuid .Parse (task . GetSidebarApp (). GetId () )
2011
+ id ,err := uuid .Parse (appID )
1995
2012
if err != nil {
1996
- return xerrors .Errorf ("parsesidebar app id: %w" ,err )
2013
+ return xerrors .Errorf ("parse app id: %w" ,err )
1997
2014
}
1998
2015
1999
- sidebarAppID = uuid.NullUUID {UUID :id ,Valid :true }
2016
+ taskAppID = uuid.NullUUID {UUID :id ,Valid :true }
2000
2017
}
2001
2018
2002
2019
// This is a hacky workaround for the issue with tasks 'disappearing' on stop:
@@ -2008,19 +2025,19 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
2008
2025
BuildNumber :workspaceBuild .BuildNumber - 1 ,
2009
2026
});err == nil {
2010
2027
hasAITask = prevBuild .HasAITask .Bool
2011
- sidebarAppID = prevBuild .AITaskSidebarAppID
2012
- warnUnknownSidebarAppID = false
2013
- s .Logger .Debug (ctx ,"task workaround: reused has_ai_task andsidebar_app_id from previous build to keep track of task" ,
2028
+ taskAppID = prevBuild .AITaskSidebarAppID
2029
+ warnUnknownTaskAppID = false
2030
+ s .Logger .Debug (ctx ,"task workaround: reused has_ai_task andapp_id from previous build to keep track of task" ,
2014
2031
slog .F ("job_id" ,job .ID .String ()),
2015
2032
slog .F ("build_number" ,prevBuild .BuildNumber ),
2016
2033
slog .F ("workspace_id" ,workspace .ID ),
2017
2034
slog .F ("workspace_build_id" ,workspaceBuild .ID ),
2018
2035
slog .F ("transition" ,string (workspaceBuild .Transition )),
2019
- slog .F ("sidebar_app_id" ,sidebarAppID .UUID ),
2036
+ slog .F ("sidebar_app_id" ,taskAppID .UUID ),
2020
2037
slog .F ("has_ai_task" ,hasAITask ),
2021
2038
)
2022
2039
}else {
2023
- s .Logger .Error (ctx ,"task workaround: tracking via has_ai_task andsidebar_app from previous build failed" ,
2040
+ s .Logger .Error (ctx ,"task workaround: tracking via has_ai_task andapp_id from previous build failed" ,
2024
2041
slog .Error (err ),
2025
2042
slog .F ("job_id" ,job .ID .String ()),
2026
2043
slog .F ("workspace_id" ,workspace .ID ),
@@ -2030,14 +2047,14 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
2030
2047
}
2031
2048
}
2032
2049
2033
- if warnUnknownSidebarAppID {
2050
+ if warnUnknownTaskAppID {
2034
2051
// Ref: https://github.com/coder/coder/issues/18776
2035
2052
// This can happen for a number of reasons:
2036
2053
// 1. Misconfigured template
2037
2054
// 2. Count=0 on the agent due to stop transition, meaning the associated coder_app was not inserted.
2038
2055
// Failing the build at this point is not ideal, so log a warning instead.
2039
- s .Logger .Warn (ctx ,"unknownai_task_sidebar_app_id " ,
2040
- slog .F ("ai_task_sidebar_app_id " ,sidebarAppID .UUID .String ()),
2056
+ s .Logger .Warn (ctx ,"unknownai_task_app_id " ,
2057
+ slog .F ("ai_task_app_id " ,taskAppID .UUID .String ()),
2041
2058
slog .F ("job_id" ,job .ID .String ()),
2042
2059
slog .F ("workspace_id" ,workspace .ID ),
2043
2060
slog .F ("workspace_build_id" ,workspaceBuild .ID ),
@@ -2051,13 +2068,13 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
2051
2068
Level : []database.LogLevel {database .LogLevelWarn ,database .LogLevelWarn ,database .LogLevelWarn ,database .LogLevelWarn },
2052
2069
Stage : []string {"Cleaning Up" ,"Cleaning Up" ,"Cleaning Up" ,"Cleaning Up" },
2053
2070
Output : []string {
2054
- fmt .Sprintf ("Unknownai_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 ()),
2071
+ fmt .Sprintf ("Unknownai_task_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." ,taskAppID .UUID .String ()),
2055
2072
"Template author: double-check the following:" ,
2056
2073
" - 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)." ,
2057
2074
" - 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." ,
2058
2075
},
2059
2076
});err != nil {
2060
- s .Logger .Error (ctx ,"insert provisioner job log for ai tasksidebar app id warning" ,
2077
+ s .Logger .Error (ctx ,"insert provisioner job log for ai task app id warning" ,
2061
2078
slog .F ("job_id" ,jobID ),
2062
2079
slog .F ("workspace_id" ,workspace .ID ),
2063
2080
slog .F ("workspace_build_id" ,workspaceBuild .ID ),
@@ -2066,7 +2083,7 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
2066
2083
}
2067
2084
// Important: reset hasAITask and sidebarAppID so that we don't run into a fk constraint violation.
2068
2085
hasAITask = false
2069
- sidebarAppID = uuid.NullUUID {}
2086
+ taskAppID = uuid.NullUUID {}
2070
2087
}
2071
2088
2072
2089
if hasAITask && workspaceBuild .Transition == database .WorkspaceTransitionStart {
@@ -2103,7 +2120,7 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
2103
2120
Bool :hasExternalAgent ,
2104
2121
Valid :true ,
2105
2122
},
2106
- SidebarAppID :sidebarAppID ,
2123
+ SidebarAppID :taskAppID ,
2107
2124
UpdatedAt :now ,
2108
2125
});err != nil {
2109
2126
return xerrors .Errorf ("update workspace build ai tasks and external agent flag: %w" ,err )