Skip to content

fix(ai): sampling settings reach the model or are refused, review sessions record them, and the reply cache key includes them #1070

Description

@dan-petty

Problem

Several model settings either never reach the model or reach it without a trace, and a review cannot tell which. Lines are at release/v0.2.25 (e3ff98c).

1. num_ctx changes page size on the gateway path but never reaches the server.

  • num_ctx is a field of AIConfig and AITaskOverride (src/devops_cli/config/settings.py:403, :436).
  • The native Ollama client sends it (ai/client/ollama.py:308-312). The gateway and OpenAI-compatible payload carries only max_tokens, temperature and top_p (ai/client/openai.py:66-79).
  • get_context_window prefers num_ctx over context_window (ai/client/unified.py:308-316), and the review sizes pages from it (ai/review/pipeline.py:2665).
  • So setting ai.tasks.analysis.num_ctx silently changes the page size, and the server still sizes its KV cache from OLLAMA_CONTEXT_LENGTH × OLLAMA_NUM_PARALLEL. On 2026-10-03 that sizing (-c 512000 -np 4 on the 48 GiB tiers) kept gemma4:31b from loading on condor and hog (cudaMalloc ... out of memory, failed to create MTP context) [measured: Ollama logs, 05:30–05:46]. fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061 has since cut the multiplier to 1.

2. Six sampling and serving keys are dropped without a word. top_k, min_p, presence_penalty, repeat_penalty, think and keep_alive are not fields of AIConfig or AITaskOverride. Pydantic ignores unknown keys by default, so ai.tasks.analysis.top_k: 20 validates and does nothing [measured offline by the model-choice evaluation]. These values can only come from a gateway deployment's litellm_params or from the Ollama tag's params.

3. Streamed devops ai chat sends no sampling at all. _apply_standard_params returns before it sets temperature or top_p when the call streams (openai.py:72-73). devops ai chat streams whenever tools are off (commands/ai.py:1090, :941). The configured chat sampling reaches only non-streamed calls.

4. Sampling cannot be left to the model. AIConfig.temperature and top_p are plain floats (settings.py:433-434; defaults 0.1 and 0.95, config/defaults.py:70-71), and a task override applies only values that are set (settings.py:494-511). Every non-reasoning request therefore overrides the Ollama tag's values with something. The tags already carry the model cards' values: qwen3-coder:30b's params are temperature 0.7, top_p 0.8, top_k 20 and repeat_penalty 1.05 [sourced: registry.ollama.ai params blob for qwen3-coder:30b; https://huggingface.co/Qwen/Qwen3-Coder-30B-A3B-Instruct].

5. Review sessions do not record sampling. review_setup records each task's temperature and top_p (ai/run_store.py:140-161), but only benchmark, corpus-score and sample-validation runs call it (commands/review.py:1430, :1783, :2021). Branch and path reviews write no sampling to profile.json. The qwen3-coder baseline (S9 20261003-021501, S10 20261003-034353, and the R2 recall runs) ran before the owner changed analysis and verification to 0.7 / 0.8 (config.yaml edited at 04:58Z). No record says which values those runs used, so the effect of the change cannot be measured from the sessions.

6. The reply cache key leaves out sampling. LLMResponseCache.generate_key hashes the provider, model, system prompt, messages and options (ai/response_cache.py:166-197). The client passes only {"enable_thinking": ...} as options (unified.py:707-726). A review after a sampling change, run without --no-cache, replays replies made with the old values for every unchanged page, for the cache's 7-day TTL. The model-choice evaluation had to tell the owner to run the first review after the change with --no-cache.

Not in this item:

Source: .data/model-choice-20261003.md, section 3 ("What the pipeline can't pass today"), and its verification pass, which corrected num_ctx (a declared field, not dropped). The lines were re-read at e3ff98c.

