Commit Graph
8 Commits
Author SHA1 Message Date
lotherk 2bd8ff8891 junction: fix duplicated Authorization, relay chunked bodies de-chunked, add J_DUMP_REQ
Three findings from putting junction in front of a real, strict upstream
(opencode.ai behind Cloudflare), each measured rather than guessed:

1. Authorization was forwarded from the client AND injected from api_key_env,
   producing two Authorization headers. Ollama ignored it; Cloudflare answered
   400 Bad Request with an HTML body, which looks like a broken endpoint.
   Now the client's copy is dropped whenever the endpoint injects a key.

2. Chunked responses were relayed verbatim while Transfer-Encoding was stripped
   by the hop-by-hop filter. Clients therefore read the hex size lines as
   content: curl showed `f\r\ndata: {"a":1}`, and Hermes reported a truncated
   JSON body while junction logged relay_failed. Responses are now de-chunked
   on the fly (relay_dechunk) and sent close-delimited; the buffered path is
   unchanged. Verified with a local chunked sink: body arrives as
   `data: {"a":1}\n\ndata: {"b":2}\n\n`, no framing bytes.

3. J_DUMP_REQ=<file> writes exactly what goes upstream with Authorization
   masked. Exists because guessing at a header problem from the outside cost
   hours; now the wire format is one file away.

make test: 45 checks PASS.
2026-10-30 12:10:28 +00:00
Hermes Agent e6db2f61af junction: heartbeats while the model thinks, not just while it queues
A streaming caller already heard ': junction: waiting for a free slot' while queued.
Once it had a slot and the upstream went quiet, the stream was silent again — the
silence a proxy with a 60 s read timeout kills. Every 10 s of upstream silence now
produces ': junction: model is still working (Ns)'; the reader's poll is woken by the
connection's heartbeat_s instead of waiting out idle_timeout.

Bounded by queue_timeout and timeout (a streamer then gets an error event + [DONE]),
and a failed comment write means the client is gone, so the router stops waiting.

tests: a stub that thinks 13 s proves heartbeats appear, the answer still arrives, and
a non-streaming caller still receives nothing injected. 49 checks PASS.
2026-10-29 15:26:44 +00:00
Hermes Agent c34082f51d junction: threads, a queue, and status lines a parser cannot see
One thread per connection plus max_inflight upstream slots; further requests wait in
line (queue_timeout) instead of being refused. A waiting caller that asked for a
stream is told why it waits with SSE comment lines (': junction: waiting for a free
slot (0 ahead of you)'), which the spec says every parser must ignore — a human
watching curl sees progress, a client sees nothing it could misinterpret. The real
answer then starts in the same stream and the comments simply stop.

Trade-off, stated in the README: a streaming caller gets its 200 before the upstream
is chosen, so a later upstream failure cannot be an HTTP status any more — it travels
as a data: {"error":...} event. Non-streaming callers get nothing injected and keep
their true status code.

Also: cache and endpoint state are locked (they are shared between threads now), and
the test stub forks per connection — a serial stub made a concurrent router look
serialised, which is exactly the kind of test that lies.
2026-10-29 15:01:36 +00:00
Hermes Agent a68ed88b84 junction is a pass-through: no token estimation, no invented max_tokens
'need' now reads only max_tokens/max_completion_tokens as the client wrote them.
chars_per_token and default_max_tokens are gone (and rejected as unknown keywords, so
an old config fails loudly instead of steering nothing). A request that declares no
budget is not sized at all — the guessing is what made a 2048-context embedding
endpoint reject requests that carried no token budget in the first place.

tests: 'need' proven from a declared max_tokens, and a request without one proven to
route by model and path alone.
2026-10-29 14:46:24 +00:00
Hermes Agent a768f1061a examples: say plainly that WoL does not cross WireGuard
The sleeping box is the one on n95's own segment; a tunnel peer needs a wake hook
that talks to that side. Also marks the LAN address as a placeholder.
2026-10-29 14:14:12 +00:00
Hermes Agent 87e6348642 junction: per-target 'as', example config for the van, C WoL helper
- A rule may send a different model name per target: 'pass peer-a as M, peer-b, cloud'
  rewrites only for peer-a, so a mixed local/cloud rule still asks the cloud for the
  name the client wanted.
- examples/olivia.conf: peers on the tunnel, embedding box, sleeping workstation with
  WoL + energy gate, cloud fallback, and the policy rules each with its reason.
- tools/junction-wol.c replaces the Python magic-packet helper; hooks stay shell.
- Forwarding no longer duplicates Host/Content-Length/X-Forwarded-*: Ollama answered
  400 to a request that was valid because it arrived with two Host headers.
- need_tokens: embeddings produce a vector, not tokens, so they are not charged
  default_max_tokens (a 2048-context embed endpoint refused every request).
- /status lists every target with its model, plus the rule's need window.
2026-10-29 14:13:46 +00:00
Hermes Agent dc31481914 junction: TLS, chunked coding, response cache, header passthrough
- TLS both directions behind one j_conn handle: https upstreams with SNI, chain and
  hostname verification (system store or tls_ca) and a 'listen ... tls cert key'
  listener. Handshake has a hard deadline; a peer that closes without close_notify
  is EOF, not an error (HTTP/1.0 bodies end at close).
- Chunked request bodies decoded into the body buffer; chunked responses relayed
  byte for byte so streaming is untouched.
- Memory-only LRU response cache (method+path+model+body), honouring no-store/
  private, client no-cache, never caching streams, flushable at runtime.
- Header passthrough with hop-by-hop removal, per-endpoint static headers,
  X-Forwarded-For/Proto, and X-Junction-{Endpoint,Ms,Cache} on every response.
- No separate reachability probe: the request itself is the test (the probe wedged
  servers that serve one connection at a time).
- tests/run.sh: 34 checks incl. a TLS peer; refuses to start on a busy test port.
2026-10-29 13:57:49 +00:00
Hermes Agent 137113b0a2 junction: pf.conf-style policy router for model endpoints (C99/POSIX)
Rules are ordered and first-match-wins: model glob, path glob, required context,
hook/retry overrides, pass <endpoint>[,<endpoint>] [as <model>] or block.
Endpoints carry shell pre-hooks (exit != 0 = not yet, retried with backoff after an
optional wake command), an offline window after a failed connect, and two timeouts
(idle + total) so a thinking model logs still_working instead of looking hung.

tests/run.sh: 14 checks against C stubs (failing, gated, slow, dead endpoints).
2026-10-29 13:24:31 +00:00