Multi-model LLM load balancer (local + frontier + optional Nova) - #7
Merged
Conversation
Fan out the shared multi-model load balancer to MLX Code. Optionally spread each chat across all installed local models (native MLX + Ollama), all frontier models via OpenRouter, and an optional Nova Gateway — health-gated and load-balanced — instead of a single pinned MLX model. Off by default; existing single-model behavior is preserved when the toggles are off. - Port pure, network-free building blocks from AIStudio: ModelRegistry (discovery + pool composition), LoadBalancer (round-robin / least-busy with health gating), OpenRouterProvider / OpenAICompatibleRequest, KeychainStore. - Add LLMBalancer service (discoverEnabledPool / healthMap / generateBalanced / dispatchBalanced) wiring discovery → health → balanced dispatch. Local MLX runs in-process via MLXService; Ollama / OpenRouter / Nova ride the generic OpenAI-compatible HTTP path. MLX discovery uses MLXService.discoverModels(). - Wire balanced dispatch into ChatViewModel with clean fallback to the single pinned MLX model when the pool is empty. - Three persisted toggles in AppSettings + a new Settings → Balancer tab (gateway URL, Keychain-stored OpenRouter key). - Add network-free LoadBalancerTests (24 tests). - Update README (Multi-model load balancing section + Mermaid flow) and CHANGELOG. Nova is never a hard requirement: works with zero Nova present; the Nova Gateway is one optional, health-probed entry that drops out if unavailable. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
Fans out the shared multi-model LLM load balancer to MLX Code. When enabled, each chat is spread across all models available to the machine — all installed local models (native MLX + a local Ollama if present), all frontier models via OpenRouter, and an optional Nova Gateway — health-gated and load-balanced — instead of a single pinned MLX model.
Off by default. When every toggle is off, behavior is exactly as before (single pinned MLX model).
Nova is never a hard requirement. With zero Nova present the balancer still works over local MLX/Ollama and/or OpenRouter. The Nova Gateway is one optional entry, health-probed via
GET <url>/v1/models; if it fails it drops from the pool and everything else keeps working. No hard dependency on Nova / PG / the gateway anywhere.What changed
ModelRegistry(discovery +assemblePooltoggle composition),LoadBalancer(round-robin / least-busy + health gating),OpenRouterProvider/OpenAICompatibleRequest,KeychainStore.LLMBalancerservice mirroring AIStudio'sLLMBackendManagerbalancer surface (discoverEnabledPool/healthMap/chatCompletionBalanced/dispatchBalanced). Local MLX runs in-process viaMLXService.chatCompletion(true token streaming); Ollama / OpenRouter / Nova ride the generic OpenAI-compatible HTTP path.MLXService.discoverModels()over its configured model paths;ModelRegistry.mlxModels(fromLocalNames:)maps them into the pool.ChatViewModel: balanced dispatch is used when any toggle is on, with a clean fallback to the single pinned MLX model when the pool is empty.AppSettings+ a new Settings → Balancer tab (gateway URL, Keychain-stored OpenRouter key).LoadBalancerTests(24 tests) covering parsing, pool composition, and selection policies.Adaptations for MLX Code
MLXService.discoverModels()(MLX Code's own configured paths), not the HF hub cache.GET <novaGatewayURL>/v1/models.com.apple.security.app-sandboxin its entitlements) — nothing to disable. Only the Xcode Source Editor Extension target carries the sandbox entitlement (required by Apple for editor extensions); left untouched. Hardened Runtime / notarization intact.Verification
xcodebuild build(Debug, macOS arm64, signing off): BUILD SUCCEEDEDxcodebuild build(Release, macOS arm64, signing off): BUILD SUCCEEDEDxcodebuild test: 546 tests, 0 failures (LoadBalancerTests: 24, 0 failures)🤖 Generated with Claude Code