Skip to content

feat: provider reports free_for_load_gb; coordinator uses it for cold-load admission - #390

Merged
Gajesh2007 merged 4 commits into
masterfrom
feat/provider-free-for-load-gb
Jun 17, 2026
Merged

Gajesh2007 merged 4 commits into
masterfrom
feat/provider-free-for-load-gb

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

Provider-reported free_for_load_gb — the single source of truth for cold-load admission

This 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 ModelLoadAdmission gate.

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:

There 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_gb populated in updateAggregateCapacity with the same loadReserve/headroom the load gate uses. Invariant test: for an idle box, the reported value equals the largest weight the provider's own canLoad() accepts.
  • Backward-compatible: additive field, decode tolerates absence (defaults to 0).

Coordinator (Go)

  • protocol.BackendCapacity.FreeForLoadGB *float64 (omitempty). Pointer ⇒ legacy provider that doesn't report it is nil.
  • freeMemoryAdmits cold branch: if reported, admit iff modelSizeGB <= freeForLoadGb (exact mirror of the provider gate); else fall back to the existing heuristic.
  • clampBackendCapacity nils out-of-range values (NaN/Inf/neg/absurd) → fall back rather than mis-admit; a legitimate 0 is 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 GB

So 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

  • Swift: maxLoadableWeightReclaimsIdleModels, …ClampsToSystemAvailable, …FloorsAtZero, …MirrorsCanLoadWhenIdle, backendCapacityRoundTripsFreeForLoad, …DecodesLegacyWithoutFreeForLoad. swift build --build-tests clean; selected suites pass.
  • Go: freeMemoryAdmits reported-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's modelSizeGB + 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.


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

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.
@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 4:32pm
d-inference-console-ui-dev Ready Ready Preview Jun 17, 2026 4:32pm
d-inference-landing Ready Ready Preview Jun 17, 2026 4:32pm

Request Review

@github-actions

github-actions Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds a provider-reported free_for_load_gb field to heartbeats for cold-load routing decisions; the coordinator-side input validation is reasonable, but the field introduces a new self-reported signal on TB-002 that the threat model partially covers and one new attack surface not yet catalogued.


Trust boundaries touched

  • TB-002 — Coordinator ↔ Provider WebSocket (registry admission, cold-dispatch gate)
  • TB-003 — Provider operator vs. process (new memory-accounting signal sourced from provider process)

Threat analysis

T-034 — Provider runs modified code while advertising a trusted identity
⚠️ Weakens (minor, bounded): freeForLoadGb is a self-reported field appended to the heartbeat BackendCapacity struct (ProviderLoop.swift:3206). Like all heartbeat fields, it is not covered by the APNs code-identity attestation. A malicious or patched provider can advertise any value — including an inflated freeForLoadGb to attract cold-load traffic for models it cannot actually serve, or zero to starve legitimate load routing. The coordinator's clamp in registry.go:2077-2086 correctly sanitises NaN/Inf/negative/oversized values back to nil, and the warm-planner gate at registry.go:2882-2884 then falls back to the static heuristic for a nil value. So the blast radius is bounded: a lying provider can at worst cause the coordinator to attempt a load that the provider OOM-rejects, which then falls back to the existing timeout path. This is an availability issue, not a confidentiality/integrity issue, and is consistent with the existing "heartbeat fields are advisory" posture. No new code-identity regression; the APNs attestation path is unaffected.

T-007 / T-012 / T-027 — Provider serves manipulated model outputs (weight hash)
ℹ️ Neutral: ModelLoadAdmission.maxLoadableWeightGb (ModelLoadAdmission.swift:66-115) is purely a memory-accounting helper. It does not alter model weight hashing, WeightHasher, or how the coordinator enforces (or fails to enforce, per SEC-007) the weight hash. No regression.

T-008 — Plaintext SSE fallback on encryption failure
ℹ️ Neutral: ProviderLoop.swift changes are limited to the heartbeat-state construction block (lines ~3176-3215). The streaming inference / encryption path is not modified.

T-009 — Swift provider excluded from private-routing due to Python flags
ℹ️ Neutral: No changes to providerSupportsPrivateTextLocked or the capability flags reported by Swift providers.

