Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

Make sure all launchers know about cloud model metadata (#19223)

J Berg456867481084
diff --git a/cmd/launch/claude.go b/cmd/launch/claude.go
index efadf709a..67ce3f81b 100644
--- a/cmd/launch/claude.go
+++ b/cmd/launch/claude.go
@@ -185,19 +185,18 @@ func (c *Claude) modelEnvVars(model string, models []LaunchModel) []string {
"CLAUDE_CODE_SUBAGENT_MODEL=" + model,
}
- var contextLength int
- if m, ok := findLaunchModel(models, model); ok && (m.Remote || isCloudModelName(model)) {
- contextLength = m.ContextLength
- }
- if contextLength <= 0 {
- if limit, ok := lookupCloudModelLimit(model); ok {
- contextLength = limit.Context
- }
- }
- if contextLength > 0 {
- env = append(env, "CLAUDE_CODE_MAX_CONTEXT_TOKENS="+strconv.Itoa(contextLength))
- if os.Getenv("CLAUDE_CODE_AUTO_COMPACT_WINDOW") == "" && contextLength >= claudeMinAutoCompactWindow {
- env = append(env, "CLAUDE_CODE_AUTO_COMPACT_WINDOW="+strconv.Itoa(min(contextLength, claudeMaxAutoCompactWindow)))
+ resolved, ok := findLaunchModel(models, model)
+ if ok {
+ resolved = resolved.WithCloudLimits().WithServerMetadata()
+ } else {
+ resolved = fallbackLaunchModel(model)
+ }
+ if resolved.Remote || isCloudModelName(model) {
+ if ctxLen := resolved.ContextLength; ctxLen > 0 {
+ env = append(env, "CLAUDE_CODE_MAX_CONTEXT_TOKENS="+strconv.Itoa(ctxLen))
+ if os.Getenv("CLAUDE_CODE_AUTO_COMPACT_WINDOW") == "" && ctxLen >= claudeMinAutoCompactWindow {
+ env = append(env, "CLAUDE_CODE_AUTO_COMPACT_WINDOW="+strconv.Itoa(min(ctxLen, claudeMaxAutoCompactWindow)))
+ }
}
}
diff --git a/cmd/launch/deepseek_harness.go b/cmd/launch/deepseek_harness.go
index 84ab05766..813b935e7 100644
--- a/cmd/launch/deepseek_harness.go
+++ b/cmd/launch/deepseek_harness.go
@@ -22,8 +22,36 @@ const (
deepSeekHarnessProvider = "ollama"
deepSeekHarnessAPIKeyEnv = "OLLAMA_LAUNCH_DSH_API_KEY"
deepSeekHarnessWebSettings = "web-search-deepseek"
+
+ deepSeekHarnessCompactionHeadroom = 65_536
+ deepSeekHarnessMaxTokensContextFrac = 8
)
+// deepSeekHarnessMaxTokens bounds the maxTokens dsh is told about so that its
+// automatic context compaction keeps working. dsh (0.2.x) reserves maxTokens
+// plus a 64k headroom out of the context window before it will compact, and
+// disables compaction entirely when that reservation reaches the window. Our
+// cloud limits often report an output limit equal to the full context window,
+// which would leave dsh running without compaction until the context is simply
+// full. The compaction threshold is also the window minus that reservation, so
+// a large maxTokens makes compaction fire early: half of a 262k window as
+// maxTokens would compact at 64k. Capping maxTokens to an eighth of the window
+// keeps compaction at roughly seven eighths, and when even that leaves under
+// two headrooms of room the value is omitted so dsh falls back to its default.
+func deepSeekHarnessMaxTokens(contextLength, maxOutputTokens int) int {
+ if maxOutputTokens <= 0 {
+ return 0
+ }
+ if contextLength <= 0 {
+ return maxOutputTokens
+ }
+ maxTokens := min(maxOutputTokens, contextLength/deepSeekHarnessMaxTokensContextFrac)
+ if contextLength-maxTokens < 2*deepSeekHarnessCompactionHeadroom {
+ return 0
+ }
+ return maxTokens
+}
+
var (
deepSeekHarnessLookPath = exec.LookPath
deepSeekHarnessCommand = exec.Command
@@ -392,8 +420,8 @@ func deepSeekHarnessModelConfigs(primary string, models []LaunchModel) []any {
if item.ContextLength > 0 {
entry["contextWindow"] = item.ContextLength
}
- if item.MaxOutputTokens > 0 {
- entry["maxTokens"] = item.MaxOutputTokens
+ if maxTokens := deepSeekHarnessMaxTokens(item.ContextLength, item.MaxOutputTokens); maxTokens > 0 {
+ entry["maxTokens"] = maxTokens
}
configs = append(configs, entry)
}
diff --git a/cmd/launch/deepseek_harness_test.go b/cmd/launch/deepseek_harness_test.go
index 212bbdfc3..392e88c3b 100644
--- a/cmd/launch/deepseek_harness_test.go
+++ b/cmd/launch/deepseek_harness_test.go
@@ -123,8 +123,8 @@ func TestDeepSeekHarnessConfigurePreservesSettingsAndIsIdempotent(t *testing.T)
t.Fatalf("local model input = %#v", local["input"])
}
cloud, _ := configuredModels[1].(map[string]any)
- if cloud["id"] != "kimi-k2.6:cloud" || cloud["contextWindow"] != 262144 || cloud["maxTokens"] != 262144 {
- t.Fatalf("cloud model = %#v", cloud)
+ if cloud["id"] != "kimi-k2.6:cloud" || cloud["contextWindow"] != 262144 || cloud["maxTokens"] != 32768 {
+ t.Fatalf("cloud model = %#v, want maxTokens clamped to a quarter of the compaction budget", cloud)
}
web, _ := settings[deepSeekHarnessWebSettings].(map[string]any)
if web["baseURL"] != "http://127.0.0.1:12345/v1" || web["apiKeyEnv"] != deepSeekHarnessAPIKeyEnv || web["model"] != "qwen3.5:latest" {
@@ -554,3 +554,23 @@ func TestDeepSeekHarnessInstallDependencyError(t *testing.T) {
t.Fatalf("error = %v", err)
}
}
+
+func TestDeepSeekHarnessMaxTokensKeepsCompactionBudget(t *testing.T) {
+ tests := []struct {
+ name string
+ contextLength int
+ maxOutput int
+ want int
+ }{
+ {"output below the fraction is kept", 262_144, 16_384, 16_384},
+ {"output equal to context is clamped", 262_144, 262_144, 32_768},
+ {"small context leaves no budget", 131_072, 131_072, 0},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := deepSeekHarnessMaxTokens(tt.contextLength, tt.maxOutput); got != tt.want {
+ t.Fatalf("deepSeekHarnessMaxTokens(%d, %d) = %d, want %d", tt.contextLength, tt.maxOutput, got, tt.want)
+ }
+ })
+ }
+}
diff --git a/cmd/launch/kimi.go b/cmd/launch/kimi.go
index 6c4935f41..0b31b182b 100644
--- a/cmd/launch/kimi.go
+++ b/cmd/launch/kimi.go
@@ -1,7 +1,6 @@
package launch
import (
- "context"
"encoding/json"
"fmt"
"os"
@@ -9,9 +8,7 @@ import (
"path/filepath"
"runtime"
"strings"
- "time"
- "github.com/ollama/ollama/api"
"github.com/ollama/ollama/envconfig"
)
@@ -23,10 +20,7 @@ const (
kimiDefaultMaxContextSize = 32768
)
-var (
- kimiGOOS = runtime.GOOS
- kimiModelShowTimeout = 5 * time.Second
-)
+var kimiGOOS = runtime.GOOS
func (k *Kimi) String() string { return "Kimi Code CLI" }
@@ -191,48 +185,13 @@ func resolveKimiMaxContextSize(model string) int {
return l.Context
}
- client, err := api.ClientFromEnvironment()
- if err != nil {
- return kimiDefaultMaxContextSize
- }
-
- ctx, cancel := context.WithTimeout(context.Background(), kimiModelShowTimeout)
- defer cancel()
- resp, err := client.Show(ctx, &api.ShowRequest{Model: model})
- if err != nil {
- return kimiDefaultMaxContextSize
- }
-
- if n, ok := modelInfoContextLength(resp.ModelInfo); ok {
+ if n := showContextLength(model); n > 0 {
return n
}
return kimiDefaultMaxContextSize
}
-func modelInfoContextLength(modelInfo map[string]any) (int, bool) {
- for key, val := range modelInfo {
- if !strings.HasSuffix(key, ".context_length") {
- continue
- }
- switch v := val.(type) {
- case float64:
- if v > 0 {
- return int(v), true
- }
- case int:
- if v > 0 {
- return v, true
- }
- case int64:
- if v > 0 {
- return int(v), true
- }
- }
- }
- return 0, false
-}
-
func ensureKimiInstalled() (string, error) {
if path, err := findKimiBinary(); err == nil {
return path, nil
diff --git a/cmd/launch/kimi_test.go b/cmd/launch/kimi_test.go
index bb5783d2b..63337ce2f 100644
--- a/cmd/launch/kimi_test.go
+++ b/cmd/launch/kimi_test.go
@@ -286,9 +286,9 @@ func TestResolveKimiMaxContextSize(t *testing.T) {
defer srv.Close()
t.Setenv("OLLAMA_HOST", srv.URL)
- oldTimeout := kimiModelShowTimeout
- kimiModelShowTimeout = 100 * 1000 * 1000 // 100ms
- t.Cleanup(func() { kimiModelShowTimeout = oldTimeout })
+ oldTimeout := modelShowTimeout
+ modelShowTimeout = 100 * 1000 * 1000 // 100ms
+ t.Cleanup(func() { modelShowTimeout = oldTimeout })
got := resolveKimiMaxContextSize("llama3.2")
if got != kimiDefaultMaxContextSize {
diff --git a/cmd/launch/model_inventory.go b/cmd/launch/model_inventory.go
index b91c20c9e..01a21271d 100644
--- a/cmd/launch/model_inventory.go
+++ b/cmd/launch/model_inventory.go
@@ -2,14 +2,30 @@ package launch
import (
"context"
+ "errors"
"slices"
"strings"
"sync"
+ "sync/atomic"
+ "time"
"github.com/ollama/ollama/api"
modelpkg "github.com/ollama/ollama/types/model"
)
+var (
+ modelShowTimeout = 5 * time.Second
+ lookupServerModelMetadata = cachedServerModelMetadata
+ serverModelMetadataCache sync.Map
+ serverModelMetadataUnavailable atomic.Bool
+)
+
+type serverModelMetadata struct {
+ ContextLength int
+ Capabilities []modelpkg.Capability
+ Thinking *modelpkg.Thinking
+}
+
// LaunchModel is the model metadata Launch passes to integration config
// writers after resolving selected model names through the per-run inventory.
type LaunchModel struct {
@@ -46,6 +62,102 @@ func (m LaunchModel) WithCloudLimits() LaunchModel {
return m
}
+func (m LaunchModel) WithServerMetadata() LaunchModel {
+ if (!m.Remote && !isCloudModelName(m.Name)) || (m.ContextLength > 0 && len(m.Capabilities) > 0) {
+ return m
+ }
+ meta, ok := lookupServerModelMetadata(m.Name)
+ if !ok {
+ return m
+ }
+ if m.ContextLength <= 0 {
+ m.ContextLength = meta.ContextLength
+ }
+ if len(m.Capabilities) == 0 {
+ m.Capabilities = slices.Clone(meta.Capabilities)
+ m.ToolCapable = slices.Contains(m.Capabilities, modelpkg.CapabilityTools)
+ }
+ if m.Thinking == nil {
+ m.Thinking = meta.Thinking.Clone()
+ }
+ return m
+}
+
+type serverModelMetadataEntry struct {
+ meta serverModelMetadata
+ ok bool
+}
+
+func cachedServerModelMetadata(model string) (serverModelMetadata, bool) {
+ if v, ok := serverModelMetadataCache.Load(model); ok {
+ entry := v.(serverModelMetadataEntry)
+ return entry.meta, entry.ok
+ }
+ if serverModelMetadataUnavailable.Load() {
+ return serverModelMetadata{}, false
+ }
+ meta, err := showModelMetadata(model)
+ if err != nil {
+ var statusErr api.StatusError
+ var authErr api.AuthorizationError
+ if !errors.As(err, &statusErr) && !errors.As(err, &authErr) {
+ serverModelMetadataUnavailable.Store(true)
+ }
+ }
+ ok := err == nil && (meta.ContextLength > 0 || len(meta.Capabilities) > 0 || meta.Thinking != nil)
+ serverModelMetadataCache.Store(model, serverModelMetadataEntry{meta: meta, ok: ok})
+ return meta, ok
+}
+
+func showModelMetadata(model string) (serverModelMetadata, error) {
+ client, err := api.ClientFromEnvironment()
+ if err != nil {
+ return serverModelMetadata{}, err
+ }
+
+ ctx, cancel := context.WithTimeout(context.Background(), modelShowTimeout)
+ defer cancel()
+ resp, err := client.Show(ctx, &api.ShowRequest{Model: model})
+ if err != nil {
+ return serverModelMetadata{}, err
+ }
+
+ meta := serverModelMetadata{
+ Capabilities: append([]modelpkg.Capability(nil), resp.Capabilities...),
+ Thinking: resp.Thinking.Clone(),
+ }
+ meta.ContextLength, _ = modelInfoContextLength(resp.ModelInfo)
+ return meta, nil
+}
+
+func showContextLength(model string) int {
+ meta, _ := showModelMetadata(model)
+ return meta.ContextLength
+}
+
+func modelInfoContextLength(modelInfo map[string]any) (int, bool) {
+ for key, val := range modelInfo {
+ if !strings.HasSuffix(key, ".context_length") {
+ continue
+ }
+ switch v := val.(type) {
+ case float64:
+ if v > 0 {
+ return int(v), true
+ }
+ case int:
+ if v > 0 {
+ return v, true
+ }
+ case int64:
+ if v > 0 {
+ return int(v), true
+ }
+ }
+ }
+ return 0, false
+}
+
type modelInventory struct {
client *api.Client
@@ -122,7 +234,7 @@ func resolveLaunchModels(names []string, models []LaunchModel) ([]LaunchModel, b
localMiss := false
for _, name := range names {
if model, ok := findLaunchModel(models, name); ok {
- resolved = append(resolved, model.WithCloudLimits())
+ resolved = append(resolved, model.WithCloudLimits().WithServerMetadata())
continue
}
if !isCloudModelName(name) {
@@ -147,7 +259,7 @@ func launchModelFromListResponse(model api.ListModelResponse) LaunchModel {
}
func fallbackLaunchModel(name string) LaunchModel {
- return LaunchModel{Name: name, Remote: isCloudModelName(name)}.WithCloudLimits()
+ return LaunchModel{Name: name, Remote: isCloudModelName(name)}.WithCloudLimits().WithServerMetadata()
}
func findLaunchModel(models []LaunchModel, name string) (LaunchModel, bool) {
diff --git a/cmd/launch/model_inventory_test.go b/cmd/launch/model_inventory_test.go
index 2a8b8075e..f6458fc13 100644
--- a/cmd/launch/model_inventory_test.go
+++ b/cmd/launch/model_inventory_test.go
@@ -2,11 +2,14 @@ package launch
import (
"context"
+ "encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
+ "sync/atomic"
"testing"
+ "time"
"github.com/ollama/ollama/api"
modelpkg "github.com/ollama/ollama/types/model"
@@ -78,3 +81,104 @@ func TestModelInventoryResolveDoesNotRefreshCloudMiss(t *testing.T) {
t.Fatalf("cloud limits not applied: %#v", got[0])
}
}
+
+func TestFallbackLaunchModelUsesServerMetadata(t *testing.T) {
+ useServerContextLookup(t)
+
+ var shown []string
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path != "/api/show" {
+ http.NotFound(w, r)
+ return
+ }
+ var req api.ShowRequest
+ if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
+ t.Fatalf("decode show request: %v", err)
+ }
+ shown = append(shown, req.Model)
+ fmt.Fprint(w, `{"capabilities":["vision","thinking","completion","tools"],"thinking":{"values":[false,"low","high"],"default":"high"},"model_info":{"deepseek4.context_length":1048576}}`)
+ }))
+ defer srv.Close()
+ t.Setenv("OLLAMA_HOST", srv.URL)
+
+ t.Run("cloud model missing from limits", func(t *testing.T) {
+ shown = nil
+ got := fallbackLaunchModel("deepseek-v4-pro-inventory-test:cloud")
+ if got.ContextLength != 1_048_576 {
+ t.Fatalf("ContextLength = %d, want 1048576", got.ContextLength)
+ }
+ if !got.ToolCapable || !got.HasCapability(modelpkg.CapabilityVision) || !got.HasCapability(modelpkg.CapabilityThinking) {
+ t.Fatalf("capabilities = %v, want vision, thinking and tools", got.Capabilities)
+ }
+ if got.Thinking == nil || got.Thinking.Default != "high" || len(got.Thinking.Values) != 3 {
+ t.Fatalf("Thinking = %#v, want the server's descriptor", got.Thinking)
+ }
+ if len(shown) != 1 || shown[0] != "deepseek-v4-pro-inventory-test:cloud" {
+ t.Fatalf("show calls = %v, want one for the model", shown)
+ }
+
+ shown = nil
+ if got := fallbackLaunchModel("deepseek-v4-pro-inventory-test:cloud"); got.ContextLength != 1_048_576 {
+ t.Fatalf("cached ContextLength = %d, want 1048576", got.ContextLength)
+ }
+ if len(shown) != 0 {
+ t.Fatalf("show calls = %v, want none when cached", shown)
+ }
+ })
+
+ t.Run("cloud model with known limits keeps the table context", func(t *testing.T) {
+ shown = nil
+ got := fallbackLaunchModel("kimi-k2.5:cloud")
+ if got.ContextLength != 262_144 || got.MaxOutputTokens != 262_144 {
+ t.Fatalf("limits = %d/%d, want the table's 262144/262144", got.ContextLength, got.MaxOutputTokens)
+ }
+ if !got.HasCapability(modelpkg.CapabilityVision) {
+ t.Fatalf("capabilities = %v, want the server's capabilities", got.Capabilities)
+ }
+ })
+
+ t.Run("local model", func(t *testing.T) {
+ shown = nil
+ got := fallbackLaunchModel("llama3.2")
+ if got.ContextLength != 0 || len(got.Capabilities) != 0 {
+ t.Fatalf("model = %#v, want no server metadata", got)
+ }
+ if len(shown) != 0 {
+ t.Fatalf("show calls = %v, want none for a local model", shown)
+ }
+ })
+
+ t.Run("resolved cloud model without metadata", func(t *testing.T) {
+ shown = nil
+ models := []LaunchModel{{Name: "glm-5.2-inventory-test:cloud", Remote: true}}
+ resolved, _ := resolveLaunchModels([]string{"glm-5.2-inventory-test:cloud"}, models)
+ if len(resolved) != 1 || resolved[0].ContextLength != 1_048_576 || !resolved[0].ToolCapable {
+ t.Fatalf("resolved = %#v, want ContextLength 1048576 and tool capability", resolved)
+ }
+ })
+}
+
+func TestServerModelMetadataStopsAfterUnreachableServer(t *testing.T) {
+ useServerContextLookup(t)
+
+ var hits atomic.Int32
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ hits.Add(1)
+ time.Sleep(300 * time.Millisecond)
+ }))
+ defer srv.Close()
+ t.Setenv("OLLAMA_HOST", srv.URL)
+
+ oldTimeout := modelShowTimeout
+ modelShowTimeout = 50 * time.Millisecond
+ t.Cleanup(func() { modelShowTimeout = oldTimeout })
+
+ for _, name := range []string{"unreachable-a:cloud", "unreachable-b:cloud", "unreachable-a:cloud"} {
+ if _, ok := cachedServerModelMetadata(name); ok {
+ t.Fatalf("lookup for %s succeeded against a hanging server", name)
+ }
+ }
+ if got := hits.Load(); got != 1 {
+ t.Fatalf("show requests = %d, want 1 before the launcher stops asking", got)
+ }
+}
diff --git a/cmd/launch/opencode.go b/cmd/launch/opencode.go
index 1f38666a6..ab7ee24cd 100644
--- a/cmd/launch/opencode.go
+++ b/cmd/launch/opencode.go
@@ -16,6 +16,8 @@ import (
const openCodeInstallScript = "curl -fsSL https://opencode.ai/install | bash"
+const openCodeDefaultMaxOutputTokens = 32_000
+
var openCodeGOOS = runtime.GOOS
// OpenCode implements Runner and Editor for OpenCode integration.
@@ -374,13 +376,12 @@ func buildModelEntries(modelList []LaunchModel) map[string]any {
}
}
}
- if model.MaxOutputTokens > 0 {
- limit := make(map[string]any)
- if model.ContextLength > 0 {
- limit["context"] = model.ContextLength
+ if model.ContextLength > 0 && (model.MaxOutputTokens > 0 || model.Remote || isCloudModelName(model.Name)) {
+ output := model.MaxOutputTokens
+ if output <= 0 {
+ output = openCodeDefaultMaxOutputTokens
}
- limit["output"] = model.MaxOutputTokens
- entry["limit"] = limit
+ entry["limit"] = map[string]any{"context": model.ContextLength, "output": output}
}
models[model.Name] = entry
}
diff --git a/cmd/launch/opencode_test.go b/cmd/launch/opencode_test.go
index 14c9af178..1479a8ec2 100644
--- a/cmd/launch/opencode_test.go
+++ b/cmd/launch/opencode_test.go
@@ -247,11 +247,20 @@ func TestBuildModelEntries(t *testing.T) {
}
})
- t.Run("omits context-only limits", func(t *testing.T) {
+ t.Run("omits context-only limits for local models", func(t *testing.T) {
models := buildModelEntries([]LaunchModel{{Name: "qwen2.5:0.5b", ContextLength: 32768}})
entry, _ := models["qwen2.5:0.5b"].(map[string]any)
if _, ok := entry["limit"]; ok {
- t.Fatalf("limit should be omitted when output limit is unknown, got %v", entry["limit"])
+ t.Fatalf("limit should be omitted for a local model, got %v", entry["limit"])
+ }
+ })
+
+ t.Run("fills in a default output limit for cloud models with unknown output", func(t *testing.T) {
+ models := buildModelEntries([]LaunchModel{{Name: "glm-5.3:cloud", Remote: true, ContextLength: 1_048_576}})
+ entry, _ := models["glm-5.3:cloud"].(map[string]any)
+ limit, _ := entry["limit"].(map[string]any)
+ if limit["context"] != 1_048_576 || limit["output"] != openCodeDefaultMaxOutputTokens {
+ t.Fatalf("limit = %v, want context 1048576 and output %d", limit, openCodeDefaultMaxOutputTokens)
}
})
}
diff --git a/cmd/launch/pi.go b/cmd/launch/pi.go
index e4848f8f2..8a9aa5e66 100644
--- a/cmd/launch/pi.go
+++ b/cmd/launch/pi.go
@@ -599,10 +599,8 @@ func (p *Pi) Edit(models []LaunchModel) error {
} else if selectedSet[id] {
// Rebuild stale managed cloud entries so createConfig refreshes
// the whole entry instead of patching it in place.
- if !hasContextWindow(modelObj) {
- if _, ok := lookupCloudModelLimit(id); ok {
- continue
- }
+ if !hasContextWindow(modelObj) && isCloudModelName(id) {
+ continue
}
newModels = append(newModels, m)
selectedSet[id] = false
diff --git a/cmd/launch/pi_test.go b/cmd/launch/pi_test.go
index e31f52d66..f258a6080 100644
--- a/cmd/launch/pi_test.go
+++ b/cmd/launch/pi_test.go
@@ -12,6 +12,7 @@ import (
"strings"
"testing"
+ "github.com/ollama/ollama/api"
"github.com/ollama/ollama/cmd/internal/fileutil"
"github.com/ollama/ollama/types/model"
)
@@ -916,6 +917,12 @@ func TestPiEdit(t *testing.T) {
// Mock Ollama server for createConfig calls during Edit
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/api/show" {
+ var req api.ShowRequest
+ json.NewDecoder(r.Body).Decode(&req)
+ if req.Model == "deepseek-v4-pro:cloud" {
+ fmt.Fprintf(w, `{"capabilities":[],"model_info":{"deepseek4.context_length":1048576}}`)
+ return
+ }
fmt.Fprintf(w, `{"capabilities":[],"model_info":{}}`)
return
}
@@ -1083,6 +1090,44 @@ func TestPiEdit(t *testing.T) {
}
})
+ t.Run("rebuilds managed cloud model missing from limits with server context", func(t *testing.T) {
+ useServerContextLookup(t)
+ cleanup()
+ os.MkdirAll(configDir, 0o755)
+
+ existingConfig := `{
+ "providers": {
+ "ollama": {
+ "baseUrl": "http://localhost:11434/v1",
+ "api": "openai-completions",
+ "apiKey": "ollama",
+ "models": [
+ {"id": "deepseek-v4-pro:cloud", "_launch": true, "input": ["text"]}
+ ]
+ }
+ }
+ }`
+ if err := os.WriteFile(configPath, []byte(existingConfig), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ if err := pi.Edit(launchModelsFromNames([]string{"deepseek-v4-pro:cloud"})); err != nil {
+ t.Fatalf("Edit() error = %v", err)
+ }
+
+ cfg := readConfig()
+ providers := cfg["providers"].(map[string]any)
+ ollama := providers["ollama"].(map[string]any)
+ modelsArray := ollama["models"].([]any)
+ if len(modelsArray) != 1 {
+ t.Fatalf("models = %v, want one entry", modelsArray)
+ }
+ modelEntry := modelsArray[0].(map[string]any)
+ if modelEntry["contextWindow"] != float64(1_048_576) {
+ t.Errorf("contextWindow = %v, want 1048576", modelEntry["contextWindow"])
+ }
+ })
+
t.Run("replaces old models with new ones", func(t *testing.T) {
cleanup()
os.MkdirAll(configDir, 0o755)
diff --git a/cmd/launch/test_config_helpers_test.go b/cmd/launch/test_config_helpers_test.go
index ac0bce9e9..84af50b8d 100644
--- a/cmd/launch/test_config_helpers_test.go
+++ b/cmd/launch/test_config_helpers_test.go
@@ -16,6 +16,18 @@ var (
func init() {
integrations = buildTestIntegrations()
integrationAliases = buildTestIntegrationAliases()
+ lookupServerModelMetadata = func(string) (serverModelMetadata, bool) { return serverModelMetadata{}, false }
+}
+
+func useServerContextLookup(t *testing.T) {
+ old := lookupServerModelMetadata
+ lookupServerModelMetadata = cachedServerModelMetadata
+ serverModelMetadataCache.Clear()
+ serverModelMetadataUnavailable.Store(false)
+ t.Cleanup(func() {
+ lookupServerModelMetadata = old
+ serverModelMetadataUnavailable.Store(false)
+ })
}
func buildTestIntegrations() map[string]Runner {