@@ -1958,7 +1958,7 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
1958
1958
agentTimeouts := make (map [time.Duration ]bool )// A set of agent timeouts.
1959
1959
// This could be a bulk insert to improve performance.
1960
1960
for _ ,protoResource := range jobType .WorkspaceBuild .Resources {
1961
- for ai ,protoAgent := range protoResource .Agents {
1961
+ for _ ,protoAgent := range protoResource .GetAgents () {
1962
1962
if protoAgent == nil {
1963
1963
continue
1964
1964
}
@@ -1967,8 +1967,7 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
1967
1967
// the agent to a task. For now we overwrite the
1968
1968
// protoAgent.Id because that matches old behavior.
1969
1969
agentID := uuid .New ()
1970
- protoAgent .Id = agentID .String ()
1971
- protoResource .Agents [ai ]= protoAgent
1970
+ protoAgent .Id = makePredeterminedAgentID (agentID )
1972
1971
1973
1972
dur := time .Duration (protoAgent .GetConnectionTimeoutSeconds ())* time .Second
1974
1973
agentTimeouts [dur ]= true
@@ -2697,13 +2696,13 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
2697
2696
}
2698
2697
2699
2698
var agentID uuid.UUID
2700
- if prAgent .GetId ()== "" {
2701
- agentID = uuid .New ()
2702
- }else {
2703
- agentID ,err = uuid .Parse (prAgent .GetId ())
2699
+ if id ,ok := predeterminedAgentID (prAgent .GetId ());ok {
2700
+ agentID ,err = uuid .Parse (id )
2704
2701
if err != nil {
2705
2702
return xerrors .Errorf ("invalid agent ID format; must be uuid: %w" ,err )
2706
2703
}
2704
+ }else {
2705
+ agentID = uuid .New ()
2707
2706
}
2708
2707
dbAgent ,err := db .InsertWorkspaceAgent (ctx , database.InsertWorkspaceAgentParams {
2709
2708
ID :agentID ,
@@ -3280,3 +3279,14 @@ func convertDisplayApps(apps *sdkproto.DisplayApps) []database.DisplayApp {
3280
3279
}
3281
3280
return dapps
3282
3281
}
3282
+
3283
+ func makePredeterminedAgentID (id uuid.UUID )string {
3284
+ return "keep:" + id .String ()
3285
+ }
3286
+
3287
+ func predeterminedAgentID (agentID string ) (string ,bool ) {
3288
+ if ! strings .HasPrefix (agentID ,"keep:" ) {
3289
+ return "" ,false
3290
+ }
3291
+ return strings .TrimPrefix (agentID ,"keep:" ),true
3292
+ }