Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-19169-model-id-conventions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Claude and Copilot agents can no longer end up on the other CLI's spelling of the same Claude model (`claude-sonnet-5.5` on claude, `claude-sonnet-5-5` on copilot), which each CLI rejects: switching backends, setting a model, and loading config now store the backend's own spelling through one shared mapping with a dashboard warning, and the model dropdowns show a wrong-convention id as stored and flag it instead of silently preselecting the valid option. Non-Claude ids are unchanged ([#19169](https://github.com/hivecommons/hive/issues/19169)).
12 changes: 11 additions & 1 deletion src/crux/agent/manager_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,20 @@ const bobBackend = "bob"
// undefined (reading 'maxTokens')". Leaving it unrewritten keeps logs honest
// about what was configured and stops the corrupted id from being handed to a
// future bob consumer.
//
// claude takes only the dotted-to-dashed repair (config.CanonicalizeClaudeModel):
// a Copilot-spelled id such as claude-sonnet-5.5, carried over when an agent
// is switched from copilot to claude, is rejected by the Claude CLI on every
// kick, so it is launched as claude-sonnet-5-5. Aliases and dashed ids pass
// through unchanged.
func normalizeModelNameForBackend(model, backend string, inferenceRoutable bool) string {
if backend == "claude" || backend == bobBackend || inferenceRoutable {
if inferenceRoutable || backend == bobBackend {
return model
}
if backend == config.ClaudeBackend {
canonical, _ := config.CanonicalizeClaudeModel(model)
return canonical
}
if backend == "copilot" {
return CopilotLaunchModel(model)
}
Expand Down
9 changes: 8 additions & 1 deletion src/crux/agent/routing_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,14 @@ func TestConnectionMCPFlags_NonClaude(t *testing.T) {

func TestNormalizeModelName(t *testing.T) {
cases := []struct{ model, backend, want string }{
{"opus", "claude", "opus"}, // claude passes through
{"opus", "claude", "opus"}, // claude passes through
{"claude-sonnet-5-5", "claude", "claude-sonnet-5-5"},
// A copilot-spelled id carried over by a backend switch is launched
// in the Claude CLI's dashed spelling instead of failing every kick.
{"claude-sonnet-5.5", "claude", "claude-sonnet-5-5"},
// And the other way: the Claude CLI spelling on copilot launches as
// the Copilot spelling, even for an id the alias list does not know.
{"claude-haiku-5-5", "copilot", "claude-haiku-5.5"},
{"deepseek-14", "litellm", "deepseek-14"}, // inference passes through
// copilot no longer takes the blind digit-suffix dot-rewrite (#4262):
// ids are canonicalized against the CLI-accepted list and UNKNOWN ids
Expand Down
74 changes: 74 additions & 0 deletions src/crux/config/model_id_conventions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package config

import (
"regexp"
"strings"
)

// CopilotBackend is the backend name of the GitHub Copilot CLI.
const CopilotBackend = "copilot"

// claudeModelIDPrefix is the family prefix of every concrete Anthropic model
// id. Bare aliases (sonnet, opus, haiku) carry no version and never need
// normalization.
const claudeModelIDPrefix = "claude-"

// claudeMinorVersionID matches a Claude id with a MAJOR and MINOR version and
// nothing after it, in either spelling: claude-sonnet-5-5 / claude-sonnet-5.5,
// claude-haiku-4-5 / claude-haiku-4.5. Group 1 is everything up to the major
// version, group 2 the minor. Bare generations (claude-opus-5) and dated or
// suffixed ids (claude-opus-4-5-20251101) do not match: they have no Copilot
// counterpart to map to.
var claudeMinorVersionID = regexp.MustCompile(`^((?i:claude)-[A-Za-z]+-[0-9]+)[.-]([0-9]+)$`)

// CanonicalizeModelForBackend returns the spelling backend's CLI uses for a
// Claude model id, and whether that differs from the input. It is the ONE
// mapping between the two naming conventions for the same Anthropic models:
//
// claude backend (Claude Code CLI, Anthropic API): DASHED
// claude-sonnet-5.5 -> claude-sonnet-5-5, claude-opus-4.6 -> claude-opus-4-6
// copilot backend (Copilot CLI catalog): DOTTED major.minor
// claude-sonnet-5-5 -> claude-sonnet-5.5, claude-haiku-4-5 -> claude-haiku-4.5
//
// Each CLI rejects the other's spelling: `claude --model claude-sonnet-5.5`
// fails every kick ("There's an issue with the selected model"), and the
// Copilot CLI rejects claude-sonnet-5-5 and silently falls back to another
// model (#9927). The wrong spelling reaches an agent when it is switched
// between the two backends and keeps its model.
//
// Everything else passes through unchanged: other backends, non-Claude ids
// (gpt-5.5, gemini-3.6-flash), aliases, bare generations (claude-opus-5) and
// gateway ids with a provider prefix (anthropic/claude-sonnet-5.5), which the
// gateway routes verbatim. Idempotent.
func CanonicalizeModelForBackend(backend, id string) (string, bool) {
trimmed := strings.TrimSpace(id)
if trimmed == "" || strings.Contains(trimmed, "/") || !strings.HasPrefix(strings.ToLower(trimmed), claudeModelIDPrefix) {
return id, false
}
var canonical string
switch backend {
case ClaudeBackend:
if !strings.Contains(trimmed, ".") {
return id, false
}
canonical = strings.ReplaceAll(trimmed, ".", "-")
case CopilotBackend:
m := claudeMinorVersionID.FindStringSubmatch(trimmed)
if m == nil {
return id, false
}
canonical = m[1] + "." + m[2]
default:
return id, false
}
if canonical == id {
return id, false
}
return canonical, true
}

// CanonicalizeClaudeModel is CanonicalizeModelForBackend for the claude
// backend.
func CanonicalizeClaudeModel(id string) (string, bool) {
return CanonicalizeModelForBackend(ClaudeBackend, id)
}
67 changes: 67 additions & 0 deletions src/crux/config/model_id_conventions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package config

import "testing"

func TestCanonicalizeModelForBackend(t *testing.T) {
cases := []struct {
backend, in, want string
changed bool
}{
// claude backend: the Claude CLI spells versions with dashes.
{ClaudeBackend, "claude-sonnet-5.5", "claude-sonnet-5-5", true},
{ClaudeBackend, "claude-opus-5.5", "claude-opus-5-5", true},
{ClaudeBackend, "claude-opus-4.6", "claude-opus-4-6", true},
{ClaudeBackend, "Claude-Sonnet-4.5", "Claude-Sonnet-4-5", true},
{ClaudeBackend, " claude-sonnet-5.5 ", "claude-sonnet-5-5", true},
{ClaudeBackend, "claude-sonnet-5-5", "claude-sonnet-5-5", false},
{ClaudeBackend, "claude-opus-5", "claude-opus-5", false},
{ClaudeBackend, "sonnet", "sonnet", false},
{ClaudeBackend, "", "", false},
{ClaudeBackend, "gpt-5.5", "gpt-5.5", false},
{ClaudeBackend, "anthropic/claude-sonnet-5.5", "anthropic/claude-sonnet-5.5", false},

// copilot backend: the same models, dotted major.minor.
{CopilotBackend, "claude-sonnet-5-5", "claude-sonnet-5.5", true},
{CopilotBackend, "claude-opus-5-5", "claude-opus-5.5", true},
{CopilotBackend, "claude-haiku-4-5", "claude-haiku-4.5", true},
{CopilotBackend, "claude-sonnet-4-6", "claude-sonnet-4.6", true},
{CopilotBackend, "claude-sonnet-5.5", "claude-sonnet-5.5", false},
// Bare generations are separator-free in both conventions.
{CopilotBackend, "claude-sonnet-5", "claude-sonnet-5", false},
{CopilotBackend, "claude-fable-5", "claude-fable-5", false},
// Dated / suffixed ids have no Copilot counterpart: unchanged.
{CopilotBackend, "claude-opus-4-5-20251101", "claude-opus-4-5-20251101", false},
// Non-Claude Copilot models pass through.
{CopilotBackend, "gpt-5.5", "gpt-5.5", false},
{CopilotBackend, "gpt-5-mini", "gpt-5-mini", false},
{CopilotBackend, "gemini-3.6-flash", "gemini-3.6-flash", false},
{CopilotBackend, "auto", "auto", false},

// Other backends are never touched.
{"gemini", "claude-sonnet-5-5", "claude-sonnet-5-5", false},
{"litellm", "claude-sonnet-5.5", "claude-sonnet-5.5", false},
}
for _, c := range cases {
got, changed := CanonicalizeModelForBackend(c.backend, c.in)
if got != c.want || changed != c.changed {
t.Errorf("CanonicalizeModelForBackend(%q, %q) = (%q, %v), want (%q, %v)", c.backend, c.in, got, changed, c.want, c.changed)
}
if again, changedAgain := CanonicalizeModelForBackend(c.backend, got); again != got || changedAgain {
t.Errorf("not idempotent for %s on %q: (%q, %v)", c.backend, got, again, changedAgain)
}
}
}

// Converting to one convention and back returns the original id.
func TestCanonicalizeModelForBackendRoundTrip(t *testing.T) {
for _, dashed := range []string{"claude-sonnet-5-5", "claude-opus-5-5", "claude-haiku-4-5", "claude-opus-4-8"} {
dotted, ok := CanonicalizeModelForBackend(CopilotBackend, dashed)
if !ok {
t.Fatalf("%q: no copilot spelling", dashed)
}
back, ok := CanonicalizeClaudeModel(dotted)
if !ok || back != dashed {
t.Errorf("%q -> %q -> %q, want round trip", dashed, dotted, back)
}
}
}
9 changes: 9 additions & 0 deletions src/crux/copilot_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package crux

import (
"strings"

"github.com/hivecommons/hive/crux/config"
)

// copilotCLIAcceptedModels are the model ids the copilot CLI's --model flag
Expand Down Expand Up @@ -103,6 +105,13 @@ func CanonicalizeCopilotModel(id string) string {
if canonical, ok := copilotModelByKey[copilotModelKey(id)]; ok {
return canonical
}
// A Claude id outside the list above still gets the Copilot spelling
// (claude-sonnet-5-5 -> claude-sonnet-5.5) from the one shared mapping
// between the Claude and Copilot conventions, so a newly released model
// does not have to be added here first.
if canonical, ok := config.CanonicalizeModelForBackend(config.CopilotBackend, id); ok {
return canonical
}
return id
}

Expand Down
4 changes: 4 additions & 0 deletions src/crux/copilot_models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func TestCanonicalizeCopilotModel(t *testing.T) {
{"unknown id unchanged", "some-future-model.9", "some-future-model.9"},
{"unknown dashless unchanged", "gpt-next", "gpt-next"},
{"auto sentinel unchanged", "auto", "auto"},
// A Claude id the list does not know yet still gets the Copilot
// spelling from the shared Claude/Copilot mapping.
{"unlisted claude dashed to dotted", "claude-haiku-5-5", "claude-haiku-5.5"},
{"unlisted claude dotted unchanged", "claude-haiku-5.5", "claude-haiku-5.5"},
{"empty unchanged", "", ""},
}
for _, tt := range tests {
Expand Down
Loading
Loading