From 561667c9be0ddf4d006759f6c9dacd8ff94bd99a Mon Sep 17 00:00:00 2001 From: Ilker Manap Date: Wed, 30 Sep 2026 23:01:40 +0200 Subject: [PATCH] Name only the replicas that would make room in headroom Candidates tried on the way to finding no room were listed as whose replicas a placement would stop. Co-Authored-By: Claude Opus 5.5 (1M context) --- internal/control/reconciler/headroom.go | 17 ++++++++++---- internal/control/reconciler/preempt_test.go | 26 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/internal/control/reconciler/headroom.go b/internal/control/reconciler/headroom.go index efa82e1..7290ecb 100644 --- a/internal/control/reconciler/headroom.go +++ b/internal/control/reconciler/headroom.go @@ -79,16 +79,25 @@ func (r *Reconciler) Headroom(model string, limit int) (Headroom, bool) { victims, nextVictim, preempting := r.victims(m), 0, false for h.More+h.ByPreempting < limit { res := place() + // Named only once they have made room: candidates tried on the way + // to finding there is none would otherwise read as whose replicas a + // placement would stop. + var tried []string for res.Placement == nil && nextVictim < len(victims) { v := victims[nextVictim] nextVictim++ inv.ReleaseReplica(v.ID) - if !slices.Contains(h.Preempts, v.Model) { - h.Preempts = append(h.Preempts, v.Model) - } - preempting = true + tried = append(tried, v.Model) res = place() } + if res.Placement != nil && len(tried) > 0 { + preempting = true + for _, m := range tried { + if !slices.Contains(h.Preempts, m) { + h.Preempts = append(h.Preempts, m) + } + } + } if res.Placement == nil { for _, rej := range res.Rejections { h.Blocked = append(h.Blocked, rej.String()) diff --git a/internal/control/reconciler/preempt_test.go b/internal/control/reconciler/preempt_test.go index 7e13e92..115f462 100644 --- a/internal/control/reconciler/preempt_test.go +++ b/internal/control/reconciler/preempt_test.go @@ -390,3 +390,29 @@ func TestARestartBorrowsALowerClassesRoomAndGivesItBack(t *testing.T) { t.Errorf("the opportunistic model did not get its room back: %+v", h.r.Replicas()) } } + +func TestHeadroomNamesOnlyTheReplicasThatWouldMakeRoom(t *testing.T) { + // vital needs a whole node and chat is on the only one; a second + // critical can never fit. Asking for 3: one by stopping chat, then no + // candidates left — nothing else may be named. + h := fillThenWant(t, gpuModel("vital", catalog.ClassCritical, 1), gpuModel("chat", "", 1), gpuNode("1", 8)) + got, _ := h.r.Headroom("vital", 3) + if got.ByPreempting != 1 || len(got.Preempts) != 1 { + t.Errorf("%+v", got) + } + // Free room for one, and candidates that cannot make room for a second: + // none of them may be listed. + small := catalog.Model{Name: "small", Source: "/m", Class: catalog.ClassOpportunistic, + Scaling: catalog.Scaling{Min: 1, Max: 1}, + Profiles: []catalog.Profile{{Name: "tp2", Engine: "vllm", GPUClass: "h100-80g", TP: 2}}} + h2 := fillThenWant(t, gpuModel("big", "", 1), small, gpuNode("1", 8), gpuNode("2", 8)) + got2, _ := h2.r.Headroom("big", 3) + if got2.More != 1 || got2.ByPreempting != 1 || len(got2.Preempts) != 1 { + t.Errorf("one free, one by stopping small: %+v", got2) + } + h3 := fillThenWant(t, gpuModel("big", "", 1), small, gpuNode("1", 8), gpuNode("2", 6)) + got3, _ := h3.r.Headroom("big", 3) + if got3.ByPreempting != 0 || len(got3.Preempts) != 0 { + t.Errorf("stopping small frees a 6-GPU node, too small for big; nobody may be named: %+v", got3) + } +}