Skip to content

fix(k8s): ollama-48gib-slow keeps its embedding model and qwen3-coder loaded and leaves every interactive pool, so a review no longer evicts the embedder #1064

Closed

Description

@dan-petty

Problem

#1061 (PR #1062, a583d98, merged 05:57:48Z on 2026-10-03) set OLLAMA_MAX_LOADED_MODELS and OLLAMA_NUM_PARALLEL to "1" on every Ollama tier. On ollama-48gib-slow (hog, 2× Quadro P6000) that breaks RAG. The gateway still sends hog both embedding groups and five chat groups, so every chat request routed there evicts the embedding model, and every embedding evicts the chat model.

Measured read-only at 06:39Z:

  • The live state. All nine DaemonSets run MAX_LOADED=1 / NUM_PARALLEL=1 (kubectl get ds). The live gateway ConfigMap (applied 05:51:02Z) routes hog in devops-chat, devops-review, qwen3-coder:30b, gemma4:31b, qwen3.8:27b, bge-m3:latest and embeddinggemma:300m.
  • The failure. A review pinned to qwen3-coder:30b started at 06:15 (ledger rows from 10551, 06:15:56). In hog's Ollama log:
    • From 06:15:34 to 06:19:47, hog loaded a runner 10 times, alternating bge-m3 (blob sha256-daec…) and qwen3-coder (sha256-1194…). Each load was followed by loaded runners count=1. bge-m3 starts in 2.3–2.5 s; qwen3-coder takes 6.4–7.4 s warm and 26.9 s cold.
    • 124 /api/embed requests arrived between 06:15:36 and 06:19:37. 16 took over 20 s, and 6 took 31.1–40.0 s (06:19:36–37). That is longer than the client's 30 s embedding read timeout (src/devops_cli/ai/rag/embeddings.py:812).
    • No /api/embed arrived after 06:19:37, while 26 /api/chat requests kept coming until 06:32:26. That fits the run-wide RAG stop (ai/rag/investigator.py:55-62), which the first EmbeddingsError triggers [inference about the client side; the client log was not read].
  • No embedding model is used here except bge-m3. embeddinggemma:300m has had no request in any Ollama or gateway log [measured by the slow-tier plan]. At release/v0.2.25 (e3ff98c), devops-cli names it only in the gateway ConfigMap, its copy in src/devops_cli/k8s/gpu_matrix.py:745-765, the tests that mirror them, the k8s/README.md examples (:90, :115) and the fallback dimension table (config/constants.py:2107). Defaults, config docs and the knowledge base do not use it. config/defaults.py:201 defaults to qwen3-embedding:0.6b, and the owner's config uses bge-m3:latest.

Hog is worth keeping as a background tier, outside the interactive pools:

  • Its speed under fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061. Hog decodes qwen3-coder at 46.6–48.2 tok/s, against about 120 on condor (48gib-fast) and 88 on gemini (64gib-standard) [measured: llama-server print_timing, 06:16–06:17]. In the run since 06:15, its 25 calls had a median of 37.2 s, against 24.9 s on 48gib-fast (n=239) and 21.1 s on 64gib-standard (n=137) [measured: spend.db, read-only].
  • Why it leaves the pools. At NUM_PARALLEL=1, a background job on hog would sit in front of review calls in its single queue.
  • Two models fit. qwen3-coder at 1 × 128k projects 29,040 MiB (28.4 GiB) on hog, bge-m3 takes 833 MiB, and llama.cpp reports 48,535 MiB free [measured: hog log, 06:15:44].
  • Ollama checks VRAM too, not just the count. When another runner is resident and a new model's predicted size exceeds 80% of free VRAM, it evicts anyway (Ollama v0.34.4 sched.go).
    • qwen3-coder is predicted at about 25 GiB, so it should log fits alongside existing models [inference from code].
    • qwen3.8:27b was predicted at 42.1 GiB and evicted bge-m3 at 04:11:03 even under MAX_LOADED=2 [measured].
    • So only qwen3-coder (or something smaller) can share hog with the embedder. The dense models stay off it.

