Repository navigation
Conversation
ashhart
added a commit
that referenced
this pull request
Nov 16, 2026
4 tasks done
…ddress, each a serve child loaded on demand A request's model field picks the child, which the router starts if need be and relays byte for byte, with --max-loaded, --idle-unload and each model's memory floor bounding what stays loaded, and --router-config FILE.toml listing the models in [[models]] tables. Single-model serve is unchanged.
ashhart
force-pushed
the
lead/serve-router
branch
from
November 22, 2026 05:02
827bebc to
595965f
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One
tensorfold serveserves one model, so switching models means restarting it, and a client can't pick between models at one address. Users coming from Ollama, LM Studio or llama.cpp's router mode expect one server that loads whatever model a request names.tensorfold serve --routerdoes that, with each model in its owntensorfold servechild.What this changes
Command:
tensorfold serve --router [--router-config FILE.toml] [--max-loaded N] [--idle-unload S] [--host H] [--port P] [--api-key K] [--api-key-file F] [--allowed-host N] [--allowed-origin O].Which models are available: without a config, every complete checkpoint in the local cache that a family serves, from the same scan
tensorfold modelsuses. A config lists models explicitly, each with anid, amodel(repo id or path), optionalaliases, and serve flags read with the serve config's own TOML rules (docs/serve-config.md). A cached model that serve would refuse is skipped and logged; one named in a config stops startup.Routing:
modelare forwarded to that model's child, by id or alias:/v1/chat/completions,/v1/completions,/v1/responses,/v1/messagesandcount_tokens,/v1/embeddings,/v1/rerank,/tokenize,/detokenize, and Ollama's/api/chat,/api/generate,/api/embed,/api/show.model_not_found, Anthropic'snot_found_error, or Ollama's.The relay: a request body is read in full and re-sent with a fresh
Content-Length, with hop-by-hop headers dropped, so there's no request-smuggling path to a child. The reply is relayed byte for byte as it arrives, SSE included, while tracking chunked or fixed framing to find its end. A client that hangs up closes the child's connection, so the child cancels the request.Children:
Managed.spawn). It has its own process group, so a Ctrl-C or closed terminal reaches only the router, which then stops every child.Authorizationandx-api-keyand sends the child's key. A request without it gets 401 on the child's port. The router's own keys (--api-key, scopes) go through the same key gate the server uses, moved verbatim fromserver.zigintoauth_gate.zig.--max-loaded N(default 1) caps how many children run at once. Loading another first stops the least recently used child with no request in flight. If every loaded child is busy, the request waits up to 5 minutes, then gets a 503.tensorfold infoestimate) is checked against what loaded children hold, and a model that can't fit even alone is refused by name.--idle-unloadstops idle children.Router-level routes:
/healthlists loaded children,/v1/modelslists every available model with aloadedflag, and Ollama's/api/tags,/api/psand/api/versionare served./metricsis refused with a note that metrics are per model.Not supported yet: every other route, including WebSocket upgrades and
GET /v1/responses/{id}, gets 404unsupported_routeby name.Unchanged: single-model
tensorfold serve; the goldens show 0 unexpected differences.Windows:
--routeris refused by name, since the child and relay code is POSIX.Issue: n/a. This came from the 16 Nov check of competitor gap docs against main (Ollama, llama.cpp's router mode, omlx, mlx-serve, qwegn and exo serve several models with on-demand loading); no issue or PR covered it.
Stacked on: cli: tensorfold chat talks to a model in the terminal, through a serve child of its own or a running server's --url #3538 (
tensorfold chat), commitsbd2e51576b,8dffea7872,762c91eab6and407722e939. This PR adds79f6a9bdda. Both extend the benchmark's serve child, and there's now one set of options:served,lock,own_group,keyandwords;environ,guard,stopandfailure;atc overlap --json: to run after review. Known text conflicts:main.zig's and README's usage lines with cli: tensorfold rm removes a cached checkpoint, or one snapshot with the refs naming it and the blobs only it links to #3525 (rm);docs/api.mdrow with server: POST /v1/responses/input_tokens counts the prompt POST /v1/responses would prefill, generating nothing #3537;zig/src/cli/models.zigis untouched, so it merges cleanly with cli: tensorfold models lists what fits this machine, with a rough one-stream speed #3483. Its scan for the router lives inhub.zig(cachedRepos), repeating about ten lines ofmodels.zig's scan until both land.Checks on this head
tools/pr_check.py: 0 errors, 1 advisory warning, the PR number).zig build test-router-host(new,/bin/shstand-in children with in-process fake servers): 49/49.zig build test-router-serve-host(new, realfake_servechildren): 3/3.zig build test-server-cpu: 1531 pass, 9 skip.zig build test-golden: 322/335 equal, 0 unexpected (main's 13 known differences); security 55/55.zig build test-serve-flags-host: 37/37.test-cli: 41 pass, 15 skip.test-cli-memory-host: 17/17.zig build test-chat-cli-host: 46/46. The fivetest-benchmark-*steps andtest-thinking-benchmark-hostpass.check-chat-windows-hostcompiles.zig fmt --check,git diff --check: clean.--max-loaded, the busy wait and its timeout;zig build server-cpu:/healthand/v1/models.Receipt
n/a for speed: each model runs in an unchanged
tensorfold servechild, so tokens and speed are the child's own. The router adds one loopback hop and relays bytes unchanged. Measuring that hop with a real model is the follow-up.Follow-ups, not built:
/api/pulland/api/deletethrough the router, and the cancel route;Checklist
The title and description match the head commit.
New tests fail before the change, pass after it, and skip cleanly without their dependency.
Comments and docstrings are one line. No measurements or history in the source.
No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
Every token still goes through the lane rounds: the router forwards to an unchanged serve.
Synthena (Ash's Agent)