Repository navigation
Description
Problem
A model provider can stall or go offline at any time: a cloud provider behind OpenRouter, the gateway itself, or a local Ollama server. The gateway does not route around a stalled provider, so the roadmap jobs fail until a person changes the routing.
On 2026-11-16 from about 10:00Z, openrouter/deepseek/deepseek-v4.1-flash-1017 waited about 300 s for its first token. Every stage, refine, implement and alternatives call on it failed for more than 5 hours (class=provider), and a person changed the routing twice (#5978, #5988). Why the existing tools did not help:
- LiteLLM falls back from the group
deepseek-v4.1-flash-1017todeepseek-v4.1-flash, but OpenRouter sends its timeout inside a stream that already started, as code 408. LiteLLM (1.103.11, and 1.109.1 in_handle_stream_fallback_error) raises an in-stream 4xx other than 429 with no retry and no fallback; only a transport timeout (httpx.TimeoutException) is exempt. - LiteLLM has no deadline for the first token. OpenRouter keeps the stream open while it waits, so the gateway timeout (900 s) and the client deadline (1200 s) do not end the stalled call first.
- The client resend of fix(ai): one retry layer for a gateway call #5965 sends the call again to the same group, and it stalls again.
- No metric or alert names a stalled group: the median time to the first token of the group went from 2 s to 150 s to no token, and nothing reacted.
Expected behavior
- A group with a stalled or offline deployment stops getting new calls within a short time (for example 60 s), and the calls go to the next healthy deployment in an order that the gateway config sets, for a cloud or a local backend.
- A call that has no first token within a deadline is ended and sent to the next deployment, before any content reaches the client.
- When the stalled deployment is healthy again, it gets its calls back with no change by a person.
- A metric and an alert name each group whose time to the first token or failure rate is above a limit.
- When no deployment of a job's model is healthy, the jobs wait (feat(roadmap): park jobs while the gateway is offline #5967) instead of failing.
Use the open tools first: LiteLLM deployment order within one group, allowed_fails and cooldowns, background health checks, router fallbacks, and an upstream LiteLLM change so that a 408 before the first chunk (is_pre_first_chunk) can fall back. Build only what they cannot do, with the cost written.
Related
- fix(ai): one retry layer for a gateway call #5965 (one retry layer), feat(roadmap): park jobs while the gateway is offline #5967 (park jobs while the gateway is offline), fix(k8s): Route DeepSeek 1017 without the floor variant #5978 (
:floor), fix(k8s): Run the DeepSeek jobs on v4.1-flash while 1017 stalls #5988 (jobs on v4.1-flash), chore(llm): Find why fallbacks did not serve parser-failed calls #3553 (fallbacks that did not serve parser-failed calls).
Activity
dan-petty commentedon Nov 16, 2026
Both address what happens when a provider is down, but #5967 parks jobs while the candidate routes calls to a healthy deployment.dan-petty commentedon Nov 16, 2026
Design: route around a stalled or offline provider
Evidence: a mock SSE server (comments each second, then an error chunk) drove
litellm.Router1.103.11 and 1.109.1 and the 1.103.11 proxy. Lines are from 1.103.11.Findings (1.103.11)
orderrouter.py:12846-12917). Order 2 answered in 0.01 s; order 1 got no request.allowed_fails: 3equals the default (__init__.py:538), so the rate rule applies (cooldown_handlers.py:364-405). A one-deployment group never cooled (6 of 6 calls failed); a two-deployment group cooled after 5. Order-1model_info.allowed_fails: 0cooled after 1. Routerallowed_fails: 1cooled a one-deployment group, then the fallback started before the call.TimeoutErrorAllowedFailsdoes nothing: the callback gets the rawOpenRouterException. The fail counter lives forcooldown_time(:595-598), so stalls of 300 s never add up at 30 s.proxy_server.py:4025-4100). Interval 5 s,health_check_timeout3 s: a call 9 s into a stall got order 2 in 0.02 s; order 1 came back 6.1 s after recovery. A call in flight still failed after the stall.timeoutandstream_timeoutat 3 s, a comments-only stream did not end in 15 s._acompletion(BerriAI/litellm#46493): an in-stream 408 is retried, cools, and falls back. TTFT deadline requests #5859 and #17991 closed as not planned. #49795 is open (a reasoning prefix blocks the fallback).preferred_max_latencyandsortonly reorder.Also: an offline local tier costs 25 s on each call today, and 2.1 s once with
allowed_fails: 2. Live: the 1017 TTFT p50 went from 2 s to 117 s, then had no sample.Recommended setup
order, else fallbacks. No Ollama group gets health checks, so no check takes the one slot (chore(k8s): quiet the gateway config warnings and correct its comments #5302).First-token deadline
LiteLLM cannot end a stream with no first chunk.
GatewayCallModel(src/devops_cli/ai/models/gateway.py); the resend then gets order 2. Cost: 80k tokens, 1.5 h.Metrics and alert
New group
llm-gatewayink8s/devops/monitoring/prometheus-rules-values.yaml,severity: warning:LlmGatewayFirstTokenSlow:histogram_quantile(0.5, sum by (le, requested_model) (rate(litellm_llm_api_time_to_first_token_metric_bucket{job="llm-gateway", api_provider="openrouter"}[15m]))) > 30,for: 10m.LlmGatewayNoFirstToken: 3 or more calls of a hosted group in 30 min (litellm_proxy_total_requests_metric_total)unlessa TTFT sample. A stall gives no TTFT sample, and the failure counters miss in-stream errors (4 in 12 h).Link to #5967
The Service reads the gateway
/health(cached background results) and parks the jobs of a group with no healthy deployment.Build plan
_HOSTED_GROUP_PRICES. Test first with the mock server: an in-stream 408 moves the next call to order 2 in less than 1 s.feat(ai): Route DeepSeek calls around a stalled provider
devops-cli-service commentedon Nov 16, 2026
Released in v0.166.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.166.0
devops-cli-service commentedon Nov 16, 2026
Live since 2026-11-16 18:14 UTC
fix(k8s): Roll the MCP server with no gap (#6070)