@@ -1276,20 +1276,27 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
1276
1276
}
1277
1277
snapshot .WorkspaceAgents = append (snapshot .WorkspaceAgents , telemetry .ConvertWorkspaceAgent (dbAgent ))
1278
1278
1279
- for _ , md := range prAgent .Metadata {
1280
- err := db .InsertWorkspaceAgentMetadata (ctx , database.InsertWorkspaceAgentMetadataParams {
1281
- WorkspaceAgentID : agentID ,
1282
- DisplayName : md .DisplayName ,
1283
- Script : md .Script ,
1284
- Key : md .Key ,
1285
- Timeout : md .Timeout ,
1286
- Interval : md .Interval ,
1287
- })
1288
- if err != nil {
1289
- return xerrors .Errorf ("insert agent metadata: %w" , err )
1279
+ // We don't need to insert metadata if the agent is not for a workspace.
1280
+ // This is probably an agent made during the provisioning process.
1281
+ _ , err = db .GetWorkspaceByAgentID (ctx , agentID )
1282
+ if err == nil {
1283
+ for _ , md := range prAgent .Metadata {
1284
+ p := database.InsertWorkspaceAgentMetadataParams {
1285
+ WorkspaceAgentID : agentID ,
1286
+ DisplayName : md .DisplayName ,
1287
+ Script : md .Script ,
1288
+ Key : md .Key ,
1289
+ Timeout : md .Timeout ,
1290
+ Interval : md .Interval ,
1291
+ }
1292
+ err := db .InsertWorkspaceAgentMetadata (ctx , p )
1293
+ if err != nil {
1294
+ return xerrors .Errorf ("insert agent metadata: %w, params: %+v" , err , p )
1295
+ }
1290
1296
}
1297
+ } else if ! errors .Is (err , sql .ErrNoRows ) {
1298
+ return xerrors .Errorf ("get workspace by agent ID: %w" , err )
1291
1299
}
1292
-
1293
1300
for _ , app := range prAgent .Apps {
1294
1301
slug := app .Slug
1295
1302
if slug == "" {
0 commit comments