feat(runner): report each model's context length, and honour the num_ctx asked for #60
feat/report-model-context-length
into main
Companion to fangorn/anvil#252, which consumes this.
Ollama defaults num_ctx to 4096 whatever the model can actually hold, and an oversized prompt is not an error there — it silently drops the head of the context, taking the system prompt and the tool definitions with it. The model then answers something it was never asked, intermittently, depending on how long the conversation has got.
Anvil can only size a request correctly if it knows the model’s real window, and only this host can answer that: the same tag pulled at a different quantization on a different machine is a different window.
Report it. The heartbeat’s inference_models entries gain context_length, read from /api/show’s architecture-prefixed <arch>.context_length. /api/tags does not carry it, so this is one extra request per model — cached by digest across heartbeats and bounded to four new lookups per beat, so a host that just pulled twenty models spreads the cost over several beats instead of stalling one. A model whose length cannot be determined is reported without the key: the server treats absent as unknown and sizes conservatively.
Apply it. num_ctx in an inference request’s options is passed through to Ollama. A request without it (an older server) keeps Ollama’s default, exactly as before.
6 new unit tests over the /api/show parsing. cargo test 222 passing, cargo clippy -- -D warnings and cargo fmt --check clean.