Repository navigation
fix(coordinator): cap per-box concurrency at quality_concurrency; keep dedicated pool warm - #439
Conversation
…p dedicated pool warm Gemma's dedicated pool was collapsing under load: ~80% of requests failed (53% cancelled, 27% error, telemetry over 30m) because the per-provider concurrency cap is a flat 24 while a 26B model only sustains ~2 concurrent at the 15 tok/s quality bar. Routing piled 10-23 concurrent onto a few warm boxes (decode collapsed to ~5 tok/s) while ~48 cold dedicated boxes sat idle: a cold box's ~30s model-load TTFT exceeds the 5s ceiling, so it is never routable on demand, and nothing was warming it. - Universal per-box cap = quality_concurrency x overcommit, computed from the STATIC single-stream decode rate (not the observed-under-load EWMA, which collapses under the very overload the cap prevents and would force cap=1). Slow models capped tight (Gemma->2); fast/over-provisioned models effectively unchanged (gpt-oss->20). Default on; EIGENINFERENCE_QUALITY_CONCURRENCY_CAP / _OVERCOMMIT (default 2.0). A provider-reported per-slot MaxConcurrency is honored over the computed cap. - Dedicated pools (e.g. Gemma) keep the WHOLE eligible pool warm so idle boxes enter service, with per-reason EligibleCold disqualifier instrumentation. - Disable cache-affinity pinning for dedicated models (concurrency-bound, not prompt-cache-bound) so it cannot reintroduce concentration. Coordinator-only. Cap defaults off in registry.New, so existing unit tests and the e2e testbed are unaffected.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This PR introduces a quality-concurrency admission cap that is a scheduling/capacity change with no direct security impact; all threat model postures are neutral. Trust Boundaries Touched
Threat Assessment
New Attack SurfaceNone introduced. The cap values ( One minor observation worth a quick code-review glance (not a new threat, existing limitation):
Open Findings ResolvedNone — this PR does not address any SEC-* finding. 🔐 Threat model: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0665ff955c
ℹ️ 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".
…pacity feed, demand-gated dedicated warming Codex review on #439 (1 P1, 2 P2), all valid: - P1: Swift providers don't report decode_tps, so resolvedDecodeTPS falls back to sqrt(memory_bandwidth) — a model-agnostic hardware proxy that under-estimates fast models (~57 tok/s gpt-oss reads as ~28). Hard-capping a fast model from it could shed healthy traffic. Now the bandwidth fallback only caps DEDICATED models (known-slow, urgently need it); a non-dedicated model without a real benchmark keeps the flat cap until its provider reports decode_tps. - P2: ModelCapacitySnapshot (/v1/models[/capacity]) used the flat-24 headroom, so a capped Gemma box was advertised routable up to 24 and upstream routers kept sending requests this path 429s. Now uses the same quality-capped headroom as routing. - P2: the dedicated whole-pool warm target is now gated on per-build demand, so a box advertising multiple matching builds (e.g. desired+previous during an alias migration) doesn't force-warm every matching build across the pool — only the one receiving traffic. Tests: added the fallback-rate-only-caps-dedicated regression; warm-target test now covers demand-gated vs idle. Full go test ./registry/... ./api/... green.
|
Found 1 test failure on Blacksmith runners: Failure
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e34357a1c9
ℹ️ 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".
Codex follow-up review (P2): the cap was applied when building the selection snapshot and in the preflight, but ReserveProviderEx's final admit re-check (providerCanAdmitLockedEx) still used the legacy flat-cap headroom. If a heartbeat bumped NumRunning between snapshot and reservation, a box that just reached its quality cap could be over-admitted via the re-check. Now the re-check uses the same quality-capped headroom. Added TestQualityCapAppliedAtAdmitRecheck.
ethenotethan
left a comment
There was a problem hiding this comment.
Automated Code Review — Layr-Labs/d-inference#
Verdict: REQUEST_CHANGES
Security — ✅ No issues found
Performance — 4 finding(s) (3 blocking)
- 🟡 [MEDIUM]
coordinator/registry/concurrency_cap.go:89-92— Nested mutex locks in hasConcurrencyHeadroomForModelCapLocked could cause deadlock- Suggestion: Document lock ordering requirements or refactor to avoid nested locking patterns
- 🔵 [INFO]
coordinator/registry/scheduler.go:908— resolvedDecodeTPS called multiple times in hot path- Suggestion: Cache the result of resolvedDecodeTPS(p) in a local variable to avoid recomputation
- 🟡 [MEDIUM]
coordinator/registry/warm_pool_controller.go:556-577— Map allocations in loop without pre-sizing- Suggestion: Pre-allocate maps with estimated capacity based on provider count to reduce allocations
- 🟡 [MEDIUM]
coordinator/registry/scheduler.go:1658— resolvedDecodeTPS called again in quickCapacityCheck- Suggestion: Cache resolvedDecodeTPS result to avoid redundant computation in tight loop
Type_diligence — 3 finding(s) (3 blocking)
- 🟡 [MEDIUM]
coordinator/registry/concurrency_cap.go:55— Missing type assertion check for dedicated model pattern lookup- Suggestion: Add ok check: if _, dedicated := r.dedicatedPatternForLocked(model); !dedicated { ... } should verify the second return value is used safely
- 🟡 [MEDIUM]
coordinator/registry/concurrency_cap_test.go:74— Missing type assertion check for dedicated model pattern lookup in test- Suggestion: Add ok check: if _, dedicated := r.dedicatedPatternForLocked(model); !dedicated { ... } should verify the second return value is used safely
- 🟡 [MEDIUM]
coordinator/registry/scheduler.go:433— Missing type assertion check for dedicated model pattern lookup- Suggestion: Add ok check: if _, dedicated := r.dedicatedPatternForLocked(model); !dedicated { ... } should verify the second return value is used safely
Additive_complexity — 6 finding(s) (3 blocking)
- 🟡 [MEDIUM]
coordinator/registry/concurrency_cap.go:1-103— New file adds complex quality-concurrency cap system when simpler per-model configuration could suffice- Suggestion: Consider if this could be simplified to a per-model concurrency map in config rather than dynamic calculation based on decode rates and quality floors
- 🟡 [MEDIUM]
coordinator/registry/concurrency_cap.go:55-82— effectiveMaxConcurrencyForModelLocked duplicates quality concurrency calculation from warm_pool_target.go- Suggestion: Extract shared qualityConcurrency calculation to a common helper function to avoid maintaining the same math in multiple places
- 🔵 [INFO]
coordinator/registry/concurrency_cap_test.go:1-265— Test file creates many test helpers that could be simplified- Suggestion: Consolidate budgetSlot, effCap, and mkFallback helpers into fewer, more focused test utilities
- 🔵 [INFO]
coordinator/registry/config.go:25-41— QualityCapConfig adds new configuration layer when existing WarmPoolConfig already has similar parameters- Suggestion: Consider merging quality cap settings into existing WarmPoolConfig to reduce configuration surface area
- 🟡 [MEDIUM]
coordinator/registry/warm_pool_controller.go:555-635— warmColdReason enum and conversion logic adds significant complexity for diagnostic logging- Suggestion: Consider if simple error strings would suffice instead of typed reasons and conversion maps, or if this diagnostic detail is truly necessary
- 🔵 [INFO]
coordinator/registry/scheduler.go:427-435— Cache affinity logic embedded in selection scan adds model-specific routing logic- Suggestion: Move dedicated model cache affinity exclusion to a separate method or configuration to keep selection logic cleaner
13 finding(s) total, 9 blocking. Verdict: REQUEST_CHANGES.
🤖 Automated review by Centaur · DAR-186

Problem
The Gemma dedicated pool (PR #434 isolated Gemma-4 onto dedicated boxes — isolation works) is collapsing under load. Live routing telemetry (
/v1/admin/routes, 4,923 Gemma reqs / 30 min):~80% of requests fail: 53% cancelled, 27% error, ~15% success.
Success rate vs the box's in-flight load at dispatch:
66% of traffic lands on boxes already running ≥10 concurrent; median served decode 5 tok/s. Meanwhile ~48 cold dedicated boxes sit idle.
Root cause (universal latent flaw)
The per-provider concurrency cap is a flat 24 (
maxConcurrencyForModelLockedfallback for token-budget providers). It's a hard-coded guess at "how many concurrent decodes before per-request TPS collapses" — but a 26B model at ~23 tok/s solo only sustains ~2 concurrent at the 15 tok/s quality floor.quality_concurrencyIS computed (warm-pool planning) but never enforced at admission. The 15 tok/s guard that should stop this is non-binding: the decode-floor preference is soft ("never fails closed"), andTTFT_HARD_REJECTgates first-token latency, not sustained decode.Before → After
flowchart TD subgraph Before A1[Gemma request] --> A2{box has headroom?<br/>cap = flat 24} A2 -->|yes, always<br/>token budget 0.4%| A3[pile onto warm box<br/>→ 10-23 concurrent] A3 --> A4[decode collapses ~5 tok/s<br/>→ cancel / error] A5[48 cold boxes] -.30s TTFT > 5s ceiling.-> A6[never selected,<br/>never warmed → idle] endflowchart TD subgraph After B1[Gemma request] --> B2{box at quality cap?<br/>cap = quality_concurrency x overcommit<br/>from STATIC tps → Gemma 2} B2 -->|under cap| B3[admit → spread across boxes] B2 -->|all warm boxes at cap| B4[fast-429 to OpenRouter] B5[warm-pool: keep WHOLE dedicated<br/>pool warm] --> B6[48 idle boxes enter service] endThe fix (coordinator-only; default-on; env-tunable)
min(reported_cap, quality_concurrency × overcommit), computed from each provider's static single-stream decode rate (resolvedDecodeTPS), not the observed-under-load EWMA (which would inherit the feedback loop and force cap=1). Slow models capped tight (Gemma→2); fast/over-provisioned models effectively unchanged (gpt-oss→20, ≤ the old 24, far above its load). A provider-reported per-slotMaxConcurrencystill binds when it's tighter. Hooked into the single shared admission gate (snap.hasHeadroom+ the preflight), so routing and the 429-shed decision stay consistent.warm + eligibleCold(the entire eligible pool), so idle dedicated boxes are proactively warmed into service. Adds per-reasonEligibleColddisqualifier instrumentation to surface why cold boxes aren't warmable.Knobs (live env, no rebuild):
EIGENINFERENCE_QUALITY_CONCURRENCY_CAP(default on),EIGENINFERENCE_QUALITY_CONCURRENCY_OVERCOMMIT(default 2.0 → Gemma 2/box; set 1.0 for the strict 15-tok/s batch, higher for throughput). Reuses the warm-poolDECODE_FLOOR_TPS(15) andFALLBACK_QUALITY_CONCURRENCY.Default off in
registry.New, so existing unit tests and the e2e testbed are unaffected; only the coordinator entrypoint turns it on.Tests
concurrency_cap_test.go: cap reads STATIC (not observed) TPS — the regression that matters; scales with model speed (slow→2, fast→20);min(reported, quality)both directions; disabled→flat-24; spread + shed through the realReserveProviderpath; dedicated warm-target = whole pool.go test ./registry/... ./api/...green;go build,gofmt,go vet,-race, and the Linux/amd64 (EigenCloud) cross-build all pass.Verify after deploy (read-only)
/v1/admin/routes: expect backend_running-at-dispatch ≤ cap, cancel rate to fall from 53%,running_providersto climb toward the pool size, success rate up from ~15%.🤖 Generated with Claude Code
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.