The ConfigMap is copied as code: get_gateway_routing_entries (src/devops_cli/k8s/gpu_matrix.py:661) returns the model_list, and tests/test_k8s_gpu_matrix.py::test_gateway_routing_entries_generation (:129) asserts that the two are equal (26 entries at e3ff98c). The owner's local edit, which comments out the two 16gib-fast embedding entries, already breaks that test and test_gateway_routes_to_provider_vram_services.

Source: .data/slow-tier-plan-20261003.md, section 3, and its verification pass. The log times above were re-read at 06:39Z.

Acceptance criteria

  • In k8s/llm/profiles/ollama-profiles.yaml, DaemonSet ollama-48gib-slow (:467-470) sets OLLAMA_MAX_LOADED_MODELS: "2" and adds OLLAMA_KEEP_ALIVE: "-1", each with a one-line comment saying why. OLLAMA_NUM_PARALLEL stays "1" on every tier. The header comment (:3-5) names the exception: ollama-48gib-slow keeps its embedding model and one background model loaded.

  • k8s/llm/gateway/configmap.yaml sends hog no interactive or review traffic. These ollama-48gib-slow deployments are deleted:

    • devops-chat's ollama_chat/qwen3.8:27b (:22-28);
    • devops-review (:99-103);
    • qwen3-coder:30b (:123-127), so the group stays an exact copy of devops-review;
    • gemma4:31b (:149-155);
    • qwen3.8:27b (:164-170).

    bge-m3:latest keeps its hog deployment and model_info.mode: embedding.

  • Both embeddinggemma:300m groups (:70-83) are deleted, and so is the 16gib-fast bge-m3:latest deployment (:55-61), so bge-m3:latest has one deployment, on hog. Nothing is left commented out.

  • A devops-background group is added, and it is the only chat group with a hog deployment:

    # Background tier: hog's only generation model; in no interactive pool.
    - model_name: devops-background
      litellm_params:
        model: ollama_chat/qwen3-coder:30b
        api_base: http://ollama-48gib-slow.llm.svc.cluster.local:11434
        timeout: 1100     # under the review client's 1,200 s read timeout, so an abandoned call frees the slot
        num_retries: 0

    It sets no max_input_tokens. LiteLLM v1.103.0 writes a deployment's top-level model_info into the cost-map entry every ollama_chat/qwen3-coder:30b deployment reads, so a window there would become the window of devops-coder, devops-reasoning, devops-review and the pinned qwen3-coder:30b group too (feat(review): per-model review quality baseline for the devops-review pool #475 keeps pinned groups windowless). The tier's OLLAMA_CONTEXT_LENGTH of 128000 is its limit.

  • router_settings.fallbacks gains - devops-review: [devops-background]. It gains no devops-chat: [devops-background] rule, and the pinned groups (qwen3-coder:30b, gpt-oss:20b) stay out of every fallback rule.

  • get_gateway_routing_entries (src/devops_cli/k8s/gpu_matrix.py:661) returns the new model_list (19 entries), and test_gateway_routing_entries_generation still asserts that they are equal.

  • tests/test_k8s_llm_gateway.py follows the manifests:

    • test_every_ollama_tier_keeps_one_model_and_serves_one_request (:369-385) expects "1" for both settings on every tier, except OLLAMA_MAX_LOADED_MODELS "2" on ollama-48gib-slow. It also reads OLLAMA_KEEP_ALIVE: "-1" on ollama-48gib-slow and unset everywhere else.
    • test_gateway_configmap_virtual_models (:112) expects devops-background, the third fallback rule and no embeddinggemma:300m.
    • test_gateway_review_pool_spans_ollama_backends (:183) and test_gateway_routes_to_provider_vram_services (:227) expect no hog deployment in the review pools and one bge-m3:latest base.
  • A new test: every non-embedding deployment whose api_base is ollama-48gib-slow belongs to devops-background, and devops-background has exactly one deployment. It fails on the current ConfigMap.

  • k8s/README.md says what devops-background is for: review path --watch, ai pipeline, ai agents and analyze --enhanced, pointed at it through environment overrides with DEVOPS_CLI_AI_MAX_RETRIES=1, and never in config.yaml. Its examples (:90, :115) name bge-m3:latest instead of embeddinggemma:300m.

  • fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061's task file is not edited. This item's task file records the hog exception.

  • The tests run offline and call no gateway, Ollama or model.

  • changelog.d/1064.md records the fix under ### Fixed. CHANGELOG.md is not edited.

  • uv run devops ci passes.

  • (person-run) Apply the profiles (kubectl apply -k k8s/llm/profiles), then the ConfigMap, then kubectl -n llm rollout restart deploy/llm-gateway. Note the time.

    • During a background job, hog's log shows fits alongside existing models and loaded runners count=2, and no predicted to exceed available memory, evicting.
    • kubectl -n llm logs ds/ollama-48gib-slow --since=15m | grep -E 'POST +"/api/(chat|embed)' shows /api/embed, plus /api/chat only while a devops-background job runs.
    • No /api/embed takes over 30 s during a generation. Record its p95; if it is over about 2 s, say so on this issue.

