@@ -1410,6 +1410,7 @@ func (ctl *controller) syncLauncherInstances(ctx context.Context, nodeDat *nodeD
14101410 remainingInstances := make ([]InstanceState , 0 , len (insts .Instances ))
14111411 deletedStoppedInstanceIDs := sets .New [string ]()
14121412 failedStoppedInstanceErrs := map [string ]error {}
1413+ runningCount := 0
14131414 for _ , inst := range insts .Instances {
14141415 if inst .Status == InstanceStatusStopped {
14151416 // Clean up stopped instances from the launcher.
@@ -1418,18 +1419,18 @@ func (ctl *controller) syncLauncherInstances(ctx context.Context, nodeDat *nodeD
14181419 logger .V (3 ).Info ("Failed to delete stopped instance from launcher during sync" ,
14191420 "instanceID" , inst .InstanceID , "err" , delErr )
14201421 // Deletion failed — the instance still occupies a slot in the launcher.
1421- // Include it in remainingInstances so capacity accounting stays accurate.
14221422 failedStoppedInstanceErrs [inst .InstanceID ] = delErr
14231423 } else {
14241424 logger .V (2 ).Info ("Deleted stopped instance from launcher during sync" ,
14251425 "instanceID" , inst .InstanceID )
14261426 deletedStoppedInstanceIDs .Insert (inst .InstanceID )
1427- }
1428- if delErr == nil || IsLauncherNotFoundError (delErr ) {
14291427 continue
14301428 }
14311429 }
14321430 remainingInstances = append (remainingInstances , inst )
1431+ if inst .Status == "running" {
1432+ runningCount ++
1433+ }
14331434 if lastUsed , exists := launcherDat .Instances [inst .InstanceID ]; exists {
14341435 newInstances [inst .InstanceID ] = lastUsed
14351436 } else {
@@ -1441,12 +1442,6 @@ func (ctl *controller) syncLauncherInstances(ctx context.Context, nodeDat *nodeD
14411442 // so that callers (e.g. selectBestLauncherPod) see accurate capacity.
14421443 insts .Instances = remainingInstances
14431444 insts .TotalInstances = len (remainingInstances )
1444- runningCount := 0
1445- for _ , inst := range remainingInstances {
1446- if inst .Status == "running" {
1447- runningCount ++
1448- }
1449- }
14501445 insts .RunningInstances = runningCount
14511446
14521447 launcherDat .Instances = newInstances
0 commit comments