Repository navigation
feat: provider reports free_for_load_gb; coordinator uses it for cold-load admission - #390
Conversation
The coordinator currently re-derives "can this provider load model X" from gpu/total memory figures, which can't see the 90% unified cap, the OS baseline, or the activation/min-KV load headroom — so it over-admits cold loads the provider then OOM-rejects (the routing-v2 meltdown mechanism) and under-admits when idle-but-evictable models are resident. Fix: have the provider report its own answer, since it already owns the authoritative ModelLoadAdmission gate. - ModelLoadAdmission.maxLoadableWeightGb(...): pure helper = the max additional model WEIGHT (GB) loadable right now, net of the load reserve (which enforces the 90% cap) and load headroom (activation + min serveable KV), clamped to real OS-available memory, and treating current MLX usage as reclaimable (idle models are LRU-evicted on a cold load). Invariant test: for an idle box this equals the largest weight the provider's own canLoad() accepts. - BackendCapacity gains free_for_load_gb (computed in updateAggregateCapacity with the same loadReserve/headroom the load gate uses). Backward-compatible: additive field, decode tolerates its absence (defaults to 0). 24GB box example (production headroom = activation 3 + minKV 1 = 4GiB, reserve 4GiB): with the OS reporting ~21-22GB available, free_for_load_gb ≈ 13-14GB, so gpt-oss-20b (~13.5GB) loads only when the box truly has room — the machine reports its real momentary capacity instead of the coordinator guessing.
…mission Use the provider-reported free_for_load_gb (max loadable model weight) as the single source of truth in freeMemoryAdmits' cold-load branch: admit iff modelSizeGB <= freeForLoadGb. This exactly mirrors the provider's own ModelLoadAdmission gate, so the coordinator can neither over-admit a load the provider OOM-rejects nor under-admit because of evictable idle weights — closing the residual gap that the total-memory heuristic (and Codex #389 P2) left open. - protocol.BackendCapacity.FreeForLoadGB *float64 (omitempty); pointer so a legacy provider that doesn't report it is nil → fall back to the existing total-memory heuristic. - clampBackendCapacity nils out-of-range values (NaN/Inf/neg/absurd) so a garbage report falls back rather than mis-admitting; a legitimate 0 is preserved. - routingSnapshot carries freeForLoadGB; populated at both snapshot sites. Tests: reported value wins over the heuristic (admit/reject), reported 0 rejects, legacy nil falls back, clamp validation.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This PR adds a provider-reported Trust boundaries touched
Threat analysisT-034 — Provider runs modified code while advertising a trusted identity T-007 / T-012 / T-027 — Provider serves manipulated model outputs (weight hash) T-008 — Plaintext SSE fallback on encryption failure T-009 — Swift provider excluded from private-routing due to Python flags T-010 — Cancellation not propagated to inference engine New attack surface not covered by an existing threatAdvisory inflation / deflation via
Recommendation: treat Additional notes
Open findings resolved by this PRNone. No existing SEC-* findings are addressed by this change. 🔐 Threat model: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0391a9a18
ℹ️ 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".
| // can't over-admit a load the provider then OOM-rejects (the meltdown | ||
| // mechanism) nor under-admit because of evictable idle weights. | ||
| if snap.freeForLoadGB != nil { | ||
| return snap.modelSizeGB <= *snap.freeForLoadGB |
There was a problem hiding this comment.
Account for request KV in cold-load gate
When free_for_load_gb is present, this branch returns before using the kvCacheGB estimate computed above, so cold-load admission only checks whether the model weights fit. The provider reports free_for_load_gb after subtracting load headroom for activations plus a minimum serveable KV budget, not the KV needed by this particular prompt/max_tokens; for a cold model whose weights barely fit, a large-context request can pass QuickCapacityCheck/routing here and then be rejected by the provider's tokenBudgetMax/GlobalKVCacheBudget after load. Please include the request KV estimate in the reported-capacity branch (or report a per-request load budget) so long cold requests don't get routed to providers that cannot serve them.
Useful? React with 👍 / 👎.
| // source of truth for cold-load admission (the coordinator no longer | ||
| // re-derives free memory). A pointer so a legacy provider that doesn't report | ||
| // it is nil (→ coordinator falls back to the total-memory heuristic). | ||
| FreeForLoadGB *float64 `json:"free_for_load_gb,omitempty"` |
There was a problem hiding this comment.
Gate load_model planning with reported free capacity
This field is now treated as the authoritative cold-load gate in the direct routing path, but the queued warming path still ignores it: TriggerModelSwaps/modelLoadCandidatePendingLocked only check catalog hardware fit before sending load_model. In the queue-before-shed path, a provider can report free_for_load_gb=9 for a 14 GB model, get rejected by preflight, then be selected by kickColdDispatch anyway; the provider fails the load and queued requests can sit until timeout because RejectUnservableQueuedRequests sees capacity rejections. Please mirror free_for_load_gb in the load_model planner so queued cold dispatch doesn't send loads the provider already reported cannot fit.
Useful? React with 👍 / 👎.
| let freeForLoadGb = ModelLoadAdmission.maxLoadableWeightGb( | ||
| totalBytes: totalMem, | ||
| systemAvailableBytes: SystemMemory.availableBytes() ?? .max, | ||
| mlxUsedBytes: mlxUsed, |
There was a problem hiding this comment.
Exclude non-evictable local work from free_for_load
Passing all current MLX usage as mlxUsedBytes makes maxLoadableWeightGb report that every resident model can be reclaimed. That is only safe when all slots are idle, but the coordinator's cold gate only checks coordinator pending requests; local endpoint streams are tracked by localReservations/scheduler state, not p.pendingCount(). When a provider is serving a local request for model A and the coordinator cold-routes model B, this heartbeat can advertise A's active weights as evictable, causing the coordinator to dispatch a load that ensureModelLoaded then cannot evict and rejects. Please subtract non-evictable active/local slot memory or report zero/omit this value while any slot is not evictable.
Useful? React with 👍 / 👎.
P2 #3 — exclude non-evictable work from free_for_load_gb (provider). The heartbeat computed max-loadable weight by treating ALL MLX usage as reclaimable, but MLX memory is global (it also covers the local inference endpoint, whose streams are tracked by localReservations, not modelSlots), so a model actively serving a local request is NOT evictable. Gate the eviction add-back on `hasInflightWork` (the comprehensive coordinator-inflight + local-streams signal): assume idle models are evictable only when nothing is in flight; otherwise reclaim nothing (conservative — never advertises a served model's weights as free). P2 #2 — gate the load planner with reported free capacity (coordinator). modelLoadCandidatePendingLocked (warm-pool / queue-before-shed cold dispatch) only checked static modelFitsHardware, so it could send a load_model the direct freeMemoryAdmits gate would reject — leaving queued requests to time out. Mirror the direct path: skip a candidate whose catalog weight exceeds the provider's reported free_for_load_gb. Legacy providers (nil) fall through to the static gate. P2 #1 (request KV not in the cold gate) is by design: free_for_load_gb guarantees the model loads and can serve a modest request (provider reserves min serveable KV); per-request KV is a runtime concern, and folding the coordinator's generic KV estimate in would break edge-fit cold loads (the model consumes the whole budget). Left as-is; the proper enhancement is a per-request load budget from the provider (follow-up). Test: planner respects free_for_load_gb (reject 14GB model at 9GB free, accept at 20GB, legacy nil falls back). Go suite + Swift build green.
|
Addressed the Codex review in P2 #3 (over-reporting evictable memory) — fixed. You're right: P2 #2 (planner ignored reported capacity) — fixed. P2 #1 (request KV not in the cold gate) — by design, left as-is. Go suite + Swift build green; gofmt clean. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 037bcc5104
ℹ️ 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".
| // can't over-admit a load the provider then OOM-rejects (the meltdown | ||
| // mechanism) nor under-admit because of evictable idle weights. | ||
| if snap.freeForLoadGB != nil { | ||
| return snap.modelSizeGB <= *snap.freeForLoadGB |
There was a problem hiding this comment.
Compare free_for_load against provider load size
This reported value is meant to mirror the provider's ModelLoadAdmission.canLoad, but the provider calls that gate with modelInfo.estimatedMemoryGb (the scanner pads on-disk bytes by the 1.2 memory overhead factor and uses GiB) while the coordinator compares against catalogSizeGB populated from raw TotalSizeBytes/1e9. For a near-threshold cold model whose raw catalog size is below free_for_load_gb but whose padded provider estimate is above it, QuickCapacityCheck and routing admit the provider and ensureModelLoaded then rejects with a 503. Please compare against the same padded GiB load estimate, or have the provider report a raw-size threshold.
Useful? React with 👍 / 👎.
| let freeForLoadGb = ModelLoadAdmission.maxLoadableWeightGb( | ||
| totalBytes: totalMem, | ||
| systemAvailableBytes: SystemMemory.availableBytes() ?? .max, | ||
| mlxUsedBytes: reclaimableMlx, | ||
| reserveBytes: loadReserve) |
There was a problem hiding this comment.
Subtract outstanding KV from free_for_load
Fresh evidence: even after the new hasInflightWork check, this heartbeat value still omits kvBudget.outstandingReservedBytes(), although availableMemoryGb() subtracts those reservations before any real load. With a local endpoint stream, coordinator pending is zero so the cold-load branch trusts free_for_load_gb; if the stream has reserved future KV that is not allocated in MLX/OS memory yet, this can advertise those bytes as loadable and route a cold model that the provider's fast/load admission rejects. Please subtract outstanding reservations here or report zero while local work is active.
Useful? React with 👍 / 👎.
| if entry.SizeGB > 0 && p.BackendCapacity != nil && p.BackendCapacity.FreeForLoadGB != nil && | ||
| entry.SizeGB > *p.BackendCapacity.FreeForLoadGB { | ||
| return 0, false |
There was a problem hiding this comment.
Keep cold-spill checks in sync with load gate
Adding the free_for_load_gb rejection only in the load planner makes it stricter than ColdSpillProviders, which still returns true after only the static hardware check. In the no-eligible-provider preflight path, a cold provider whose entry.SizeGB exceeds this reported limit can still cause the request to be queued as a cold spill, but the subsequent TriggerModelSwaps pass rejects the same provider here and sends no load_model, so the request waits for the queue timeout instead of failing fast. Please mirror this gate in the cold-spill predicate as well.
Useful? React with 👍 / 👎.
| if entry.SizeGB > 0 && p.BackendCapacity != nil && p.BackendCapacity.FreeForLoadGB != nil && | ||
| entry.SizeGB > *p.BackendCapacity.FreeForLoadGB { | ||
| return 0, false |
There was a problem hiding this comment.
Gate warm-pool loads with free_for_load
This new check only protects the TriggerModelSwaps planner, but the active warm-pool planner still builds load_model actions through warmPoolCandidateLocked using only modelFitsHardware and a free-memory score. When queue/capacity pressure raises the warm target, a provider that reports free_for_load_gb below the model size can still be selected by the warm pool and sent a load_model the provider already said cannot fit, causing failed warm attempts and pending-load cooldowns instead of choosing a truly loadable node. Please apply the same reported-capacity gate in the warm-pool candidate path.
Useful? React with 👍 / 👎.
…d paths Second Codex #390 pass — make the reported-capacity gate consistent everywhere and apples-to-apples, via one shared helper so the paths can't drift. - New reportedFreeForLoadAdmits() helper + coldLoadCatalogGBToMemGiB normalization (P2 #4): the provider's free_for_load_gb is padded GiB (ModelLoadAdmission uses estimatedMemoryGb = on-disk × 1.2 / 2^30), but the coordinator compared raw catalogSizeGB (TotalSizeBytes/1e9). A near-threshold model whose RAW size fit but whose PADDED estimate didn't was admitted then 503'd at load. Normalize catalog GB → padded GiB (×1.2×(1e9/2^30) ≈ 1.1176) before comparing, so the coordinator gate exactly mirrors the provider's canLoad. - Apply the helper in all four cold-load decision paths so they stay in sync: direct admission (freeMemoryAdmits), the swap planner (modelLoadCandidatePendingLocked), the warm pool (warmPoolCandidateLocked, P2 #1) and the cold-spill predicate (coldSpillProviderEligibleLocked, P2 #2). Previously only the first two were gated, so the warm pool could issue a load_model the provider rejects, and cold-spill would queue a request the planner then refuses to load (sit until the 120s timeout). - Provider (P2 #3): subtract outstanding KV reservations (kvBudget.outstandingReservedBytes()) from the heartbeat free_for_load_gb, exactly as availableMemoryGb does, so it can't advertise reserved-but-not-yet- allocated bytes as loadable. maxLoadableWeightGb gains an outstandingReservationBytes parameter. Tests: near-threshold normalization (raw fits, padded rejects), planner gate, outstanding-KV subtraction. Go suite (17 pkgs) + Swift build green; gofmt clean.
|
Second pass — all 4 new findings addressed in P2 #4 (units/padding mismatch) — fixed. You're right that P2 #1 (warm-pool) + P2 #2 (cold-spill) — fixed. Extracted a single P2 #3 (outstanding KV) — fixed. The heartbeat Go suite (17 pkgs) + Swift build green; gofmt clean. The four cold-load paths now share one gate and the comparison is apples-to-apples with the provider's |
…-lm 7994762ef9; review nits - The gitlink was the only conflict: pinned to #390's merge commit 7994762ef9 (contains dev's 62b29ecd96, #388 and #390). - assistantStateArrays includes the carried row also after begin took it, so the executor test catches a wrong carried row (red with the step's first frame's row; its doc's "with the carried row" now holds). - inference.md: invariant 1 says a merged assisted frame runs the plain lane's ops and rests on ResidualRMSNorm's byte parity; the intro and Planning name the assistant's capture frontier. - Changelog: the measured gain (bench tool, two M5 Ultras). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Provider-reported
free_for_load_gb— the single source of truth for cold-load admissionThis is the proper "fix A" for the cold-load memory mismatch that drove the routing-v2 meltdown (and the residual Codex flagged on #389 P2). Instead of the coordinator re-deriving "can this provider load model X?" from gpu/total memory figures, the provider reports the answer it already computes via its authoritative
ModelLoadAdmissiongate.Why
The coordinator's re-derivation can't see the 90% unified-memory cap, the OS baseline, the activation/min-KV load headroom, or eviction of idle models. So it both:
insufficient memory to load model→ jetsam → WSread_error), andThere is no way to perfectly mirror the provider's gate from the coordinator — so report it.
Provider (Swift)
ModelLoadAdmission.maxLoadableWeightGb(...)— pure helper: max additional model weight (GB) loadable now, net of the load reserve (which enforces the 90% cap) + load headroom (activation 3 GiB + min serveable KV 1 GiB), clamped to real OS-available memory, treating current MLX usage as reclaimable (idle models are LRU-evicted on a cold load).BackendCapacity.free_for_load_gbpopulated inupdateAggregateCapacitywith the sameloadReserve/headroom the load gate uses. Invariant test: for an idle box, the reported value equals the largest weight the provider's owncanLoad()accepts.Coordinator (Go)
protocol.BackendCapacity.FreeForLoadGB *float64(omitempty). Pointer ⇒ legacy provider that doesn't report it isnil.freeMemoryAdmitscold branch: if reported, admit iffmodelSizeGB <= freeForLoadGb(exact mirror of the provider gate); else fall back to the existing heuristic.clampBackendCapacitynils out-of-range values (NaN/Inf/neg/absurd) → fall back rather than mis-admit; a legitimate0is preserved.How this behaves on a 24 GB machine (asked during review)
Production headroom = activation 3 + min-KV 1 = 4 GiB; reserve =
max(configReserve 4, physical − 90% cap)= 4 GiB. With the OS reporting ~21–22 GB available on an idle 24 GB box:free_for_load_gb ≈ min(24, sysAvail) − 4 (reserve) − 4 (headroom) ≈ 13–14 GBSo a 24 GB box advertises ~13–14 GB of loadable weight and the coordinator routes gpt-oss-20b (~13.5 GB) to it only when it genuinely has the room, and never sends it gemma-26b (~14–31 GB). The machine reports its real, momentary capacity (it already does this for its own load gate — see
gptOssLoadsOn24GB); the coordinator now respects it instead of guessing from total RAM (which would send a 24 GB box a 14 GB model:14+4 ≤ 24→ admit → provider OOM/reject). It's self-tuning per machine — no hardcoded RAM tiers.Tests
maxLoadableWeightReclaimsIdleModels,…ClampsToSystemAvailable,…FloorsAtZero,…MirrorsCanLoadWhenIdle,backendCapacityRoundTripsFreeForLoad,…DecodesLegacyWithoutFreeForLoad.swift build --build-testsclean; selected suites pass.freeMemoryAdmitsreported-value admit/reject, reported-0 rejects, legacy nil falls back, clamp validation.go build ./...+go test ./...green; gofmt clean.Note on stacking / reconciliation with #389
Branched off
master(per request), so the fallback heuristic here is master'smodelSizeGB + kv + 4 ≤ total. #389 independently improves that same fallback to the evictable-idle real-free check. They touch the same cold branch, so when both land I'll reconcile to: reported value (this PR) as the fast path + #389's evictable heuristic as the fallback. No behavioral conflict — they converge.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.