Skip to content

fix(routing): relaunch safety — debounce cold-dispatch kick, real-free cold-load admission, safe-by-default flags - #389

Merged
Gajesh2007 merged 5 commits into
fix/prefill-tps-coordinatorfrom
fix/routing-v2-relaunch-safety
Jun 17, 2026
Merged

Gajesh2007 merged 5 commits into
fix/prefill-tps-coordinatorfrom
fix/routing-v2-relaunch-safety

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

Routing v2 relaunch safety

Follow-up to the routing-v2 production incident (write-lock storm + OOM cold loads). Stacked on #387 (prefill-overflow gate); base is fix/prefill-tps-coordinator. Together the stack is the Tier-1 relaunch posture: prefill gate fixed, cold-dispatch off, warm-pool observe-only — plus the safety fixes so Tier-2 (turning cold-dispatch back on) is safe later.

Changes

1. Debounce the cold-dispatch kick (write-lock storm) — coordinator/api/cold_dispatch.go, server.go
kickColdDispatch fired TriggerModelSwaps (registry write lock) on every enqueue → O(request volume) lock acquisitions → reader starvation (/v1/stats 503s, stale heartbeats). New coldKickState coalesces into single-flight + min-interval: a burst of N enqueues collapses to one swap pass. Interval via EIGENINFERENCE_COLD_DISPATCH_MIN_INTERVAL (default 1s). Idempotent TriggerModelSwaps means dropped kicks lose nothing.

2. Cold-load admission uses real free memory, not total (OOM loads) — coordinator/registry/scheduler.go
The cold-load branch of freeMemoryAdmits checked weights + kv + 4 <= TOTAL (assuming the provider evicts everything), while the provider's authoritative ModelLoadAdmission gate checks against real free memory. Coordinator over-admitted → insufficient memory to load model → jetsam OOM → WS read_error disconnects. Now: realFree = total − gpuMemoryActiveGB − 4 and require weights + kv + 3 (activation reserve) <= realFree. GPU cache is reclaimable so it is not subtracted.

Strictly safer: at the branch required = modelSize + kv, so new admit ⇔ modelSize+kv+7+gpuActive ≤ total vs old modelSize+kv+4 ≤ total. For all gpuActive ≥ 0 the new set is a subset of the old — it never admits a load the old check rejected, so it cannot over-admit relative to today.

TODO left in code: the clean long-term fix is for the provider to report freeForLoadGb in BackendCapacity (single source of truth) — intentionally not done here (no protocol change).

3. Safe-by-default flags — coordinator/api/cold_dispatch.go, coordinator/registry/config.go

  • EIGENINFERENCE_COLD_DISPATCH → opt-in (default false). It drove the meltdown; enable only after the safety fixes are validated.
  • WARM_POOL_OBSERVE_ONLY → default true. Warm pool plans + emits telemetry but issues no load_model actions unless explicitly enabled.
  • EIGENINFERENCE_QUEUE_BEFORE_SHED left default-true.

4. Docs — AGENTS.md
Corrected the stale estimatedMemoryGb * 3.0 / "3× memory gate" claims (pitfall note + mutation checklist) to the real ModelLoadAdmission gate (weights + activation reserve + min serveable KV ≤ real free, no multiplier) and noted freeMemoryAdmits now mirrors it conservatively.

Tests

  • New: TestColdKickCoalescesInFlight, TestColdKickRunsAgainAfterInterval, TestColdDispatchMinInterval, TestEnvEnabledDefaultFalse, TestColdDispatchFlagDefaultsOff, TestFreeMemoryAdmitsColdLoadStrictlySaferThanTotal (grid), …RejectsOverActiveMemory, …AdmitsWhenRealFreeFits, TestReadConfigWarmPoolObserveOnlyOptOut.
  • go build ./... clean; go test ./... green (incl. registry, api, routingsim, internal/e2e); gofmt -l empty; -race clean on the kick tests.

Note on stacking

