Skip to content

feat(news-creator): switchable Ollama / llama.cpp server backend with an explicit LLM_BACKEND (ADR-001066) - #440

Merged
Kaikei-e merged 9 commits into
mainfrom
feat/llamacpp-inference-backend
Dec 3, 2026
Merged

Kaikei-e merged 9 commits into
mainfrom
feat/llamacpp-inference-backend

Conversation

@Kaikei-e

@Kaikei-e Kaikei-e commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Summary

ADR-001066: news-creator can now send its generation traffic to either Ollama or llama.cpp llama-server, selected explicitly with LLM_BACKEND. Its inbound Ollama-shaped API, the four callers and their Pact contracts are unchanged.

  • Backend selection without an implicit default. LLM_BACKEND accepts ollama or llamacpp; unset or any other value fails startup.
    • The host key is NEWS_CREATOR_LLM_BACKEND, declared "ollama" in deploy/desired-env.lkal and listed in required_env.
    • It is not named LLM_BACKEND on the host because rag-orchestrator already reads that name, with the values ollama|eino.
  • Startup upstream check. news-creator verifies at startup that the upstream server is the declared kind and fails loudly on a mismatch. llama-server must report owned_by == "llamacpp" on /v1/models; Ollama must answer /api/tags with 200.
  • llama.cpp drivers.
    • Raw prompts go verbatim to /v1/completions; chat goes to /v1/chat/completions. SSE is translated back to the Ollama shape, with token counts and nanosecond durations from usage / timings.
    • Context overflow raises an explicit error instead of being silently truncated.
    • When thinking is off, the chat request also sends thinking_budget_tokens: 0. Against a real llama-server with the production Gemma 4 GGUF, a json_schema chat request otherwise spends max_tokens in a thought channel and returns empty content.
  • llama-server image and overlay.
    • news-creator/Dockerfile.llamacpp pins build b12808 for both cuda and vulkan, and the flavor build arg is required.
    • entrypoint-llamacpp.sh downloads the GGUF and MTP draft with the same sha256 pins as ADR-000981. It takes exactly three required inputs; every other server argument is a fixed constant.
    • compose/compose.llamacpp-cuda.yaml is an opt-in overlay and is not included in compose/compose.yaml.
  • generation-proxy additionally allows POST /v1/completions, POST /v1/chat/completions and GET /v1/models. Its /health stays local.
  • Benchmark script. scripts/benchmark_real_articles.py runs both backends through news-creator's own summary prompt path and drivers. The news-creator runtime settings must be given explicitly, and a dry-run mode prints the parameters that decide whether Ollama rebuilds its runner.

Benchmark (same GPU, same GGUF and MTP draft, 24 recent articles)

Metric Ollama llama-server --flash-attn on
TTFT median 0.297 s 0.178 s (−40%)
Prefill tok/s 5221 8495 (+63%)
Decode tok/s 106.8 106.8 (±0%)
End-to-end per output token 10.58 ms 10.08 ms (−4.7%)
MTP draft acceptance 30.1% 29.4%

With --flash-attn auto, llama-server decoded 5.7% slower, so the entrypoint forces on. Whether production switches to llamacpp on NVIDIA is left to a separate ADR; production stays on ollama.

Deploy note

NEWS_CREATOR_LLM_BACKEND is a new required host env key. Reconcile it onto the production host with kisage before this merges. Otherwise compose refuses to render and the deploy does not start.

Test plan

  • cd news-creator/app && uv run pytest: 1538 passed, 1 skipped.
  • go test ./... in docker/inference-proxy.
  • ./scripts/lint/run.sh news-creator/app, compose, docker/inference-proxy and repo.
  • check_layers.sh --changed, docdag validate --immutable-since origin/main, alt-harness adr-gate --base origin/main.
  • Live wire check of the drivers against a real llama-server:
    • generate, stream, schema chat, tools, chat stream and context overflow;
    • the startup kind check, both matching and mismatched, against llama-server and Ollama.
  • docker compose ... config fails with NEWS_CREATOR_LLM_BACKEND unset and renders with it set. The cuda overlay renders with LLM_BACKEND=llamacpp on news-creator.

🤖 Generated with Claude Code

Kaikei-e and others added 9 commits December 3, 2026 19:56
…wire mapping, LLM_BACKEND selection and the OpenAI-compatible proxy routes (ADR-001066)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n the deep health expectation with the existing pass/fail shape (ADR-001066)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… LLM_BACKEND, a llama-server image and an opt-in CUDA overlay (ADR-001066)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…that the upstream server kind matches it, and a zero reasoning budget whenever llama.cpp chat thinking is off (ADR-001066)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m server kind at startup, zero the llama.cpp reasoning budget when thinking is off, and declare the host key as NEWS_CREATOR_LLM_BACKEND (ADR-001066)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ma's physical batch size of 1024 (ADR-001066)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… benchmark both backends through news-creator's own prompt path with explicit runtime settings (ADR-001066)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ama-server entrypoint (ADR-001066)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pt ADR-001066 with the Ollama vs llama-server benchmark results

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-03T13:06:05.378250Z
We couldn’t complete this review. Comment @codex review to try again.
8bf8f74 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Kaikei-e
Kaikei-e merged commit 3b471aa into main Dec 3, 2026
45 checks passed
@Kaikei-e
Kaikei-e deleted the feat/llamacpp-inference-backend branch December 3, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant