From f8503600f47b8b926623ea37db58459ee51ac586 Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Fri, 11 Sep 2026 17:20:58 -0700 Subject: [PATCH 1/2] Reject overflowing occupancy before recording solo throughput --- coordinator/registry/solo_tps.go | 14 +++-- .../registry/solo_tps_overflow_test.go | 57 +++++++++++++++++++ 2 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 coordinator/registry/solo_tps_overflow_test.go diff --git a/coordinator/registry/solo_tps.go b/coordinator/registry/solo_tps.go index bb20f4c39c..6f087b3832 100644 --- a/coordinator/registry/solo_tps.go +++ b/coordinator/registry/solo_tps.go @@ -129,11 +129,15 @@ func soloSampleEligible(bc *protocol.BackendCapacity) bool { } load := 0 for _, slot := range bc.Slots { - if n := slot.NumRunning + slot.NumWaiting; n > 0 { - load += n - } - if load > 1 { - return false + for _, n := range [...]int{slot.NumRunning, slot.NumWaiting} { + // Compare before adding untrusted counts: load stays in [0, 1], + // so an overflowing busy report cannot appear uncontended. + if n > 1-load { + return false + } + if n > 0 { + load += n + } } } return true diff --git a/coordinator/registry/solo_tps_overflow_test.go b/coordinator/registry/solo_tps_overflow_test.go new file mode 100644 index 0000000000..ca08faca1b --- /dev/null +++ b/coordinator/registry/solo_tps_overflow_test.go @@ -0,0 +1,57 @@ +package registry + +import ( + "math" + "testing" + + "github.com/eigeninference/d-inference/coordinator/protocol" +) + +func TestHeartbeatRejectsOverflowingSoloOccupancy(t *testing.T) { + for _, counts := range [][2]int{{math.MaxInt, 1}, {1, math.MaxInt}, {math.MaxInt, math.MaxInt}} { + reg := New(testLogger()) + registration := testRegisterMessage() + provider := reg.Register("busy", nil, registration) + model := registration.Models[0].ID + if !reg.Heartbeat(provider.ID, &protocol.HeartbeatMessage{ + BackendCapacity: &protocol.BackendCapacity{Slots: []protocol.BackendSlotCapacity{{ + Model: model, State: "running", NumRunning: counts[0], NumWaiting: counts[1], + ObservedDecodeTPS: 40, + }}}, + }) { + t.Fatal("otherwise valid heartbeat was rejected") + } + // Load-inclusive service estimates still accept the reading; a busy + // box cannot donate the same reading as an uncontended quality rate. + if got := reg.tpsRegistry.Median(model, registration.Hardware.ChipFamily); got != 40 { + t.Fatalf("load-inclusive sample was lost: %v", got) + } + if rate, samples := reg.tpsRegistry.SoloMedian(model, chipClassKey(registration.Hardware)); rate != 0 || samples != 0 { + t.Errorf("running/waiting %v produced solo rate %v from %d samples", counts, rate, samples) + } + } +} + +func TestSoloSampleEligibilityCountsWithoutOverflow(t *testing.T) { + for _, tc := range []struct { + name string + slots []protocol.BackendSlotCapacity + want bool + }{ + {"idle", nil, true}, + {"single decode", []protocol.BackendSlotCapacity{{NumRunning: 1}}, true}, + {"single waiting", []protocol.BackendSlotCapacity{{NumWaiting: 1}}, true}, + {"peers across slots", []protocol.BackendSlotCapacity{{NumRunning: 1}, {NumWaiting: 1}}, false}, + {"negative report ignored", []protocol.BackendSlotCapacity{{NumRunning: -1}, {NumRunning: 1}}, true}, + {"negative cannot hide peers", []protocol.BackendSlotCapacity{{NumRunning: -1, NumWaiting: 2}}, false}, + } { + t.Run(tc.name, func(t *testing.T) { + if got := soloSampleEligible(&protocol.BackendCapacity{Slots: tc.slots}); got != tc.want { + t.Fatalf("solo eligible = %v, want %v", got, tc.want) + } + }) + } + if soloSampleEligible(nil) { + t.Fatal("missing capacity is not a solo sample") + } +} From adba553053211cc8171f35e8e3ad10aba9b60e8b Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Fri, 11 Sep 2026 17:21:47 -0700 Subject: [PATCH 2/2] Document overflow-safe solo sample admission --- docs/architecture/scheduling.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/architecture/scheduling.md b/docs/architecture/scheduling.md index 656fbd653e..53e1e727ee 100644 --- a/docs/architecture/scheduling.md +++ b/docs/architecture/scheduling.md @@ -1,6 +1,6 @@ # Scheduling: queues, slots, capacity and the warm pool -> Last updated: 2026-09-10 · commit `213b8c2b6` +> Last updated: 2026-09-11 · commit `f8503600f` Scheduling is the coordinator's model of *how much work the fleet can take and where the weights are*: the per-model request queue, the per-slot state @@ -237,6 +237,13 @@ decode rate is the provider's median solo sample (at least `defaultQualityCapSoloMinSamples`, the default of `EIGENINFERENCE_QUALITY_CAP_SOLO_MIN_SAMPLES`), or a seeded/benchmark rate. +Solo samples require at most one running or waiting request across the whole +provider and a running decode in the sampled slot (`coordinator/registry/solo_tps.go`, +`soloSampleEligible`; `coordinator/registry/heartbeat.go`). Each occupancy count +is compared against the remaining allowance before addition, so an overflowing +busy report cannot enter the solo sample pool. The separate load-inclusive TPS +store still receives valid observed rates from busy providers. + ### Model slots, pending loads and swaps **`maxModelSlots`.** The number of models a provider keeps resident at once