Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9b78dc

Browse files
committed
fix(agent/agentcontainers): refresh containers before status change
The previous method of refreshing before we change the devcontainer status introduced an intermediary state where the devcontainer might not yet have been assigned a container and will flicker as stopped before going into running.
1 parent 7a3a6d4 commit e9b78dc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

agent/agentcontainers/api.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,15 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D
10021002

10031003
logger.Info(ctx, "devcontainer created successfully")
10041004

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+
10051014
api.mu.Lock()
10061015
dc = api.knownDevcontainers[dc.WorkspaceFolder]
10071016
// Update the devcontainer status to Running or Stopped based on the
@@ -1020,13 +1029,6 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D
10201029
api.knownDevcontainers[dc.WorkspaceFolder] = dc
10211030
api.mu.Unlock()
10221031

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-
10301032
return nil
10311033
}
10321034

0 commit comments

Comments
 (0)