Repository navigation
Description
Problem Description
A devops command that calls the LLM gateway through the Cloudflare Tunnel (https://ai.example.com/v1) fails when the model works for more than 125 s before the reply is complete. The Cloudflare Proxy Read Timeout is 125 s. Only an Enterprise zone can change it.
The client sends each gateway chat call without streaming (_openai_compat_messages in src/devops_cli/ai/client/openai.py). Thus no byte comes back until the full reply is ready. At 125 s, the edge returns 524 to the client and closes the request to the origin. LiteLLM then records a 499, and cancel_on_disconnect stops the Ollama task. That setting is correct: it releases the GPU slot.
The retry transport retries every 5xx status, 524 included (src/devops_cli/ai/retries/__init__.py). Each retry sends the same long prompt to a different tier, and the edge cuts it again at 125 s. One call can use 5 × 125 s of GPU time and return no reply.
Reproduction Steps
- Use the default configuration:
ai.provider: gateway,ai.gateway_url: https://ai.example.com/v1,ai.model: qwen3.8:27b. - Send a chat call that makes the model work for more than 125 s, for example an
analysiscall with a prompt of about 90k tokens. - Each attempt fails with 524 after about 125 s. The gateway counts a 499 for each attempt.
Expected vs Actual Behavior
- Expected: the call returns the full reply while the client's own read timeout (1,200 s for a review) is not reached.
- Actual: each attempt stops at about 125 s, and the retries stop at the same point.
Environment Diagnostics
devops-cli 0.7.1 (main at 69928b0). Gateway: LiteLLM v1.103.0. Tunnel: cloudflared 2026.10.4. Ingress: Traefik on k3s. Client: openai 3.26.1.
Logs, Traces, or Terminal Output
Measured on 2026-10-27:
litellm_deployment_failure_responses_total{exception_status="499"}: 73 in 24 h, 38 of them in the last 2 h. All areqwen3.8:27b(DEFAULT_AI_MODEL) on/v1/chat/completions. No other model has a 499.- cloudflared logs
Incoming request ended abruptly: context canceledforai.example.com/v1/chat/completions. The times agree to the second with the Ollamacancel tasklines. - The cancelled Ollama tasks ran 124.7, 124.9, 125.0 and 125.0 s on idle runners.
- Two prompts, of about 21k and 90k tokens, came back again and again at intervals of about 60 s. This agrees with the 60 s backoff limit of the retry transport.
- Cloudflare gives the Proxy Read Timeout as 125 s, with status 524, changeable only on Enterprise zones: https://developers.cloudflare.com/fundamentals/reference/connection-limits/ and https://developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/error-524/
Feasibility
- A stream stays open past 125 s through the tunnel. A probe on 2026-10-27 streamed a
qwen3.8:27breply throughai.example.comfor 200 s. The first byte came at 1.7 s, and no gap was longer than 1.7 s. The probe closed the connection itself at 200 s. Thus bytes on the wire stop the edge timeout, and no hop (Cloudflare, cloudflared, Traefik) buffers the stream. - LiteLLM can send bytes before the first token. The deployed LiteLLM
v1.103.0haslitellm_settings.sse_keepalive_ping_interval_seconds(litellm/__init__.py:263). When it is set and the request hasstream: true,open_sse_before_first_byte(litellm/proxy/common_request_processing.py) opens the response after one interval. It then writes: pingSSE comments until the first token comes, and in each later gap. It does nothing for a request withoutstream: true(ttft_keepalive_interval). A deployment can turn it off withkeepalive_seconds: 0. - The client ignores the pings. openai 3.26.1 skips SSE comment lines (
openai/_streaming.py:404). It raisesopenai.APIErroron adata:frame that holdserror(openai/_streaming.py:94).
Proposed fix
Use open tools: the LiteLLM keepalive and the OpenAI SDK stream. Build nothing new.
- In
k8s/llm/gateway/config.yaml, setlitellm_settings.sse_keepalive_ping_interval_secondsto a value well below 125 s. Start with 30 s: a call whose first token comes in less than 30 s keeps itsx-litellm-*headers (see "Costs to decide"). - In
src/devops_cli/ai/client/openai.py, make_openai_compat_messagessendstream: truewithstream_options.include_usagefor thegatewayprovider. Build the sameLLMResponsefrom the chunks: content, reasoning, usage, finish reason and model. Use the stream reader that_openai_compat_streamuses now. Keep theDEFAULT_AI_MAX_RESPONSE_BYTESlimit on the streamed body. - Map an
openai.APIErrorfrom an error frame to the same error that an HTTP error status gives. Theexceptclause catches onlyAPIStatusErrorandAPIConnectionErrornow. After the first ping, the status line is 200, so a later failure comes only as an error frame.
Costs to decide
- After a ping, LiteLLM cannot send its
x-litellm-*headers. Thenextract_served_byandextract_served_model(src/devops_cli/ai/client/network.py) return None, and fix(ai): a hosted gateway call is priced at the deployment model that the gateway names, not at the route name #2080 prices a hosted call from that header. Decide how to keep the served model. One option is to turn off the keepalive on hosted deployments (keepalive_seconds: 0), because they reply fast. Record the decision in the change's design. - Open WebUI streams through the same gateway, so it gets the pings too. Make sure that it ignores SSE comments.
- Out of scope: the
ollamaprovider throughollama.example.comhas the same 125 s limit, and Ollama sends no keepalive. No task in the default configuration uses it.
Options considered and not taken
- WebSocket (Realtime API, or the WebSocket mode of the Responses API). The backends are Ollama (
ollama_chat), which has no realtime API, and the client uses Chat Completions. It is a large client change for the result that the SSE keepalive gives. - Turn off proxy buffering in the ingress. The ingress is Traefik, not nginx, and the gateway route has no buffering middleware. The probe shows no buffering on the path.
- Increase the Proxy Read Timeout. Only an Enterprise zone can do this.
- A DNS-only host or a LAN path to the gateway. This shows the origin and goes around the tunnel and Access. The cluster accepts external traffic only through the tunnel (
k8s/ingress/traefik-values.yaml). - Status polling with an asynchronous job API. Neither LiteLLM nor Ollama has one for chat. The build cost is high.
- Cluster Service DNS. In-cluster callers use it already. The 499 traffic comes through cloudflared, from workstation CLIs that cannot use cluster DNS.
- Stop the retry of a 524. This treats the symptom. After the fix, a slow model cannot cause a 524 on a gateway chat call, so the retry policy can stay as it is.
Acceptance criteria
- A fail-to-pass test shows that a gateway chat call reads a reply whose stream starts with
: pingcomments. The call returns the sameLLMResponsefields as a call without streaming. - A test shows that an error frame after a ping gives the same error as the HTTP status.
- The response size limit applies to a streamed reply.
- A live call through the tunnel whose first token comes after more than 125 s returns its reply. The pull request comment records the timing.
- For 24 h after the rollout, the gateway counts no 499 on
/v1/chat/completionsthat a client did not cancel itself. The pull request comment records the Prometheus result.
Related
- feat(monitoring): the ai-spend dashboard counts gateway traffic from the gateway's own series, shows failed attempts and names each caller #1668 names each gateway caller on the ai-spend dashboard. It can show which commands made the retries.
- fix(ai): a hosted gateway call is priced at the deployment model that the gateway names, not at the route name #2080 prices a hosted call from the
x-litellmserved-model header.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 27, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
The title prefix is fix and the body describes a defect where long replies are cut at 125 s.73 failed calls in 24 h waste GPU time and block long analysis prompts for all users.It unblocks the core long-reply use case and stops 5 x 125 s of wasted GPU per call.The fix enables an existing LiteLLM setting and switches the client to streaming, but the streaming path needs testing.Both deal with gateway call failures, but #1668 adds dashboard visibility while this item fixes the timeout by enabling streaming.dan-petty commentedon Oct 27, 2026
More evidence, from the spend ledger of one workstation (
.data/ai/spend.db) on 2026-10-27:analysiscalls toqwen3.8:27bthrough the tunnel failed after 125.1 to 125.8 s withfinish_reason: error.devops roadmap intakeuses theanalysistask. Two intake runs in that time had failed calls of this type, so intake is one of the callers.analysiscalls that passed in the same runs had prompts of about 4,000 tokens and took 50 to 79 s. They made 1,155 to 3,923 completion tokens, and 75 to 88 % of these were reasoning tokens (reasoning_effort: high).Thus a large prompt is not necessary for the cut. A small prompt also goes past 125 s when the model reasons for a long time. Any
devops roadmap intakerun can show the failure, so it is a simpler reproduction than step 2 in the body.fix(ai): chat calls stream their reply, and the gateway keeps the str…
chore(main): release 0.7.4 (#2377)