Repository navigation
Description
Problem
Under Ollama, a fifth to a third of qwen3-coder calls through the gateway took about 190–215 s, or a multiple of that, whatever their size. They accounted for most of a review's model time.
Measured in S9 (20261003-021501, release/v0.2.25, 356 files, 371 calls, 2,152.7 s; spend.db read-only):
| Tier | Calls | Calls of about 190 s or more | Share of call-seconds | Median of the others |
|---|---|---|---|---|
| 48gib-fast | 189 | 35 (19%) | 80% | 8.5 s |
| 64gib-standard | 122 | 28 (23%) | 81% | 13.6 s |
| 48gib-slow | 23 | 7 (30%) | 81% | 22.8 s |
- The vLLM era had none: session
20260928-040906made 980 calls with none at 185 s or more. - The stall showed on every tier and added roughly the same ~200 s whatever the call's size. It survived fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061 (one slot per tier).
- fix(ai): the spend ledger records every attempt the gateway failed, including the retry transport's, and its gap to the gateway's count is measured first #1019's S10 comment matched backend attempts to ledger rows: second attempts started 184.9–186.2 s after the first ones, and qwen3-coder completed one request twice, the first completion never delivered.
The measurement this item first asked for has been made (the ten-run loop S12–S21 of 2026-10-03, read from the gateway and Ollama logs):
- The ~190 s stall is the ~125 s cut that the Cloudflare edge applies to a long-held request, plus a ~60 s resend by the router or the client.
- Verification wall time follows the slowest chat (ρ 0.90).
- Every review call took the edge path (5,010/5,010 rows on 2026-10-03), although the gateway is reachable on the LAN through its NodePort.
Routing makes the queue wait. The router-wide routing_strategy: simple-shuffle with num_retries: 5 (k8s/llm/gateway/configmap.yaml:171-172) spreads devops-review over three one-slot tiers with weights 9/6/6 (configmap.yaml:79-94). With weighted shuffle, three in-flight requests land on three different tiers only 21% of the time, so requests queue behind each other on one Ollama while another tier idles. The client allows 16 review requests in flight (config/defaults.py:433), and /model/info reports no slot count (ai/gateway_tune.py:116-132). Ollama queues up to 512 requests by default, so the gateway's 429s never fire. Queue wait was 82–87.5% of Ollama time in S11 and the loop.
This item is phase P0 of the evidence-first review (#1137). Its body was rewritten on 2026-10-03 so the acceptance criteria stay current; the title is unchanged.
Acceptance criteria
-
devops ai gateway connectsaves the gateway's NodePort URL fromnode_port_address(k8s/node_port.py), probing only/health/livelinessand/model/info, so review calls take the LAN path instead of the edge. - The gateway sets
cancel_on_disconnect: true, and review requests carrynum_retries: 0, so a cut request is neither finished unseen nor resent behind the client's back. - The router-wide
routing_strategychanges fromsimple-shuffletoleast-busy(configmap.yaml:171). Simulated queue-wait share at a cap of 3 is 39% under shuffle and 0% under least-busy [estimate]. - The client cap comes from a slots table. Review in-flight requests are capped at the sum of slots in a config table (distinct
api_base×OLLAMA_NUM_PARALLEL; 3 for devops-review today). This replaces the constant 16 (config/defaults.py:433), because/model/infocarries no slot count. - A configmap test pins
cancel_on_disconnect, the routing strategy and the review group's settings, in the style oftests/test_k8s_llm_gateway.py. - A recorded measurement procedure, fixed LogQL and PromQL queries for edge cuts, backend chats and queue-wait share, is stored in the task file. A person-run step saves its output into the review session directory.
- (person-run, other clients quiesced with
devops ai quiesce) On one fixed-input review: 0 edge cuts; backend chats equal ledger attempts (needs fix(ai): the spend ledger records every attempt the gateway failed, including the retry transport's, and its gap to the gateway's count is measured first #1019); queue-wait share at most 10%; LAN path 100%. - Tests run offline, call no gateway, Ollama or model, and each runs in under 1 s.
-
changelog.d/1069.mdrecords the fix under### Fixed.CHANGELOG.mdis not edited. -
uv run devops cipasses.
Key questions
- Does least-busy change other groups? (proposed) Yes, router-wide. Single-deployment groups are unaffected, and multi-deployment groups lose their throughput weights, which the client cap makes harmless. The person-run checks this.
- Is this fix(ai): the spend ledger records every attempt the gateway failed, including the retry transport's, and its gap to the gateway's count is measured first #1019? (proposed) No, but they share a measurement. fix(ai): the spend ledger records every attempt the gateway failed, including the retry transport's, and its gap to the gateway's count is measured first #1019 makes every failed attempt visible in the ledger; this item removes the cut and the resend. The "backend chats = ledger attempts" check needs fix(ai): the spend ledger records every attempt the gateway failed, including the retry transport's, and its gap to the gateway's count is measured first #1019.
- Does the gateway health-check routing item (being built, not yet filed) change this? (proposed) It may change router settings (
allowed_fails, cooldowns). Whichever lands second records the other's settings in the configmap test. - Why not route through the gateway alone, without a client cap? (proposed) The gateway cannot see that two models on one tier share one slot, and its 429s put a deployment into cooldown. The client cap from the slots table holds until the review's job queue (phase P3 of feat(review): evidence-first code review — tools find, version-pinned facts ground, models explain and plan, fixes are re-checked #1137) schedules per slot.
Strategic alignment
- Parent: feat(review): evidence-first code review — tools find, version-pinned facts ground, models explain and plan, fixes are re-checked #1137 (phase P0). P1.
- Value / Effort: High / Medium. The stall was the largest share of review model time in S9 and the loop, larger than any model choice.
- Depends on: none. fix(ai): the spend ledger records every attempt the gateway failed, including the retry transport's, and its gap to the gateway's count is measured first #1019 for the person-run attempt count.
- Related: fix(ai): the spend ledger records every attempt the gateway failed, including the retry transport's, and its gap to the gateway's count is measured first #1019 (attempts the ledger misses), fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061 (one slot per tier), fix(ai): client timeouts, streamed response limits, model-resolution errors and dead round-robin state #960 (client timeouts, v0.2.25), feat(ai): llm gateway tuning cost from real traffic and no-load capacity estimates #477 (gateway cost), feat(ai): ollama model residency per-pod model budget, keep-alive, ms/token #598 (Ollama residency), the gateway health-check routing item (unfiled).
Amended 2026-10-04: the client retries only what can succeed, and only the call that failed
Measured during an owner-run evaluation on 2026-10-04 (.data/ai-eval/iter-20261004T024327Z; review sessions 20261004-024421 to 20261004-033712):
-
A 400 re-ran a whole page. In the slowest review (991.7 s total; the typical review took about 545 s), one file got an HTTP 400 and a retry. Its persona stage took 748 s, against 306 s and 340 s in the two runs before it. The retry loop counts every
AIClientErroras temporary, a 4xx included (ai/review/pipeline.py:1638-1644). One failure therefore re-sends all five persona calls for the page: 74 calls instead of 70 in that run. -
One call stalled before it reached the gateway. A
qwen3-codercall took 432.8 s (.data/ai/spend.db: finish_reason stop, 6,522 prompt and 94 completion tokens). From 03:42:33 to 03:49:16 the gateway and every Ollama tier were idle: in-flight requests stayed at their idle value, and no completion was recorded. The time was lost between the client and the gateway, on the edge path this item moves off. No client record shows the attempt, its status or the 400 body; per-attempt records are fix(ai): the spend ledger records every attempt the gateway failed, including the retry transport's, and its gap to the gateway's count is measured first #1019. -
The edge path cut chat requests too. In the chat benchmark arm, the client ran one worker, yet gateway in-flight requests rose from 4 to 10 over 45 minutes, with 9 completions in 40 minutes.
devops-chatgenerations on theollama-16gibtier ran 16–25 minutes each, one ending in a 500 at 25 minutes, and every one was cut at the edge after about 125 s and resent. The output-token cap that stops those runaway generations belongs to fix(ai): sampling settings reach the model or are refused, review sessions record them, and the reply cache key includes them #1070. This item's LAN path,cancel_on_disconnectand least-busy routing cover the pile-up. -
Only retryable statuses are retried. The review client retries 408, 429 and 5xx replies and connection errors. A 4xx reply, a 400 included, is not retried: it is reported with its status and the start of its body. Test: a fake transport answers 400 once; the persona call fails without a second attempt, and the report shows the status.
-
A failed persona call retries alone. A retry re-sends only the persona call that failed, never the page's other persona calls. Test: with five personas on one page and one transient 503, the fake transport sees six calls, not ten.
-
The person-run measurement above also counts persona calls per page, and that count equals the number of personas when no call failed.
-
One retry layer. Today a chat call can be sent up to 25 times.
_retry_chat_dispatch(ai/client/unified.py:610-640) retries any exception up toDEFAULT_AI_MAX_RETRIES+ 1 = 5 times. Each of those attempts goes through the tenacity retry transport (ai/client/base.py:53-60), which retries up to 5 times on its own. Every send can wait out the 3,600 s read timeout. In the chat arm on 2026-10-04, this kept one benchmark task resending into a backlog for over 45 minutes. Exactly one layer retries, with the status rules above. Test: a fake transport that always answers 503 sees exactlymax_retries + 1sends per call. -
Abandoned connections are closed. After the edge cut its requests, the benchmark process still held two sockets in CLOSE-WAIT to the gateway. A cancelled or failed attempt closes its connection. Test: after a cut request, the client's connection pool holds no closed-by-peer connection.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty-bot commentedon Oct 6, 2026
Moved to v0.2.28: v0.2.28 started with fewer than its 12 items and was topped up to 12 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)
fix(ai): review calls through the gateway no longer stall on ollama (#…
feat(release): v0.2.28 (#1283)
fix(ai): gateway requests stay within the backend slot count in every…
feat(release): v0.2.37 (#1720)