LAN router for a 3-machine llama.cpp cluster: one OpenAI-compatible /v1 endpoint, on-demand bazzite node, instant game preemption
  • Go 90.4%
  • Jinja 8.8%
  • Makefile 0.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Troed Sångberg 70b113e9a0 fix(proxy): keep the flavor when a stale observation meets a stopped node
serve-if-live treated any observed model as live, even after the node's
server had stopped (idle stop, bazinga restart). The next request then
asked bazinga for a profile-less start; bazinga resolves an empty profile
to the profile named "default", which flavored configs do not define, and
rejects it with 400 "unknown profile" in a millisecond and without a log
line. conduct marked the node unhealthy, cooled it down and answered
"no healthy node for model" - indistinguishable from an unreachable node.

flavorForEnsure now takes the fresh health read the caller already made
(the Resolve reason, or resolveNext's Health) and only serves a model as
is when the node is up; a stopped node always gets the model's flavor.

Also log the discarded EnsureReady error, which is what made this
invisible for days.

TestStaleObservationDoesNotSkipFlavorOnColdStart reproduces the sequence
(observe live, server stops, request) against a fake that mirrors
bazinga's 400 for an empty profile.
2026-11-13 16:57:52 +00:00
cmd/conduct feat(orchestrator): profile-aware EnsureReady with drain margin 2026-11-08 08:02:29 +00:00
deploy chore(hygiene): replace internal hostnames/paths with placeholders; add public repo hygiene notes 2026-09-06 11:36:28 +02:00
docs/superpowers docs: add model-flavor switching implementation plan 2026-11-07 19:23:16 +00:00
internal fix(proxy): keep the flavor when a stale observation meets a stopped node 2026-11-13 16:57:52 +00:00
.gitignore chore(hygiene): replace internal hostnames/paths with placeholders; add public repo hygiene notes 2026-09-06 11:36:28 +02:00
AGENTS.md chore: add conduct.png and the BRIEF.md prerequisite to AGENTS.md 2026-10-17 07:37:32 +00:00
conduct.png chore: add conduct.png and the BRIEF.md prerequisite to AGENTS.md 2026-10-17 07:37:32 +00:00
go.mod feat: conduct scaffold with healthz, Makefile and systemd unit 2026-09-05 13:47:25 +02:00
Makefile chore(hygiene): replace internal hostnames/paths with placeholders; add public repo hygiene notes 2026-09-06 11:36:28 +02:00
README.md docs: correct the flavor start-timeout chain, add cutover note 2026-11-08 10:28:44 +00:00
SECURITY.md feat: complete conduct service with wiring, README and SECURITY 2026-09-05 14:22:30 +02:00

conduct

A small LAN router for a 3-machine llama.cpp cluster. Exposes one OpenAI-compatible endpoint (http://<server-host>:8100/v1) that routes each request to the right node by model name, starts the gaming PC's llama-server on demand, and skips it instantly when someone games.

Config

~/.config/conduct/config.json (created on first run):

{
  "listen": ":8100",
  "nodes": {
    "ws-router":   {"type":"static","baseURL":"http://<workstation>:11434",
                    "discover":true,"discoverSources":["preset"]},
    "headless-gemma": {"type":"static","baseURL":"http://localhost:11434"},
    "bazzite-gemma":  {"type":"bazinga","baseURL":"http://<gaming-box-host>:8089","llmURL":"http://<gaming-box-host>:11434"}
  },
  "models": {
    "gemma-4-12b": ["bazzite-gemma","headless-gemma"],
    "qwen3.8-27b": ["ws-router"]
  },
  "idleStopSeconds": 600,
  "startTimeoutSec": 90
}

bazinga nodes are driven through the bazinga API on the gaming box (start on demand, drained stop after idle, instant skip while a game or Remote Play session is active).

A bazinga node can also declare flavors: named server profiles on that node — different builds, each serving its own models — with one of them up at a time. conduct swaps them on request: when a request names a model the node's active flavor does not serve, conduct drives bazinga's drain-stop of the incumbent and start of the owning profile (decision log: flavor-cold-start, flavor-swap basalt->llama). A model already loaded on the node is served as is.

"ws-router": {"type":"bazinga","baseURL":"http://<ws-host>:8089",
  "llmURL":"http://<ws-host>:9931","idleStop":false,
  "imageGatewayURL":"http://<ws-host>:8189","discover":true,
  "flavors":{"basalt":{"models":["<model-a>"],"startTimeoutSec":300},
             "llama":{"models":["<model-b>"]}}}

A flavor's models are the client-facing names — the names the models map uses — and they name their node: routing and /v1/models follow the flavor table with no models entry (a models entry still sets priority order), and the declared models are listed even while the node is cold; with discover: true the loaded flavor's live listing merges in without duplicates. Per-flavor startTimeoutSec replaces the global start timeout for that flavor's cold start and swaps — but it is only how long conduct waits before giving up. What bounds the load itself, killing a server that is too slow to come up, is bazinga's per-profile startTimeoutSeconds, configured on the bazinga side (its README documents profiles). Set the flavor's value to match bazinga's: conduct adds a 60 s drain margin on top of it when waiting for a swap (drain-stop of the incumbent first), a margin sized for bazinga's default drain windows (~20 s grace, ~45 s hard deadline) — so bazinga gives up on a slow load first and conduct never abandons a start it would otherwise have won.

Deploying bazinga on the workstation reaps-orphan-cold-reloads whatever server is currently up (it adopts the process, then reaps it): expect one cold reload at cutover.

idleStop: false opts a node out of conduct's idle shutdown — the workstation's server stays up; otherwise idle stop is on. imageGatewayURL is allowed on bazinga nodes as on static ones. Whether bazinga preempts the server for a running game (gamePreemption) is configured on the bazinga side — bazinga's docs are the authority there.

A node that serves a model under a different name than the config key gets a per-node modelAliases map: incoming name → name that node actually serves. conduct rewrites the model field of the forwarded request (and its /slots probes) for that node only; clients always use the models key, and /v1/models lists the model back under that key.

/v1/models also reports, per model, the token window the cluster will really serve: the node's live n_ctx once the model is loaded, falling back to the --ctx-size it launches with. Nodes otherwise advertise the model's native (training) window, which a preset-sized --ctx-size does not match.

Besides the models declared above, /v1/models and routing also accept the models a node with "discover": true advertises (see below).

"nodes": {
  "ws-router": {"type":"static","baseURL":"http://<workstation>:11434",
                "modelAliases": {"qwen3.8-27b": "Qwen3.8-27B-IQ4"}}
}

Model preset

Every llama-server node serves gemma-4-12b in router mode from one canonical preset: deploy/models-preset.ini in this repo. It holds the full parameter set for the model (context size, cache quants, chat template, sampling, reasoning off) plus the absolute model/mmproj/template paths under the uniform model dir /var/mnt/d6174ce5-701c-4276-aeb2-58f01a3930ce/llm-models (a real mount on the gaming box, a symlink to ~/llm-models on the headless server). Same model, same parameters, whichever node answers.

The serve command is identical on both nodes:

llama-server --models-dir /var/mnt/d6174…/llm-models \
    --models-preset /var/mnt/d6174…/llm-models/models-preset.ini \
    --models-max 1 --no-webui --host 0.0.0.0 --port 11434

Replicate after editing the preset (the gaming PC's copy lives in the same model dir, wrapped in its distrobox):

make sync-preset

Adding a model

discoverSources selects which of llama.cpp's model sources a discoverable node may contribute: preset (the default), models_dir (any .gguf in the node's --models-dir) and cache (HF-cache downloads). Preset-only is the default because a preset is the only source that carries tuned serving parameters — a bare .gguf is advertised with llama.cpp's defaults and the model's native context window. Adding "discoverSources":["preset","models_dir"] makes loose GGUFs join the cluster too; an unrecognised value fails the config load. Entries a node advertises without a source field are kept, so a server that omits the label cannot silently un-discover a whole node.

Add a preset section to the node that should serve it and tell that node to re-read its preset — no conduct config edit and no conduct restart:

# on the workstation, add a [section] to ~/llm-models/models-preset.ini
curl 'http://127.0.0.1:<node-port>/models?reload=1'
# in OpenCode: /models-discovery-refresh

Reloading the node is your step, not conduct's: ?reload=1 can unload a running model whose preset changed, and on a node with a large model directory it is slow enough that the listing times out. Conduct only reads the list the node already advertises.

On the workstation's flavor node the re-list step is the same: conduct never sends ?reload=1, and a request for a model whose flavor is already active starts nothing, so a preset section added while that flavor's server is up stays invisible to it until you re-list. And here the "no conduct config edit" above does not apply: a model you want served while the node is cold must also be declared in that flavor's models list.

Only a node with "discover": true contributes models; the pinned headless node and the gaming node stay off unless opted in, so a discovered model can never displace the always-loaded Gemma. Declared models entries and modelAliases always win: they keep their priority order, client-facing name and aliases, and a discovered id that collides with one is ignored.

A model added as a bare .gguf (no preset section) is not part of the cluster — it is only discovered when the node's discoverSources says so.

The workstation node runs --models-max 1: two clients on two different models will swap the model between requests, and each swap pays a load delay. Conduct probes with autoload=false, so listing or resolving a model never loads or evicts one — only the client's own request may.

Client

Point any OpenAI client at http://<server-host>:8100/v1. Model ids are the keys of models, plus the ids a discover: true node advertises — every node serves them under the same --alias, unless the node needs a different name, in which case modelAliases maps it per node.

Routing prefers an idle node: when the primary's slot is busy the next node takes the request (this is what allows two concurrent users of one model), and only when every node is busy does a request queue. Requests touching the gaming box keep its idle timer fresh so it is not stopped mid-conversation.

Deploy

make deploy HOST=<server-host>

Development

go test ./...