An open-source, faster Devin alternative
TypeScript
exclude paused VMs from worker slot count
Brian Reardon1f487ecd5b0c
diff --git a/cmd/worker/main.go b/cmd/worker/main.goindex 05120d11..13cb0da3 100644--- a/cmd/worker/main.go+++ b/cmd/worker/main.go@@ -704,7 +704,16 @@ func main() {log.Printf("opensandbox-worker: machine ID (hostname): %s", hostname)}hb.Start(func() (int, int, float64, float64, float64) {- count, _ := mgr.Count(context.Background())+ // Report the ACTIVE (non-paused) VM count as the slot usage:+ // paused VMs reclaimed their RAM and resume instantly, so they+ // must not consume placement slots or drive scale-up. The+ // RSS/CPU/disk hard caps remain the real capacity limits.+ var count int+ if qemuMgr != nil {+ count = qemuMgr.ActiveCount()+ } else {+ count, _ = mgr.Count(context.Background())+ }cpuPct, memPct, diskPct := worker.SystemStats()return cfg.MaxCapacity, count, cpuPct, memPct, diskPct})diff --git a/internal/qemu/manager.go b/internal/qemu/manager.goindex 103a16b0..c47a4bd1 100644--- a/internal/qemu/manager.go+++ b/internal/qemu/manager.go@@ -2167,6 +2167,24 @@ func (m *Manager) Count(ctx context.Context) (int, error) {return len(m.vms), nil}+// ActiveCount returns the number of non-paused VMs. This is the count that+// should gate placement against MaxCapacity and drive scale-up utilization:+// paused VMs have paged their guest RAM out to swap (~no resource use) and+// resume instantly, so they must not consume placement slots or trigger+// scale-up. The RSS/CPU/disk hard caps remain the real capacity limits;+// MaxCapacity then caps only the resource-using (active) boxes per worker.+func (m *Manager) ActiveCount() int {+ m.mu.RLock()+ defer m.mu.RUnlock()+ n := 0+ for _, vm := range m.vms {+ if vm.pausedAt.IsZero() {+ n+++ }+ }+ return n+}+// Close stops all VMs and cleans up.func (m *Manager) Close() {m.stopGhostReaper()