Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(agent): normalise the provider prefix in the Hermes set_model skip-gate (MUL-6958) (#7908)
garfield-nd3df7c38ed1f6
diff --git a/server/pkg/agent/hermes.go b/server/pkg/agent/hermes.goindex c46f7a8b36..f3e2fe0d06 100644--- a/server/pkg/agent/hermes.go+++ b/server/pkg/agent/hermes.go@@ -576,9 +576,19 @@ func (b *hermesBackend) Execute(ctx context.Context, prompt string, opts ExecOpt// downside. An empty sessionCurrentModel (older runtime or unparsable// state) falls through and still sends set_model, preserving prior// behaviour. See MUL-5029 / NousResearch/hermes-agent#59089.- if opts.Model != "" && effectiveModel == sessionCurrentModel {+ //+ // The comparison is provider-normalised (acpModelIDsEquivalent), not a+ // raw string match: Hermes always reports its current model in the+ // provider-encoded `provider:model` form, while agent.model is stored+ // verbatim from the API and is routinely bare. A literal == therefore+ // never matched for those agents, so the gate above was dead code and+ // the MUL-5029 mis-routing hazard it exists to prevent stayed live for+ // exactly the agents that hit it. See acpModelIDsEquivalent for the+ // evidence and for what the redundant call actually costs.+ if opts.Model != "" && acpModelIDsEquivalent(effectiveModel, sessionCurrentModel) {b.cfg.Logger.Info("hermes session already on requested model; skipping redundant set_model","model", opts.Model,+ "session_model", sessionCurrentModel,"session_id", sessionID,)} else if opts.Model != "" {@@ -2130,6 +2140,73 @@ func extractACPAuthMethods(result json.RawMessage) []string {return ids}+// splitACPModelID splits an ACP model id into its optional `provider:` prefix+// and the bare model name. Ids without a colon (or with a leading colon) carry+// no provider and return ("", id). Mirrors the prefix convention acpModelEntry+// derives dropdown grouping from.+//+// Bare model names can themselves contain colons in theory, so only the FIRST+// colon is treated as the provider separator — the remainder is the model.+func splitACPModelID(modelID string) (provider, model string) {+ id := strings.TrimSpace(modelID)+ if idx := strings.Index(id, ":"); idx > 0 {+ return id[:idx], id[idx+1:]+ }+ return "", id+}++// acpModelIDsEquivalent reports whether a configured model id and the id the+// runtime reports as current denote the same selection.+//+// Normalisation is needed because two id namespaces meet here: agent.model is+// persisted verbatim (handler/agent.go CreateAgent/UpdateAgent) and the CLI+// documents the bare spelling as valid, while an ACP runtime commonly answers+// session/new with a provider-encoded `provider:model` id. A raw == across+// those two spellings misses, which is why the MUL-5029 skip-gate added in+// #5690 never fired for bare-configured agents and set_model was replayed+// every turn.+//+// The rules are deliberately asymmetric, because the risk is:+// - Either side empty → not equivalent (caller handles the empty-model case).+// - Bare configured id → equivalent on the model name alone. It expresses no+// provider preference, so the session's own provider is authoritative.+// This is the case the gate exists for.+// - Explicit configured provider → equivalent only when the session reports+// that same provider. A session reporting a bare id cannot confirm the+// match, so fall through and send set_model rather than silently swallow a+// provider switch the caller explicitly asked for. Bare current ids are+// not hypothetical: acp_effort_test.go captures an unprefixed+// `gpt-5.6-sol` from jcode, which routes through this same backend.+// Hermes Agent's encoder has a bare branch too — acp_adapter+// `_encode_model_choice` returns the model alone when the provider is+// empty — but a normally-configured install always resolves one, and a+// live `hermes acp` v0.20.0 session reports the prefixed form.+//+// Provider and model are compared case-insensitively: Hermes lowercases the+// provider when encoding the id, so a config written as `Custom:...` would+// otherwise miss.+//+// splitACPModelID cannot distinguish a provider prefix from a colon inside a+// bare model name (Ollama-style `llama3:8b`). That degradation is safe in the+// only direction that matters: `llama3:8b` vs `custom:llama3:8b` compares+// unequal and falls back to sending set_model, never to a false skip.+func acpModelIDsEquivalent(configured, current string) bool {+ configured = strings.TrimSpace(configured)+ current = strings.TrimSpace(current)+ if configured == "" || current == "" {+ return false+ }+ cfgProvider, cfgModel := splitACPModelID(configured)+ curProvider, curModel := splitACPModelID(current)+ if !strings.EqualFold(cfgModel, curModel) {+ return false+ }+ if cfgProvider == "" {+ return true+ }+ return strings.EqualFold(cfgProvider, curProvider)+}+// extractACPCurrentModelID pulls the model selected by the ACP runtime out of// a session/new or session/resume response. Hermes returns this when it uses// its own default model, so token usage can still be attributed to a real modeldiff --git a/server/pkg/agent/hermes_test.go b/server/pkg/agent/hermes_test.goindex e81ebe02cb..321841fe83 100644--- a/server/pkg/agent/hermes_test.go+++ b/server/pkg/agent/hermes_test.go@@ -82,6 +82,171 @@ func TestExtractACPCurrentModelIDMissing(t *testing.T) {}}+// ── acpModelIDsEquivalent ──++func TestACPModelIDsEquivalent(t *testing.T) {+ t.Parallel()+ tests := []struct {+ name string+ configured string+ current string+ want bool+ }{+ {+ // The regression this helper exists for: agent.model is stored+ // bare, Hermes reports the provider-encoded form. A raw string+ // compare missed, so the MUL-5029 skip-gate never fired and every+ // turn re-sent set_model — rebuilding the runtime-side agent and+ // re-running the provider auto-detection the gate exists to avoid.+ name: "bare configured vs provider-encoded current",+ configured: "claude-sonnet-4-5",+ current: "custom:claude-sonnet-4-5",+ want: true,+ },+ {+ name: "both provider-encoded and identical",+ configured: "custom:claude-sonnet-4-5",+ current: "custom:claude-sonnet-4-5",+ want: true,+ },+ {+ name: "second bare model vs encoded",+ configured: "claude-haiku-4-5",+ current: "custom:claude-haiku-4-5",+ want: true,+ },+ {+ // A real provider switch must still send set_model.+ name: "same model, different explicit providers",+ configured: "openrouter:claude-sonnet-4-5",+ current: "custom:claude-sonnet-4-5",+ want: false,+ },+ {+ name: "different models under same provider",+ configured: "custom:claude-sonnet-4-5",+ current: "custom:claude-haiku-4-5",+ want: false,+ },+ {+ name: "different bare models",+ configured: "claude-sonnet-4-5",+ current: "custom:claude-opus-4-5",+ want: false,+ },+ {+ // Hermes lowercases the provider when encoding; a config written+ // with different casing must still match.+ name: "provider casing differs",+ configured: "Custom:Claude-Sonnet-4-5",+ current: "custom:claude-sonnet-4-5",+ want: true,+ },+ {+ // Older runtime / unparsable state: fall through and send+ // set_model, preserving prior behaviour.+ name: "empty current",+ configured: "claude-sonnet-4-5",+ current: "",+ want: false,+ },+ {+ name: "empty configured",+ configured: "",+ current: "custom:claude-sonnet-4-5",+ want: false,+ },+ {+ name: "both empty",+ configured: "",+ current: "",+ want: false,+ },+ {+ name: "surrounding whitespace is ignored",+ configured: " claude-sonnet-4-5 ",+ current: "custom:claude-sonnet-4-5",+ want: true,+ },+ {+ // Model names carrying a slash (OpenRouter-style) must not be+ // confused with the provider prefix.+ name: "slash-bearing model name, bare vs encoded",+ configured: "moonshotai/kimi-k2.6",+ current: "nous:moonshotai/kimi-k2.6",+ want: true,+ },+ {+ // The asymmetric case. A bare *configured* id expresses no+ // provider preference, but an explicit one does, and a bare+ // *current* id cannot confirm it was honoured. Treating this as+ // equivalent would silently swallow the switch the member asked+ // for, so it must fall through and send set_model.+ //+ // Bare current ids are not hypothetical: acp_effort_test.go+ // captures an unprefixed `gpt-5.6-sol` from jcode, which routes+ // through this same backend. Hermes Agent's encoder has a bare+ // branch too, though a normally-configured install resolves a+ // provider and reports the prefixed form.+ name: "explicit configured provider vs bare current",+ configured: "openrouter:hermes-4",+ current: "hermes-4",+ want: false,+ },+ {+ // Both sides bare and identical: nothing to switch to, and the+ // runtimes above really do answer this way.+ name: "both bare and identical",+ configured: "hermes-4",+ current: "hermes-4",+ want: true,+ },+ {+ name: "both bare, different models",+ configured: "hermes-4",+ current: "gpt-5.6-sol",+ want: false,+ },+ }+ for _, tc := range tests {+ t.Run(tc.name, func(t *testing.T) {+ t.Parallel()+ if got := acpModelIDsEquivalent(tc.configured, tc.current); got != tc.want {+ t.Errorf("acpModelIDsEquivalent(%q, %q) = %v, want %v",+ tc.configured, tc.current, got, tc.want)+ }+ })+ }+}++func TestSplitACPModelID(t *testing.T) {+ t.Parallel()+ tests := []struct {+ in string+ wantProvider string+ wantModel string+ }{+ {"custom:claude-sonnet-4-5", "custom", "claude-sonnet-4-5"},+ {"claude-sonnet-4-5", "", "claude-sonnet-4-5"},+ {"nous:moonshotai/kimi-k2.6", "nous", "moonshotai/kimi-k2.6"},+ {"", "", ""},+ // Leading colon carries no provider — index 0 is not a separator.+ {":weird", "", ":weird"},+ // Only the first colon separates; the rest belongs to the model.+ {"custom:vendor:model", "custom", "vendor:model"},+ }+ for _, tc := range tests {+ t.Run(tc.in, func(t *testing.T) {+ t.Parallel()+ gotProvider, gotModel := splitACPModelID(tc.in)+ if gotProvider != tc.wantProvider || gotModel != tc.wantModel {+ t.Errorf("splitACPModelID(%q) = (%q, %q), want (%q, %q)",+ tc.in, gotProvider, gotModel, tc.wantProvider, tc.wantModel)+ }+ })+ }+}+// ── resolveResumedSessionID ──func TestResolveResumedSessionIDMatching(t *testing.T) {@@ -3741,6 +3906,99 @@ func TestHermesSendsSetModelWhenModelDiffersFromCurrent(t *testing.T) {}}+// TestHermesSkipsRedundantSetModelForBareConfiguredModel pins the defect this+// change exists for, at the level it actually lives at. agent.model is stored+// bare (the spelling the CLI documents) while the session reports the+// provider-encoded form, so the raw == in the MUL-5029 gate missed and+// set_model went out every turn. Asserting on acpModelIDsEquivalent alone+// would not have caught that the gate never fired.+func TestHermesSkipsRedundantSetModelForBareConfiguredModel(t *testing.T) {+ t.Parallel()++ recordPath := filepath.Join(t.TempDir(), "frames.jsonl")+ fakePath := filepath.Join(t.TempDir(), "hermes")+ writeTestExecutable(t, fakePath, []byte(fakeACPRecordingScriptWithCurrentModel(recordPath, "ses_new", "custom:deepseek-v4-pro")))++ backend, err := New("hermes", Config{ExecutablePath: fakePath, Logger: slog.Default()})+ if err != nil {+ t.Fatalf("new hermes backend: %v", err)+ }++ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)+ defer cancel()+ session, err := backend.Execute(ctx, "prompt-ignored", ExecOptions{+ Timeout: 5 * time.Second,+ Model: "deepseek-v4-pro",+ })+ if err != nil {+ t.Fatalf("execute: %v", err)+ }+ go func() {+ for range session.Messages {+ }+ }()+ select {+ case result := <-session.Result:+ if result.Status != "completed" {+ t.Fatalf("expected completed result, got %q: %s", result.Status, result.Error)+ }+ case <-time.After(10 * time.Second):+ t.Fatal("timeout waiting for result")+ }++ assertNoRecordedFrame(t, recordPath, "session/set_model")+}++// TestHermesSendsSetModelWhenExplicitProviderAndBareCurrent guards the+// asymmetry of the equivalence rules. A caller that names a provider+// explicitly must get the switch even when the runtime reports a bare current+// id, because a bare id cannot confirm which provider is actually in use.+// Runtimes really do answer this way — acp_effort_test.go captures an+// unprefixed `gpt-5.6-sol` from jcode, which routes through this backend.+func TestHermesSendsSetModelWhenExplicitProviderAndBareCurrent(t *testing.T) {+ t.Parallel()++ recordPath := filepath.Join(t.TempDir(), "frames.jsonl")+ fakePath := filepath.Join(t.TempDir(), "hermes")+ writeTestExecutable(t, fakePath, []byte(fakeACPRecordingScriptWithCurrentModel(recordPath, "ses_new", "hermes-4")))++ backend, err := New("hermes", Config{ExecutablePath: fakePath, Logger: slog.Default()})+ if err != nil {+ t.Fatalf("new hermes backend: %v", err)+ }++ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)+ defer cancel()+ session, err := backend.Execute(ctx, "prompt-ignored", ExecOptions{+ Timeout: 5 * time.Second,+ Model: "openrouter:hermes-4",+ })+ if err != nil {+ t.Fatalf("execute: %v", err)+ }+ go func() {+ for range session.Messages {+ }+ }()+ select {+ case result := <-session.Result:+ if result.Status != "completed" {+ t.Fatalf("expected completed result, got %q: %s", result.Status, result.Error)+ }+ case <-time.After(10 * time.Second):+ t.Fatal("timeout waiting for result")+ }++ frame := findRecordedFrame(t, recordPath, "session/set_model")+ params, ok := frame["params"].(map[string]any)+ if !ok {+ t.Fatalf("session/set_model params: got %T, want map", frame["params"])+ }+ if params["modelId"] != "openrouter:hermes-4" {+ t.Errorf("session/set_model.modelId = %v, want openrouter:hermes-4", params["modelId"])+ }+}+// TestHermesResumeIncludesMcpServers pins the contract that// session/resume carries the managed MCP set. Without this, a resumed// Hermes task lost access to MCP tools that a fresh task on the same