Hermes c8b4e51a16 Cluster: mehrere Instanzen auf einem Port, Drain bei SIGTERM, gemeinsamer Cache
Drei Teile, die zusammengehören, ohne dass ein Dienst dazwischen nötig wäre.

so_reuseport: mehrere Instanzen binden dieselbe Adresse, der Kernel verteilt. Zusammen
mit dem neuen Drain ergibt das ein Rolling Update — die neue Instanz nimmt Verkehr an,
während die alte noch bedient. SIGTERM schließt zuerst den Listener, bedient Laufendes
fertig und beendet dann; ein Request, der nach drain_timeout (Standard 15 s) noch hängt,
wird verworfen und geloggt. Vorher war SIGTERM ein Abbruch mitten in der Antwort.
packaging/junction@.service macht daraus zwei Befehle (start junction@blue, stop
junction@green); auf n95 durchgespielt: zwei Listener auf einem Port, blue loggt
draining/drained, green antwortet weiter mit 200.

Gemeinsamer Cache ohne Redis: jeder Knoten gibt seinen Speicher über einen eigenen Port
aus, cache_peer fragt ihn bei einem lokalen Fehlschlag, ein Fill wird asynchron
weitergereicht (höchstens vier gleichzeitig, ein verworfener Push ist kein Fehler). Der
Transport ist eine kleine HTTP-Teilmenge mit einem Rahmen aus zwei 32-Bit-Längen —
Head und Body so, wie der Knoten sie gesendet hätte. Ein Treffer beim Nachbarn landet
mit der Restlaufzeit lokal, damit der nächste Aufruf nicht wieder fragt. Ohne
cache_secret_env öffnet der Port gar nicht erst.

Zwei echte Funde dabei: SO_REUSEPORT ist unter -D_POSIX_C_SOURCE=200809L nicht
deklariert, ein #ifdef darum kompiliert stillschweigend weg (Symptom: "Address already
in use" trotz so_reuseport on) — der Makefile setzt jetzt -D_DEFAULT_SOURCE. Und ein
Peer-Aufruf ohne Half-Close lässt den Nachbarn auf seinen Empfangs-Timeout warten,
womit jeder Lookup in den 150 ms verhungert und der Mesh wie kaputt aussieht.

--check prüft die Konfiguration jetzt wirklich, ohne zu binden (stand schon als
Behauptung in den Beispielen).

Tests: neuer Abschnitt 33/34 (15 Prüfungen, eigener Portbereich PORT+200…207):
Peer-Treffer ohne Anbieter-Aufruf, Geheimnis erzwungen, fehlendes Geheimnis = kein
Port, stiller Peer kostet genau den Timeout (203 ms gemessen), zwei Instanzen auf einem
Port, Drain, Übergabe ohne Ausfall, exclusiver Port ohne so_reuseport.
make test: PASS, 210 Prüfungen, 154 s.
2026-11-08 09:08:43 +00:00

junction

A policy router for OpenAI-compatible model endpoints. C99 + POSIX, plus OpenSSL when built with TLS. No branding in the code: the only name in the sources is junction (even the log prefix is a config keyword), so a product name can be layered on later without touching logic.

junction sits in front of N model servers and decides per request which one serves it — and what to do when none of them wants to.

