diff --git a/README.md b/README.md index 135ec79..d5557ed 100644 --- a/README.md +++ b/README.md @@ -324,6 +324,12 @@ reporting the provider's error. The wait is visible: the prompt line says `retrying in 5 s: ...` until the next attempt answers, so a pause does not look like a hang. Ctrl-C during a wait ends it at once. +A stream that goes completely silent is treated as a hang, not as a slow +answer: curl is started with `--speed-limit 1 --speed-time 180` +(`SPLINTER_STREAM_STALL_S` overrides the seconds), so a provider that sends +nothing for that long is cut off and the retry runs. A provider that keeps +streaming - even slowly - is never interrupted by it. + ## Colour, measured A CDE palette is eight mid-tones; painted literally, a role can sit a few diff --git a/docs/PLUGINS.md b/docs/PLUGINS.md index 9fee2bf..fd1151c 100644 --- a/docs/PLUGINS.md +++ b/docs/PLUGINS.md @@ -264,31 +264,34 @@ and that header is the identity: a 200 with the header is junction, a 200 without it is "not junction, or a proxy in front of it" — a health check that trusts any answer is wrong exactly when it matters. -Every response header is kept, not only the identity one. `/status` adds the -ordinary HTTP headers, the model route adds `X-Junction-Ms`/`X-Junction-Cache` -and its own `X-Junction-Endpoint`. That last one is **the probe's** route -(`/v1/models` is routed to `opencode-go` by junction's rules), not the route of -the conversation — so the widget does not print it as "endpoint". The real -route comes from `/status`' `rules`: the rule matching this run's model (the -active provider's model) gives the targets, and the endpoint table gives their -health. +The widget is only what belongs to the model this run is on: its name (from +the engine, not from the provider's configured default — `/model` can switch +the model without touching the config) and the targets the matching +`/status` rule sends it to. Nothing else: a `!` marks a target whose own +health probe is failing. ``` junction -20m up mcp 5/5 models 9 -route kontron! kompute0 -kompute1 kompute2 -q 1/32 req 11 ok 0 fail ep 25 (3 ex) -probe-ms=449 probe-cache=off mcp=1 +deepseek-v4.1-flash +route opencode-go0 +opencode-go1 +opencode-go2 +ollama0-splinter +4/4 up ``` -A `!` marks a route target whose own health probe is failing; `/junction` -spells out `route health: 3/4 up, down: kontron`. The numbers come from the -status route (uptime, MCP servers, queue, requests, endpoints, p95) and -`/v1/models` (how many models it serves, and the probe's headers). junction -accepts `/status`, `/v1/status`, `/queue` and `/v1/queue` as the same route; -the plugin remembers which one answered and only tries the whole list when it -stops. It does not count a second time. +The rule is chosen by exact model match, then glob (`*`, `?`), then +catch-all; rules with a `path` describe another route (`/v1/models`) and are +skipped. A target whose probe is down gets the `!`. + +Everything else is `/junction`, not the sidebar: uptime, MCP servers, queue, +requests, endpoints with p95 and exhausted counts, the model count from +`/v1/models`, and **every response header** of every probe grouped by source. +That includes `X-Junction-Ms`/`X-Junction-Cache` and the probe's own +`X-Junction-Endpoint` (which is `/v1/models` -> `opencode-go`, not the +conversation's route). junction accepts `/status`, `/v1/status`, `/queue` and +`/v1/queue` as the same route; the plugin remembers which one answered and +only tries the whole list when it stops. It does not count a second time. That is a widget, a status segment (`junction 20m up`), the tool `junction_status` and `/junction`. The address and the key come from the diff --git a/include/splinter_plugin.h b/include/splinter_plugin.h index 608dbe2..7d8c95a 100644 --- a/include/splinter_plugin.h +++ b/include/splinter_plugin.h @@ -152,6 +152,14 @@ int sp_host_add_compactor(struct sp_host *, const struct sp_compactor *); int sp_host_add_gate(struct sp_host *, const struct sp_gate *); int sp_host_add_status(struct sp_host *, const struct sp_status *); const struct sp_meter *sp_host_meter(struct sp_host *); +/* + * The model the engine is on right now. The config says what a provider was + * configured with; /model can change the model without touching it, and a + * plugin that shows routing must not guess (it did, and named the wrong + * route). Empty until the engine sets it. + */ +const char *sp_host_model(struct sp_host *h); +void sp_host_set_model(struct sp_host *h, const char *model); void sp_host_set_meter(struct sp_host *, const struct sp_meter *); /* * Thread-safe: a copy under the host lock, and a change of only the caller's diff --git a/plugins/junction/junction.c b/plugins/junction/junction.c index 71c4934..0d1f62d 100644 --- a/plugins/junction/junction.c +++ b/plugins/junction/junction.c @@ -670,46 +670,39 @@ compose(void) } { /* - * The route the conversation takes, from the rule that matches - * this run's model. A target whose own health probe fails gets - * a "!"; /junction spells the counts out. + * Only what belongs to the model this run is on: its name and the + * route the matching rule gives it, one target per row. A "!" + * marks a target whose own health probe is failing. The server + * counters (MCP servers, queue, requests, probe headers) are not + * about the conversation and live in /junction. */ - char marked[sizeof(j.route) + 64], copy[sizeof(j.route)]; + char copy[sizeof(j.route)]; char *tok, *save = NULL; - size_t off = 0; + size_t off; + int first = 1; - marked[0] = '\0'; + off = (size_t)snprintf(j.widget, sizeof(j.widget), "%s\nroute ", + j.model[0] != '\0' ? j.model : "(model unknown)"); snprintf(copy, sizeof(copy), "%s", j.route); for (tok = strtok_r(copy, " ", &save); tok != NULL; tok = strtok_r(NULL, " ", &save)) { - const struct jep *e = route_ep(tok); - int is_down = (e != NULL && e->probe_ok != 1); + const struct jep *ep = route_ep(tok); + int is_down = (ep != NULL && ep->probe_ok != 1); - off += (size_t)snprintf(marked + off, - sizeof(marked) - off, "%s%s%s", - off > 0 ? " " : "", tok, is_down ? "!" : ""); + if (off < sizeof(j.widget)) + off += (size_t)snprintf(j.widget + off, + sizeof(j.widget) - off, "%s%s%s", + first ? "" : "\n", tok, + is_down ? "!" : ""); + first = 0; } - if (marked[0] != '\0') - snprintf(j.widget, sizeof(j.widget), - "%s up mcp %u/%u models %u\n" - "route %s\n" - "q %u/%u req %u ok %u fail ep %u (%u ex)\n" - "%s", - d, j.mcp_ok, j.mcp_total, j.models, marked, - j.queue_inflight, j.queue_max, j.req_ok, - j.req_fail, j.endpoints, j.exhausted, - j.stats[0] != '\0' ? j.stats : - "(no X-Junction headers)"); - else - snprintf(j.widget, sizeof(j.widget), - "%s up mcp %u/%u models %u\n" - "q %u/%u req %u ok %u fail ep %u (%u ex)\n" - "%s", - d, j.mcp_ok, j.mcp_total, j.models, - j.queue_inflight, j.queue_max, j.req_ok, - j.req_fail, j.endpoints, j.exhausted, - j.stats[0] != '\0' ? j.stats : - "(no X-Junction headers)"); + if (first) + off = (size_t)snprintf(j.widget, sizeof(j.widget), + "%s\nroute (no rule matched)", + j.model[0] != '\0' ? j.model : "(model unknown)"); + if (off < sizeof(j.widget)) + snprintf(j.widget + off, sizeof(j.widget) - off, + "\n%u/%u up", j.route_up, j.route_n); } if (j.mcp_total > 0 && j.mcp_ok < j.mcp_total) snprintf(j.status, sizeof(j.status), "junction %s up, mcp %u/%u", @@ -755,6 +748,14 @@ current_model(char *buf, size_t cap) size_t i; buf[0] = '\0'; + { + const char *live = sp_host_model(j.host); + + if (live != NULL && *live != '\0') { + snprintf(buf, cap, "%s", live); + return; + } + } if (cfg == NULL) return; for (i = 0; act != NULL && *act != '\0' && i < cfg->ndelegates; i++) diff --git a/src/backend/engine.c b/src/backend/engine.c index acaebfa..c9cb84c 100644 --- a/src/backend/engine.c +++ b/src/backend/engine.c @@ -211,6 +211,8 @@ sp_engine_state(struct sp_engine *e, struct sp_engine_state *st) if (e == NULL || st == NULL) return -1; memset(st, 0, sizeof(*st)); + if (e->host != NULL) + sp_host_set_model(e->host, e->cur_model); snprintf(st->model, sizeof(st->model), "%s", e->cur_model); snprintf(st->endpoint, sizeof(st->endpoint), "%s", e->cur_endpoint); snprintf(st->agent, sizeof(st->agent), "%s", e->agent_name); @@ -1636,6 +1638,8 @@ cmd_model(struct sp_engine *e, const char *args, struct sp_buf *out) } sp_buf_free(&perr); } + if (e->host != NULL) + sp_host_set_model(e->host, e->cur_model); ev_push(e, SP_EV_STATE, 0, NULL, NULL); } @@ -2171,6 +2175,7 @@ load_plugins(struct sp_engine *e, const struct sp_engine_opts *o, e->ag.host = host; e->host = host; sp_host_set_config(host, e->conf); + sp_host_set_model(host, e->cur_model); for (k = 0; k < o->nplugins && k < SP_ENGINE_PLUGINS; k++) { const char *p = o->plugins[k]; char self[512], found[800]; diff --git a/src/backend/plugin.c b/src/backend/plugin.c index 9bc3482..7510787 100644 --- a/src/backend/plugin.c +++ b/src/backend/plugin.c @@ -82,6 +82,7 @@ struct sp_host { size_t compactions; size_t failed; unsigned turns; + char model[256]; /* what the run is on */ /* loaded plugins, in load order, so shutdown() runs in reverse */ const struct sp_plugin *loaded[MAX_PLUGINS]; size_t nloaded; @@ -489,6 +490,29 @@ sp_host_compaction_stats(struct sp_host *h, size_t *compactions, return h != NULL ? h->compactions : 0; } +const char * +sp_host_model(struct sp_host *h) +{ + static __thread char copy[256]; + + if (h == NULL) + return ""; + pthread_mutex_lock(&h->lock); + snprintf(copy, sizeof(copy), "%s", h->model); + pthread_mutex_unlock(&h->lock); + return copy; +} + +void +sp_host_set_model(struct sp_host *h, const char *model) +{ + if (h == NULL) + return; + pthread_mutex_lock(&h->lock); + snprintf(h->model, sizeof(h->model), "%s", model != NULL ? model : ""); + pthread_mutex_unlock(&h->lock); +} + struct sp_registry * sp_host_registry(struct sp_host *h) { diff --git a/src/backend/transport_anthropic.c b/src/backend/transport_anthropic.c index 1a4940e..4ac56c5 100644 --- a/src/backend/transport_anthropic.c +++ b/src/backend/transport_anthropic.c @@ -170,8 +170,21 @@ as_curl(const struct as_ctx *c, const char *body_path, int stream, args[n++] = "-sS"; args[n++] = "-A"; args[n++] = "splinter/" SP_VERSION; - if (stream) + if (stream) { + /* + * A stream that goes completely silent is a hang, not a slow + * answer: a provider can stream for minutes, but no byte at all + * for SPLINTER_STREAM_STALL_S (default 180) means nobody will + * answer. curl ends the transfer with 28, the agent retries. + */ + const char *stall = getenv("SPLINTER_STREAM_STALL_S"); + args[n++] = "-N"; + args[n++] = "--speed-limit"; + args[n++] = "1"; + args[n++] = "--speed-time"; + args[n++] = stall != NULL && atoi(stall) > 0 ? stall : "180"; + } args[n++] = "-m"; args[n++] = tmo; args[n++] = "-X"; diff --git a/src/backend/transport_openai.c b/src/backend/transport_openai.c index fd715ab..9ce0a55 100644 --- a/src/backend/transport_openai.c +++ b/src/backend/transport_openai.c @@ -156,8 +156,21 @@ openai_curl(const struct openai_ctx *c, const char *body_path, int stream, args[n++] = "-sS"; args[n++] = "-A"; args[n++] = ua; - if (stream) + if (stream) { + /* + * A stream that goes completely silent is a hang, not a slow + * answer: a provider can stream for minutes, but no byte at all + * for SPLINTER_STREAM_STALL_S (default 180) means nobody will + * answer. curl ends the transfer with 28, the agent retries. + */ + const char *stall = getenv("SPLINTER_STREAM_STALL_S"); + args[n++] = "-N"; + args[n++] = "--speed-limit"; + args[n++] = "1"; + args[n++] = "--speed-time"; + args[n++] = stall != NULL && atoi(stall) > 0 ? stall : "180"; + } args[n++] = "-m"; args[n++] = tmo; args[n++] = "-X"; diff --git a/src/frontend/curses.c b/src/frontend/curses.c index 1b8dfd5..d87aff5 100644 --- a/src/frontend/curses.c +++ b/src/frontend/curses.c @@ -1265,7 +1265,7 @@ draw_sidebar(struct ui_state *s, const char *id, const char *dir, y++; snprintf(key, sizeof(key), "widget.%s", name); sidebar_heading(&y, cols, sp_td(key, name)); - side_text(&y, cols, text, 6, 1); + side_text(&y, cols, text, 8, 1); snprintf(cont_name, sizeof(cont_name), "%s", name); } if (cont_name[0] != '\0' && y < getmaxy(ui_side) - 2) diff --git a/tests/test_junction.c b/tests/test_junction.c index e2da059..1ca4aa2 100644 --- a/tests/test_junction.c +++ b/tests/test_junction.c @@ -99,16 +99,15 @@ main(int argc, char **argv) CHECK(sp_host_widget_snapshot(host, snap, sizeof(snap)) > 0); CHECK(strstr(snap, "junction: ") != NULL); CHECK(strstr(snap, "up") != NULL); - CHECK(strstr(snap, "mcp=1") != NULL); - CHECK(strstr(snap, "mcp 4/5") != NULL); - /* the alias /v1/status answered, and the model route's headers are shown */ - CHECK(strstr(snap, "models 3") != NULL); - /* the session's route, not the probe's: a is up, b is not, hence "b!" */ - CHECK(strstr(snap, "route a b!") != NULL); - CHECK(strstr(snap, "probe-ms=12") != NULL); - /* the probe's endpoint header is not presented as the session's route */ + /* + * The widget is only the model and its route: a is up, b is not (hence + * "b!"), and the counters are not repeated here - they are /junction's + * business. + */ + CHECK(strstr(snap, "m\nroute a\nb!\n1/2 up") != NULL); + CHECK(strstr(snap, "mcp 4/5") == NULL); + CHECK(strstr(snap, "models 3") == NULL); CHECK(strstr(snap, "endpoint=") == NULL); - CHECK(strstr(snap, "1 ex") != NULL); CHECK(!continuation_has_colon(snap)); /* the status segment the status line and /status show */