Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(daemon): stop validating saved model settings against fallback catalogs (#8811)

Bohan Jiang1aa815a73880
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.go
index 00785e21e7..6cea16d50e 100644
--- a/server/internal/daemon/daemon.go
+++ b/server/internal/daemon/daemon.go
@@ -7547,13 +7547,14 @@ func resolveTaskModelSelection(
// service_tier is catalog-owned and currently Codex-only. As with
// thinking_level, stale or incompatible persisted values degrade to the
- // runtime default instead of failing the task. Catalog lookup errors pass
- // through so a transient discovery failure does not silently disable a
- // previously valid user choice.
+ // runtime default instead of failing the task. A catalog that cannot
+ // validate — a lookup error, or a fallback catalog standing in for a
+ // failed discovery — passes the value through, so a discovery failure does
+ // not silently disable a previously valid user choice (MUL-7691).
if sel.ServiceTier != "" {
ok, err := agent.ValidateServiceTierWith(loadCatalog, provider, sel.Model, sel.ServiceTier)
if err != nil {
- taskLog.Warn("service_tier: catalog lookup failed; passing through",
+ taskLog.Warn("service_tier: catalog cannot validate; passing through",
"provider", provider,
"model", sel.Model,
"service_tier", sel.ServiceTier,
@@ -7569,21 +7570,22 @@ func resolveTaskModelSelection(
}
}
// Per-model guard: the server validates the literal token against the
- // provider's enum, but per-model gaps (Claude's `xhigh` on a non-Opus
- // model, Codex's per-model `supported_reasoning_levels`) only resolve
- // here, against the daemon's local CLI catalog. Invalid combinations
- // log a warning and drop the level rather than failing the task, so a
- // stale persisted value never blocks execution. An empty model is
- // resolved by ValidateThinkingLevelWith to the provider's default model so
- // default-model tasks aren't misjudged — except for codex, whose empty
+ // provider's enum, but per-model gaps (Codex's per-model
+ // `supported_reasoning_levels`, Claude's per-model `supportedEffortLevels`)
+ // only resolve here, against the daemon's local CLI catalog. Invalid
+ // combinations log a warning and drop the level rather than failing the
+ // task, so a stale persisted value never blocks execution. An empty model
+ // is resolved by ValidateThinkingLevelWith to the provider's default model
+ // so default-model tasks aren't misjudged — except for codex, whose empty
// model follows config.toml (any model) and so fails closed, dropping the
- // level here without a catalog read at all. Discovery errors fail open for
- // resolved models: if we can't list models, we keep the persisted level
- // and let the CLI object.
+ // level here without a catalog read at all. Only a verified catalog can
+ // drop a level: on a lookup error or a fallback/empty catalog we keep the
+ // persisted level and let the CLI object, unless the binary itself has no
+ // such effort flag (MUL-7691).
if sel.ThinkingLevel != "" {
ok, err := agent.ValidateThinkingLevelWith(loadCatalog, provider, sel.Model, sel.ThinkingLevel)
if err != nil {
- taskLog.Warn("thinking_level: catalog lookup failed; passing through",
+ taskLog.Warn("thinking_level: catalog cannot validate; passing through",
"provider", provider,
"model", sel.Model,
"thinking_level", sel.ThinkingLevel,
diff --git a/server/internal/daemon/model_qualify_test.go b/server/internal/daemon/model_qualify_test.go
index 8a97fcec8f..d04fe2e738 100644
--- a/server/internal/daemon/model_qualify_test.go
+++ b/server/internal/daemon/model_qualify_test.go
@@ -219,6 +219,86 @@ func TestResolveTaskModelSelectionFailsOpenOnDiscoveryError(t *testing.T) {
}
}
+// A catalog discovery did not verify — a static fallback or an empty list —
+// cannot say what the runtime supports, so every provider launches with the
+// saved selection untouched, even where the stand-in disagrees with it. The
+// installed binary's own effort vocabulary is the only thing still enforced
+// (MUL-7691).
+func TestResolveTaskModelSelectionPassesThroughUnverifiedCatalogs(t *testing.T) {
+ levels := func(values ...string) *agent.ModelThinking {
+ out := &agent.ModelThinking{}
+ for _, v := range values {
+ out.SupportedLevels = append(out.SupportedLevels, agent.ThinkingLevel{Value: v})
+ }
+ return out
+ }
+ claudeFallback := func(cli []string) agent.Catalog {
+ return agent.Catalog{
+ Models: []agent.Model{
+ {ID: "claude-sonnet-4-6", Default: true, Thinking: levels("low", "medium", "high")},
+ },
+ Fallback: true,
+ CLIThinkingLevels: cli,
+ }
+ }
+ full := []string{"low", "medium", "high", "xhigh", "max"}
+ for _, tc := range []struct {
+ name string
+ provider string
+ catalog agent.Catalog
+ in, want taskModelSelection
+ }{
+ {
+ name: "claude model newer than the static list", provider: "claude", catalog: claudeFallback(full),
+ in: taskModelSelection{Model: "claude-opus-5-5", ThinkingLevel: "xhigh"},
+ want: taskModelSelection{Model: "claude-opus-5-5", ThinkingLevel: "xhigh"},
+ },
+ {
+ name: "claude listed model the stand-in narrows", provider: "claude", catalog: claudeFallback(full),
+ in: taskModelSelection{Model: "claude-sonnet-4-6", ThinkingLevel: "max"},
+ want: taskModelSelection{Model: "claude-sonnet-4-6", ThinkingLevel: "max"},
+ },
+ {
+ name: "claude empty model does not borrow the stand-in default", provider: "claude", catalog: claudeFallback(full),
+ in: taskModelSelection{ThinkingLevel: "xhigh"},
+ want: taskModelSelection{ThinkingLevel: "xhigh"},
+ },
+ {
+ name: "claude CLI without --effort still drops the level", provider: "claude", catalog: claudeFallback([]string{}),
+ in: taskModelSelection{Model: "claude-opus-5-5", ThinkingLevel: "high"},
+ want: taskModelSelection{Model: "claude-opus-5-5"},
+ },
+ {
+ name: "grok", provider: "grok",
+ catalog: agent.Catalog{Models: []agent.Model{{ID: "grok-4.5", Thinking: levels("low", "medium", "high")}}, Fallback: true},
+ in: taskModelSelection{Model: "grok-4.5", ThinkingLevel: "xhigh"},
+ want: taskModelSelection{Model: "grok-4.5", ThinkingLevel: "xhigh"},
+ },
+ {
+ name: "codex service tier", provider: "codex",
+ catalog: agent.Catalog{Models: []agent.Model{{ID: "gpt-5.5", Thinking: levels("low")}}, Fallback: true},
+ in: taskModelSelection{Model: "gpt-5.5", ThinkingLevel: "xhigh", ServiceTier: "priority"},
+ want: taskModelSelection{Model: "gpt-5.5", ThinkingLevel: "xhigh", ServiceTier: "priority"},
+ },
+ {
+ name: "empty opencode catalog", provider: "opencode", catalog: agent.Catalog{Models: []agent.Model{}},
+ in: taskModelSelection{Model: "deepseek/deepseek-v4", ThinkingLevel: "max"},
+ want: taskModelSelection{Model: "deepseek/deepseek-v4", ThinkingLevel: "max"},
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ reads := stubModelDiscovery(t, map[string]agent.Catalog{tc.provider: tc.catalog})
+ got := resolveTaskModelSelection(context.Background(), tc.provider, agent.Command{}, tc.in, quietTaskLog())
+ if got != tc.want {
+ t.Errorf("launch selection = %+v, want %+v", got, tc.want)
+ }
+ if reads() != 1 {
+ t.Errorf("catalog reads = %d, want 1", reads())
+ }
+ })
+ }
+}
+
// Exercise real discovery through the daemon's task-launch guard rather than
// injecting a prebuilt fallback: live discovery fails, bundled succeeds but
// lacks the saved model. Model-scoped overrides pass through; the CLI-version
diff --git a/server/pkg/agent/claude_models.go b/server/pkg/agent/claude_models.go
index b1ddc0f277..d5562d64e7 100644
--- a/server/pkg/agent/claude_models.go
+++ b/server/pkg/agent/claude_models.go
@@ -241,8 +241,8 @@ func discoverClaudeCatalog(ctx context.Context, runtimeCmd Command) Catalog {
func claudeStaticCatalog(ctx context.Context, runtimeCmd Command) Catalog {
static := claudeStaticModels()
- annotateClaudeThinking(ctx, static, runtimeCmd)
- return Catalog{Models: static, Fallback: true}
+ cliLevels := annotateClaudeThinking(ctx, static, runtimeCmd)
+ return Catalog{Models: static, Fallback: true, CLIThinkingLevels: cliLevels}
}
// discoverClaudeModels enumerates the local Claude Code catalog over the
@@ -425,9 +425,8 @@ func claudeModelLabel(info claudeModelInfo, id string) string {
// claudeThinkingFromInfo builds the per-model effort catalog from the row's own
// advertisement. This is the discovery path's clearest win over the static one:
-// loadClaudeThinkingByModel has to scrape `claude --help` for a global superset
-// and then narrow it through claudeModelEffortAllow, a hand-kept table of which
-// models really take xhigh. Here each model states its own levels.
+// annotateClaudeThinking can only scrape `claude --help` for a global superset
+// and offer it on every model. Here each model states its own levels.
//
// DefaultLevel is deliberately left empty. The rows carry no default-effort
// field, and empty already means "the runtime picks, we don't know" — a more
diff --git a/server/pkg/agent/claude_models_test.go b/server/pkg/agent/claude_models_test.go
index bdf84d3b6a..a827de8d16 100644
--- a/server/pkg/agent/claude_models_test.go
+++ b/server/pkg/agent/claude_models_test.go
@@ -140,8 +140,8 @@ func TestClaudeModelsFromInfos_CurrentCLI(t *testing.T) {
}
}
- // Effort levels come from the row itself, replacing the `claude --help`
- // scrape plus the hand-kept claudeModelEffortAllow table.
+ // Effort levels come from the row itself, not the `claude --help`
+ // superset the static catalog offers on every model.
opus := models[0]
if opus.Thinking == nil {
t.Fatal("opus should advertise a thinking catalog")
diff --git a/server/pkg/agent/grok_test.go b/server/pkg/agent/grok_test.go
index 0f50ac5f29..491202c89b 100644
--- a/server/pkg/agent/grok_test.go
+++ b/server/pkg/agent/grok_test.go
@@ -1192,27 +1192,20 @@ func TestGrokThinkingCatalogIsPerModel(t *testing.T) {
}
}
-func TestGrokValidateThinkingLevelUsesPerModelCatalog(t *testing.T) {
- for _, tc := range []struct {
- model string
- level string
- want bool
- }{
- {model: "grok-4.6", level: "high", want: true},
- {model: "grok-4.6", level: "low", want: true},
- {model: "grok-4.6", level: "xhigh", want: true},
- {model: "grok-4.5", level: "low", want: true},
- {model: "grok-4.5", level: "none", want: false},
- {model: "grok-4.5", level: "xhigh", want: false},
- {model: "grok-composer-2.5-fast", level: "low", want: false},
- {model: "future-grok", level: "high", want: false},
+// The static Grok list only shapes the fallback picker. A saved level is never
+// judged against it — not even where it disagrees with the list — because a
+// stand-in cannot say what the installed CLI accepts (MUL-7691).
+func TestGrokFallbackCatalogPassesThinkingLevelThrough(t *testing.T) {
+ for _, tc := range []struct{ model, level string }{
+ {model: "grok-4.6", level: "high"},
+ {model: "grok-4.5", level: "xhigh"},
+ {model: "grok-composer-2.5-fast", level: "low"},
+ {model: "future-grok", level: "high"},
+ {model: "", level: "high"},
} {
got, err := ValidateThinkingLevel(context.Background(), "grok", Command{Path: "/nonexistent/grok"}, tc.model, tc.level)
- if err != nil {
- t.Fatalf("ValidateThinkingLevel(%q, %q): %v", tc.model, tc.level, err)
- }
- if got != tc.want {
- t.Errorf("ValidateThinkingLevel(%q, %q) = %v, want %v", tc.model, tc.level, got, tc.want)
+ if got || !errors.Is(err, errUnverifiedCatalog) {
+ t.Errorf("ValidateThinkingLevel(%q, %q) = (%v, %v), want errUnverifiedCatalog", tc.model, tc.level, got, err)
}
}
}
diff --git a/server/pkg/agent/models.go b/server/pkg/agent/models.go
index 750a2e51b8..4efcac37fe 100644
--- a/server/pkg/agent/models.go
+++ b/server/pkg/agent/models.go
@@ -125,11 +125,37 @@ type Catalog struct {
// enter the server's day-scale model-catalog cache, which would pin one
// transient failure as the answer for 24h (MUL-5549).
Fallback bool
+ // CLIThinkingLevels is the effort vocabulary the installed binary itself
+ // accepts, read from the binary (claude's `--help`) rather than from any
+ // model list. nil means it is unknown; a non-nil empty slice means the
+ // binary has no effort flag at all.
+ //
+ // It is the one capability an unverified catalog still enforces: it
+ // describes the executable, not a guess about models, so it holds whether
+ // or not discovery succeeded (MUL-7691).
+ CLIThinkingLevels []string
+}
+
+// Verified reports whether the catalog is the runtime's own answer, and so may
+// be used to reject, rewrite, or drop a saved model, thinking level, or
+// service tier.
+//
+// A fallback is a static stand-in for a discovery that failed, and an empty
+// catalog is what the providers without one return in the same situation.
+// Both mean "unknown", not "unsupported": the saved value goes to the CLI
+// as-is and the CLI is the judge (MUL-7691).
+func (c Catalog) Verified() bool {
+ return !c.Fallback && len(c.Models) > 0
}
// discovered adapts a plain `([]Model, error)` discovery function to Catalog
// for providers that have no static fallback — for them a failure is already
// reported as an empty list or an error, which downstream guards handle.
+//
+// An empty list deliberately stays unflagged. The server treats a completed
+// empty report as fresh truth and drops its cached catalog, while a fallback
+// report leaves the cache alone; flagging it here would change that. The
+// capability checks read emptiness themselves (Catalog.Verified).
func discovered(models []Model, err error) (Catalog, error) {
return Catalog{Models: models}, err
}
@@ -364,9 +390,9 @@ func ModelSelectorMustBeProviderQualified(providerType string) bool {
func QualifyModelID(catalog Catalog, model string) (string, bool) {
model = strings.TrimSpace(model)
// A fallback catalog is a static stand-in, not what the runtime actually
- // supports (see Catalog.Fallback) — qualifying against it would rewrite a
+ // supports (see Catalog.Verified) — qualifying against it would rewrite a
// working id into one the CLI never advertised.
- if model == "" || catalog.Fallback {
+ if model == "" || !catalog.Verified() {
return model, false
}
for _, m := range catalog.Models {
@@ -426,25 +452,18 @@ func ModelSelectionSupported(providerType string) bool {
}
// ModelKnownIncompatibleWithProvider reports whether a saved model is a known
-// mismatch for a target runtime provider. Static catalogs are sufficient to
-// recognize known-good IDs, but they are not allow-lists: Claude and Codex can
-// gain same-family model IDs through live discovery without a Multica release.
-// Unknown/custom model strings still return false because the UI and CLI allow
-// manual entries and the server should not erase values it cannot confidently
-// classify.
+// mismatch for a target runtime provider. Only Claude and Codex are judged, and
+// only by model-family prefix: they gain same-family model IDs through live
+// discovery without a Multica release, so no static list could be an
+// allow-list here. Unknown/custom model strings still return false because the
+// UI and CLI allow manual entries and the server should not erase values it
+// cannot confidently classify.
func ModelKnownIncompatibleWithProvider(providerType, model string) bool {
model = strings.TrimSpace(model)
if model == "" {
return false
}
- accepted, ok := acceptedModelIDsForProvider(providerType)
- if !ok {
- return false
- }
- if accepted[modelIDForCapabilityLookup(providerType, model)] {
- return false
- }
lookupID := modelIDForCapabilityLookup(providerType, model)
switch providerType {
case "claude":
@@ -455,6 +474,8 @@ func ModelKnownIncompatibleWithProvider(providerType, model string) bool {
if strings.HasPrefix(lookupID, "gpt-") || isOpenAIReasoningSeriesID(lookupID) {
return false
}
+ default:
+ return false
}
return isRuntimeSpecificModelID(model)
}
@@ -477,32 +498,11 @@ func modelIDForCapabilityLookup(providerType, model string) string {
return claudeContextWindowTagRe.ReplaceAllString(model, "")
}
-func acceptedModelIDsForProvider(providerType string) (map[string]bool, bool) {
- switch {
- case providerType == "claude":
- return modelIDSet(claudeStaticModels()), true
- case providerType == "codex":
- return modelIDSet(codexStaticModels()), true
- default:
- return nil, false
- }
-}
-
-func modelIDSet(models []Model) map[string]bool {
- out := make(map[string]bool, len(models))
- for _, m := range models {
- out[m.ID] = true
- }
- return out
-}
-
func isRuntimeSpecificModelID(model string) bool {
if strings.Contains(model, "/") {
return true
}
- return modelHasKnownPrefix(model) ||
- modelIDSet(claudeStaticModels())[model] ||
- modelIDSet(codexStaticModels())[model]
+ return modelHasKnownPrefix(model)
}
func modelHasKnownPrefix(model string) bool {
@@ -602,7 +602,9 @@ func claudeStaticModels() []Model {
// carries its own reasoning catalog so old/offline CLIs retain the same model
// + thinking picker contract as dynamic discovery. Service tiers are
// intentionally NOT guessed here: they are runtime/version/account-sensitive,
-// so a discovery failure hides the speed picker and fails the override closed.
+// so a discovery failure hides the speed picker. None of this is validated
+// against — a saved model, effort, or tier reaches the CLI as-is while this
+// list stands in (Catalog.Verified, MUL-7691).
func codexStaticModels() []Model {
// `Default` here is NOT a user-facing "default model" badge — the picker
// stopped rendering that (Multica follows the CLI config when the model is
@@ -2504,9 +2506,9 @@ func grokStaticModels() []Model {
// these fallback catalogs with the installed CLI's advertised values.
//
// grok-4.6 documents and accepts `xhigh` (docs.x.ai/developers/grok-4-6,
-// grok 1.0.5 `--effort`). grok-4.5 does not; the server's dynamic literal
-// gate lets the token through and ValidateThinkingLevel still fails it closed
-// for 4.5 using the per-model catalog.
+// grok 1.0.5 `--effort`). grok-4.5 does not, so the fallback picker does not
+// offer it there. The daemon does not validate against this list: while it
+// stands in, a saved level reaches the CLI as-is (Catalog.Verified).
func annotateGrokThinking(models []Model) {
for i := range models {
switch models[i].ID {
diff --git a/server/pkg/agent/thinking.go b/server/pkg/agent/thinking.go
index e18d9428d0..277ced198f 100644
--- a/server/pkg/agent/thinking.go
+++ b/server/pkg/agent/thinking.go
@@ -3,8 +3,10 @@ package agent
import (
"context"
"encoding/json"
+ "errors"
"fmt"
"regexp"
+ "slices"
"strings"
"sync"
"time"
@@ -40,7 +42,7 @@ type thinkingCacheKey struct {
}
type thinkingCacheEntry struct {
- value map[string]*ModelThinking // keyed by model ID
+ value claudeEffortHelp
expiresAt time.Time
}
@@ -51,17 +53,17 @@ var (
thinkingCache = map[thinkingCacheKey]thinkingCacheEntry{}
)
-func thinkingCacheGet(key thinkingCacheKey) (map[string]*ModelThinking, bool) {
+func thinkingCacheGet(key thinkingCacheKey) (claudeEffortHelp, bool) {
thinkingCacheMu.Lock()
defer thinkingCacheMu.Unlock()
entry, ok := thinkingCache[key]
if !ok || time.Now().After(entry.expiresAt) {
- return nil, false
+ return claudeEffortHelp{}, false
}
return entry.value, true
}
-func thinkingCachePut(key thinkingCacheKey, value map[string]*ModelThinking) {
+func thinkingCachePut(key thinkingCacheKey, value claudeEffortHelp) {
thinkingCacheMu.Lock()
defer thinkingCacheMu.Unlock()
thinkingCache[key] = thinkingCacheEntry{value: value, expiresAt: time.Now().Add(thinkingDiscoveryTTL)}
@@ -77,11 +79,14 @@ func resetThinkingCacheForTests() {
// ── Claude ───────────────────────────────────────────────────────────
//
-// `claude --help` advertises `--effort <level>` with the full superset
-// in parentheses; we parse that line to learn which levels the CLI
-// version on this host accepts. Per-model gaps (Opus-only `xhigh`,
-// session-only `max`) come from a hand-maintained table because the
-// CLI does not expose model→effort mappings programmatically.
+// Live discovery (claude_models.go) gets each model's effort levels from the
+// CLI itself. This section only serves the static catalog used when that
+// discovery fails: `claude --help` advertises `--effort <level>` with the full
+// superset in parentheses, and every static model offers that superset. There
+// is deliberately no per-model table — a fallback catalog is a picker
+// affordance, not something the daemon validates against, so narrowing it per
+// model would only be one more list to keep in step with new models
+// (MUL-7691).
// claudeEffortRe matches the help line emitted by `claude --help`:
//
@@ -101,50 +106,48 @@ var claudeEffortLabel = map[string]string{
"max": "Max",
}
-// claudeModelEffortAllow restricts the level set per model where the
-// upstream documentation says only some are valid. Empty / missing
-// model → use the parsed superset as-is (current Claude Code default).
-// Update this map when Anthropic publishes a new model that does not
-// support `xhigh` / `max`.
-var claudeModelEffortAllow = map[string]map[string]bool{
- // Opus is the only model that publicly supports xhigh; the help
- // list still includes it for Sonnet / Haiku so we filter here.
- "claude-opus-5": {"low": true, "medium": true, "high": true, "xhigh": true, "max": true},
- "claude-opus-4-8": {"low": true, "medium": true, "high": true, "xhigh": true, "max": true},
- "claude-opus-4-7": {"low": true, "medium": true, "high": true, "xhigh": true, "max": true},
- "claude-opus-4-6": {"low": true, "medium": true, "high": true, "xhigh": true, "max": true},
- "claude-sonnet-4-6": {"low": true, "medium": true, "high": true, "max": true},
- "claude-sonnet-4-5": {"low": true, "medium": true, "high": true, "max": true},
- "claude-haiku-4-5-20251001": {"low": true, "medium": true, "high": true},
-}
-
-// claudeStaticEffortFallback is the conservative subset used when
-// parsing the `--effort` help line fails (binary missing, output drift,
-// etc.). Picked from the lowest-common-denominator across recent
-// Claude Code releases.
+// claudeStaticEffortFallback is the conservative picker used when
+// `claude --help` cannot be captured at all (binary missing, timeout).
+// Picked from the lowest-common-denominator across recent Claude Code
+// releases.
var claudeStaticEffortFallback = []string{"low", "medium", "high"}
// claudeStaticEffortFullSuperset is what `claude --help` listed on
-// 2.1.121. Used as the catalog superset when a model isn't in the
-// per-model allow-list — we'd rather over-offer and let the CLI
-// reject than artificially block valid combinations.
+// 2.1.121. The picker offers it when help names `--effort` but its value
+// list no longer parses — we'd rather over-offer and let the CLI reject
+// than artificially block valid combinations.
var claudeStaticEffortFullSuperset = []string{"low", "medium", "high", "xhigh", "max"}
-// annotateClaudeThinking populates each entry's Thinking field by
-// running `claude --help` once and projecting the parsed superset
-// through claudeModelEffortAllow. Errors are silently absorbed so a
-// missing CLI doesn't break model listing — the UI just hides the
-// picker for that model.
-func annotateClaudeThinking(ctx context.Context, models []Model, cmd Command) {
- mapping := loadClaudeThinkingByModel(ctx, cmd)
- for i := range models {
- if t, ok := mapping[models[i].ID]; ok && t != nil {
- models[i].Thinking = t
+// claudeEffortHelp is what one `claude --help` run established about
+// `--effort`.
+type claudeEffortHelp struct {
+ // flag is the binary's own vocabulary, surfaced as
+ // Catalog.CLIThinkingLevels: nil when help could not establish it, a
+ // non-nil empty slice when the binary predates the flag.
+ flag []string
+ // picker is what the static catalog offers every model.
+ picker []string
+}
+
+// annotateClaudeThinking gives every static model the effort picker read
+// from `claude --help` and returns the binary's own `--effort` vocabulary
+// (see claudeEffortHelp.flag). Errors are silently absorbed so a missing
+// CLI doesn't break model listing.
+func annotateClaudeThinking(ctx context.Context, models []Model, cmd Command) []string {
+ help := loadClaudeEffortHelp(ctx, cmd)
+ levels := claudeThinkingLevels(help.picker)
+ if len(levels) > 0 {
+ for i := range models {
+ models[i].Thinking = &ModelThinking{
+ SupportedLevels: append([]ThinkingLevel(nil), levels...),
+ DefaultLevel: "medium",
+ }
}
}
+ return help.flag
}
-func loadClaudeThinkingByModel(ctx context.Context, cmd Command) map[string]*ModelThinking {
+func loadClaudeEffortHelp(ctx context.Context, cmd Command) claudeEffortHelp {
if cmd.Path == "" {
cmd.Path = "claude"
}
@@ -153,59 +156,45 @@ func loadClaudeThinkingByModel(ctx context.Context, cmd Command) map[string]*Mod
if cached, ok := thinkingCacheGet(key); ok {
return cached
}
-
- superset := claudeEffortSuperset(ctx, cmd)
- result := map[string]*ModelThinking{}
- for _, m := range claudeStaticModels() {
- allow := claudeModelEffortAllow[m.ID]
- levels := projectClaudeLevels(superset, allow)
- if len(levels) == 0 {
- continue
- }
- result[m.ID] = &ModelThinking{
- SupportedLevels: levels,
- DefaultLevel: "medium",
- }
- }
- thinkingCachePut(key, result)
- return result
+ help := readClaudeEffortHelp(ctx, cmd)
+ thinkingCachePut(key, help)
+ return help
}
-// claudeEffortSuperset returns the parsed `--effort` value list. When
-// the help output can't be captured at all it returns the static
-// fallback rather than nothing so callers can still render a usable
-// picker.
-func claudeEffortSuperset(ctx context.Context, runtimeCmd Command) []string {
+// readClaudeEffortHelp runs `claude --help`. When its output can't be
+// captured at all the binary's vocabulary is unknown, and the picker still
+// gets the conservative static subset so it stays usable.
+func readClaudeEffortHelp(ctx context.Context, runtimeCmd Command) claudeEffortHelp {
cmd := runtimeCmd.exec(ctx, "--help")
hideAgentWindow(cmd)
out, err := combinedOutputOwned(cmd, runtimeCmd.logger)
if err != nil {
- return append([]string(nil), claudeStaticEffortFallback...)
+ return claudeEffortHelp{picker: append([]string(nil), claudeStaticEffortFallback...)}
}
- return claudeEffortLevelsFromHelp(string(out))
+ return claudeEffortHelpFromText(string(out))
}
-// claudeEffortLevelsFromHelp decides the effort superset from a
-// successfully captured `claude --help`. Three cases:
-// - the value list parsed → use it verbatim;
+// claudeEffortHelpFromText reads a successfully captured `claude --help`.
+// Three cases:
+// - the value list parsed → it is both the binary's vocabulary and the
+// picker;
// - `--effort` is advertised but the value list didn't parse → help
-// format drifted; fall back to the last known good superset so
-// newer levels are still offered until we hand-edit the fallback;
-// - `--effort` is absent entirely → the installed CLI predates the
-// flag. Return no levels: offering any would let the daemon pass
-// ValidateThinkingLevel and inject --effort, which such a binary
-// rejects with `error: unknown option '--effort'` — hard-failing
-// every task for an agent with a persisted thinking_level instead
-// of degrading to a plain run.
-func claudeEffortLevelsFromHelp(helpText string) []string {
- parsed := parseClaudeEffortHelp(helpText)
- if len(parsed) > 0 {
- return parsed
+// format drifted. The vocabulary is unknown, so nothing is vetoed, and
+// the picker falls back to the last known good superset;
+// - `--effort` is absent entirely → the installed CLI predates the flag.
+// Its vocabulary is empty and the picker offers nothing: injecting
+// --effort would make such a binary reject the launch with
+// `error: unknown option '--effort'` — hard-failing every task for an
+// agent with a persisted thinking_level instead of degrading to a plain
+// run.
+func claudeEffortHelpFromText(helpText string) claudeEffortHelp {
+ if parsed := parseClaudeEffortHelp(helpText); len(parsed) > 0 {
+ return claudeEffortHelp{flag: parsed, picker: parsed}
}
if strings.Contains(helpText, "--effort") {
- return append([]string(nil), claudeStaticEffortFullSuperset...)
+ return claudeEffortHelp{picker: append([]string(nil), claudeStaticEffortFullSuperset...)}
}
- return nil
+ return claudeEffortHelp{flag: []string{}}
}
// parseClaudeEffortHelp extracts the comma-separated value list from a
@@ -227,12 +216,9 @@ func parseClaudeEffortHelp(helpText string) []string {
return out
}
-func projectClaudeLevels(superset []string, allow map[string]bool) []ThinkingLevel {
- out := make([]ThinkingLevel, 0, len(superset))
- for _, value := range superset {
- if allow != nil && !allow[value] {
- continue
- }
+func claudeThinkingLevels(values []string) []ThinkingLevel {
+ out := make([]ThinkingLevel, 0, len(values))
+ for _, value := range values {
label, ok := claudeEffortLabel[value]
if !ok {
// New value the daemon hasn't been taught yet — surface
@@ -671,6 +657,13 @@ func catalogLoader(ctx context.Context, providerType string, cmd Command) func()
// - omp: fails closed for the same reason by a different route — see
// ThinkingRequiresExplicitModel.
//
+// Only a catalog discovery verified may reject a level. A fallback or empty
+// catalog (see Catalog.Verified) answers with errUnverifiedCatalog, which the
+// daemon treats like any lookup failure: the saved level goes to the CLI
+// unchanged. The one thing still enforced there is the binary's own effort
+// vocabulary (Catalog.CLIThinkingLevels) — a Claude CLI without `--effort`
+// rejects the launch outright, whatever model it would have run.
+//
// The lookup goes through ListModels so it sees the *current* CLI
// catalog (including dynamic discovery for codex), not just a static
// map. The function is intentionally pure of HTTP concerns so the
@@ -707,6 +700,12 @@ func ValidateThinkingLevelWith(loadCatalog func() (Catalog, error), providerType
if err != nil {
return false, err
}
+ if catalog.CLIThinkingLevels != nil && !slices.Contains(catalog.CLIThinkingLevels, value) {
+ return false, nil
+ }
+ if !catalog.Verified() {
+ return false, fmt.Errorf("%w; cannot validate %s thinking level %q", errUnverifiedCatalog, providerType, value)
+ }
models := catalog.Models
target := modelIDForCapabilityLookup(providerType, model)
if target == "" {
@@ -750,12 +749,15 @@ func ValidateThinkingLevelWith(loadCatalog func() (Catalog, error), providerType
}
return false, nil
}
- if missingFromFallbackCatalog(catalog, providerType, model) {
- return false, fmt.Errorf("model %q absent from fallback %s catalog; cannot validate thinking level", model, providerType)
- }
return false, nil
}
+// errUnverifiedCatalog is what the capability checks answer when the catalog
+// they were handed is not the runtime's own (see Catalog.Verified). It is an
+// error rather than a "no" on purpose: the daemon passes a value it could not
+// check through to the CLI instead of discarding the user's saved choice.
+var errUnverifiedCatalog = errors.New("model discovery did not return the runtime's own catalog")
+
// ThinkingRequiresExplicitModel reports whether a provider refuses to carry an
// effort unless a model is pinned, because its empty-model resolution happens
// somewhere Multica cannot observe:
@@ -821,9 +823,10 @@ func ValidateServiceTierWith(loadCatalog func() (Catalog, error), providerType,
return false, err
}
// Explicit standard routing is a CLI-version capability, not a per-model
- // capability. Resolve it before the fallback missing-model check: an old
- // CLI must never pass "default" through just because its fallback omits
- // the saved (live-only) model.
+ // one: discoverCodexCatalog stamps it on every entry, fallback entries
+ // included, from the installed version alone. Resolve it before the
+ // unverified-catalog pass-through below: an old CLI must never receive
+ // "default" just because discovery failed.
if value == codexStandardServiceTier {
for _, candidate := range catalog.Models {
if candidate.SupportsExplicitStandardServiceTier {
@@ -832,8 +835,8 @@ func ValidateServiceTierWith(loadCatalog func() (Catalog, error), providerType,
}
return false, nil
}
- if missingFromFallbackCatalog(catalog, providerType, model) {
- return false, fmt.Errorf("model %q absent from fallback %s catalog; cannot validate service tier", model, providerType)
+ if !catalog.Verified() {
+ return false, fmt.Errorf("%w; cannot validate %s service tier %q", errUnverifiedCatalog, providerType, value)
}
for _, m := range catalog.Models {
if m.ID != model {
@@ -849,22 +852,6 @@ func ValidateServiceTierWith(loadCatalog func() (Catalog, error), providerType,
return false, nil
}
-// Codex fallback is useful for known models, but its omissions are not
-// evidence that a live-only model lacks a capability. The daemon passes validation
-// errors through to the CLI rather than discarding a saved user override.
-func missingFromFallbackCatalog(catalog Catalog, providerType, model string) bool {
- if providerType != "codex" || !catalog.Fallback || model == "" {
- return false
- }
- target := modelIDForCapabilityLookup(providerType, model)
- for _, candidate := range catalog.Models {
- if modelIDForCapabilityLookup(providerType, candidate.ID) == target {
- return false
- }
- }
- return true
-}
-
func anyModelSupportsThinkingValue(models []Model, value string) bool {
for _, m := range models {
if m.Thinking == nil {
diff --git a/server/pkg/agent/thinking_test.go b/server/pkg/agent/thinking_test.go
index b2540771f5..76dbc0441e 100644
--- a/server/pkg/agent/thinking_test.go
+++ b/server/pkg/agent/thinking_test.go
@@ -2,6 +2,7 @@ package agent
import (
"context"
+ "errors"
"log/slog"
"os"
"path/filepath"
@@ -58,73 +59,84 @@ Options:
}
}
-func TestClaudeEffortLevelsFromHelp_DriftedFormatFallsBackToFullSuperset(t *testing.T) {
+func TestClaudeEffortHelpFromText(t *testing.T) {
t.Parallel()
- // The flag is advertised but the parenthesised value list is gone —
- // genuine help drift, so keep offering the last known good superset.
- help := `Usage: claude [options]
-
-Options:
- --effort <level> Choose how hard the model thinks
-`
- got := claudeEffortLevelsFromHelp(help)
- if !reflect.DeepEqual(got, claudeStaticEffortFullSuperset) {
- t.Fatalf("claudeEffortLevelsFromHelp: got %v, want full superset %v", got, claudeStaticEffortFullSuperset)
+ full := []string{"low", "medium", "high", "xhigh", "max"}
+ for _, tc := range []struct {
+ name string
+ help string
+ wantFlag []string
+ wantPicker []string
+ }{
+ {
+ name: "parsed value list is both the vocabulary and the picker",
+ help: "Options:\n --effort <level> Effort level for the current session (low, medium, high, xhigh, max)\n",
+ wantFlag: full,
+ wantPicker: full,
+ },
+ {
+ // The flag is advertised but the parenthesised value list is gone —
+ // genuine help drift. The vocabulary is unknown, so nothing may be
+ // vetoed, and the picker keeps offering the last known good superset.
+ name: "drifted format",
+ help: "Options:\n --effort <level> Choose how hard the model thinks\n",
+ wantFlag: nil,
+ wantPicker: claudeStaticEffortFullSuperset,
+ },
+ {
+ // A CLI released before --effort existed (e.g. claude 2.1.2). Its
+ // vocabulary is empty, not unknown: injecting --effort makes the
+ // binary reject the launch with "unknown option", failing the task.
+ name: "pre-effort CLI",
+ help: "Options:\n --model <model> Model to use\n --verbose\n",
+ wantFlag: []string{},
+ wantPicker: nil,
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ got := claudeEffortHelpFromText(tc.help)
+ if !reflect.DeepEqual(got.flag, tc.wantFlag) {
+ t.Errorf("flag = %#v, want %#v", got.flag, tc.wantFlag)
+ }
+ if !reflect.DeepEqual(got.picker, tc.wantPicker) {
+ t.Errorf("picker = %#v, want %#v", got.picker, tc.wantPicker)
+ }
+ })
}
}
-func TestClaudeEffortLevelsFromHelp_PreEffortCLIReturnsNoLevels(t *testing.T) {
- t.Parallel()
- // A CLI released before --effort existed (e.g. claude 2.1.2) has no
- // mention of the flag anywhere in --help. This must yield NO levels —
- // the old fallback-to-full-superset here made the daemon inject
- // --effort, which the binary rejects with "unknown option", failing
- // the task outright.
- help := `Usage: claude [options]
-
-Options:
- --model <model> Model to use
- --verbose
-`
- if got := claudeEffortLevelsFromHelp(help); got != nil {
- t.Fatalf("claudeEffortLevelsFromHelp: expected nil for pre-effort CLI, got %v", got)
+// Without discovery, every static model offers what `claude --help` lists —
+// there is no per-model table narrowing it (MUL-7691) — and the catalog
+// carries the binary's own vocabulary for the daemon to enforce.
+func TestClaudeStaticCatalogOffersHelpSupersetOnEveryModel(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("shell-script fake binary requires a POSIX shell")
}
-}
+ // This test resets the package-global thinking cache, so it must remain serial.
+ fakeClaude := writeFakeClaudeHelpBinary(t)
+ resetThinkingCacheForTests()
+ defer resetThinkingCacheForTests()
-func TestProjectClaudeLevels_PerModelSubset(t *testing.T) {
- t.Parallel()
- superset := []string{"low", "medium", "high", "xhigh", "max"}
- // Sonnet should drop xhigh per claudeModelEffortAllow.
- got := projectClaudeLevels(superset, claudeModelEffortAllow["claude-sonnet-4-6"])
- values := make([]string, 0, len(got))
- for _, lvl := range got {
- values = append(values, lvl.Value)
+ catalog := claudeStaticCatalog(context.Background(), Command{Path: fakeClaude})
+ want := []string{"low", "medium", "high", "xhigh", "max"}
+ if !catalog.Fallback {
+ t.Fatal("static catalog must be flagged Fallback")
}
- want := []string{"low", "medium", "high", "max"}
- if !reflect.DeepEqual(values, want) {
- t.Fatalf("projectClaudeLevels: got %v, want %v", values, want)
- }
- // Opus keeps xhigh.
- got = projectClaudeLevels(superset, claudeModelEffortAllow["claude-opus-4-7"])
- values = values[:0]
- for _, lvl := range got {
- values = append(values, lvl.Value)
- }
- if !reflect.DeepEqual(values, superset) {
- t.Fatalf("projectClaudeLevels for Opus: got %v, want %v", values, superset)
- }
- // Opus 5 declares `xhigh_effort` + `max_effort` upstream, so it keeps the
- // full superset like the rest of the Opus family. Without an entry here it
- // would fall through to "no allow-list" and coincidentally get the same
- // levels — this pins the mapping so a later Sonnet-style restriction on the
- // fallback path can't silently widen it.
- got = projectClaudeLevels(superset, claudeModelEffortAllow["claude-opus-5"])
- values = values[:0]
- for _, lvl := range got {
- values = append(values, lvl.Value)
- }
- if !reflect.DeepEqual(values, superset) {
- t.Fatalf("projectClaudeLevels for Opus 5: got %v, want %v", values, superset)
+ if !reflect.DeepEqual(catalog.CLIThinkingLevels, want) {
+ t.Errorf("CLIThinkingLevels = %v, want %v", catalog.CLIThinkingLevels, want)
+ }
+ for _, m := range catalog.Models {
+ if m.Thinking == nil {
+ t.Errorf("%s: no effort picker", m.ID)
+ continue
+ }
+ got := make([]string, 0, len(m.Thinking.SupportedLevels))
+ for _, lvl := range m.Thinking.SupportedLevels {
+ got = append(got, lvl.Value)
+ }
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("%s: levels = %v, want %v", m.ID, got, want)
+ }
}
}
@@ -446,69 +458,109 @@ exit 1
})
}
-func TestValidateThinkingLevelCodexPerModelFallbackCatalog(t *testing.T) {
+// A fallback catalog is a picker affordance, not an answer: whatever the static
+// list says about a model, a saved level passes through to the CLI (MUL-7691).
+func TestValidateThinkingLevelCodexFallbackCatalogPassesThrough(t *testing.T) {
t.Parallel()
- for _, tc := range []struct {
- model string
- level string
- want bool
- }{
- {model: "gpt-6-astra", level: "low", want: true},
- {model: "gpt-6-astra", level: "max", want: true},
- {model: "gpt-6-astra", level: "ultra", want: true},
- {model: "gpt-5.6-sol", level: "ultra", want: true},
- {model: "gpt-5.6-terra", level: "ultra", want: true},
- {model: "gpt-5.6-luna", level: "max", want: true},
- {model: "gpt-5.6-luna", level: "ultra", want: false},
- {model: "gpt-5.3-codex", level: "xhigh", want: true},
- {model: "gpt-5.3-codex", level: "max", want: false},
+ for _, tc := range []struct{ model, level string }{
+ {model: "gpt-6-astra", level: "ultra"},
+ {model: "gpt-5.6-luna", level: "ultra"}, // the static list gives Luna no ultra
+ {model: "gpt-5.3-codex", level: "max"}, // ...nor gpt-5.3-codex max
+ {model: "gpt-7", level: "high"}, // absent from the static list
} {
got, err := ValidateThinkingLevel(context.Background(), "codex", Command{Path: "/nonexistent/codex"}, tc.model, tc.level)
- if err != nil {
- t.Fatalf("ValidateThinkingLevel(%q, %q): %v", tc.model, tc.level, err)
+ if got || !errors.Is(err, errUnverifiedCatalog) {
+ t.Errorf("ValidateThinkingLevel(%q, %q) = (%v, %v), want errUnverifiedCatalog", tc.model, tc.level, got, err)
}
- if got != tc.want {
- t.Errorf("ValidateThinkingLevel(%q, %q) = %v, want %v", tc.model, tc.level, got, tc.want)
+ }
+}
+
+// Only a verified catalog may reject a saved capability. A fallback stand-in and
+// an empty catalog both mean "unknown", for every provider alike: the value
+// passes through with errUnverifiedCatalog whether or not the stand-in happens
+// to list the model, and an empty model no longer borrows the stand-in's
+// Default entry (MUL-7691).
+func TestValidateCapabilitiesPassThroughUnverifiedCatalog(t *testing.T) {
+ t.Parallel()
+ listed := Model{ID: "listed", Default: true, Thinking: &ModelThinking{SupportedLevels: []ThinkingLevel{{Value: "low"}}}}
+ unverified := map[string]Catalog{
+ "fallback": {Models: []Model{listed}, Fallback: true},
+ "empty": {Models: []Model{}},
+ }
+ for _, provider := range []string{"claude", "codex", "grok", "codebuddy", "dim", "opencode", "reasonix"} {
+ for name, catalog := range unverified {
+ load := func() (Catalog, error) { return catalog, nil }
+ models := []string{"listed", "unlisted"}
+ if !ThinkingRequiresExplicitModel(provider) {
+ models = append(models, "")
+ }
+ for _, model := range models {
+ if ok, err := ValidateThinkingLevelWith(load, provider, model, "high"); ok || !errors.Is(err, errUnverifiedCatalog) {
+ t.Errorf("%s, %s catalog, model %q: got (%v, %v), want errUnverifiedCatalog", provider, name, model, ok, err)
+ }
+ }
+ }
+ }
+ for name, catalog := range unverified {
+ load := func() (Catalog, error) { return catalog, nil }
+ for _, model := range []string{"listed", "unlisted"} {
+ if ok, err := ValidateServiceTierWith(load, "codex", model, "priority"); ok || !errors.Is(err, errUnverifiedCatalog) {
+ t.Errorf("service tier, %s catalog, model %q: got (%v, %v), want errUnverifiedCatalog", name, model, ok, err)
+ }
+ }
+ }
+
+ // A verified catalog still decides: a listed model without the value, or a
+ // model it does not list, drops the value without an error.
+ verified := func() (Catalog, error) { return Catalog{Models: []Model{listed}}, nil }
+ for _, model := range []string{"listed", "unlisted"} {
+ if ok, err := ValidateThinkingLevelWith(verified, "codex", model, "high"); ok || err != nil {
+ t.Errorf("verified catalog, model %q thinking: got (%v, %v), want (false, nil)", model, ok, err)
+ }
+ if ok, err := ValidateServiceTierWith(verified, "codex", model, "priority"); ok || err != nil {
+ t.Errorf("verified catalog, model %q tier: got (%v, %v), want (false, nil)", model, ok, err)
}
}
+
+ // codex's empty model fails closed before any catalog read, so a failed
+ // discovery cannot turn it into a pass-through.
+ noRead := func() (Catalog, error) { t.Error("empty model must not read catalog"); return Catalog{}, nil }
+ if ok, err := ValidateThinkingLevelWith(noRead, "codex", "", "high"); ok || err != nil {
+ t.Errorf("empty model thinking = (%v, %v), want (false, nil)", ok, err)
+ }
+ if ok, err := ValidateServiceTierWith(noRead, "codex", "", "priority"); ok || err != nil {
+ t.Errorf("empty model tier = (%v, %v), want (false, nil)", ok, err)
+ }
}
-// A fallback is not an allow-list for live-only models. Unknown models on an
-// authoritative catalog still fail closed, and known fallback models still
-// have their capabilities checked instead of being passed through.
-func TestValidateCodexCapabilitiesMissingFromFallback(t *testing.T) {
- fallback := Catalog{Models: []Model{{ID: "gpt-5.5"}}, Fallback: true}
+// The binary's own effort vocabulary is the one thing an unverified catalog
+// still enforces: a value outside it makes the CLI reject the launch outright,
+// so it is dropped rather than passed through.
+func TestValidateThinkingLevelEnforcesCLIVocabularyOnUnverifiedCatalog(t *testing.T) {
+ t.Parallel()
for _, tc := range []struct {
- name string
- validate func(func() (Catalog, error), string, string, string) (bool, error)
- value string
+ name string
+ cli []string
+ value string
+ passThrough bool
}{
- {"thinking", ValidateThinkingLevelWith, "high"},
- {"service tier", ValidateServiceTierWith, "priority"},
+ {name: "binary has no effort flag", cli: []string{}, value: "high"},
+ {name: "value outside the vocabulary", cli: []string{"low", "medium", "high"}, value: "max"},
+ {name: "value inside the vocabulary", cli: []string{"low", "medium", "high"}, value: "high", passThrough: true},
+ {name: "vocabulary unknown", cli: nil, value: "max", passThrough: true},
} {
t.Run(tc.name, func(t *testing.T) {
- load := func() (Catalog, error) { return fallback, nil }
- if valid, err := tc.validate(load, "codex", "gpt-6-sol", tc.value); valid || err == nil {
- t.Fatalf("missing live-only model: got (%v, %v), want validation error", valid, err)
+ load := func() (Catalog, error) {
+ return Catalog{Models: claudeStaticModels(), Fallback: true, CLIThinkingLevels: tc.cli}, nil
}
- if valid, err := tc.validate(load, "codex", "gpt-5.5", tc.value); valid || err != nil {
- t.Fatalf("known fallback model with unsupported value: got (%v, %v), want (false, nil)", valid, err)
- }
- fallback.Fallback = false
- if valid, err := tc.validate(load, "codex", "gpt-6-sol", tc.value); valid || err != nil {
- t.Fatalf("authoritative catalog omits model: got (%v, %v), want (false, nil)", valid, err)
+ for _, model := range []string{"claude-opus-5", "claude-opus-5-5", ""} {
+ ok, err := ValidateThinkingLevelWith(load, "claude", model, tc.value)
+ if ok || errors.Is(err, errUnverifiedCatalog) != tc.passThrough {
+ t.Errorf("model %q: got (%v, %v), want pass-through=%v", model, ok, err, tc.passThrough)
+ }
}
- fallback.Fallback = true
})
}
-
- load := func() (Catalog, error) { t.Fatal("empty model must not read catalog"); return Catalog{}, nil }
- if valid, err := ValidateThinkingLevelWith(load, "codex", "", "high"); valid || err != nil {
- t.Fatalf("empty model thinking = (%v, %v), want (false, nil)", valid, err)
- }
- if valid, err := ValidateServiceTierWith(load, "codex", "", "priority"); valid || err != nil {
- t.Fatalf("empty model tier = (%v, %v), want (false, nil)", valid, err)
- }
}
func TestValidateServiceTierStandardUsesCLICapabilityOnFallback(t *testing.T) {
@@ -775,28 +827,32 @@ func TestValidateThinkingLevel_PiRPCPerModelCatalog(t *testing.T) {
check("openai-multi/gpt-5.6-luna", "", true)
}
-func TestValidateThinkingLevel_EmptyModelResolvesToDefault(t *testing.T) {
- if runtime.GOOS == "windows" {
- t.Skip("shell-script fake binary requires a POSIX shell")
+// claudeVerifiedCatalog has the shape live Claude discovery produces: each
+// model states its own effort levels and the CLI's default row is flagged
+// Default.
+func claudeVerifiedCatalog() (Catalog, error) {
+ levels := func(values ...string) *ModelThinking {
+ out := &ModelThinking{}
+ for _, v := range values {
+ out.SupportedLevels = append(out.SupportedLevels, ThinkingLevel{Value: v})
+ }
+ return out
}
- // This test resets the package-global thinking cache, so it must remain serial.
-
- // We need a `claude` whose --help advertises the full superset
- // (low/medium/high/xhigh/max) so per-model projection actually has
- // something to filter. A non-existent path falls back to a conservative
- // [low,medium,high] which would hide the per-model behaviour we're
- // trying to verify.
- fakeClaude := writeFakeClaudeHelpBinary(t)
- resetThinkingCacheForTests()
- defer resetThinkingCacheForTests()
+ return Catalog{Models: []Model{
+ {ID: "claude-sonnet-4-6", Default: true, Thinking: levels("low", "medium", "high", "max")},
+ {ID: "claude-opus-4-7", Thinking: levels("low", "medium", "high", "xhigh", "max")},
+ {ID: "claude-opus-5", Thinking: levels("low", "medium", "high", "xhigh", "max")},
+ }}, nil
+}
- ctx := context.Background()
+func TestValidateThinkingLevel_EmptyModelResolvesToDefault(t *testing.T) {
+ t.Parallel()
t.Run("valid level on default model passes", func(t *testing.T) {
- // Claude's catalog flags Sonnet 4.6 as Default. Sonnet supports
- // low/medium/high/max (no xhigh) per claudeModelEffortAllow, so
- // "high" must round-trip when model is left empty.
- ok, err := ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, "", "high")
+ // The catalog flags Sonnet 4.6 as Default. Sonnet advertises
+ // low/medium/high/max (no xhigh), so "high" must round-trip when model
+ // is left empty.
+ ok, err := ValidateThinkingLevelWith(claudeVerifiedCatalog, "claude", "", "high")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@@ -806,9 +862,9 @@ func TestValidateThinkingLevel_EmptyModelResolvesToDefault(t *testing.T) {
})
t.Run("invalid level on default model fails", func(t *testing.T) {
- // "xhigh" is opus-only; resolving "" to default (sonnet 4.6)
+ // Sonnet does not advertise xhigh; resolving "" to the default model
// should reject it, not silently accept.
- ok, err := ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, "", "xhigh")
+ ok, err := ValidateThinkingLevelWith(claudeVerifiedCatalog, "claude", "", "xhigh")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@@ -820,7 +876,7 @@ func TestValidateThinkingLevel_EmptyModelResolvesToDefault(t *testing.T) {
t.Run("empty value always valid", func(t *testing.T) {
// Empty value means "use runtime default" — should pass
// regardless of model resolution.
- ok, err := ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, "", "")
+ ok, err := ValidateThinkingLevelWith(claudeVerifiedCatalog, "claude", "", "")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@@ -831,84 +887,38 @@ func TestValidateThinkingLevel_EmptyModelResolvesToDefault(t *testing.T) {
}
func TestValidateThinkingLevel_ExplicitModel(t *testing.T) {
- if runtime.GOOS == "windows" {
- t.Skip("shell-script fake binary requires a POSIX shell")
- }
- // This test resets the package-global thinking cache, so it must remain serial.
- fakeClaude := writeFakeClaudeHelpBinary(t)
- resetThinkingCacheForTests()
- defer resetThinkingCacheForTests()
-
- ctx := context.Background()
-
- // xhigh IS valid on Opus 4.7.
- ok, err := ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, "claude-opus-4-7", "xhigh")
- if err != nil {
- t.Fatalf("unexpected err: %v", err)
- }
- if !ok {
- t.Errorf("xhigh should be valid on opus-4-7; got false")
- }
-
- // The whole Opus effort range round-trips on Opus 5, which is the point of
- // adding it to the catalog: an agent pinned to it can still carry a
- // persisted thinking_level without the daemon dropping the flag.
- for _, level := range []string{"low", "medium", "high", "xhigh", "max"} {
- ok, err := ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, "claude-opus-5", level)
+ t.Parallel()
+ check := func(model, value string, want bool) {
+ t.Helper()
+ ok, err := ValidateThinkingLevelWith(claudeVerifiedCatalog, "claude", model, value)
if err != nil {
- t.Fatalf("unexpected err for opus-5 %q: %v", level, err)
+ t.Fatalf("ValidateThinkingLevelWith(claude, %q, %q): unexpected err: %v", model, value, err)
}
- if !ok {
- t.Errorf("%q should be valid on opus-5; got false", level)
+ if ok != want {
+ t.Errorf("ValidateThinkingLevelWith(claude, %q, %q) = %v, want %v", model, value, ok, want)
}
}
+ check("claude-opus-4-7", "xhigh", true)
+ for _, level := range []string{"low", "medium", "high", "xhigh", "max"} {
+ check("claude-opus-5", level, true)
+ }
+
// Claude Code appends a bracketed context-window tag to the model ID for
// long-context sessions. Capability validation must inherit the base
// model's effort catalog without rewriting the model passed to the CLI.
- ok, err = ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, "claude-opus-5[1m]", "xhigh")
- if err != nil {
- t.Fatalf("unexpected err for context-tagged opus-5: %v", err)
- }
- if !ok {
- t.Error("xhigh should be valid on the opus-5[1m] context variant")
- }
-
- ok, err = ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, "claude-opus-5[500k]", "high")
- if err != nil {
- t.Fatalf("unexpected err for future context-tag shape: %v", err)
- }
- if !ok {
- t.Error("high should be valid on a syntactically valid opus-5 context variant")
- }
+ check("claude-opus-5[1m]", "xhigh", true)
+ check("claude-opus-5[500k]", "high", true)
// Arbitrary bracket suffixes are not context-window tags. Keep malformed
// variants fail-closed even when their apparent base model is known.
- ok, err = ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, "claude-opus-5[weird]", "high")
- if err != nil {
- t.Fatalf("unexpected err for malformed context tag: %v", err)
- }
- if ok {
- t.Error("malformed context tag must fail closed")
- }
+ check("claude-opus-5[weird]", "high", false)
- // xhigh is NOT valid on Sonnet — should fail.
- ok, err = ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, "claude-sonnet-4-6[1m]", "xhigh")
- if err != nil {
- t.Fatalf("unexpected err: %v", err)
- }
- if ok {
- t.Errorf("xhigh must not be valid on sonnet-4-6; got true")
- }
+ // Sonnet does not advertise xhigh.
+ check("claude-sonnet-4-6[1m]", "xhigh", false)
- // An unknown model with a valid token still fails closed (no guess).
- ok, err = ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, "claude-nonexistent", "high")
- if err != nil {
- t.Fatalf("unexpected err: %v", err)
- }
- if ok {
- t.Errorf("unknown model must fail closed; got true")
- }
+ // A model a verified catalog does not list still fails closed (no guess).
+ check("claude-nonexistent", "high", false)
}
// TestValidateThinkingLevel_CodexEmptyModelFailsClosed pins the MUL-4347
@@ -1049,8 +1059,8 @@ echo "opencode 9.9.9"
}
// writeFakeClaudeHelpBinary writes a small shell script that mimics
-// `claude --help`, emitting the full effort superset line so per-model
-// projection has something to filter. Returns the path to the executable.
+// `claude --help`, emitting the full effort superset line. Returns the path
+// to the executable.
func writeFakeClaudeHelpBinary(t *testing.T) string {
t.Helper()
dir := t.TempDir()
@@ -1194,22 +1204,18 @@ func TestThinkingCacheKeyDistinct(t *testing.T) {
b := thinkingCacheKey{provider: "claude", command: "/bin/claude", cliVersion: "2.1.122"}
c := thinkingCacheKey{provider: "claude", command: "/opt/claude", cliVersion: "2.1.121"}
- thinkingCachePut(a, map[string]*ModelThinking{"x": {DefaultLevel: "a"}})
- thinkingCachePut(b, map[string]*ModelThinking{"x": {DefaultLevel: "b"}})
- thinkingCachePut(c, map[string]*ModelThinking{"x": {DefaultLevel: "c"}})
+ thinkingCachePut(a, claudeEffortHelp{picker: []string{"a"}})
+ thinkingCachePut(b, claudeEffortHelp{picker: []string{"b"}})
+ thinkingCachePut(c, claudeEffortHelp{picker: []string{"c"}})
assertLevel := func(name string, key thinkingCacheKey, want string) {
t.Helper()
- models, ok := thinkingCacheGet(key)
+ help, ok := thinkingCacheGet(key)
if !ok {
t.Fatalf("cache key %s: entry missing", name)
}
- model, ok := models["x"]
- if !ok || model == nil {
- t.Fatalf("cache key %s: model x missing", name)
- }
- if model.DefaultLevel != want {
- t.Errorf("cache key %s: got %q, want %q", name, model.DefaultLevel, want)
+ if len(help.picker) != 1 || help.picker[0] != want {
+ t.Errorf("cache key %s: got %v, want [%s]", name, help.picker, want)
}
}
@@ -1503,29 +1509,31 @@ func argIndexOf(slice []string, target string) int {
return -1
}
-func TestValidateThinkingLevel_ClaudeFable51AcceptsFullEffortRange(t *testing.T) {
+// End to end through a Claude CLI whose discovery fails: a model the static
+// list does not name (a release newer than this daemon) and an empty model both
+// carry their saved level through to the CLI — the list needs no update for
+// either. Only a level outside the binary's own `--effort` vocabulary is
+// dropped (MUL-7691).
+func TestValidateThinkingLevel_ClaudeFallbackPassesSavedLevelThrough(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("shell-script fake binary requires a POSIX shell")
}
// This test resets the package-global thinking cache, so it must remain serial.
-
- // A model missing from the Claude catalog never gets a Thinking entry, so
- // the daemon's pre-execution guard silently drops any persisted effort for
- // it. Fable 5.1 supports the full low..max range, so once it is in the
- // catalog every level must round-trip.
fakeClaude := writeFakeClaudeHelpBinary(t)
resetThinkingCacheForTests()
defer resetThinkingCacheForTests()
ctx := context.Background()
-
- for _, level := range []string{"low", "medium", "high", "xhigh", "max"} {
- ok, err := ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, "claude-fable-5-1", level)
- if err != nil {
- t.Fatalf("unexpected err for %q: %v", level, err)
+ for _, model := range []string{"claude-fable-5-1", "claude-opus-5-5", ""} {
+ for _, level := range []string{"low", "medium", "high", "xhigh", "max"} {
+ ok, err := ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, model, level)
+ if ok || !errors.Is(err, errUnverifiedCatalog) {
+ t.Errorf("model %q, level %q: got (%v, %v), want errUnverifiedCatalog", model, level, ok, err)
+ }
}
- if !ok {
- t.Errorf("level %q must be valid on claude-fable-5-1; got false", level)
+ ok, err := ValidateThinkingLevel(ctx, "claude", Command{Path: fakeClaude}, model, "ultra")
+ if ok || err != nil {
+ t.Errorf("model %q, level outside --help: got (%v, %v), want (false, nil)", model, ok, err)
}
}
}