What it does

  • Ordered rules, like a firewall. req ... pass ... / block, first match wins. Match on model glob, path glob and required context.

  • Shell pre-hooks per endpoint. A hook that exits non-zero means "not available yet" — retried with backoff for a bounded time, optionally after a wake command.

  • Unreachable means offline, immediately. A connect failure is not a retry case.

  • Honest timeouts. Two per endpoint: idle ("nothing for N seconds", logged as still_working) and total. A thinking model never looks like a hang.

  • Context-aware, without guessing. need reads max_tokens / max_completion_tokens from the request and nothing else — no character counting, no assumed default. An endpoint whose context is smaller than a declared budget is skipped; a request that declares nothing is passed through unsized.

  • Failover with cooldown, and a 503 that names why each endpoint was skipped.

  • A second attempt before failover. 429, 408 and 5xx are retried on the same endpoint (retry_num, retry_backoff), because such a state usually clears in seconds while the next link in the chain costs money or context. Connect failures are explicitly not retried — "unreachable" is offline, and waiting for that is the hooks' job. A stream that has already started is never repeated.

  • Key pools per endpoint. api_key_env may stand several times; each attempt takes the next key, so a 429 on one account is answered by trying the next one instead of giving up the endpoint. /status and /metrics show the pool size as keys.

  • Prometheus /metrics. The same numbers as /status, in the text format a scraper reads — junction_endpoint_up{endpoint="…"} is 1 unless the endpoint is paused, offline, cooling down or over its hard budget.

  • Concurrency with a queue. One thread per connection, max_inflight upstream requests at a time, the rest wait in line instead of being refused. A waiting streaming caller is told why it waits — as SSE comments (: junction: waiting for a free slot (2 ahead of you)), which every conformant parser ignores and a human watching curl sees. The same heartbeat keeps a thinking model's stream alive — every 10 s of upstream silence produces : junction: model is still working (12s), so a proxy with a 60 s read timeout does not kill a stream that is perfectly alive. As soon as real data arrives the comments stop; nothing is buffered, nothing is rewritten. A non-streaming caller gets nothing injected at all and keeps its real status code.

    This is bounded, not endless: queue_timeout caps the wait for a slot, timeout caps the upstream request, and when either expires a streamer receives an error event plus data: [DONE]. If the client vanishes, the next comment write fails and the router stops waiting for a model nobody is listening to.

  • TLS both ways. https:// upstreams (SNI, optional chain + hostname verification, custom CA) and an optional TLS listener — no stunnel needed.

  • Chunked transfer coding. Chunked request bodies are decoded; chunked responses are relayed byte for byte, so streaming (text/event-stream) survives untouched.

  • Response cache. Memory-only LRU keyed on method + path + model + body, honouring Cache-Control: no-store/private, bypassed by the client's no-cache, flushed with one call. Streams are never cached.

  • Header passthrough. Client headers are forwarded (hop-by-hop removed), static headers can be added per endpoint, and X-Forwarded-For/Proto are appended. Every response carries X-Junction-Endpoint, X-Junction-Ms, X-Junction-Cache.

A worked, annotated configuration for a mixed local/cloud setup is in examples/olivia.conf; config.example is the same grammar, reduced to the bones.

Build / run

make                      # -> ./junction (TLS auto-detected via openssl headers)
make J_WITH_TLS=0         # dependency-free build: http:// upstreams only
make test                 # stub endpoints, no network, no models (~2.5 min)

sudo make install         # /usr/local/bin + /usr/local/share/junction
# systemd unit: packaging/junction.service — RuntimeDirectory=junction belongs in it,
# otherwise the unix control socket cannot be created after a reboot (/run is tmpfs).
./junction --config junction.conf [--port 8090]
curl -s localhost:8090/status

Configuration — pf.conf style

Keyword, arguments, braces. # comments, double quotes group words, unknown keywords are a hard error with a line number. Full example: config.example.

# listen 0.0.0.0:8443 tls /etc/junction/tls/cert.pem /etc/junction/tls/key.pem
listen 0.0.0.0:8090
chars_per_token 4
default_max_tokens 4096
connect_timeout_ms 1500
offline_hold_s 20
cache_ttl 300
cache_entries 128
cache_bytes 33554432

endpoint peer1 {
    base http://192.0.2.10:8081/v1
    kind remote
    context 64000
    priority 20
    timeout 600
    idle_timeout 60
    cooldown 120
    hook /usr/local/share/junction/hooks/check-http.sh
}

endpoint workstation {
    base http://192.0.2.20:8080/v1
    context 128000
    timeout 1800
    idle_timeout 30
    hook_retry 180
    hook_backoff 5
    wake /usr/local/share/junction/hooks/wake-wol.sh
    hook /usr/local/share/junction/hooks/check-http.sh
    header "X-Box: workstation"
}

