Skip to content

An open-source, faster Devin alternative

TypeScript

adjust rolling replace gate

Brian Reardona9fb0d9d6104
diff --git a/internal/controlplane/scaler.go b/internal/controlplane/scaler.go
index d0172c2b..d760456c 100644
--- a/internal/controlplane/scaler.go
+++ b/internal/controlplane/scaler.go
@@ -361,36 +361,43 @@ func (s *Scaler) evaluateRegion(ctx context.Context, region string) {
}
if needsScaleUp {
- // Check cooldown before scaling up
+ // Cascade of guards. Important: each guard logs and SKIPS scale-up but
+ // must NOT `return` from Evaluate — Phase 5 (rollingReplace) below has
+ // to run regardless. Without this, a cluster pinned at maxWorkers with
+ // all stale workers can't ever roll because the early-return short-
+ // circuits both scaleUp AND rollingReplace, and rollingReplace is the
+ // only path that actually frees a slot (drain → terminate → scaleUp).
+ canScaleUp := true
if last, ok := s.state.GetLastScaleUp(region); ok && time.Since(last) < s.cooldown {
log.Printf("scaler: region %s needs scale-up (%s) but cooldown active (%s remaining)",
region, reason, s.cooldown-time.Since(last))
- return
- }
-
- // Don't scale up if there are already pending (unregistered) workers
- pending := s.state.GetPendingLaunches(region)
- if len(pending) > 0 {
- log.Printf("scaler: region %s needs scale-up (%s) but %d worker(s) still pending registration",
- region, reason, len(pending))
- return
+ canScaleUp = false
+ }
+ if canScaleUp {
+ pending := s.state.GetPendingLaunches(region)
+ if len(pending) > 0 {
+ log.Printf("scaler: region %s needs scale-up (%s) but %d worker(s) still pending registration",
+ region, reason, len(pending))
+ canScaleUp = false
+ }
}
-
- // Don't exceed max workers per region (exclude draining workers from capacity)
- effectiveWorkers := 0
- for _, w := range workers {
- if !s.state.IsDraining(w.MachineID) {
- effectiveWorkers++
+ if canScaleUp {
+ effectiveWorkers := 0
+ for _, w := range workers {
+ if !s.state.IsDraining(w.MachineID) {
+ effectiveWorkers++
+ }
+ }
+ if effectiveWorkers+len(s.state.GetPendingLaunches(region)) >= s.maxWorkers {
+ log.Printf("scaler: region %s at max workers (%d/%d), skipping scale-up", region, effectiveWorkers, s.maxWorkers)
+ canScaleUp = false
}
}
- if effectiveWorkers+len(s.state.GetPendingLaunches(region)) >= s.maxWorkers {
- log.Printf("scaler: region %s at max workers (%d/%d), skipping scale-up", region, effectiveWorkers, s.maxWorkers)
- return
+ if canScaleUp {
+ log.Printf("scaler: region %s %s, scaling up (cpu=%.1f%% mem=%.1f%% disk=%.1f%% util=%.1f%%)",
+ region, reason, maxCPU, maxMem, maxDisk, utilization*100)
+ s.scaleUp(ctx, region)
}
-
- log.Printf("scaler: region %s %s, scaling up (cpu=%.1f%% mem=%.1f%% disk=%.1f%% util=%.1f%%)",
- region, reason, maxCPU, maxMem, maxDisk, utilization*100)
- s.scaleUp(ctx, region)
} else if utilization < scaleDownThreshold && len(workers) > s.minWorkers {
// Phase 4: Scale down via smart drain (live-migrate sandboxes, then destroy)
log.Printf("scaler: region %s utilization %.1f%% < %.0f%%, initiating smart drain", region, utilization*100, scaleDownThreshold*100)