T-010 — Cancellation not propagated to inference engine
ℹ️ Neutral: Cancellation wiring is untouched.


New attack surface not covered by an existing threat

Advisory inflation / deflation via freeForLoadGb (no existing threat ID):

freeForLoadGb is the first provider-reported field that directly gates whether the coordinator will route new model-load work to a provider. Prior heartbeat values (GPU memory active/peak/cache, totalMemory) were informational. This one feeds a routing decision (registry.go:2882-2884, cold_dispatch.go — not shown in diff). Two abuse cases:

  1. Inflation (over-admit): A provider reports a large freeForLoadGb to attract cold-load traffic for models it cannot fit. The coordinator sends a load_model, the provider OOM-rejects, queued cold-dispatch requests time out. This is a targeted availability attack against consumers waiting on a specific model. The existing maxMemoryGBFloat clamp (registry.go:2082) caps the value at 1024 GB, which is a reasonable upper bound.

  2. Deflation (under-admit / self-exclusion): A provider always reports 0 (a valid, non-nil value per the comment at registry.go:2077 — "A legitimate 0 ('can't load anything now') is kept"). The coordinator will never route cold loads to it, effectively letting the provider opt out of model-load work while remaining registered and serving warm requests. This bypasses the coordinator's load-balancing intent without triggering any untrust logic. Consider whether a sustained freeForLoadGb == 0 alongside non-zero gpuMemoryActiveGb should generate a warning or affect provider scoring.

Recommendation: treat freeForLoadGb as untrusted advisory data (the clamping already does this for invalid values) and document in the threat model that a provider can manipulate cold-load routing through this field. The nil-fallback to the static heuristic is the correct safety net and should be preserved for all edge cases.


Additional notes

  • registry.go:2082 — math.IsInf(v, 0) correctly catches both ±Inf. ✅
  • registry.go:2082 — v > maxMemoryGBFloat (1024 GB) is a reasonable cap but note it allows values up to 1024 GB which exceeds current Apple Silicon maximums by ~8×; tightening to actual maximum unified memory (e.g. 192 GB for M3 Ultra) would reduce the inflation window, though the OOM-reject fallback limits practical damage.
  • ProviderLoop.swift:3196 — hasInflightWork conservatively treats any in-flight local stream as non-reclaimable. This is correct and prevents the heartbeat from advertising memory that is actively reserved by kvBudget. ✅
  • ModelLoadAdmission.swift:98 — saturatingAdd is used throughout to prevent integer overflow on the UInt64 arithmetic. ✅

Open findings resolved by this PR

None. No existing SEC-* findings are addressed by this change.


🔐 Threat model: docs/threat-model.yaml · Updates on each push to this PR

@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: 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".

Comment thread coordinator/registry/scheduler.go Outdated
// 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

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 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"`

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 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,

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 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.
@Gajesh2007

Copy link
Copy Markdown
Member Author

Addressed the Codex review in 037bcc51.

P2 #3 (over-reporting evictable memory) — fixed. You're right: MLX.GPU.activeMemory is global and also covers the local inference endpoint (ProviderLoop runs startLocalEndpoint; local streams are tracked by localReservations, not modelSlots), so treating all MLX usage as reclaimable could advertise an actively-served model's weights as free. Fixed by gating the eviction add-back on hasInflightWork — the comprehensive signal that covers both coordinator-inflight (inflightTasks/requestToModel) and local streams (localReservations): assume idle models are evictable only when nothing is in flight; otherwise reclaim nothing (conservative — never over-reports).

P2 #2 (planner ignored reported capacity) — fixed. modelLoadCandidatePendingLocked (warm-pool / queue-before-shed cold dispatch) only checked static modelFitsHardware. Now it also skips any candidate whose catalog weight exceeds the provider's reported free_for_load_gb, mirroring the direct freeMemoryAdmits gate, so the planner can't send a load_model the provider then rejects (which would leave queued requests to time out). Legacy providers (nil) fall through to the static gate. Added TestModelLoadCandidateRespectsFreeForLoad.

