Skip to content

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

Go

MUL-8184 Fix Hermes reasoning options for non-default models (#9452)

Timf9036be46a03
diff --git a/server/pkg/agent/acp_effort.go b/server/pkg/agent/acp_effort.go
index ba2a5a41ba..34f84ffb83 100644
--- a/server/pkg/agent/acp_effort.go
+++ b/server/pkg/agent/acp_effort.go
@@ -166,19 +166,9 @@ func parseACPEffortOption(raw json.RawMessage) (acpEffortOption, bool) {
// would wave it through, and the task would silently run at the default — the
// exact fake switch this whole path exists to prevent.
//
-// Models other than the current one keep a nil Thinking, which hides the picker
-// for them. Reading a real per-model catalog means driving the session's own
-// `model` config option once per model and consuming each refreshed response;
-// that is a follow-up, not something to fake here.
+// Other models stay nil unless discovery explicitly probes them after switching.
func annotateACPThinkingForSessionModel(models []Model, sessionResult json.RawMessage) {
- option, ok := parseACPEffortOption(sessionResult)
- if !ok || len(option.Choices) == 0 {
- return
- }
- thinking := &ModelThinking{
- SupportedLevels: option.Choices,
- DefaultLevel: option.CurrentValue,
- }
+ thinking := acpModelThinking(sessionResult)
for i := range models {
// Default is set from the session's advertised currentModelId, so it
// marks the one model this catalog actually describes. If nothing is
@@ -189,6 +179,85 @@ func annotateACPThinkingForSessionModel(models []Model, sessionResult json.RawMe
}
}
+// acpModelThinking is the effort catalog one ACP session state advertises, or
+// nil when it advertises none.
+func acpModelThinking(raw json.RawMessage) *ModelThinking {
+ option, ok := parseACPEffortOption(raw)
+ if !ok || len(option.Choices) == 0 {
+ return nil
+ }
+ return &ModelThinking{SupportedLevels: option.Choices, DefaultLevel: option.CurrentValue}
+}
+
+func hasACPConfigOptions(raw json.RawMessage) bool {
+ var result map[string]json.RawMessage
+ if json.Unmarshal(raw, &result) != nil {
+ return false
+ }
+ _, camel := result["configOptions"]
+ _, snake := result["config_options"]
+ return camel || snake
+}
+
+// acpOptionsAfterModelSwitch returns the session's configOptions as they
+// stand once session/set_model has run, or nil when the runtime exposed none
+// and the caller's pre-switch view is therefore stale.
+//
+// Two correlated sources, in order: the set_model response when it carries
+// configOptions, otherwise a re-read through the advertised `model` selector,
+// since session/set_config_option echoes the full configuration. The
+// config_option_update notification some runtimes publish instead is never
+// used: it is uncorrelated, may land after the response, and can still
+// describe the previous model.
+func acpOptionsAfterModelSwitch(ctx context.Context, request acpRequestFn, sessionID, modelID string, session, switched json.RawMessage) (json.RawMessage, error) {
+ if hasACPConfigOptions(switched) {
+ return switched, nil
+ }
+ if _, ok := findACPConfigOption(session, "model"); !ok {
+ return nil, nil
+ }
+ refreshed, err := request(ctx, "session/set_config_option", map[string]any{
+ "sessionId": sessionID, "configId": "model", "value": modelID,
+ })
+ if err != nil || !hasACPConfigOptions(refreshed) {
+ return nil, err
+ }
+ return refreshed, nil
+}
+
+// probeACPModelEffort fills in the effort catalog for every model other than
+// the session's current one by switching the throwaway discovery session onto
+// each and reading the options it advertises there — the per-model read that
+// annotateACPThinkingForSessionModel cannot do from a single response. A model
+// whose switch yields no options keeps a nil Thinking rather than borrowing a
+// sibling's levels. A session with no configOptions at all (Hermes Agent) is
+// skipped outright: switching models there cannot surface a catalog.
+func probeACPModelEffort(ctx context.Context, request acpRequestFn, sessionResult json.RawMessage, models []Model) {
+ sessionID := extractACPSessionID(sessionResult)
+ if sessionID == "" || !hasACPConfigOptions(sessionResult) {
+ return
+ }
+ for i := range models {
+ if models[i].Default {
+ continue
+ }
+ if ctx.Err() != nil {
+ return
+ }
+ switched, err := request(ctx, "session/set_model", map[string]any{
+ "sessionId": sessionID, "modelId": models[i].ID,
+ })
+ if err != nil {
+ continue
+ }
+ options, err := acpOptionsAfterModelSwitch(ctx, request, sessionID, models[i].ID, sessionResult, switched)
+ if err != nil {
+ continue
+ }
+ models[i].Thinking = acpModelThinking(options)
+ }
+}
+
// acpRequestFn is the ACP JSON-RPC call each backend's client already exposes.
// Taking it as a function keeps this helper independent of which client struct
// a given backend spawned.
diff --git a/server/pkg/agent/hermes.go b/server/pkg/agent/hermes.go
index a771e0ba99..814975b043 100644
--- a/server/pkg/agent/hermes.go
+++ b/server/pkg/agent/hermes.go
@@ -800,6 +800,7 @@ func (b *hermesBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
// 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.
+ effortStateIsCurrent := true
if opts.Model != "" && acpModelIDsEquivalent(effectiveModel, sessionCurrentModel) {
b.cfg.Logger.Info("hermes session already on requested model; skipping redundant set_model",
"model", opts.Model,
@@ -807,10 +808,11 @@ func (b *hermesBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
"session_id", sessionID,
)
} else if opts.Model != "" {
- if _, err := c.request(runCtx, "session/set_model", map[string]any{
+ modelResult, err := c.request(runCtx, "session/set_model", map[string]any{
"sessionId": sessionID,
"modelId": opts.Model,
- }); err != nil {
+ })
+ if err != nil {
b.cfg.Logger.Warn("hermes set_session_model failed", "error", err, "requested_model", opts.Model)
finalStatus = "failed"
finalError = fmt.Sprintf("hermes could not switch to model %q: %v", opts.Model, err)
@@ -838,6 +840,21 @@ func (b *hermesBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
return
}
b.cfg.Logger.Info("hermes session model set", "model", opts.Model)
+ // Effort options may depend on the model, so re-read them once
+ // the switch lands. A runtime that exposes no post-switch state
+ // leaves sessionResult describing the previous model; flag that
+ // so step 3b skips its local vocabulary check.
+ if opts.ThinkingLevel != "" {
+ options, err := acpOptionsAfterModelSwitch(runCtx, c.request, sessionID, opts.Model, sessionResult, modelResult)
+ if err != nil {
+ b.cfg.Logger.Warn("hermes could not refresh model options", "error", err, "requested_model", opts.Model)
+ }
+ if options != nil {
+ sessionResult = options
+ } else {
+ effortStateIsCurrent = false
+ }
+ }
}
// 3b. Apply a persisted thinking override through whichever effort
@@ -848,10 +865,11 @@ func (b *hermesBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
// above this must NOT fail the task — an effort we could not apply
// still runs the prompt at the runtime's own default.
//
- // sessionResult stops describing the live session once set_model runs,
- // because an ACP effort option may depend on the current model.
+ // sessionResult is the post-switch state when the runtime exposed one;
+ // otherwise effortStateIsCurrent is false and the helper lets the
+ // runtime validate the level itself.
applyACPEffortOption(runCtx, c.request, "hermes", b.cfg.Logger,
- sessionID, sessionResult, opts.ThinkingLevel, opts.Model == "")
+ sessionID, sessionResult, opts.ThinkingLevel, effortStateIsCurrent)
// 4. Send the prompt and wait for PromptResponse.
//
diff --git a/server/pkg/agent/hermes_effort_execute_unix_test.go b/server/pkg/agent/hermes_effort_execute_unix_test.go
index c14423c965..ee8d324eb2 100644
--- a/server/pkg/agent/hermes_effort_execute_unix_test.go
+++ b/server/pkg/agent/hermes_effort_execute_unix_test.go
@@ -33,10 +33,16 @@ while IFS= read -r line; do
*'"method":"session/new"'*|*'"method":"session/resume"'*)
printf '{"jsonrpc":"2.0","id":%s,"result":` + sessionResult + `}\n' "$id"
;;
+ *'"configId":"model"'*)
+ printf '{"jsonrpc":"2.0","id":%s,"result":{"configOptions":[{"id":"thought_level","currentValue":"low","options":[{"value":"low"},{"value":"high"}]}]}}\n' "$id"
+ ;;
*'"method":"session/set_config_option"'*)
requested=$(printf '%s' "$line" | sed -n 's/.*"value":"\([^"]*\)".*/\1/p')
printf '{"jsonrpc":"2.0","id":%s,"result":{"configOptions":[{"id":"reasoning_effort","currentValue":"%s","options":[{"value":"low"},{"value":"medium"},{"value":"high"}]}]}}\n' "$id" "$requested"
;;
+ *'"method":"session/set_model"'*)
+ printf '{"jsonrpc":"2.0","id":%s,"result":{}}\n' "$id"
+ ;;
*'"method":"session/prompt"'*)
printf '{"jsonrpc":"2.0","id":%s,"result":{"stopReason":"end_turn"}}\n' "$id"
exit 0
@@ -129,3 +135,14 @@ func TestHermesExecuteSendsNothingForHermesAgent(t *testing.T) {
t.Errorf("the turn should still have prompted; log:\n%s", rpcLog)
}
}
+
+// TestHermesExecuteUsesSwitchedModelEffort covers a runtime whose set_model
+// response is empty: the level must be applied from the options re-read through
+// the session's model selector, not from the pre-switch session state.
+func TestHermesExecuteUsesSwitchedModelEffort(t *testing.T) {
+ session := `{"sessionId":"ses-hermes","configOptions":[{"id":"model","currentValue":"initial","options":[{"value":"initial"},{"value":"other-model"}]}]}`
+ rpcLog := runHermesEffortTurn(t, session, "high", ExecOptions{Model: "other-model"})
+ if !strings.Contains(rpcLog, `"configId":"thought_level","sessionId":"ses-hermes","value":"high"`) {
+ t.Fatalf("switched model effort was not applied; log:\n%s", rpcLog)
+ }
+}
diff --git a/server/pkg/agent/hermes_model_discovery_unix_test.go b/server/pkg/agent/hermes_model_discovery_unix_test.go
index 5b202bf8ed..ac131dd85c 100644
--- a/server/pkg/agent/hermes_model_discovery_unix_test.go
+++ b/server/pkg/agent/hermes_model_discovery_unix_test.go
@@ -21,6 +21,31 @@ import (
"time"
)
+// TestDiscoverHermesModelsProbesPerModelEffort covers a runtime whose set_model
+// response is empty: the non-default model's catalog must come from the options
+// re-read through the session's model selector.
+func TestDiscoverHermesModelsProbesPerModelEffort(t *testing.T) {
+ script := `#!/bin/sh
+while IFS= read -r line; do
+ id=$(printf '%s' "$line" | sed -n 's/.*"id":\([0-9]*\).*/\1/p')
+ case "$line" in
+ *'"method":"session/new"'*) printf '{"jsonrpc":"2.0","id":%s,"result":{"sessionId":"s","models":{"currentModelId":"a","availableModels":[{"modelId":"a"},{"modelId":"b"}]},"configOptions":[{"id":"model","currentValue":"a","options":[{"value":"a"},{"value":"b"}]},{"id":"effort","currentValue":"low","options":[{"value":"low"}]}]}}\n' "$id" ;;
+ *'"configId":"model"'*) printf '{"jsonrpc":"2.0","id":%s,"result":{"configOptions":[{"id":"effort","currentValue":"high","options":[{"value":"high"},{"value":"max"}]}]}}\n' "$id" ;;
+ *) printf '{"jsonrpc":"2.0","id":%s,"result":{}}\n' "$id" ;;
+ esac
+done
+`
+ fakePath := filepath.Join(t.TempDir(), "hermes")
+ writeTestExecutable(t, fakePath, []byte(script))
+ models, err := discoverHermesModels(context.Background(), Command{Path: fakePath})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(models) != 2 || models[1].Thinking == nil || models[1].Thinking.DefaultLevel != "high" || len(models[1].Thinking.SupportedLevels) != 2 {
+ t.Fatalf("models = %+v", models)
+ }
+}
+
// hermesACPProviderUnconfiguredScript is a `hermes acp` stand-in that completes
// initialize and then rejects session/new exactly as hermes 0.20.0 does when it
// resolves no LLM provider — verified against the real binary by pointing it at
diff --git a/server/pkg/agent/models.go b/server/pkg/agent/models.go
index c3246b3494..03ad69be1b 100644
--- a/server/pkg/agent/models.go
+++ b/server/pkg/agent/models.go
@@ -1589,9 +1589,11 @@ func discoverHermesModels(ctx context.Context, runtimeCmd Command) ([]Model, err
// The same handshake carries an effort selector on jcode and carries
// none on Hermes Agent, so annotate is what tells the two apart —
// Hermes Agent models come back with a nil Thinking and show no
- // picker. Only the session's current model is annotated; see
- // annotateACPThinkingForSessionModel.
- annotate: annotateACPThinkingForSessionModel,
+ // picker. annotate covers the session's current model; the probe
+ // switches the discovery session onto each remaining model for its
+ // own catalog. See probeACPModelEffort.
+ annotate: annotateACPThinkingForSessionModel,
+ probeModelEffort: true,
})
if err != nil {
return nil, annotateHermesDiscoveryUnconfigured(err)
@@ -1911,7 +1913,7 @@ func acpConfigOptionCurrentValue(raw json.RawMessage, configID string) (string,
// Only the session's current model gets a catalog: reasonix derives the effort
// vocabulary from the current model's provider entry, so the advertised list
// describes that model alone. Every other model keeps a nil Thinking and shows
-// no picker until per-model probing exists. See
+// no picker until reasonix opts into probeModelEffort. See
// annotateACPThinkingForSessionModel.
func discoverReasonixModels(ctx context.Context, runtimeCmd Command) ([]Model, error) {
return discoverACPModels(ctx, runtimeCmd, acpDiscoveryProvider{
@@ -2030,6 +2032,9 @@ type acpDiscoveryProvider struct {
// ignores. CodeBuddy uses it to read its effort catalog out of the same
// handshake, which is why it needs no separate discovery call at all.
annotate func([]Model, json.RawMessage)
+ // probeModelEffort switches the throwaway session onto each non-current
+ // model to read that model's own effort catalog; see probeACPModelEffort.
+ probeModelEffort bool
// timeout bounds the whole handshake — spawn, initialize, session/new.
// Zero means acpDiscoveryDefaultTimeout.
//
@@ -2124,7 +2129,7 @@ func discoverACPModels(ctx context.Context, runtimeCmd Command, p acpDiscoveryPr
scanner := bufio.NewScanner(stdout)
scanner.Buffer(make([]byte, 0, 1024*1024), 4*1024*1024)
nextID := 1
- requestACP := func(method string, params map[string]any) (json.RawMessage, error) {
+ requestACP := func(method string, params any) (json.RawMessage, error) {
id := nextID
nextID++
msg := map[string]any{
@@ -2249,6 +2254,14 @@ func discoverACPModels(ctx context.Context, runtimeCmd Command, p acpDiscoveryPr
if p.annotate != nil {
p.annotate(models, sessionResult)
}
+ if p.probeModelEffort {
+ probeACPModelEffort(runCtx, func(_ context.Context, method string, params any) (json.RawMessage, error) {
+ return requestACP(method, params)
+ }, sessionResult, models)
+ if err := runCtx.Err(); err != nil {
+ return fail("per-model effort discovery", err)
+ }
+ }
return models, nil
}