endpoint cloud {
    base https://api.example.com/v1
    context 200000
    timeout 900
    idle_timeout 120
    cache off
    tls_verify on
    api_key_env EXAMPLE_API_KEY
}

# rules — first match wins
req need >64000 pass workstation, cloud
req for "*coder*" retry 300 pass workstation as "Qwen3.8-Flash-Next-GSQ-RCO-IQ1_M"
req path "/v1/models" check none pass peer1
req for "blocked-*" block
req for "*" pass peer1, cloud

Rule syntax

req [for <model-glob>] [path <glob>] [need >N | <N | N]
    [check hooks|none] [retry <seconds>]
    ( pass <endpoint>[,<endpoint>...] [as <model>] | block )
  • for — model glob (fnmatch) against the model in the request body.
  • need — the output budget the client declared (max_tokens/max_completion_tokens); >64000 matches a declared budget above 64k. A request without one never matches a need rule: junction is a pass-through and does not invent sizes.
  • check hooks|none — override the endpoint's hook list for this rule.
  • retry <s> — override hook_retry ("wait up to N s for the box").
  • pass a, b — try a, then b on failure.
  • as <model> — after a target, rewrite the model field for that target only: pass peer-a as "qwen3.8-flash-next-q1m", peer-b, cloud sends the local id to the peers and the requested id to the cloud.
  • block — refuse with 403.

No matching rule → 503 no_matching_rule: an unmatched request is a config gap, not something to quietly send to a cloud.

Images and context limits

An image is recognised inside messages, not anywhere in the body. A request counts as an image request when a message carries a content part whose type is image_url, input_image or image, or when image_url is followed directly by an object or a string. What does not count: a tool schema that merely describes a parameter named image_url (every agent ships one), and a tool result that quotes an image part as text. That distinction is the whole point — a body-wide scan turned every agent request into an image request, and those were then routed to the vision chain, where they failed for reasons that had nothing to do with the caller. A body without a messages array falls back to the whole-body scan: better one image too many than an image delivered to a text model.

vision on|off per endpoint decides who may serve it. An image request whose chain would only reach vision off endpoints is refused with a 503 that names the reason, instead of being handed to a text model that would answer with an empty message.

Limits come from the endpoint, in two steps. First the model list it publishes — limit.context per model replaces the number in the endpoint block for that model (limit.output does the same for the output budget). Endpoints that publish no limits at all are asked again through their own API: ollama.com answers /api/show with model_info["<arch>.context_length"], which is where its real windows live. Only when both are silent does the endpoint's context key apply. Nothing in that chain is estimated, and need still reads only the budget the client declared.

Retry, key pools, metrics

A 429, 408 or 5xx is retried on the same endpoint before the chain moves on:

retry_num 1          # additional attempts on the same endpoint (0 = never)
retry_backoff 0.5    # attempt n waits n × this many seconds

The reason is cost, not politeness: an overloaded cloud node usually recovers in seconds, while the next link in the chain may be a paid one or one that cannot hold the context. What is not retried: connect failures (that state is offline, and hooks own it), any 4xx other than the ones named, and anything after the stream head has reached the client. Retry-After is not evaluated — the pause comes from retry_backoff alone.

When the whole chain is offline or cooling down, failing at once is the wrong answer for a van: the uplink often returns in seconds.

offline_wait 20     # seconds a request may wait for the chain to come back (0 = never)

The wait happens before a queue slot is taken, so a waiting request does not occupy an upstream place. It is bounded by offline_wait; after that the old behaviour applies and the caller gets the 503 naming what each target was missing. A request whose stream has already started never waits.

A key pool is written by repeating api_key_env:

endpoint cloud {
    base https://api.example.com/v1
    api_key_env EXAMPLE_KEY_A
    api_key_env EXAMPLE_KEY_B
}

Each attempt takes the next key, so two accounts are two quotas: a 429 on A is answered with B, and only when every key has failed does the endpoint count as failed.

GET /metrics serves the same numbers as /status in the Prometheus text format — requests and retries, tokens, cost, cache, queue, compression, and per endpoint up, requests, inflight, last_ms, offline/cooldown seconds, usage percent, pool size, paused and cost. Like /status it is not authenticated.

A scraper that does not run on this host does not need to reach the model port for that:

metrics tcp 192.168.1.148:9180

That listener answers GET /metrics and nothing else — /v1 and /admin stay on listen, so a monitoring container can read the numbers without also being able to pause endpoints or rewrite the configuration.

Virtual keys, limits, spend

A virtual key is a token junction minted itself: the client sends it, the real upstream key never leaves the process, and the key can be pinned to a model glob and a set of endpoints.

vkey "webui" token_env VKEY_WEBUI allow "deepseek-*" endpoints "cloud,ollama1"
vkey "navigator" token_env VKEY_NAVIGATOR allow "deepseek-*" rpm 30 budget 5
field meaning
token_env env var holding the key's value (never the value itself in the config)
allow model glob; "*" = any
endpoints comma list of endpoint names; omitted = any
rpm requests per minute; the window is a hard minute, not a sliding one
budget spend cap in USD per calendar month

Two limits, two answers: over rpm the caller gets 429 vkey_rate_limited with a Retry-After in seconds; over budget it gets 403 vkey_budget_exhausted. Both are visible in /status (vkeys[]: rpm, budget_usd, spent_usd, window_hits, hits, denied) and in /metrics (junction_vkey_*).

The spend comes from the spend log, one JSON line per request that reported usage:

spend_log /var/lib/junction/spend.jsonl
{"ts":1794084400,"vkey":"webui","model":"deepseek-v4.1-flash","endpoint":"cloud",
 "tokens_in":1200,"tokens_out":300,"tokens_cached":1000,"cost_usd":0.000720}

The dashboard shows the same three things without reading the model port: a card with every virtual key (model glob, rpm, budget, spend, requests, refusals), the month's total and its per-model split. It asks over the control channel (spend.get), the same way it asks for status and rules.

GET /spend answers for the ledger what /status answers for the process: the month's total and its split per key and per model, ?month=YYYY-MM for any month the file still covers. Without a spend_log it says so (404 no spend_log configured) instead of returning zeros that look like a month without spending.

Timestamps in the ledger are wall-clock (time(NULL)), not the monotonic clock the timeouts use. That distinction cost a bug: with monotonic seconds the file said "ts":66841, and after the next restart the month's spend was invisible — a budget that forgets every restart is no budget. /spend is what made it visible.

At startup the keys' spent amounts are recomputed from that file for the current month. Without it a budget would be full again after every restart, which is the one thing a budget must not be. /status also keeps the in-memory numbers, so a request costs one append, not a read of the whole ledger.

Honest about the boundary: a vkey is accounting, not a door. A caller that sends no key, or a wrong one, is routed as before — restricting that would need a require_vkey switch and a list of every client that currently calls without one (WebUI, Navigator, dashboard scripts), or half the fleet stops. Until then a limit only binds callers who were given a key.

Guards — the policy is a script, not a keyword

junction refuses to pretend it knows what should be blocked. A guard is a command that sees the request and decides:

guard request cmd "/usr/local/share/junction/hooks/guard.sh"
JUNCTION_PATH    JUNCTION_MODEL    JUNCTION_VKEY
JUNCTION_BODY_FILE               (the body, in a temp file)
JUNCTION_BODY_BYTES

Exit 0 lets the request through; anything else refuses it with 403 guard_refused, and stdout becomes the reason in the body and in the log. If the script says nothing, the refusal names its exit code (guard_exit_3) instead of inventing an empty reason.

Three things that are deliberate:

  • The body is a file, not stdin. A script that reads only the first line would hang the write into a full pipe; a file cannot deadlock.
  • The guard runs before routing, so a refused request occupies no endpoint, no queue slot and no upstream budget.
  • Request side only. Inspecting the answer would mean buffering every stream, which is the one thing this router is built not to do. When a guard is configured the guard line appears in every request's log (guard_pass / guard_refused), and junction_guard_refused_total counts the refusals.

Keys

Global: listen, connect_timeout_ms, offline_hold_s, max_body_bytes, log_prefix, cache_ttl, cache_entries, cache_bytes, max_inflight, queue_timeout, retry_num, retry_backoff, offline_wait, guard, metrics, spend_log.

Endpoint:

key meaning
base OpenAI-compatible base URL including /v1 (http:// or https://)
context usable context window in tokens
kind free-form label (local, remote, cloud)
priority lower wins when a rule lists several
timeout total wall clock for one request (seconds)
connect_timeout_ms per-endpoint connect limit; 0 = the global value
weight 1..100, how often this endpoint is chosen (default 1)

A chain can be named once and reused, and a pool may name another pool:

  pool lokal   box3, box6
  pool alles   cloud, lokal
  req for "*"  pass alles

| idle_timeout | silence before still_working is logged (seconds) | | cooldown | rest after a failed request (seconds) | | hook | shell command; exit 0 = usable, non-zero = not yet (repeatable) | | hook_retry | how long to keep retrying hooks | | hook_backoff | sleep between hook attempts | | wake | command run once before the hook retries begin | | api_key_env | env var sent as Authorization: Bearer ... (repeatable: a pool, tried in turn) | | tls_verify | on (default) / off | | tls_ca | CA bundle for a private CA (default: system store) | | cache | on / off for this endpoint | | header | static request header, "Name: value" (repeatable) | | vision | on / off — can this endpoint read images? Omitted = not checked | | kind opencode | the endpoint is an opencode serve; requests are translated | | auth_basic <user> | HTTP Basic instead of a bearer token (opencode wants this) | | pass_cmd <cmd> | stdout is the password — opencode makes a new one on every start | | base_cmd <cmd> | stdout is the base URL — the background server binds a random port |

Hooks

Plain POSIX shell, with the request in the environment:

JUNCTION_BACKEND  JUNCTION_BASE  JUNCTION_PATH  JUNCTION_MODEL
JUNCTION_NEED_TOKENS  JUNCTION_ATTEMPT

Exit non-zero and print the reason on stdout — it lands in /status and in the 503 body. Examples in hooks/: check-http.sh, check-budget.sh, wake-wol.sh.

MCP gateway — junction as one MCP server for all tools

junction can also serve MCP. Every MCP server you list in the configuration is reached through junction, so an agent connects once and sees every tool, instead of subscribing to each server separately. Same role the MCP gateway of LiteLLM plays.

mcp tasksd url http://127.0.0.1:8781/mcp
mcp skilld url http://127.0.0.1:8790/mcp header "Authorization: Bearer …" timeout 20
mcp_cache_ttl 60
key meaning
mcp <name> url <url> an upstream MCP server (Streamable HTTP, JSON-RPC 2.0)
mcp <name> cmd "<command>" an upstream MCP server spoken over stdin/stdout (spawned by junction, one quoted command)
header "Name: value" repeated; for tokens and anything else the server wants
timeout <s> per call; default 10 — a server that does not answer delays the tool list, it does not block it
off keep the entry, do not use it
mcp_cache_ttl <s> how long the aggregated tool list is kept, default 60

The client talks to http://<junction>:8090/mcp and gets initialize, ping, tools/list, tools/call, prompts/list, prompts/get, resources/list and resources/read. Names are prefixed with the server name — tasksd__task_create, tasksd__summarize, tasksd__memory://tasks — because two servers may well have a tool or a prompt of the same name; the call methods split the prefix off before forwarding, so the server sees exactly the name it published. Descriptions, input schemas and prompt arguments are passed through untouched.

The prefix is also why a resource URI looks different at the client than at the server: resources/list returns tasksd__memory://tasks, resources/read takes that prefix away again. A URI that belongs to no configured server is refused instead of being guessed at.

Two transports are supported. An upstream is either an HTTP endpoint or a command that junction starts itself and speaks to over stdin/stdout:

mcp tasksd url http://127.0.0.1:8781/mcp timeout 20
mcp local  cmd "python3 /srv/mcp/filesystem.py --root /data"

A stdio server is started on first use, initialize is sent once, and the process stays alive between calls — a stdio server keeps session state, and a fresh process per call would be a different server every time. A command that does not answer is torn down and reported like a dead HTTP server: the other servers' tools still arrive.

What it deliberately does not do: no session cookie, no server-to-client push, no SSE answer to a request, no resources/subscribe (the capability is advertised as subscribe: false). A tool call is a question with one answer. Requests without an id are notifications and get 202 with no body.

A server that is down or silent is skipped with a log line; the tools of the others still arrive. Nothing is invented to fill the gap.

Control plane

Method Path Effect
GET /status endpoints, counters, cache stats, rules
GET /metrics the same counters as Prometheus text (unauthenticated, like /status)
GET /spend[?month=YYYY-MM] cost of that month from the spend log, per key and per model
— {"cmd":"spend.get","month":"YYYY-MM"} on the control channel — the same numbers, for the dashboard
POST /admin/pause/<name> stop routing there
POST /admin/resume/<name> clear pause + cooldown + offline
POST /admin/flush/cache drop every cached response

/status also reports the queue: inflight, waiting, max_inflight, timeout_s.

Everything else is proxied to the endpoint the rules choose.

make install also installs junction-wol (C, 100 lines) for the wake-wol.sh hook — building a magic packet should not need an interpreter either.

Cluster: several instances, one port, one cache

No Redis, no etcd, no proxy in front — the cluster is two mechanisms, both optional.

SO_REUSEPORT (so_reuseport on) lets several instances bind the same address; the kernel distributes the connections. A new instance takes traffic while the old one is still serving.

Drain (drain_timeout, default 15 s): on SIGTERM junction closes the listening socket first, finishes the requests it is already serving, and only then exits. Once the socket is closed the kernel hands new connections to the remaining instance of the group, so there is no window where nothing answers. A request that is still running after drain_timeout is abandoned with a drain_timeout log line — an update must not depend on a stuck upstream.

With a templated unit (packaging/junction.service copied to junction@.service and one config per colour) a rolling update is two commands:

systemctl start junction@blue     # new binary, same port, same rules
systemctl stop  junction@green    # old instance drains, then exits

Shared cache (cache tcp, cache_secret_env, cache_peer, cache_peer_timeout_ms): every instance keeps its cache in its own memory and hands it out over a port of its own. A node that misses locally asks its peers before it pays the provider; a node that fills an entry pushes it to its peers. The transport is a small HTTP subset — a second implementation does not need the binary:

GET /cache/<16 hex>   -> 200, X-Age: <s>, then the frame
PUT /cache/<16 hex>   -> 204, request body is the frame, X-TTL: <s>
GET /cache/stats      -> 200, JSON: entries, bytes, hits, misses

frame = 4 byte head length, 4 byte body length (big endian), head, body

The head is the exact HTTP head the node would have sent, so a peer hit is served without rebuilding anything. A hit is stored locally with the remaining TTL, so the next caller does not ask the peer again. Fills are pushed asynchronously, at most four at a time; a dropped push is not an error, the entry is in the local cache either way. X-Junction-Peer: <secret> (from the variable named by cache_secret_env) guards the port; without a secret the listener does not open at all, and the log says so.

cache_peer_timeout_ms (default 150) is the whole cost of a peer that accepts and then says nothing — measured at 203 ms in the suite. Peers are a shortcut, never a dependency: if every peer is dead, the request goes to the provider as if the mesh did not exist.

What it is not: no coherence protocol. POST /admin/flush/cache flushes one node; the others converge by TTL only. No TLS on the peer port — it belongs on loopback or a trusted LAN, and the secret is the only authorization.

Counters: /status has cache_peers (peers, lookups, hits, pushes, errors) and draining/reuseport; /metrics has junction_cache_peer_lookups_total, junction_cache_peer_hits_total, junction_cache_peer_pushes_total, junction_cache_peer_errors_total, junction_cache_peers and junction_draining.

Known limits (v0.1, deliberately named)

  • The queue is FIFO-ish: max_inflight slots go to whoever asks next; there is no prioritisation and no fairness guarantee beyond that.
  • HTTP/1.1 only — no HTTP/2, no h2c.
  • The cache is memory-only and lost on restart; it does not survive SIGHUP. Across instances it is shared by peers (see above), but without coherence: the only invalidation is the TTL.
  • TLS client is verified against the system store or tls_ca; there is no certificate pinning and no client-certificate auth.
  • junction does not tokenise. It sees only the numbers the client writes, so a request that declares no budget is routed by its model and path alone.

Tests

tests/run.sh

C stubs for a failing endpoint, a hook-gated one, a slow one (6 s silence), a dead port, and a TLS peer with a self-signed cert. Checks: offline detection, cooldown and failover, hook retry, still_working, block rules, catch-all, model rewrite, no_matching_rule, config errors, chunked request decoding (byte-exact body), cache miss/hit/flush/bypass, header passthrough and injection, TLS listener, https upstream, and that certificate verification actually refuses a self-signed peer. The suite also pins the two distinctions that are easy to get wrong: an image counts only inside messages (a tool schema naming image_url and an escaped image part in a tool result both stay text, while a real image part still reaches the vision chain), and a limit published only in the endpoint's own API (/api/show) still beats the number in the endpoint block. Three more cover the retry path: a 503 is retried on the same endpoint and logged with the upstream status, a 429 on the first key of a pool rotates to the second, and /metrics answers in the Prometheus text format with junction_endpoint_up and the retry counter. The metrics listener is tested for the opposite too: model traffic and /admin get a 404 there. For MCP the suite checks twelve things against two fake servers: the aggregated tool list, the call going to the right server with unchanged arguments, prompts bundled and un-prefixed on prompts/get, a resource URI un-prefixed on resources/read, an unknown prefix refused, and a dead server not taking the list down. A guard script is tested from both sides: one that refuses a word it does not want (with its reason in the body and in /metrics), one that exits silently (the exit code becomes the reason), and a request that passes and is logged as guard_pass. /spend is checked against a seeded ledger: the month's total, the split per key and model, a month with nothing in it, a malformed month, and a router without a ledger saying exactly that. The key limits have their own file: a rpm 1 key is served once and then refused with 429 and a Retry-After, a key whose budget the ledger already used up is refused before it routes anything, and a priced request through a key shows up in the log file, in /status and in /metrics. The offline wait has its own section too: with the only endpoint missing the first request fails as before, and once the endpoint is back the next request waits out the offline hold (measured ~2 s) and is served instead of refused. Two more sections cover the cluster. The shared cache is tested with two instances: node A answers a request and fills, node B answers the same request from A's cache (via=peer in the log) without calling the provider at all, and keeps the entry for the next caller; the peer port refuses a caller without the secret and with a wrong one; a node without a secret does not open the port; and a peer that accepts but never answers costs exactly the timeout (203 ms measured) instead of stalling the request. The rolling update is tested for real: a second instance binds the same port while the first serves, SIGTERM on the first logs draining and drained and it exits, the second serves during and after the handover, and without so_reuseport the port stays exclusive. Pass = PASS (210 checks), including two that would have caught the two mistakes this design invites: a serial stub making a concurrent router look serialised, and a "waiting" comment leaking into a caller that never asked for a stream.

The suite refuses to run if a test port is already taken — a stale junction on :8105 once answered requests with someone else's config and made a good test look broken.

S
Description
junction (from n95, ~/src/junction)
Readme
1.4 MiB
0 Stars 3 Watchers 0 Forks
Languages
C 64.5%
Shell 21.2%
Python 7.2%
JavaScript 2.9%
HTML 2.6%
Other 1.6%