Base is fix/prefill-tps-coordinator (#387). After #387 merges to master I'll rebase this onto master so it reviews as a clean standalone diff.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

… storm

kickColdDispatch fired TriggerModelSwaps (which takes the registry WRITE
lock via expire/reservePendingModelLoads) on every queue enqueue, turning
an O(1)/tick model-swap pass into O(request volume) write-lock
acquisitions and starving readers under load.

Coalesce the per-enqueue kick into a single-flight + min-interval gate
(coldKickState): while a swap pass is in flight, all kicks drop; after it
completes, kicks within the min-interval drop. A burst of N enqueues now
collapses into one swap pass. Interval is env-tunable via
EIGENINFERENCE_COLD_DISPATCH_MIN_INTERVAL (default 1s).

TriggerModelSwaps is already idempotent (only loads models with queued
demand and no warm provider, de-dups in-flight loads), so dropping
redundant kicks loses nothing.
freeMemoryAdmits' cold-load branch (model on disk, not loaded, no
in-flight requests) admitted a load when modelSizeGB + kvCacheGB + 4 <=
TOTAL memory — i.e. it assumed the provider would LRU-evict *everything*
down to bare OS overhead. The provider's authoritative ModelLoadAdmission
gate instead checks against REAL FREE memory (total - resident, minus an
activation + KV headroom), so the coordinator over-admitted cold loads
the provider then OOM-rejected.

Mirror the provider gate conservatively: realFree = totalMemoryGB -
gpuMemoryActiveGB - coldLoadOSReserveGB (GPU cache is reclaimable, left
as free); required = modelSizeGB + kvCacheGB + activationReserveGB (3.0).
For any gpuMemoryActiveGB >= 0 this admits a strict subset of the old
check, so it is monotonically safer and never over-admits. Added a
strictly-safer-than-total invariant test plus OOM-regression and
admit-when-fits cases.

TODO noted in code: the clean long-term fix is for the provider to report
freeForLoadGb in BackendCapacity so the coordinator consumes a single
source of truth instead of re-deriving free memory.
Both autonomous load paths that drove the routing-v2 meltdown are now
opt-in:

- EIGENINFERENCE_COLD_DISPATCH now defaults to FALSE (added
  envEnabledDefaultFalse). Cold-dispatch spill + the proactive swap kick
  stay off until explicitly enabled with =true. QUEUE_BEFORE_SHED remains
  default-true.
- WARM_POOL_OBSERVE_ONLY now defaults to TRUE: the warm-pool controller
  still computes targets and emits telemetry but issues no load_model
  actions unless an operator opts out with =false.

Updated the flag/config default tests accordingly.
The Common Pitfalls / Mutation Checklist described the provider load gate
as requiring estimatedMemoryGb * 3.0 headroom. That heuristic is gone:
ModelLoadAdmission.canLoad now admits when weights + (activation reserve +
min serveable KV) <= real free memory (clamped to OS-available, under the
90% unified cap) — no 2.86x/3x multiplier. Also note the coordinator's
freeMemoryAdmits now mirrors this conservatively (Fix 2).
@vercel