Acceptance criteria

  • num_ctx is refused where it cannot be sent. A client for the gateway provider or an OpenAI-compatible provider raises a configuration error naming the task when its resolved config sets num_ctx. The error says that the server's context comes from the tier's OLLAMA_CONTEXT_LENGTH, and that context_window sizes pages. The native Ollama client still sends it. A test covers both providers.
  • Unknown keys under ai and ai.tasks.<task> fail validation. The error names the key. For the six keys above, it also says where they belong: a gateway deployment's litellm_params or the Ollama tag. A test loads ai.tasks.analysis.top_k: 20 and gets the error. It fails on the current code, which accepts it.
  • Streamed calls send the same sampling as unstreamed ones. _build_compat_payload(..., stream=True) includes temperature and top_p. A test pins it and fails on the current code.
  • Sampling can be left to the model. AIConfig and AITaskOverride gain use_model_sampling: bool | None, inherited like the other overrides. When it is true, no request for that task carries temperature or top_p, on either the gateway or the native Ollama path. Tests cover a task that sets it and a task that inherits it.
  • Every review session records its sampling. Branch, path and PR reviews write review_setup()'s models and sampling into profile.json, plus reasoning_effort, the reply cap and use_model_sampling for each task (analysis, verification and compose). A value the client does not send is written as null. A test runs a path review with a fake client and reads them back.
  • The reply cache key includes what the client sends. The cache options carry the request's temperature, top_p, reasoning_effort and reply cap, beside enable_thinking. A test makes two calls with the same messages and temperatures 0.7 and 1.0, and gets two keys and two model calls. It fails on the current code.
  • docs/CONFIGURATION.md and the knowledge base say which settings reach the model on which provider, and that per-model sampling (top_k, repeat_penalty, presence_penalty, min_p, think) lives in the gateway deployment or the Ollama tag.
  • The tests run offline, call no gateway, Ollama or model, and each runs in under 1 s.
  • uv run devops ci passes.
  • (person-run) Run one pinned review after the change. Its profile.json shows 0.7 / 0.8 for analysis and verification. A second review of the same commit with temperature 1.0 makes model calls for every page instead of replaying the first review's replies.

Key questions

  • Why not add top_k, min_p, presence_penalty and repeat_penalty as config fields? (proposed) They belong to a model, and a task can route to a group that mixes models: devops-review serves qwen3-coder and gpt-oss. A gateway deployment's litellm_params is per model and per host, and the Ollama tags already carry the cards' values. Refusing the keys stops the silent drop without adding a second place to set them.
  • Why refuse num_ctx on the gateway path instead of sending it? (proposed) A request whose num_ctx differs from the loaded runner's makes Ollama reload the model [inference from Ollama's scheduler; to confirm in the PR from its source]. With one model and one slot per tier (fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061), every task that sent its own value would reload the tier's model in front of the queue. Server context is set per tier in k8s/llm/profiles/ollama-profiles.yaml.
  • Will refusing unknown keys break existing configs? (proposed) It may, which is the point before 1.0. The owner's config.yaml has one unknown key under ai, lightllm_url, which nothing reads; it would have to go. Strictness for the rest of Settings is refactor(config): a settings field is the one declaration, and the option, env and config-show registries become views of it #1000's (one declaration per setting).
  • Why use_model_sampling rather than allowing temperature: null? (proposed) In a task override, null already means "inherit from ai", so it cannot also mean "send nothing". A separate flag keeps both meanings.
  • Should the cache key include the served model? (proposed) No. fix(review): a group-analysis reply that fails its checks is neither cached nor served #1013 already answers that, and the client does not know the served model before the call.
  • Should the session record what the gateway applied (tag params, think)? (proposed) No. The client records what it sent. What the gateway or the tag adds is visible only on the server side.
  • Why P2? (proposed) The gaps cost measurement more than quality today. qwen3-coder's tag already carries its card's top_k and repeat_penalty, the owner sets temperature and top_p per task, and fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061 fixed the server's context sizing. The cache replay and the missing sampling record make model comparisons untrustworthy until they are fixed.

Depends on: none.
Order:

Related:

Update 2026-10-08: refinement

The six gaps stand.

Activity

  1. added
    type/bug
    scope/ai
    scope/config
    priority/p2-medium
    on Oct 3, 2026
  2. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Review redesign (#1137, 2026-10-03): this item is a child kept whole. It serves #1147 (sampling recorded for each explanation job) and phase P3's job keys (P3-7). #479's per-deployment reasoning_effort and max_tokens move here or to #888 before #479 closes.

  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Addition from the 2026-10-08 client-library audit (checked at release/v0.2.29, 05e9388).

    The native Ollama streamed request, _ollama_stream_request (ai/client/ollama.py:451-461), sends no options (num_ctx, num_predict, temperature, top_p) and no trace-context headers. The unstreamed request sends all of them (:287-304). So a streamed Ollama call drops the configured sampling, the context size and the reply cap set by limit_completion_tokens.

    This item's streaming criterion covers only _build_compat_payload(stream=True).

    Proposed criterion: streamed and unstreamed native Ollama requests carry the same options and the same trace headers. A test records both requests through an httpx2 MockTransport and fails on the current code.

    Key question for the owner: should streamed calls send num_ctx when the server sets OLLAMA_CONTEXT_LENGTH?

    • Proposed: yes, the same as unstreamed calls, following this item's rule that the native Ollama client sends it.

    Found by the 2026-10-08 client-library audit.

  4. added a commit that references this issue on Oct 24, 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/p2-mediumscope/aiscope/configtype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions