@@ -1002,15 +1002,6 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D
1002
1002
1003
1003
logger .Info (ctx ,"devcontainer created successfully" )
1004
1004
1005
- // Ensure the container list is updated immediately after creation.
1006
- // This makes sure that dc.Container is populated before we acquire
1007
- // the lock avoiding a temporary inconsistency in the API state
1008
- // where status is running, but the container is nil.
1009
- if err := api .RefreshContainers (ctx );err != nil {
1010
- logger .Error (ctx ,"failed to trigger immediate refresh after devcontainer creation" ,slog .Error (err ))
1011
- return xerrors .Errorf ("refresh containers: %w" ,err )
1012
- }
1013
-
1014
1005
api .mu .Lock ()
1015
1006
dc = api .knownDevcontainers [dc .WorkspaceFolder ]
1016
1007
// Update the devcontainer status to Running or Stopped based on the
@@ -1029,6 +1020,13 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D
1029
1020
api .knownDevcontainers [dc .WorkspaceFolder ]= dc
1030
1021
api .mu .Unlock ()
1031
1022
1023
+ // Ensure an immediate refresh to accurately reflect the
1024
+ // devcontainer state after recreation.
1025
+ if err := api .RefreshContainers (ctx );err != nil {
1026
+ logger .Error (ctx ,"failed to trigger immediate refresh after devcontainer creation" ,slog .Error (err ))
1027
+ return xerrors .Errorf ("refresh containers: %w" ,err )
1028
+ }
1029
+
1032
1030
return nil
1033
1031
}
1034
1032