vercel Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
d-inference Ready Ready Preview Jun 17, 2026 3:33pm
d-inference-console-ui-dev Ready Ready Preview Jun 17, 2026 3:33pm
d-inference-landing Ready Ready Preview Jun 17, 2026 3:33pm

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d8383db96

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coordinator/registry/scheduler.go Outdated
if snap.availableOnDisk && !snap.modelLoaded && snap.totalPending == 0 {
const osReserveGB = 4.0
return snap.modelSizeGB+kvCacheGB+osReserveGB <= snap.totalMemoryGB
realFree := snap.totalMemoryGB - snap.gpuMemoryActiveGB - coldLoadOSReserveGB

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't count evictable idle models as unavailable memory

When a provider has only idle resident models and receives a request for another on-disk model, ensureModelLoaded can evict those idle slots before loading the requested model. Subtracting all GPUMemoryActiveGB here treats those evictable weights as non-reclaimable, so a 64 GB provider with a 45 GB idle model will reject a 16 GB cold load even though the provider would unload the idle model and serve it; with EIGENINFERENCE_QUEUE_BEFORE_SHED=false this becomes an immediate 429, and with the default it adds avoidable queue/heartbeat latency instead of direct cold dispatch.

Useful? React with 👍 / 👎.

Comment thread coordinator/registry/scheduler.go Outdated
const osReserveGB = 4.0
return snap.modelSizeGB+kvCacheGB+osReserveGB <= snap.totalMemoryGB
realFree := snap.totalMemoryGB - snap.gpuMemoryActiveGB - coldLoadOSReserveGB
return required+activationReserveGB <= realFree

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mirror the provider load headroom

For near-limit cold loads with small max_tokens, this equation can still admit requests the provider rejects: ModelLoadAdmission.requiredToLoadGb uses activation reserve plus a fixed minimum serveable KV headroom, and the provider's reserve is max(configReserve, physical-hardCap) for the 90% unified-memory cap, while this code uses the request's often-sub-1GiB KV estimate and a flat 4 GB reserve. A large model that fits total-4GB but not the provider's cap-aware load gate will be routed and then fail at load time, preserving the over-admission path this change is intended to close.

Useful? React with 👍 / 👎.

…table

Codex #389 P2: the cold-load branch of freeMemoryAdmits subtracted ALL
gpuMemoryActiveGB, treating resident models as non-reclaimable. But that branch
is gated on totalPending == 0 — no in-flight requests — so every resident model
is idle and the provider LRU-evicts it to load the requested one. The old
subtraction wrongly rejected cold loads onto boxes whose only resident models
were idle (e.g. a 64GB box with a 45GB idle model refusing a 16GB load), adding
queue/heartbeat latency by default or an outright 429 with QUEUE_BEFORE_SHED=false.

Drop the gpuMemoryActiveGB subtraction in the cold branch: idle weights are
free, so the model only needs to fit in (total - OS reserve) plus the activation
reserve the provider also requires. The activation reserve (+3GB over the old
total-only check) remains the meaningful safety, so this is still a strict
subset of the pre-fix admits (never over-admits relative to before). The
standard/serving branch (totalPending > 0) still counts active memory as
unavailable, since a serving model can't be evicted.

Tests: repurpose the over-active-memory test to assert idle memory is evictable
(admit), add a serving-branch test that still rejects, keep the strictly-safer
grid invariant. Documents the residual Codex #389 P2 (cap-aware reserve) whose
clean fix is the provider reporting freeForLoadGb (tracked follow-up).
@Gajesh2007

Copy link
Copy Markdown
Member Author

Addressed the Codex review in b9a0800c.

P2 #1 — evictable idle memory (fixed). The cold-load branch is gated on totalPending == 0, so every resident model is idle and the provider LRU-evicts it to load the requested one. Subtracting gpuMemoryActiveGB there was wrong — it rejected loads onto boxes whose only resident models were idle/evictable (your 64GB-with-45GB-idle example). Dropped the subtraction in the cold branch: required + activationReserve ≤ total − OSReserve. The activation reserve (+3GB over the old total-only check) stays, so this remains a strict subset of the pre-fix admits (never over-admits vs. before). The standard/serving branch (totalPending > 0) still counts active memory, since a serving model can't be evicted. Tests: repurposed the over-active-memory test to assert idle memory is evictable (admit), added a serving-branch reject test, kept the strictly-safer grid invariant.

P2 #2 — cap-aware load headroom (documented residual). Agreed: re-deriving the provider's max(configReserve, physical−hardCap) + min-serveable-KV from the request KV + a flat reserve can still admit a near-limit large model the provider rejects. This is the over-admission gap that only the proper fix closes — the provider reporting its own freeForLoadGb in BackendCapacity (single source of truth), already tracked as a follow-up and noted in-code. Low impact for the relaunch since cold-dispatch is now off by default (Fix 3).

Full coordinator suite green; gofmt clean.

@Gajesh2007
Gajesh2007 merged commit ddf0e63 into fix/prefill-tps-coordinator Jun 17, 2026
6 of 7 checks passed
davidtai added a commit that referenced this pull request Nov 6, 2026
…99695c0

The gitlink was the only conflict: pinned to #389's merge commit 2e499695c0,
which contains dev's 62b29ecd96 and #389. The docs merged without conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Nov 6, 2026
dev pins mlx-swift-lm 2e499695c0 (#389), which 7994762ef9 contains: the pin
stays 7994762ef9. #1851's provider handles #389's new GLM5Next vision error
case, which failed the provider build at 607a70b.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch had an error being deployed

1 failed and 3 active deployments
Preview – d-inference — b9a0800c Deployed Jun 17, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — b9a0800c Deployed Jun 17, 2026 by vercel[bot]
Preview – d-inference-landing — b9a0800c Deployed Jun 17, 2026 by vercel[bot]
benchmarks — b9a0800c Deployed Jun 17, 2026 by Gajesh2007 via E2E Benchmarks #1103
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant