www: a hand-written project page, installed to share/junction/www
One file, no build step, no external request: no font, no script, no image. Every number on it was measured on a running instance — 15,191 lines of C in 30 files and 33 test programs are the counts of this tree, and the routing example (rule line 566, 2.2 s, the six X-Junction headers) is copied from a real response rather than composed. Serve it with whatever answers port 80. junction stays a router and does not serve it itself — a static handler in a request-path process would be a second job for the thing whose only job is to pick a target. The existing docs/index.html is a different, older page (HTML 4.01, 613 lines, untouched since 5 November); it stays as it is.
This commit is contained in:
1 parent
89173a2ced
commit
7c78ce1a7c
3 files changed
+262
No files matched your search
@@ -50,6 +50,8 @@ install: junction $(TOOLS)
|
||||
install -m 0644 config.example $(DESTDIR)$(PREFIX)/share/junction/junction.conf
|
||||
install -d $(DESTDIR)$(PREFIX)/share/junction/examples
|
||||
install -m 0644 examples/*.conf $(DESTDIR)$(PREFIX)/share/junction/examples/
|
||||
install -d $(DESTDIR)$(PREFIX)/share/junction/www
|
||||
install -m 0644 src/www/*.html $(DESTDIR)$(PREFIX)/share/junction/www/
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) junction $(TOOLS)
|
||||
|
||||
@@ -89,6 +89,11 @@ sudo make install # /usr/local/bin + /usr/local/share/junction
|
||||
curl -s localhost:8090/status
|
||||
```
|
||||
|
||||
`make install` also drops the hand-written project page at
|
||||
`/usr/local/share/junction/www/index.html` — one file, no build step, no external
|
||||
request (no font, no script, no image). Serve that directory with whatever answers
|
||||
port 80; junction itself is a router, not a web server, and does not serve it.
|
||||
|
||||
`--check` loads the file through the same parser and prints one line
|
||||
(`config ok: N endpoints, N rules, N vkeys, listen host:port`), without binding a
|
||||
port: "run it through the parser once before the restart" is a command, not a
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="color-scheme" content="light dark">
|
||||
<title>junction — a policy router for model endpoints</title>
|
||||
<meta name="description" content="junction is a policy router for OpenAI-compatible model endpoints. One text file of pf.conf-style rules decides per request which server answers, and what happens when none of them wants to. C99 and POSIX.">
|
||||
<style>
|
||||
:root{
|
||||
--bg:#e3e7ec; --panel:#d6dce4; --ink:#17202b; --dim:#4d5a69; --rule:#aab4c0;
|
||||
--acc:#1d5f80; --read:#2a6f97; --mut:#9a5b0c; --des:#a3282b; --term:#0f1720; --termink:#d3dce6;
|
||||
--serif:Charter,"Bitstream Charter","Iowa Old Style","Palatino Linotype",Palatino,Georgia,serif;
|
||||
--mono:ui-monospace,"DejaVu Sans Mono","Liberation Mono",Menlo,Consolas,monospace;
|
||||
}
|
||||
@media (prefers-color-scheme:dark){:root{
|
||||
--bg:#141a22; --panel:#1c242f; --ink:#d9e0e8; --dim:#93a0af; --rule:#334050;
|
||||
--acc:#7dbbd8; --read:#6fb0d6; --mut:#e0a24f; --des:#ee7b7e; --term:#0b1016; --termink:#cfd8e2;}}
|
||||
*{box-sizing:border-box}
|
||||
html{-webkit-text-size-adjust:100%}
|
||||
body{margin:0;background:var(--bg);color:var(--ink);font:1.0625rem/1.62 var(--serif)}
|
||||
a{color:var(--acc);text-underline-offset:.18em}
|
||||
a:focus-visible{outline:2px solid var(--acc);outline-offset:3px}
|
||||
code,pre,.m{font-family:var(--mono)}
|
||||
code{font-size:.88em;background:var(--panel);padding:.08em .32em}
|
||||
.bar{display:flex;justify-content:space-between;gap:1rem;padding:.55rem 1rem;border-bottom:1px solid var(--rule);font:.8rem var(--mono);color:var(--dim)}
|
||||
.bar b{color:var(--ink);font-weight:600}
|
||||
.shell{display:grid;grid-template-columns:minmax(0,1fr);max-width:68rem;margin:0 auto;padding:0 1rem}
|
||||
nav.rail{display:none}
|
||||
main{min-width:0;max-width:44rem;padding:2.5rem 0 5rem}
|
||||
@media (min-width:62rem){
|
||||
.shell{grid-template-columns:11.5rem minmax(0,1fr);gap:3rem}
|
||||
nav.rail{display:block;position:sticky;top:0;align-self:start;padding:2.6rem 0;font:.85rem/1.9 var(--mono)}
|
||||
nav.rail a{display:block;color:var(--dim);text-decoration:none;border-left:2px solid var(--rule);padding-left:.8rem}
|
||||
nav.rail a:hover{color:var(--ink);border-color:var(--acc)}
|
||||
}
|
||||
h1{font:700 clamp(3rem,11vw,5.2rem)/.95 var(--serif);letter-spacing:-.035em;margin:.2em 0 .25em}
|
||||
h2{font:700 1.45rem/1.2 var(--serif);margin:3.2rem 0 .8rem;padding-top:1.2rem;border-top:1px solid var(--rule)}
|
||||
h3{font:600 1rem var(--serif);margin:1.5rem 0 .3rem}
|
||||
p{margin:.8em 0} .lead{font-size:1.28rem;line-height:1.5}
|
||||
.dim{color:var(--dim)} .small{font-size:.9rem}
|
||||
pre{background:var(--term);color:var(--termink);margin:1.2rem 0;padding:1rem 1.1rem;overflow-x:auto;font-size:.82rem;line-height:1.55;border-left:4px solid var(--acc)}
|
||||
pre .u{color:#fff;font-weight:600} pre .d{color:#7f8ea0} pre .r{color:#7fbfe6} pre .a{color:#f0b35e} pre .x{color:#ff8f92}
|
||||
@media (prefers-color-scheme:dark){pre .u{color:#fff}}
|
||||
.tw{overflow-x:auto;margin:1.1rem 0}
|
||||
table{border-collapse:collapse;width:100%;font-size:.93rem}
|
||||
th{text-align:left;font-weight:600;color:var(--dim);padding:.3rem .7rem;border-bottom:1px solid var(--rule)}
|
||||
td{padding:.42rem .7rem;border-bottom:1px solid var(--rule);vertical-align:top}
|
||||
td:first-child{font:.82rem var(--mono);white-space:nowrap}
|
||||
tr.r td:first-child{box-shadow:inset 4px 0 var(--read)} tr.a td:first-child{box-shadow:inset 4px 0 var(--mut)} tr.x td:first-child{box-shadow:inset 4px 0 var(--des)}
|
||||
@media (max-width:40rem){table,tbody,tr,td{display:block}tr:first-child{display:none}tr{border-bottom:1px solid var(--rule);padding:.35rem 0}td{border:0;padding:.1rem .7rem}td:first-child{white-space:normal;overflow-wrap:anywhere}}
|
||||
.key{display:flex;flex-wrap:wrap;gap:.4rem 1.4rem;font:.82rem var(--mono);margin:.8rem 0}
|
||||
.key span:before{content:"";display:inline-block;width:.9rem;height:.5rem;margin-right:.45rem;background:var(--c)}
|
||||
dl{margin:1rem 0} dt{font:600 .9rem var(--mono);margin-top:1rem} dd{margin:.15rem 0 0}
|
||||
ul{padding-left:1.2rem} li{margin:.3rem 0}
|
||||
.cols{display:grid;gap:0 2rem;grid-template-columns:repeat(auto-fit,minmax(15rem,1fr))}
|
||||
footer{border-top:1px solid var(--rule);margin-top:4rem;padding-top:1.2rem;font-size:.88rem;color:var(--dim)}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="bar"><span><b>junction</b>(1)</span><span>policy router</span></div>
|
||||
<div class="shell">
|
||||
<nav class="rail" aria-label="Sections">
|
||||
<a href="#what">what it is</a><a href="#rule">a rule</a><a href="#decide">how it decides</a><a href="#review">judge & review</a><a href="#mcp">mcp gateway</a><a href="#keys">keys & spend</a><a href="#ops">operation</a><a href="#build">build</a><a href="#limits">limits</a>
|
||||
</nav>
|
||||
<main>
|
||||
<h1>junction</h1>
|
||||
<p class="lead">A policy router for OpenAI-compatible model endpoints. It sits in front of N model servers and decides <em>per request</em> which one answers — and what happens when none of them wants to.</p>
|
||||
<p>You run more than one model server: a paid cloud account, two free tiers, a workstation that sleeps, a box on the LAN that is only good for small prompts. Your clients speak <code>/v1/chat/completions</code> and should keep doing so. junction is the thing in between.</p>
|
||||
|
||||
<pre><span class="d"># a request arrives, junction answers</span>
|
||||
<span class="u">client</span> POST /v1/chat/completions <span class="d">model: deepseek-v4.1-flash</span>
|
||||
<span class="u">rule</span> for "deepseek-v4.1-flash*" pass ds41flash <span class="r">line 566</span>
|
||||
<span class="u">pool</span> ds41flash → opencode-go0, go1, go2 <span class="d">round-robin</span>
|
||||
<span class="u">sent</span> opencode-go1 <span class="a">one attempt, 2.2 s</span>
|
||||
<span class="u">client</span> 200, answer + <span class="r">X-Junction-Endpoint: opencode-go1</span></pre>
|
||||
<p class="small dim">Everything in that block was measured on a running instance, not composed for this page.</p>
|
||||
|
||||
<h2 id="what">What it is</h2>
|
||||
<p>junction reads one text file of rules and picks a target per request. It tries the next one when the first fails, keeps streams intact, and says in the response headers and in <code>/status</code> exactly what it did.</p>
|
||||
<p>The rule language is deliberately close to <code>pf.conf</code>: first match wins, an unknown keyword is a hard error with a line number, and there is no silent fallback to “somewhere”. A request that matches no rule gets <code>503 no_matching_rule</code>, because a gap in the configuration is not a routing decision.</p>
|
||||
<p>Written in C99 and POSIX, about 15,200 lines of C in 30 files. OpenSSL is the only optional dependency and only needed for TLS. No runtime, no config daemon, no database.</p>
|
||||
|
||||
<h2 id="rule">A rule, and its neighbours</h2>
|
||||
<pre><span class="d"># listen 0.0.0.0:8443 tls /etc/junction/tls/cert.pem /etc/junction/tls/key.pem</span>
|
||||
listen 0.0.0.0:8090
|
||||
|
||||
endpoint workstation {
|
||||
base http://192.0.2.20:8080/v1
|
||||
context 128000
|
||||
timeout 1800
|
||||
idle_timeout 30
|
||||
hook /usr/local/share/junction/hooks/check-http.sh
|
||||
wake /usr/local/share/junction/hooks/wake-wol.sh
|
||||
}
|
||||
|
||||
endpoint cloud {
|
||||
base https://api.example.com/v1
|
||||
context 200000
|
||||
api_key_env EXAMPLE_API_KEY <span class="d"># repeatable: a key pool</span>
|
||||
}
|
||||
|
||||
pool ds41flash opencode-go/deepseek-v4.1-flash#max, ollama0/deepseek-v4.1-flash#max
|
||||
|
||||
<span class="d"># rules — first match wins</span>
|
||||
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</pre>
|
||||
<p>Every clause is optional except the final <code>pass</code> or <code>block</code>. Match on model glob, path glob, the output budget the client declared, and whether the request carries an image.</p>
|
||||
<div class="tw"><table>
|
||||
<tr><th>clause</th><th>meaning</th></tr>
|
||||
<tr class="r"><td>req for <glob></td><td>Model glob, matched with <code>fnmatch</code> against the model in the request body.</td></tr>
|
||||
<tr class="r"><td>req path <glob></td><td>Path glob. <code>/v1/models</code> usually wants a different target than the chat path.</td></tr>
|
||||
<tr class="r"><td>need >N | <N | N</td><td>The output budget the client <em>declared</em> as <code>max_tokens</code>. junction does not count characters and does not invent a default; a request that declares nothing never matches a <code>need</code> rule.</td></tr>
|
||||
<tr class="a"><td>retry <s></td><td>Override <code>hook_retry</code> for this rule — how long to wait for a box to boot.</td></tr>
|
||||
<tr class="a"><td>review N</td><td>N hidden self-review rounds after the first answer.</td></tr>
|
||||
<tr class="a"><td>judge every N <target></td><td>Escalate every Nth call of a conversation to a stronger judge.</td></tr>
|
||||
<tr class="a"><td>check hooks | none</td><td>Run the endpoint's hooks for this rule, or skip them.</td></tr>
|
||||
<tr class="x"><td>pass a, b [as M]</td><td>Try a, then b on failure. <code>as</code> rewrites the model name for that target only.</td></tr>
|
||||
<tr class="x"><td>block</td><td>Refuse with 403.</td></tr>
|
||||
</table></div>
|
||||
|
||||
<h2 id="decide">How a request is decided</h2>
|
||||
<p>A client asks for model <code>chat</code> with roughly 3,000 prompt tokens and a declared output budget of 4,096. Rules are read top to bottom:</p>
|
||||
<pre>req path "/v1/models" check none pass cloud <span class="d">no match</span> — different path
|
||||
req for "*embed*" check none pass embed <span class="d">no match</span> — different model
|
||||
req vision pass workstation, cloud as "v" <span class="d">no match</span> — no image
|
||||
req need >64000 pass workstation, cloud <span class="d">no match</span> — 4,096 is below 64,000
|
||||
req for "*" pass workstation, cloud <span class="a">match</span></pre>
|
||||
<p>The matched rule lists two targets. junction asks the first; if its connection is refused, that target is marked offline for <code>offline_hold_s</code> and the second is tried within the same request. Every response says which target answered:</p>
|
||||
<pre>X-Junction-Endpoint: opencode-go1
|
||||
X-Junction-Ms: 2186
|
||||
X-Junction-Cache: off
|
||||
X-Junction-Tokens-In: 37
|
||||
X-Junction-Tokens-Out: 13
|
||||
X-Junction-Cost-Usd: 0.000027</pre>
|
||||
<p class="small dim">Those six header lines and their values are copied from a real response of a local instance.</p>
|
||||
|
||||
<h3>When something fails</h3>
|
||||
<dl>
|
||||
<dt>Unreachable is offline, immediately</dt><dd>A connect failure is not a retry case. The endpoint is benched for <code>offline_hold_s</code> and the chain moves on, so a machine that is off does not cost every request a timeout.</dd>
|
||||
<dt>Two timeouts, not one</dt><dd><code>timeout</code> is the total wall clock; <code>idle_timeout</code> is silence. A thinking model is not a hang, and a stream that has stopped producing gets a keep-alive comment rather than a severed connection.</dd>
|
||||
<dt>A second attempt before failover</dt><dd><code>429</code>, <code>408</code> and <code>5xx</code> are retried on the <em>same</em> endpoint, because such a state usually clears in seconds while the next link may cost money. Connect failures are explicitly not retried, and a stream that has already started is never repeated.</dd>
|
||||
<dt>The provider knows better</dt><dd>A <code>Retry-After</code> — seconds or an HTTP date — wins over the configured backoff, capped by <code>retry_max_wait</code>. An hour of waiting is not a retry, it is an outage with an announcement.</dd>
|
||||
<dt>Key pools</dt><dd>Repeating <code>api_key_env</code> makes a pool. Each attempt takes the next key, so two accounts are two quotas: a <code>429</code> on A is answered by B, and only when every key failed is the endpoint down.</dd>
|
||||
<dt>The queue, not a refusal</dt><dd><code>max_inflight</code> upstream requests at a time, the rest wait in line. A waiting <em>streaming</em> caller is told why it waits, as an SSE comment that every conformant parser ignores and a human watching <code>curl</code> sees.</dd>
|
||||
</dl>
|
||||
|
||||
<h2 id="review">Judge and review</h2>
|
||||
<p>Two mechanisms that spend extra calls on purpose, both declared in the rule.</p>
|
||||
<h3>Self-review — the worker checks itself</h3>
|
||||
<pre>req for "qwen3.6-35b-checked" balance round-robin check none \
|
||||
review 2 \
|
||||
pass qwen3.6-35b as "/models/unsloth/Qwen3.6-35B-A3B-MTP-GGUF/Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf"</pre>
|
||||
<p>The worker answers first. junction then appends that answer plus a fixed review instruction to the <em>same</em> conversation and sends it back to the same endpoint. That happens N times; only the last answer is written to the client. The intermediate answers and the review text never reach it.</p>
|
||||
<p>Two details matter in practice. An answer carrying <code>tool_calls</code> is passed through unreviewed, because reviewing a tool call as text would be a different request than the one the client must execute. And if a round returns the answer verbatim, the answer is stable: the remaining rounds are skipped and the log says <code>converged=1</code>, so a reviewer that would keep rewriting a correct answer does not get the chance.</p>
|
||||
<p>Depth is a per-request decision as well as a rule: <code>X-Junction-Review-Rounds: 7</code> or <code>X-Junction-Effort: medium</code> asks for a different depth for one call, and <code>X-Junction-Review-Rounds: 0</code> turns it off.</p>
|
||||
<h3>Sampled judge — a virtual model that escalates</h3>
|
||||
<pre>req for "qwen3.6-35b-judged" balance round-robin check none \
|
||||
judge every 5 ds41flash cache off \
|
||||
judge every 10 claude-openai0 as "claude-opus-5-5" cache 1h \
|
||||
pass qwen3.6-35b as "..."</pre>
|
||||
<p>The 5th call of a conversation goes to the <code>ds41flash</code> pool, the 10th to Claude Opus, then the counter resets. The judge gets the <em>whole</em> body, including every previous assistant message, so it can see what the worker did and correct it. A rule with a judge becomes a virtual model in <code>/v1/models</code>: the client asks for the virtual name, the worker does the turns.</p>
|
||||
<p>If the judge fails, the same request is offered to the rule's normal targets, so a rate-limited judge still leaves the worker serving the turn. Every response of a judged rule also announces the <em>next</em> judge in <code>X-Junction-Judge-Next</code> and <code>-In</code>, so a client can see one coming.</p>
|
||||
<p class="small dim">The counter table lives in RAM: 4096 conversations, least-recently-used eviction, one hour of idle expiry. The rule's identity is its model and path globs, not its line number, so inserting a comment above it keeps the counters. These resets change <em>when</em> a judge runs, never whether an answer is correct.</p>
|
||||
<h3>Skipping is named, never silent</h3>
|
||||
<p>Review passes an answer through untouched when it cannot review it. The reason is always reported (<code>X-Junction-Review-Skipped</code>, the log, or the final SSE <code>junction</code> object):</p>
|
||||
<div class="tw"><table>
|
||||
<tr><th>reason</th><th>when</th></tr>
|
||||
<tr><td>n>1</td><td>The client asked for several choices; they cannot be reviewed as one answer.</td></tr>
|
||||
<tr><td>tool_calls</td><td>The answer carries a non-empty <code>tool_calls</code> array.</td></tr>
|
||||
<tr><td>content_array</td><td>The answer's <code>content</code> is an array of parts.</td></tr>
|
||||
<tr><td>no_text</td><td>No string content — typically a model that spent its whole budget in reasoning.</td></tr>
|
||||
<tr><td>budget</td><td>The key's monthly budget is spent before the next round.</td></tr>
|
||||
<tr><td>error</td><td>A review round failed; the last good answer is delivered.</td></tr>
|
||||
<tr><td>protocol</td><td>Not an OpenAI chat path, or an endpoint kind that review does not support.</td></tr>
|
||||
</table></div>
|
||||
|
||||
<h2 id="mcp">MCP gateway</h2>
|
||||
<p>junction can also <em>serve</em> MCP. Every MCP server in the configuration is reached through it, so an agent connects once and sees every tool instead of subscribing to each server separately.</p>
|
||||
<pre>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 local cmd "python3 /srv/mcp/filesystem.py --root /data"
|
||||
mcp_cache_ttl 60</pre>
|
||||
<p>Names are prefixed with the server name — <code>tasksd__task_create</code>, <code>tasksd__memory://tasks</code> — because two servers may well publish a tool of the same name. The call methods split the prefix off again, so the server sees exactly the name it published.</p>
|
||||
<p>Two transports: an HTTP endpoint, or a command that junction starts itself and speaks to over stdin/stdout. A stdio server is started on first use and stays alive between calls, because it keeps session state and a fresh process per call would be a different server every time.</p>
|
||||
<p>Both kinds fail the same honest way: a server that is down or silent is skipped with a log line and <em>the other servers' tools still arrive</em>. Nothing is invented to fill the gap.</p>
|
||||
<h3>Who may call it</h3>
|
||||
<p><code>/mcp</code> is not a model path. Through it an agent creates tasks, rewrites skills and stores memories — it writes, it does not merely route. So the default is <code>mcp_auth auto</code>: from loopback no key is needed, from any other address the caller must present a virtual key that junction itself minted. Without one the answer is <code>401</code> with <code>WWW-Authenticate: Bearer</code>, so a client can tell “no key” from “junction is down”.</p>
|
||||
|
||||
<h2 id="keys">Keys, budgets and the ledger</h2>
|
||||
<p>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.</p>
|
||||
<pre>vkey "webui" token_env VKEY_WEBUI allow "deepseek-*" endpoints "cloud,ollama1"
|
||||
vkey "navigator" token_env VKEY_NAVIGATOR allow "deepseek-*" rpm 30 budget 5</pre>
|
||||
<div class="tw"><table>
|
||||
<tr><th>field</th><th>meaning</th></tr>
|
||||
<tr><td>allow</td><td>Model glob; <code>"*"</code> = any. Both this and the global <code>models allow</code> must agree.</td></tr>
|
||||
<tr><td>endpoints</td><td>Comma list of endpoint names; omitted = any.</td></tr>
|
||||
<tr><td>rpm</td><td>Requests per minute. Over it: <code>429</code> with <code>Retry-After</code>.</td></tr>
|
||||
<tr><td>budget</td><td>Spend cap in USD per calendar month. Over it: <code>403 vkey_budget_exhausted</code>.</td></tr>
|
||||
</table></div>
|
||||
<p>Spend is recomputed from the ledger at startup, so a budget is not full again after every restart — the one thing a budget must not be. And junction is honest about the boundary: <strong>a vkey is accounting, not a door.</strong> A caller that sends no key is routed as before. A limit only binds callers who were given a key.</p>
|
||||
<h3>The request log</h3>
|
||||
<p><code>spend_log</code> is not only a ledger: every served request leaves one JSON line, and that line is the only place where a single request is complete.</p>
|
||||
<pre>{"ts":1795193823,"model":"deepseek-v4.1-flash","endpoint":"opencode-go1",
|
||||
"status":200,"latency_ms":2523,"rule_line":533,"cache":"miss","retries":0,
|
||||
"tokens_in":37,"tokens_out":13,"cost_usd":0.000027}</pre>
|
||||
<p>No exporter, no collector, no agent — the file is the interface, and <code>/spend</code> reads the same file so the ledger and the dashboard can never disagree. A streamed answer cannot be billed after the fact, so it gets zeros rather than a guess.</p>
|
||||
|
||||
<h2 id="ops">Operation</h2>
|
||||
<div class="tw"><table>
|
||||
<tr><th>method</th><th>path</th><th>effect</th></tr>
|
||||
<tr class="r"><td>GET</td><td>/status</td><td>Endpoints, counters, cache, queue, rules as JSON. Also served as <code>/v1/status</code>, <code>/queue</code>, <code>/v1/queue</code>.</td></tr>
|
||||
<tr class="r"><td>GET</td><td>/metrics</td><td>The same numbers in Prometheus text format, including per-endpoint latency histograms.</td></tr>
|
||||
<tr class="r"><td>GET</td><td>/spend[?month=YYYY-MM]</td><td>Cost of that month from the ledger, per key and per model.</td></tr>
|
||||
<tr class="a"><td>POST</td><td>/admin/pause/<name></td><td>Stop routing there.</td></tr>
|
||||
<tr class="a"><td>POST</td><td>/admin/resume/<name></td><td>Clear pause, cooldown and offline.</td></tr>
|
||||
<tr class="a"><td>POST</td><td>/admin/flush/cache</td><td>Drop every cached response.</td></tr>
|
||||
</table></div>
|
||||
<p>The latency histogram is a deliberate choice over an average: an endpoint answering 95 % fast and 5 % of the time in a minute keeps a harmless mean, and an average hides exactly the requests that hurt.</p>
|
||||
<h3>Is the endpoint really there?</h3>
|
||||
<p>A background thread asks every endpoint for its model list. No answer means offline for <code>offline_hold_s</code>; a recovered endpoint is back before any request had to pay for the discovery. <code>/status</code> carries <code>probe_ok</code> and <code>probe_age_s</code>, so “the router thinks it is down” and “the router has not looked yet” are distinguishable.</p>
|
||||
<h3>Several instances, one port, one cache</h3>
|
||||
<p><code>so_reuseport</code> lets several instances bind the same address and the kernel distributes connections. On <code>SIGTERM</code> an instance closes its listening socket first, finishes what it is already serving, and only then exits — so a rolling update has no window where nothing answers. A shared cache lets a node that misses locally ask its peers before it pays the provider; peers are a shortcut, never a dependency, and if every peer is dead the request goes to the provider as if the mesh did not exist.</p>
|
||||
|
||||
<h2 id="build">Build</h2>
|
||||
<pre>make <span class="d"># -> ./junction, TLS auto-detected via openssl headers</span>
|
||||
make J_WITH_TLS=0 <span class="d"># dependency-free build: http:// upstreams only</span>
|
||||
make test <span class="d"># stub endpoints, no network, no models</span>
|
||||
|
||||
sudo make install <span class="d"># /usr/local/bin + /usr/local/share/junction</span>
|
||||
|
||||
./junction --config junction.conf --check <span class="d"># parse, report, bind nothing</span>
|
||||
./junction --config junction.conf
|
||||
curl -s localhost:8090/status</pre>
|
||||
<p><code>--check</code> loads the file through the same parser and prints one line — “run it through the parser once before the restart” is a command, not a thing to remember. The flags are <code>-std=c99 -Wall -Wextra -Wpedantic -Wshadow -Wconversion</code>.</p>
|
||||
<p>Configuration comes from the environment too: an <code>OPENCODE_GO_API_KEY</code>, <code>OLLAMA_KEY</code> or <code>ANTHROPIC_API_KEY</code> in the environment is an endpoint. No block needs to be written for it, and what the file already defines wins.</p>
|
||||
|
||||
<h2 id="limits">Known limits, deliberately named</h2>
|
||||
<ul>
|
||||
<li><strong>HTTP/1.1 only</strong> — no HTTP/2, no h2c.</li>
|
||||
<li><strong>The cache is memory-only</strong> and lost on restart. Across instances it is shared by peers, but without coherence: the only invalidation is the TTL.</li>
|
||||
<li><strong>junction does not tokenise.</strong> It sees only the numbers the client writes, so a request that declares no budget is routed by its model and path alone.</li>
|
||||
<li><strong>No prioritisation in the queue</strong> beyond first come, first served.</li>
|
||||
<li><strong>The judge counter table is in RAM</strong>, reset on restart; that changes when a judge runs, never whether an answer is correct.</li>
|
||||
<li><strong>TLS client verification</strong> uses the system store or a per-endpoint CA. There is no certificate pinning and no client-certificate auth.</li>
|
||||
</ul>
|
||||
|
||||
<footer>junction, C99 + POSIX. Source: <code>git.kropa.tech/hiddenbox/junction</code>. The full reference is <code>README.md</code>; a worked configuration is <code>examples/olivia.conf</code>. About 15,200 lines of C in 30 files, 33 test programs.</footer>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user