Files
junction/config.example
T
Hermes 5d4befcf51 junction: zweiter Versuch vor dem Failover, Schlüssel-Pool, /metrics
Drei Lücken gegenüber LiteLLM, die im Betrieb wirklich fehlten:

1. Retry auf demselben Endpunkt. Bisher galt: ein 429 oder 5xx, und die Kette
   zog weiter. Das ist teuer, wenn der nächste Link bezahlt ist oder den Kontext
   nicht hält, und es ist falsch, wenn der Anbieter eine Sekunde später wieder
   antwortet. retry_num/retry_backoff wiederholen 429, 408 und 5xx auf demselben
   Endpunkt (Vorgabe: ein Versuch, 0,5 s, linear steigend). Verbindungsfehler
   werden ausdrücklich nicht wiederholt — die heißen offline, und darauf zu warten
   ist Aufgabe der Hooks. Nach dem Streaming-Kopf wird nie wiederholt. Retry-After
   wird nicht ausgewertet; das steht so im README.

2. Schlüssel-Pool. api_key_env darf mehrfach stehen; jeder Versuch nimmt den
   nächsten Schlüssel (key_rr), also beantwortet ein 429 auf Konto A den Versuch
   mit Konto B, statt den Endpunkt aufzugeben. Die Zahl der Versuche ist mindestens
   die Zahl der Schlüssel, damit auch bei retry_num 0 jedes Konto zum Zug kommt.
   /status und /metrics zeigen die Poolgröße als keys. models.c nimmt für die
   Modellliste und /api/show weiterhin den ersten Schlüssel — mehr Schlüssel heißt
   nicht mehr Quotesichtbarkeit.

3. /metrics im Prometheus-Textformat, dieselben Zahlen wie /status: Anfragen,
   Retries, Tokens, Kosten, Cache, Warteschlange, Kürzung, und je Endpunkt up,
   Anfragen, inflight, last_ms, Offline-/Cooldown-Sekunden, Kontingent, Poolgröße,
   Pause und Kosten. up ist 1, solange nichts den Endpunkt ausschließt — pausiert,
   offline, im Cooldown oder über dem harten Budget heißt 0.

   Dazu ein zweiter, ausdrücklich kleiner Listener (`metrics tcp host:port`), der
   nur GET /metrics kennt. Grund: junction lauscht auf 127.0.0.1, Prometheus läuft
   im Container und kommt dort nicht heran. /v1 und /admin ins Netz zu legen wäre
   der falsche Preis — /admin pausiert Endpunkte ohne jede Authentisierung. Der
   Metrik-Port beantwortet alles andere mit 404.

Tests (eigene Datei tests/retry-metrics.sh, damit run.sh lesbar bleibt):
- Ein Stub, der die erste Chat-Anfrage mit 503 abweist, wird beim zweiten Versuch
  bedient; Log und Zähler nennen den Grund (upstream_status_503).
- Ein Stub, der den ersten Schlüssel mit 429 abweist, wird über den zweiten
  bedient (X-Stub-Auth zeigt ihn), /status nennt keys=2.
- /metrics antwortet im Textformat, jede Zeile name{labels} value; der
  Metrik-Listener liefert /metrics, aber 404 für Modellpfad und /admin.

Dafür zwei neue Stub-Modi: --fail-n N (Zähler in $STUB_STATE, weil der Stub je
Verbindung forkt) und --deny-auth SUBSTR. Nur Chat-Anfragen zählen, sonst
verbraucht der Modelle-Abruf beim Start das Fehlerkontingent.

make test: PASS, 146 Prüfungen. Live: /usr/local/bin/junction ersetzt, Dienst neu
gestartet, metrics tcp 192.168.1.148:9180 in /etc/junction/junction.conf, Prometheus
(scrape_interval 30s) meldet das Ziel als up.
2026-11-07 20:05:52 +00:00

125 lines
4.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# junction.conf — pf.conf-style. keyword, arguments, braces. '#' starts a comment.
# Double quotes group words. Unknown keywords are a hard error with a line number.
# Plain listener:
listen 0.0.0.0:8090
# ... or TLS (https clients without a proxy in front):
# listen 0.0.0.0:8443 tls /etc/junction/tls/cert.pem /etc/junction/tls/key.pem
connect_timeout_ms 1500
offline_hold_s 20
max_body_bytes 67108864
# How many upstream requests may run at once; the rest wait in line. A waiting
# streaming caller gets SSE comments explaining the wait, a plain one waits silently.
max_inflight 4
queue_timeout 300
# Retry before failover: 429/408/5xx are tried again on the SAME endpoint, because such
# a state usually clears in seconds while the next link may cost money or context.
# 0 disables it. retry_backoff is per attempt (attempt n waits n × this).
retry_num 1
retry_backoff 0.5
# Response cache (memory only). ttl 0 disables it. Only complete, non-streamed 200
# answers are stored, keyed on method + path + model + body.
# Only /metrics, only read-only. A Prometheus in a container or on another host can
# scrape the numbers here without reaching the model port (and /admin) at all.
# metrics tcp 192.168.1.148:9180
cache_ttl 300
cache_entries 128
cache_bytes 33554432
# --------------------------------------------------------------------- endpoints
endpoint peer1 {
base http://192.0.2.10:8081/v1
kind remote
context 64000
priority 20
timeout 600
idle_timeout 60
cooldown 120
hook /opt/junction/hooks/check-http.sh
}
endpoint peer2 {
base http://192.0.2.10:8082/v1
kind remote
context 64000
priority 20
timeout 600
idle_timeout 60
cooldown 120
hook /opt/junction/hooks/check-http.sh
}
endpoint workstation {
base http://192.0.2.20:8080/v1
kind local
context 128000
priority 10
timeout 1800
idle_timeout 30
cooldown 60
hook_retry 180
hook_backoff 5
wake /opt/junction/hooks/wake-wol.sh
hook /opt/junction/hooks/check-http.sh
hook /opt/junction/hooks/check-budget.sh
}
endpoint cloud {
base https://api.example.com/v1
kind cloud
# Rückfall, keine Wahrheit: die Grenzen der Modelle holt junction beim Start aus
# der Modellliste des Endpunkts (GET /models → limit.context / limit.output).
# Diese Zahl gilt nur, wenn der Abruf scheitert oder das Modell dort fehlt.
context 200000
priority 90
timeout 900
idle_timeout 120
cache off # never store cloud answers
api_key_env EXAMPLE_API_KEY
# Zweites Konto, zweites Kontingent: die Zeile darf mehrfach stehen. Jeder Versuch
# nimmt den nächsten Schlüssel, ein 429 auf dem ersten wird also mit dem zweiten
# beantwortet, statt den Endpunkt aufzugeben.
# api_key_env EXAMPLE_API_KEY_2
tls_verify on # off only for a self-signed internal endpoint
# tls_ca /etc/junction/tls/internal-ca.pem
header "X-Title: olivia" # static header sent with every request here
}
# --------------------------------------------------------------------------- mcp
#
# junction wird dadurch selbst zum MCP-Server: ein Agent verbindet sich mit
# http://127.0.0.1:8090/mcp und sieht die Werkzeuge aller hier eingetragenen
# Server, mit dem Servernamen als Präfix ("tasksd__task_create"). Ein toter
# Server wird übersprungen, die übrigen Werkzeuge kommen trotzdem.
#
# mcp tasksd url http://127.0.0.1:8781/mcp
# mcp skilld url http://127.0.0.1:8790/mcp header "Authorization: Bearer CHANGE_ME"
# mcp_cache_ttl 60
# ------------------------------------------------------------------------- rules
# First matching rule wins. Rules may use:
# for <model-glob> need >N | <N | N path <glob>
# check hooks|none retry <seconds>
# pass <endpoint>[,<endpoint>...] [as <model>] | block
# A client that DECLARES more output than the peers can hold goes to the big box.
# 'need' reads max_tokens from the request; there is no character counting and no
# default, so a request that states nothing is not sized by guesswork.
req need >64000 pass workstation, cloud
# Coding work: prefer the workstation, wake it, wait up to 5 minutes for the hooks,
# and hand it the model name it actually serves.
req for "*coder*" check hooks retry 300 pass workstation as "Qwen3.8-Flash-Next-GSQ-RCO-IQ1_M"
req for "Qwen3.8-Flash-Next*" check hooks retry 60 pass workstation, peer1, peer2
# Cheap metadata calls never need a model at all.
req path "/v1/models" check none pass peer1, peer2, cloud
# Anything unseen is refused rather than silently sent to the cloud.
req for "*" block