Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Route Assistant gateway fallback through model resolution

rcourtmand20017cdb2d3
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 19643ca6b7..01fd8667be 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -426,7 +426,10 @@ runtime cost control, and shared AI transport surfaces.
provider/model route. This fallback must use chat-suitable model resolution
from `internal/ai/modelresolution`, skipping obvious non-chat endpoints such
as realtime, audio, moderation, embedding, and content-safety catalog
- entries. Fallback planning must not block the selected provider's first
+ entries. Gateway-equivalent routes, such as a direct provider model exposed
+ through a configured gateway, must be produced by that model-resolution
+ policy rather than hardcoded in chat execution or frontend UI logic.
+ Fallback planning must not block the selected provider's first
attempt on live catalog reads for every other configured provider; the hot
path may queue only explicit provider preferences or stable provider defaults
and defer fallback provider construction until the selected route actually
diff --git a/internal/ai/chat/service.go b/internal/ai/chat/service.go
index b8e08eb897..700daa9661 100644
--- a/internal/ai/chat/service.go
+++ b/internal/ai/chat/service.go
@@ -3086,7 +3086,7 @@ func (s *Service) chatProviderAttempts(_ context.Context, cfg *config.AIConfig,
}
primaryProvider, _ := config.ParseModelString(primaryModel)
- if gatewayModel, ok := modelresolution.OpenRouterEquivalentChatModel(cfg, primaryModel); ok {
+ for _, gatewayModel := range modelresolution.GatewayEquivalentChatModels(cfg, primaryModel) {
addAttempt(gatewayModel, nil)
}
for _, providerName := range cfg.GetConfiguredProviders() {
diff --git a/internal/ai/chat/service_execute_additional_test.go b/internal/ai/chat/service_execute_additional_test.go
index bfbe088a83..02a8b503f3 100644
--- a/internal/ai/chat/service_execute_additional_test.go
+++ b/internal/ai/chat/service_execute_additional_test.go
@@ -1060,7 +1060,7 @@ func TestService_ChatProviderAttemptsUsesStableFallbackModelsWithoutLiveCatalog(
}
}
-func TestService_ChatProviderAttemptsPrefersSameModelOpenRouterGatewayFallback(t *testing.T) {
+func TestService_ChatProviderAttemptsPrefersSameModelGatewayFallbackBeforeProviderDefaults(t *testing.T) {
service := &Service{}
cfg := &config.AIConfig{
ChatModel: "deepseek:deepseek-v4-pro",
diff --git a/internal/ai/modelresolution/model_resolution.go b/internal/ai/modelresolution/model_resolution.go
index 62b6072c25..6bc6db736b 100644
--- a/internal/ai/modelresolution/model_resolution.go
+++ b/internal/ai/modelresolution/model_resolution.go
@@ -111,11 +111,51 @@ func ResolveConfiguredChatProviderModelOffline(cfg *config.AIConfig, provider st
return "", fmt.Errorf("no chat model configured for %s provider", provider)
}
+type gatewayEquivalentResolver struct {
+ resolve func(cfg *config.AIConfig, model string) (string, bool)
+}
+
+var gatewayEquivalentResolvers = []gatewayEquivalentResolver{
+ {resolve: openRouterEquivalentChatModel},
+}
+
+// GatewayEquivalentChatModels maps a configured direct-provider chat model to
+// equivalent routes through configured gateway providers. Provider-specific
+// route syntax belongs in this model-resolution registry; chat execution should
+// consume the returned candidates without hardcoding a gateway.
+func GatewayEquivalentChatModels(cfg *config.AIConfig, model string) []string {
+ if cfg == nil {
+ return nil
+ }
+ routes := make([]string, 0, len(gatewayEquivalentResolvers))
+ seen := make(map[string]struct{}, len(gatewayEquivalentResolvers))
+ for _, resolver := range gatewayEquivalentResolvers {
+ candidate, ok := resolver.resolve(cfg, model)
+ if !ok {
+ continue
+ }
+ candidate = strings.TrimSpace(candidate)
+ if candidate == "" {
+ continue
+ }
+ if _, exists := seen[candidate]; exists {
+ continue
+ }
+ seen[candidate] = struct{}{}
+ routes = append(routes, candidate)
+ }
+ return routes
+}
+
// OpenRouterEquivalentChatModel maps a configured direct-provider chat model to
// the same vendor/model route through OpenRouter when that gateway is configured.
// It never calls a live model catalog; unsupported gateway routes simply fail as
// normal provider attempts and the chat fallback planner can continue.
func OpenRouterEquivalentChatModel(cfg *config.AIConfig, model string) (string, bool) {
+ return openRouterEquivalentChatModel(cfg, model)
+}
+
+func openRouterEquivalentChatModel(cfg *config.AIConfig, model string) (string, bool) {
if cfg == nil || !cfg.HasProvider(config.AIProviderOpenRouter) {
return "", false
}
diff --git a/internal/ai/modelresolution/model_resolution_offline_test.go b/internal/ai/modelresolution/model_resolution_offline_test.go
index 61d3460560..ed423ff524 100644
--- a/internal/ai/modelresolution/model_resolution_offline_test.go
+++ b/internal/ai/modelresolution/model_resolution_offline_test.go
@@ -127,3 +127,32 @@ func TestOpenRouterEquivalentChatModel_RejectsUnavailableOrNonGatewayRoutes(t *t
}
}
}
+
+func TestGatewayEquivalentChatModels_ReturnsConfiguredGatewayRoutes(t *testing.T) {
+ t.Parallel()
+
+ cfg := &config.AIConfig{
+ OpenRouterAPIKey: "sk-or-test",
+ DeepSeekAPIKey: "deepseek-test",
+ }
+
+ got := GatewayEquivalentChatModels(cfg, "deepseek:deepseek-v4-pro")
+ want := []string{"openrouter:deepseek/deepseek-v4-pro"}
+ if len(got) != len(want) {
+ t.Fatalf("GatewayEquivalentChatModels length = %d, want %d: %#v", len(got), len(want), got)
+ }
+ for i := range want {
+ if got[i] != want[i] {
+ t.Fatalf("GatewayEquivalentChatModels[%d] = %q, want %q", i, got[i], want[i])
+ }
+ }
+}
+
+func TestGatewayEquivalentChatModels_ReturnsEmptyWithoutConfiguredGateway(t *testing.T) {
+ t.Parallel()
+
+ cfg := &config.AIConfig{DeepSeekAPIKey: "deepseek-test"}
+ if got := GatewayEquivalentChatModels(cfg, "deepseek:deepseek-v4-pro"); len(got) != 0 {
+ t.Fatalf("GatewayEquivalentChatModels without gateway = %#v, want empty", got)
+ }
+}