Key questions

  • Why not keep one model on hog? (proposed) The cap of 1 is what fails. Between 06:15:34 and 06:19:47, bge-m3 and qwen3-coder evicted each other 10 times, and six embeddings waited 31–40 s, past the client's 30 s. Embeddings then stopped while chat continued. Hog serving bge-m3 alone would also work, and the owner can do that today by removing the five chat deployments. But hog would then hold no generation model, and the two models fit together with about 18 GiB to spare. So hog keeps two: the embedder and qwen3-coder.
  • Why no failover for embeddings? (proposed) Not in this item. LiteLLM v1.103.0 ignores per-deployment timeout and num_retries on ollama/ embeddings: the Ollama embed handler posts through litellm.module_level_aclient with no per-call timeout (default request_timeout 6000 s), and _aembedding never applies a deployment's num_retries [code: LiteLLM v1.103.0 main.py, router.py and the Ollama embed handler, per the plan's verification]. A hung hog would therefore never fail over within the client's 30 s, and only fast failures (connection refused, 5xx) would. The obvious second host, gemini, serves four generation models, so MAX_LOADED=2 there would still let an embedding evict its review model. Until then, a restart of hog's Ollama pod pauses RAG. Once the RAG client fixes (fix(ai): a failing embedding model pauses rag lookups instead of ending rag for the run, and each embedding model gets its own prompts, cache keys, dimension and bounded chunks #1065) land, the review carries on without RAG.
  • Why devops-review: [devops-background] and not devops-chat: [devops-background]? (proposed) LiteLLM chains fallbacks. A devops-chat rule would also let devops-coder (compose) and devops-reasoning failures reach hog through devops-coder → devops-chat → devops-background. Fallbacks fire on errors once the group's retries fail, and a gateway timeout counts as one: the router's 1,500 s timeout outlasts the review client's 1,200 s, so a devops-review call that timed out at the gateway was already given up, and the fallback then spends hog's slot (up to 1,100 s) on a reply nobody reads. Because context_window_fallbacks is set, an oversized devops-review prompt re-raises instead of falling back, so it never reaches hog. The pinned groups get no fallback (test_a_review_model_has_a_group_of_its_review_deployments_alone, feat(review): per-model review quality baseline for the devops-review pool #475), so a review pinned to qwen3-coder:30b gets none.
  • Why timeout: 1100 and num_retries: 0? (proposed) At one slot, a call the client has abandoned still holds hog until the gateway gives up. 1,100 s is under the review client's 1,200 s read timeout (config/defaults.py:300). num_retries: 0 stops the gateway re-queuing the same work on the same slot. The client retries too: ai.max_retries is 5 in the owner's config, and _retry_chat_dispatch (ai/client/unified.py:630) re-sends after a timeout. That is why the README's recipe sets DEVOPS_CLI_AI_MAX_RETRIES=1.
  • Why KEEP_ALIVE=-1 on hog only? (proposed) The gateway sends hog only two models, so nothing needs to be unloaded there. Without it, Ollama unloads a model after 5 idle minutes and the next call pays the reload (6.4–7.4 s warm, 26.9 s cold). The gateway path sends no per-request keep_alive. A third model would evict one of the two; the embedding-model switch (feat(ai): embeddings through the llm gateway, with embedding model evaluation #481) runs ollama stop first.
  • How does this interact with the gateway health-check routing item now being built (its issue is not filed yet)? (proposed) This item owns placement: groups, weights, fallbacks, per-deployment timeout/num_retries and the hog exception. That item owns liveness. It must not probe devops-background: the group has one deployment, so a probe queues behind real work at NUM_PARALLEL=1 and times out. It should probe at most the one model each Ollama host keeps loaded, because on Ollama a chat probe loads the model it names. It should also keep model_info.mode: embedding on the embedding entries and ignore transient errors. Both items edit the ConfigMap, gpu_matrix.py and their tests, so whichever lands second rebases.
  • Do reviews lose capacity? (proposed) A little. Hog carried weight 1 of 16 in qwen3-coder:30b and 1 of 22 in devops-review. Its calls since 06:15 had a median of 37.2 s against 21–25 s on the other two tiers. While hawk (16gib-fast) is NotReady, the pools are condor and gemini.
  • Is this a v0.2.25 critical fix? (proposed) Yes. It fixes a regression that fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061 (a583d98) introduced in v0.2.25, which has not shipped. While hog sits in the pools, any review routed there turns RAG off for the run. It is P1, as fix(review): passing criteria leave a finding for the verifier instead of verifying it, and running the cited test counts as evidence #1043 and fix(review): the scanned-clean check invalidates only claims about a dependency's own advisories #1044 were.

Depends on: none.
Order: lands before the v0.2.25 cut. The health-check routing item edits the same ConfigMap, gpu_matrix.py and tests; whichever lands second rebases. #1060 (backlog) and #795 (v0.2.29) also edit ollama-profiles.yaml; this item lands first.
Related:

Activity

  1. added this to the v0.2.25 milestone on Oct 3, 2026
  2. added
    type/bug
    scope/k8s
    priority/p1-high
    on Oct 3, 2026
  3. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Closed by #1071, merged into release/v0.2.25.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  4. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Applied and checked (2026-10-03 14:24Z). kubectl apply -k k8s/llm/profiles, kubectl apply -f k8s/llm/gateway/configmap.yaml, kubectl -n llm rollout restart deploy/llm-gateway at 14:24:23Z, after a kubectl diff that showed only this item's changes (the background tier's OLLAMA_MAX_LOADED_MODELS 1 → 2 and OLLAMA_KEEP_ALIVE "-1", and the gateway ConfigMap). Both rollouts completed; no other tier's pods restarted.

    • Gateway: started clean at 14:24:28Z and lists devops-background.
    • Background tier (ollama-48gib-slow), exercised directly through a port-forward (no gateway key needed): one bge-m3:latest embed (3.9 s, cold load), one qwen3-coder:30b generation (7.1 s, cold load), then three embeds at 22–40 ms. The log shows llama-server model fits alongside existing models (predicted 25.1 GiB, num_ctx 128000) and no predicted to exceed available memory, evicting. /api/ps lists both models loaded, keep-alive unbounded.
    • Before this change the same tier swapped the two models 9 times in 4 minutes and six embeds timed out at 30 s, which switched RAG off for the run (review session 20261003-060647).
    • Through the gateway (14:42Z): a pod in llm with the key from llm-gateway-secrets via secretKeyRef sent one devops-background chat to the in-cluster gateway URL: HTTP 200 in 0.6 s, reply "OK", and the background tier logged the matching POST /api/chat (83 ms, model already loaded).
    • Not checked here: embed latency while a long generation runs (each model has its own runner; they share the GPU).
  5. added a commit that references this issue on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/k8stype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions