From c91225629d049d2e6b1f069f6bcae5426776dfd9 Mon Sep 17 00:00:00 2001 From: Ed Zynda Date: Mon, 30 Mar 2026 16:12:16 +0300 Subject: [PATCH] fix: handle custom provider model persistence and bare model names Two related fixes for --provider-url handling: 1. Don't restore custom/* models from preferences without --provider-url - When user runs with --provider-url, model defaults to custom/custom - If they switch models, custom/custom gets persisted to preferences - On next run without --provider-url, restoring custom/custom fails - Now we skip restoring custom/* models when no --provider-url is provided 2. Auto-prefix bare model names with custom/ when --provider-url is set - Users often provide just the model name (e.g., qwen3.5-35b-a3b) - This failed with 'invalid model format' error - Now auto-prefixed with custom/ for OpenAI-compatible endpoints --- cmd/root.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 43df9cdb..2a23400b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -680,9 +680,15 @@ func runNormalMode(ctx context.Context) error { // Restore persisted model preference when no explicit --model flag or // config file model is set. Precedence: CLI flag > config file > saved // preference > built-in default. This mirrors how themes are persisted. + // Skip custom/* models unless --provider-url is also provided, since the + // custom provider requires a URL that was only valid for the previous session. if !modelFlagChanged && !viper.InConfig("model") { if pref := ui.LoadModelPreference(); pref != "" { - viper.Set("model", pref) + if strings.HasPrefix(pref, "custom/") && viper.GetString("provider-url") == "" { + // Don't restore custom models without a provider URL + } else { + viper.Set("model", pref) + } } } @@ -703,6 +709,15 @@ func runNormalMode(ctx context.Context) error { viper.Set("model", "custom/custom") } + // When --provider-url is set with an explicit --model that lacks a provider + // prefix (no "/"), auto-prefix with "custom/" for OpenAI-compatible endpoints. + if viper.GetString("provider-url") != "" && modelFlagChanged { + model := viper.GetString("model") + if model != "" && !strings.Contains(model, "/") { + viper.Set("model", "custom/"+model) + } + } + // Load MCP configuration. mcpConfig, err := config.LoadAndValidateConfig() if err != nil {