P2 #1 (request KV not in the cold gate) — by design, left as-is. free_for_load_gb deliberately answers "can the model LOAD and serve a modest request" (the provider reserves min serveable KV in its headroom); per-request KV is a runtime concern handled by GlobalKVCacheBudget once loaded. Folding in the coordinator's generic KV estimate would break edge-fit cold loads — e.g. on a 24GB box gpt-oss uses the entire free_for_load_gb budget for weights, so weights + anyKV > free_for_load_gb → it'd never cold-load. The clean enhancement (a per-request/KV-aware load budget reported by the provider) is a tracked follow-up; for now a large-context cold request that doesn't fit is rejected at runtime and reroutes.

Go suite + Swift build green; gofmt clean.

@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: 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".

Comment thread coordinator/registry/scheduler.go Outdated
// 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

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 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 👍 / 👎.

Comment on lines +3197 to +3201
let freeForLoadGb = ModelLoadAdmission.maxLoadableWeightGb(
totalBytes: totalMem,
systemAvailableBytes: SystemMemory.availableBytes() ?? .max,
mlxUsedBytes: reclaimableMlx,
reserveBytes: loadReserve)

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 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 👍 / 👎.

Comment thread coordinator/registry/registry.go Outdated
Comment on lines +2886 to +2888
if entry.SizeGB > 0 && p.BackendCapacity != nil && p.BackendCapacity.FreeForLoadGB != nil &&
entry.SizeGB > *p.BackendCapacity.FreeForLoadGB {
return 0, false

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 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 👍 / 👎.

Comment thread coordinator/registry/registry.go Outdated
Comment on lines +2886 to +2888
if entry.SizeGB > 0 && p.BackendCapacity != nil && p.BackendCapacity.FreeForLoadGB != nil &&
entry.SizeGB > *p.BackendCapacity.FreeForLoadGB {
return 0, false

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 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.
@Gajesh2007

Copy link
Copy Markdown
Member Author

Second pass — all 4 new findings addressed in be346d1e, via one shared helper so the paths can't drift again.

P2 #4 (units/padding mismatch) — fixed. You're right that free_for_load_gb is padded GiB (provider's canLoad uses estimatedMemoryGb = on-disk ×1.2 / 2^30) while the coordinator compared raw catalogSizeGB (TotalSizeBytes/1e9). Added coldLoadCatalogGBToMemGiB = 1.2 × (1e9/2^30) ≈ 1.1176 and normalize catalog GB → padded GiB before comparing, so the gate exactly mirrors canLoad (near-threshold models no longer admitted-then-503'd). Conservative by construction. New test TestFreeMemoryAdmitsColdLoadNormalizesCatalogSize.

P2 #1 (warm-pool) + P2 #2 (cold-spill) — fixed. Extracted a single reportedFreeForLoadAdmits() helper and applied it in all four cold-load paths: direct admission, the swap planner, warmPoolCandidateLocked, and coldSpillProviderEligibleLocked. 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 (sit until the 120s timeout). Now they're consistent — one helper, no drift.

P2 #3 (outstanding KV) — fixed. The heartbeat free_for_load_gb now subtracts kvBudget.outstandingReservedBytes(), exactly as the real load gate (availableMemoryGb) does, so it can't advertise reserved-but-unallocated bytes as loadable. maxLoadableWeightGb gained an outstandingReservationBytes param. New test maxLoadableWeightSubtractsOutstandingReservations.

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 canLoad.

@Gajesh2007
Gajesh2007 merged commit bf8022e into master Jun 17, 2026
10 of 11 checks passed
jonathan308 added a commit that referenced this pull request Nov 6, 2026
…-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>

This branch had an error being deployed

1 failed and 3 active deployments
Preview – d-inference-console-ui-dev — be346d1e Deployed Jun 17, 2026 by vercel[bot]
Preview – d-inference — be346d1e Deployed Jun 17, 2026 by vercel[bot]
Preview – d-inference-landing — be346d1e Deployed Jun 17, 2026 by vercel[bot]
benchmarks — be346d1e Deployed Jun 17, 2026 by Gajesh2007 via E2E Benchmarks #1107
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