@@ -660,8 +660,19 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
660
660
}
661
661
662
662
case dc .Container == nil :
663
- if ! api .devcontainerNames [dc .Name ] {
664
- dc .Name = ""
663
+ if ! api .devcontainerNames [dc .Name ] {// TODO(mafredri): Change this, not stable after https://github.com/coder/coder/pull/18513
664
+ // If this is a runtime-detected container, check if we
665
+ // should remove it.
666
+ // TODO(mafredri): Consider using afero.
667
+ if _ ,err := os .Stat (dc .WorkspaceFolder );errors .Is (err ,os .ErrNotExist ) {
668
+ // If the workspace folder doesn't exist, we can assume
669
+ // that the devcontainer is no longer valid and should be
670
+ // removed.
671
+ logger .Debug (ctx ,"devcontainer workspace folder does not exist, removing devcontainer" )
672
+ delete (api .knownDevcontainers ,dc .WorkspaceFolder )
673
+ // TODO(mafredri): Delete the agent if it exists.
674
+ continue
675
+ }
665
676
}
666
677
dc .Status = codersdk .WorkspaceAgentDevcontainerStatusStopped
667
678
dc .Dirty = false