feat: smart federation routing (load + VRAM + model + prefix affinity + cross-server sync) and unified Cluster UI#10124
Open
localai-bot wants to merge 16 commits into
Open
feat: smart federation routing (load + VRAM + model + prefix affinity + cross-server sync) and unified Cluster UI#10124localai-bot wants to merge 16 commits into
localai-bot wants to merge 16 commits into
Conversation
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
… VRAM) Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
…ting Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
…raction Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
…ffinity routing Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
…ractModel param Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
… sync Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
…c channel Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
…e sidebar entry Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
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.
Smart, prefix-cache-aware routing for the p2p federation server, sharing the routing brain with the NATS distributed mode, plus a unified Cluster UI. Builds on #10123 (the
pkg/clusterroutingextraction).What
The p2p federation server graduates from a blind round-robin TCP proxy into a model-aware, prefix-cache-aware, load+VRAM-aware L7 router - using the same
pkg/clusterroutingpolicy the NATS side uses, and reusing the existingcore/services/nodes/prefixcacheengine (extractor, radix index, andSync) rather than reimplementing any of it. The two distributed UIs are folded into one Cluster page.How
Stage 1 - load + VRAM-aware (L4): gossip each node's free GPU VRAM (
schema.NodeData.AvailableVRAM, fromxsysinfo); select viaclusterrouting.PickBestReplica(least in-flight, then most free VRAM). Adds a clock-injectableNodeData.IsOnlineAt.Stage 2 - L7 + model + prefix affinity: convert the proxy to an L7 HTTP-terminating proxy: buffer the request under a configurable cap (
--upload-limit, 413 over), choose a peer, stream the response (SSE keeps flowing), bypass websocket upgrades to a duplex copy, and forceConnection: closeon non-duplex forwards to avoid a keep-alive leak. Model-aware: peers gossip their model set (NodeData.Models); candidates are filtered to peers serving the requested model (empty set = eligible, so mixed-version swarms aren't starved). Prefix affinity: reuseprefixcache.ExtractChain/Indexto find the warm peer for a prompt prefix, then make the final pick with a new load-guardedclusterrouting.PickWithAffinity(keeps the VRAM tier). Observed after each serve.Stage 3 - cross-server affinity sync (opt-in): with
--affinity-sync, federation servers share affinity by reusingprefixcache.Syncover a newgenericChannelPublisheron edgevpn's generic channel (node.EnableGenericHub+ a generic-channel handler; only sync-enabled servers join, so workers/members see no traffic). Same observe/invalidate event structs as the NATS path. Also adds the eviction ticker the federation index was missing (prevents unbounded tree growth, on or off).Stage 4 - unified Cluster UI: fold
/app/p2p("swarm") and/app/nodes("nodes") into one/app/clusterpage with a shared summary and two collapsible, capability-gated sections (Distributed / Swarm). The two large pages are reused verbatim via anembeddedprop (no rewrite); a newuseP2PModehook mirrorsuseDistributedMode. Old routes redirect; one sidebar entry; i18n across 5 languages. No backend /capabilities.js/ Go-embed changes.Notes / scope
prefixcache,pkg/radixtree, the messaging events, and both existing UI pages already existed and are reused; the only new selection primitive isPickWithAffinity(to retain VRAM thatprefixcache.Selectlacks).NodeDatais JSON-marshaled, so old peers omit the new fields (read as zero/nil = eligible / lowest VRAM tier).--affinity-syncis off by default (single federation server is the common case); enable it on every server that should cohere.Testing
pkg/clusterrouting,core/schema,core/p2pcandidate/model/affinity/L7/sync).go test -race ./core/p2p/ ./core/schema/ ./pkg/clusterrouting/... ./core/services/nodes/prefixcache/green;golangci-lint0 issues on the changed Go packages.npm run build(Vite) compiles clean; eslint adds 0 new errors. The full Playwright e2e + coverage run needs CI /make test-ui(browsers + the Go mock server).proxyHTTPToPeer), the live generic-channel broadcast, and the UI e2e are integration-only; their decision/message/render logic is unit-tested or read-verified. Recommended manual smoke before merge: single-server L7, two-server--affinity-sync, and the/app/clusterpage + redirects.Assisted-by: Claude Code:claude-opus-4-8