Skip to content

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

Go

MUL-5991 feat(agent): drive ACP thinking_level from the backend's own configOptions (reasonix first) (#6752)

Bohan Jiang84a02cc2acb2
diff --git a/server/internal/service/builtin_skills/multica-creating-agents/SKILL.md b/server/internal/service/builtin_skills/multica-creating-agents/SKILL.md
index 626afc707f..16aed1ab87 100644
--- a/server/internal/service/builtin_skills/multica-creating-agents/SKILL.md
+++ b/server/internal/service/builtin_skills/multica-creating-agents/SKILL.md
@@ -119,7 +119,7 @@ multica agent copy <source-agent-id> --runtime-id <target> --model <model> # cr
| `avatar_url` | `agent.avatar_url` | none; an explicit non-empty value is preserved, while omitted/empty creates a random `emoji:<glyph>` avatar | catalog/listing UI only — NOT the runtime prompt |
| `runtime_id` | `agent.runtime_id` (nullable) | required at create (400) + must resolve to a runtime in this workspace | selects runtime/provider; `NULL` means unbound — see below |
| `model` | `agent.model` (nullable) | none beyond runtime support | daemon reads; empty = runtime default |
-| `thinking_level` | `agent.thinking_level` (nullable) | provider-level enum/safe-token gate; unknown literal → 400. Pi accepts only `off|minimal|low|medium|high|xhigh|max`, then the daemon checks the selected model's RPC-discovered subset. A runtime with no reasoning control (e.g. `hermes`) rejects EVERY non-empty value and says so — that 400 is a capability answer, not a bad token | daemon; empty = runtime default |
+| `thinking_level` | `agent.thinking_level` (nullable) | provider-level enum/safe-token gate; unknown literal → 400. Pi accepts only `off|minimal|low|medium|high|xhigh|max`, then the daemon checks the selected model's RPC-discovered subset. ACP runtimes that advertise an effort selector in `session/new` (currently `reasonix`) take the safe-token path and are checked against the discovered catalog by the daemon; that catalog covers only the model the discovery session was on, so other models show no picker until per-model probing exists. A runtime with no reasoning control (e.g. `hermes`) rejects EVERY non-empty value and says so — that 400 is a capability answer, not a bad token | daemon; empty = runtime default |
| `service_tier` | `agent.service_tier` (nullable) | Codex-only safe token; other providers reject; exact model/tier pair checked by daemon | daemon → Codex app-server; empty = local Codex config |
| `custom_args` | `agent.custom_args` (JSON array) | JSON shape checked CLI-side; server stores as-is | daemon (extra CLI switches); defaults to `[]` |
| `runtime_config` | `agent.runtime_config` (JSON) | JSON shape checked CLI-side; server stores as-is | runtime-specific config; defaults to `{}` |
diff --git a/server/internal/service/builtin_skills/multica-creating-agents/references/creating-agents-source-map.md b/server/internal/service/builtin_skills/multica-creating-agents/references/creating-agents-source-map.md
index 2a18694aaa..17d64bf448 100644
--- a/server/internal/service/builtin_skills/multica-creating-agents/references/creating-agents-source-map.md
+++ b/server/internal/service/builtin_skills/multica-creating-agents/references/creating-agents-source-map.md
@@ -100,8 +100,12 @@ only.
| Pi RPC model/thinking discovery | `models.go` `discoverPiModelsRPC` / `piThinkingFromRPCModel` | Starts an ephemeral `pi --mode rpc --no-session` process, requests `get_state` + `get_available_models`, preserves extension-registered providers, marks the current model as Default, and mirrors Pi's exact per-model `reasoning` / `thinkingLevelMap` rules. Older/forked Pi falls back to `--list-models` with no guessed thinking catalog. |
| Pi invocation effort | `pi.go` `buildPiArgs` / `piBlockedArgs` | A non-empty persisted value becomes `--thinking <level>`; custom `--thinking` flags are filtered so the first-class field is the sole owner. |
| Per-model thinking validation | `thinking.go` `ValidateThinkingLevel` | Accepts only values in the explicit model's `Thinking.SupportedLevels`; Pi empty-model validation resolves to the RPC current-model Default, while an empty Codex model fails closed because its effective `config.toml` model is unknown. |
-| Dynamic Codex token gate | `thinking.go` `IsKnownThinkingValue` | Server persistence accepts syntactically safe Codex/OpenCode tokens so new catalog values do not require a Multica release; Pi instead uses its fixed seven-token CLI vocabulary. Exact support remains a daemon-local per-model check. |
-| Runtime reasoning capability | `thinking.go` `ThinkingControlSupported` | True for the fixed-enum providers (including Pi) plus Codex/OpenCode. False for runtimes with no effort dial on the surface the daemon drives — Hermes' ACP adapter never carries `reasoning_config` onto a session, so its CLI-level `agent.reasoning_effort` cannot be reached from Multica (verified against Hermes Agent v0.18.2, MUL-5770) |
+| Dynamic Codex token gate | `thinking.go` `IsKnownThinkingValue` | Server persistence accepts syntactically safe Codex/OpenCode/Kimi and ACP-catalog tokens so new catalog values do not require a Multica release; Pi instead uses its fixed seven-token CLI vocabulary. Exact support remains a daemon-local per-model check. |
+| Runtime reasoning capability | `thinking.go` `ThinkingControlSupported` | True for the fixed-enum providers (including Pi), the dynamic-catalog providers (Codex/OpenCode/Kimi), and the ACP-catalog providers in `acpCatalogThinkingProviders`. False for runtimes with no effort dial on the surface the daemon drives — Hermes' ACP adapter never carries `reasoning_config` onto a session, so its CLI-level `agent.reasoning_effort` cannot be reached from Multica (verified against Hermes Agent v0.18.2, MUL-5770) |
+| Generic ACP effort catalog | `acp_effort.go` `parseACPEffortOption` / `annotateACPThinkingForSessionModel` | One provider-neutral parser reads the effort selector out of any ACP `session/new` response (option id or category `effort` / `thought_level`), taking the advertised values verbatim. CodeBuddy keeps a flag whitelist on top because it applies the level via `--effort`, not over ACP |
+| ACP effort catalogs are per model, not per session | `acp_effort.go` `annotateACPThinkingForSessionModel` | Only the model marked `Default` (the advertised `currentModelId`) is annotated. ACP options may depend on each other, and reasonix v1.21.5 derives the catalog from the current model's provider entry — `deepseek-v4-flash` advertises `low`, `deepseek-v4-pro` does not, and some models expose no effort at all. Copying one catalog across models would offer levels the runtime then refuses. Other models keep `Thinking=nil` until per-model probing exists |
+| ACP effort application | `acp_effort.go` `applyACPEffortOption` | Sends `session/set_config_option` with the id the session advertised, then re-reads `currentValue`. The read-back proves only that the session reports the new value — not that the runtime threaded it into its provider request; it catches Kimi ≤0.28.1 confirming `on` after being set to `max`. Failures warn and let the prompt through rather than failing the task. `stateIsCurrent=false` after a model switch skips the local vocabulary check, because the advertised list then describes the previous model |
+| ACP effort opt-in | `thinking.go` `acpCatalogThinkingProviders` | A runtime joins only when its `Execute` calls `applyACPEffortOption` AND someone has confirmed from source or a real run that it acts on the setting — currently `reasonix` (GitHub #6720). This list, not the read-back, is where that verification is recorded. Speaking ACP is not sufficient: Copilot discovers over ACP but executes through its own CLI, so a catalog there would render a picker with nothing behind it |
| Per-model service-tier validation | `thinking.go` `ValidateServiceTier` | Accepts only a tier advertised for the explicit Codex model; empty model fails closed because config.toml is unknown |
| Daemon invalid-combination handling | `internal/daemon/daemon.go` 3860–3892 | Before execution, invalid `(provider, model, thinking_level)` combinations log a warning and omit the override rather than failing the task |
diff --git a/server/pkg/agent/acp_effort.go b/server/pkg/agent/acp_effort.go
new file mode 100644
index 0000000000..ba2a5a41ba
--- /dev/null
+++ b/server/pkg/agent/acp_effort.go
@@ -0,0 +1,305 @@
+package agent
+
+import (
+ "context"
+ "encoding/json"
+ "log/slog"
+ "strings"
+)
+
+// acp_effort.go holds the provider-neutral half of ACP reasoning-effort
+// support: locating the effort selector a backend advertises in its
+// `session/new` response, turning it into a model catalog, and pushing a
+// persisted level back onto a live session.
+//
+// ACP gives us two generic primitives — `configOptions` on the session/new
+// result and `session/set_config_option` — so discovery and application are
+// the same shape for every backend. What the protocol does NOT standardise is
+// the part that still needs convention here:
+//
+// - Semantics. There is no "this option is reasoning effort" marker, so the
+// selector is matched by id/category against acpEffortOptionIDs.
+// - Vocabulary. reasonix advertises auto|disabled|low|high|max, Codex
+// none|minimal|…|ultra. We pass tokens through verbatim (MUL-2339) rather
+// than flattening them onto a shared enum.
+// - Whether setting it does anything. The protocol says a client MAY set an
+// option; it does not say the agent must act on it. Kimi ≤0.28.1 and
+// Hermes v0.18.2 both accept a level and leave the session unchanged
+// (see discoverKimiModels and ThinkingControlSupported). That is why
+// applyACPEffortOption reads the value back instead of assuming success,
+// and why a runtime only reaches this path once its Execute opts in.
+
+// acpEffortOptionIDs are the option id / category tokens that mark a
+// reasoning-effort selector. reasonix advertises id `effort` under category
+// `thought_level`; CodeBuddy and jcode advertise `thought_level`. Matching
+// either field keeps both shapes working without a per-runtime table.
+var acpEffortOptionIDs = map[string]bool{
+ "effort": true,
+ "thought_level": true,
+}
+
+// acpEffortOption is the effort selector one backend advertised.
+type acpEffortOption struct {
+ // ConfigID is what session/set_config_option must be given. It is NOT
+ // interchangeable across backends — reasonix uses `effort`, CodeBuddy
+ // `thought_level`, Kimi `thinking` — so it is read from the session rather
+ // than hard-coded per runtime.
+ ConfigID string
+ // CurrentValue is the level the session starts on; "" when the backend
+ // does not report one.
+ CurrentValue string
+ // Choices are the advertised levels in advertised order. Labels come from
+ // the backend's own `name` field so the picker reads the way that CLI's
+ // own UI does.
+ Choices []ThinkingLevel
+}
+
+// supports reports whether value is one of the advertised choices.
+func (o acpEffortOption) supports(value string) bool {
+ for _, choice := range o.Choices {
+ if choice.Value == value {
+ return true
+ }
+ }
+ return false
+}
+
+// values returns the advertised tokens, order preserved.
+func (o acpEffortOption) values() []string {
+ out := make([]string, 0, len(o.Choices))
+ for _, choice := range o.Choices {
+ out = append(out, choice.Value)
+ }
+ return out
+}
+
+// parseACPEffortOption extracts the effort selector from an ACP session/new (or
+// session/resume) result. Reports false when the response carries no
+// recognisable option, which every caller treats as "this runtime has no
+// effort dial" rather than as an error.
+//
+// Values are taken verbatim: the CLI owns its vocabulary, and a whitelist here
+// would silently drop levels a backend genuinely accepts. Callers that must
+// narrow the set — CodeBuddy, whose `--effort` flag rejects a session-only
+// choice the ACP surface still advertises — apply their own overlay on top.
+func parseACPEffortOption(raw json.RawMessage) (acpEffortOption, bool) {
+ type acpChoice struct {
+ Value string `json:"value"`
+ Name string `json:"name"`
+ }
+ type acpOption struct {
+ ID string `json:"id"`
+ Category string `json:"category"`
+ CurrentValue string `json:"currentValue"`
+ CurrentValueSnake string `json:"current_value"`
+ Options []acpChoice `json:"options"`
+ }
+ var resp struct {
+ ConfigOptions []acpOption `json:"configOptions"`
+ ConfigOptionsSnake []acpOption `json:"config_options"`
+ }
+ if err := json.Unmarshal(raw, &resp); err != nil {
+ return acpEffortOption{}, false
+ }
+ options := resp.ConfigOptions
+ if len(options) == 0 {
+ options = resp.ConfigOptionsSnake
+ }
+
+ for _, opt := range options {
+ id := strings.TrimSpace(opt.ID)
+ if !acpEffortOptionIDs[strings.ToLower(id)] &&
+ !acpEffortOptionIDs[strings.ToLower(strings.TrimSpace(opt.Category))] {
+ continue
+ }
+ // An option we can read but not address is useless: without an id
+ // there is nothing to send back to session/set_config_option.
+ if id == "" {
+ continue
+ }
+ result := acpEffortOption{ConfigID: id}
+ seen := map[string]bool{}
+ for _, choice := range opt.Options {
+ value := strings.TrimSpace(choice.Value)
+ if value == "" || seen[value] {
+ continue
+ }
+ seen[value] = true
+ label := strings.TrimSpace(choice.Name)
+ if label == "" {
+ label = strings.Title(value) //nolint:staticcheck
+ }
+ result.Choices = append(result.Choices, ThinkingLevel{Value: value, Label: label})
+ }
+ current := strings.TrimSpace(opt.CurrentValue)
+ if current == "" {
+ current = strings.TrimSpace(opt.CurrentValueSnake)
+ }
+ // Only echo a default we also advertise. A currentValue outside the
+ // choice list (CodeBuddy's `enabled`) becomes an empty DefaultLevel,
+ // which the UI renders as a generic "Default" instead of a level the
+ // picker cannot offer.
+ if result.supports(current) {
+ result.CurrentValue = current
+ }
+ return result, true
+ }
+ return acpEffortOption{}, false
+}
+
+// annotateACPThinkingForSessionModel fills in the effort catalog for the model
+// the session is currently on, from the SAME session/new response the models
+// came from, so the catalog costs no extra process.
+//
+// ONLY that model is annotated, and this is the load-bearing part. A session's
+// configOptions describe the session's *current* configuration, and the ACP
+// session-config RFD lets options depend on each other: change the model and
+// the effort option can change vocabulary or disappear. reasonix v1.21.5 does
+// exactly that — `SessionConfigState` resolves the provider entry for the
+// current model and derives the catalog with `EffortCapabilityForEntry`, so
+// `deepseek-v4-flash` advertises `low` while `deepseek-v4-pro` does not, GLM /
+// OpenAI / MiniMax / Ollama Cloud each carry their own vocabulary, and a model
+// whose protocol resolves to none gets no effort option at all.
+//
+// Copying one model's catalog onto its siblings therefore invents levels the
+// runtime will refuse: the picker would offer `low` on pro, ValidateThinkingLevel
+// 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.
+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,
+ }
+ 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
+ // marked, annotate nothing rather than guessing.
+ if models[i].Default {
+ models[i].Thinking = thinking
+ }
+ }
+}
+
+// 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.
+type acpRequestFn func(ctx context.Context, method string, params any) (json.RawMessage, error)
+
+// applyACPEffortOption pushes a persisted thinking level onto a live ACP
+// session using the selector that session advertised.
+//
+// A configuration failure never blocks the task: the prompt goes out either
+// way and the warnings are the only record that the level shown in the UI may
+// not be the level in effect. Which level that is depends on how it failed —
+// on a request error the session keeps what it had (the CLI's own setting on a
+// fresh session, the previous turn's level on a resumed one); on an
+// unconfirmed reply it sits at whatever the backend reports.
+//
+// The read-back is worth doing but it is NOT proof the level took effect. It
+// confirms one thing only: that the session's own configOptions now report the
+// value we asked for. It catches a runtime that accepts the call and leaves the
+// setting where it was — Kimi ≤0.28.1 confirms "on" after being set to "max" —
+// but a runtime could equally echo the new value and still not thread it into
+// the provider request. Nothing observable on this wire distinguishes that.
+// Knowing a runtime actually honours the setting comes from checking its source
+// or a real run, which is what admission to acpCatalogThinkingProviders means;
+// the read-back is runtime confirmation and diagnostics on top of that.
+//
+// stateIsCurrent says whether sessionResult still describes the session as it
+// is right now. It does not after a model switch: ACP options may depend on
+// each other, so the effort vocabulary advertised for the model the session
+// opened on can differ from the one it is on after session/set_model — and
+// reasonix returns an empty result from set_model, publishing the refreshed
+// options only through a config_option_update notification that the shared
+// client drops. When the state is stale we skip the local vocabulary check
+// rather than test the level against the wrong model's list, send the request,
+// and let the runtime's own answer decide.
+func applyACPEffortOption(
+ ctx context.Context,
+ request acpRequestFn,
+ backend string,
+ logger *slog.Logger,
+ sessionID string,
+ sessionResult json.RawMessage,
+ level string,
+ stateIsCurrent bool,
+) {
+ if level == "" {
+ return
+ }
+ if logger == nil {
+ logger = slog.Default()
+ }
+
+ option, ok := parseACPEffortOption(sessionResult)
+ if !ok || len(option.Choices) == 0 {
+ // The agent carries a level the server accepted against a previously
+ // discovered catalog, but this session advertises none. A CLI
+ // downgrade, a different account, or a model without the dial all land
+ // here. Without an option id there is nothing to address, so there is
+ // no request to send even speculatively.
+ logger.Warn("session advertises no reasoning-effort option; sending the prompt without it",
+ "backend", backend,
+ "requested_level", level,
+ )
+ return
+ }
+ if stateIsCurrent && !option.supports(level) {
+ // Sending an unadvertised token invites a hard error from the backend
+ // on a call whose failure we deliberately swallow. Skipping keeps the
+ // session on a level it actually understands. Only trustworthy while
+ // the advertised list still describes the live session — see
+ // stateIsCurrent.
+ logger.Warn("session does not advertise the requested reasoning effort; sending the prompt without it",
+ "backend", backend,
+ "config_id", option.ConfigID,
+ "requested_level", level,
+ "advertised_levels", strings.Join(option.values(), ","),
+ )
+ return
+ }
+
+ result, err := request(ctx, "session/set_config_option", map[string]any{
+ "sessionId": sessionID,
+ "configId": option.ConfigID,
+ "value": level,
+ })
+ if err != nil {
+ logger.Warn("runtime rejected the reasoning effort request; sending the prompt anyway",
+ "backend", backend,
+ "config_id", option.ConfigID,
+ "requested_level", level,
+ "effective_level", "unchanged",
+ "error", err,
+ )
+ return
+ }
+
+ effectiveLevel, confirmed := acpConfigOptionCurrentValue(result, option.ConfigID)
+ if !confirmed || effectiveLevel != level {
+ if !confirmed {
+ effectiveLevel = "unknown"
+ }
+ logger.Warn("runtime did not confirm the requested reasoning effort; sending the prompt anyway",
+ "backend", backend,
+ "config_id", option.ConfigID,
+ "requested_level", level,
+ "effective_level", effectiveLevel,
+ )
+ return
+ }
+ logger.Info("session reasoning effort confirmed",
+ "backend", backend,
+ "config_id", option.ConfigID,
+ "level", effectiveLevel,
+ )
+}
diff --git a/server/pkg/agent/acp_effort_test.go b/server/pkg/agent/acp_effort_test.go
new file mode 100644
index 0000000000..18a6c96599
--- /dev/null
+++ b/server/pkg/agent/acp_effort_test.go
@@ -0,0 +1,393 @@
+package agent
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "io"
+ "log/slog"
+ "strings"
+ "testing"
+)
+
+// reasonixEffortSessionResult is the shape reasonix v1.21.x returns from
+// `session/new`, captured from the real CLI over stdio (GitHub #6720). Note the
+// option id is `effort` while the category is `thought_level`: matching either
+// is what lets one parser serve reasonix and CodeBuddy.
+const reasonixEffortSessionResult = `{"sessionId":"ses-reasonix",` +
+ `"models":{"currentModelId":"deepseek-v4-flash",` +
+ `"availableModels":[{"modelId":"deepseek-v4-flash","name":"DeepSeek V4 Flash"},` +
+ `{"modelId":"deepseek-v4","name":"DeepSeek V4"}]},` +
+ `"configOptions":[` +
+ `{"type":"select","id":"mode","name":"Mode","currentValue":"default","options":[{"value":"default","name":"Default"}]},` +
+ `{"type":"select","id":"effort","name":"Effort","category":"thought_level","currentValue":"max","options":[` +
+ `{"value":"auto","name":"Auto"},{"value":"disabled","name":"Disabled"},{"value":"low","name":"Low"},` +
+ `{"value":"high","name":"High"},{"value":"max","name":"Max"}]}]}`
+
+func discardLogger() *slog.Logger {
+ return slog.New(slog.NewTextHandler(io.Discard, nil))
+}
+
+// ── parseACPEffortOption ─────────────────────────────────────────────
+
+// TestParseACPEffortOptionReasonix is the case the generalization exists for:
+// the levels must come through verbatim, including `auto` and `disabled`, which
+// CodeBuddy's flag whitelist would have dropped.
+func TestParseACPEffortOptionReasonix(t *testing.T) {
+ t.Parallel()
+ option, ok := parseACPEffortOption(json.RawMessage(reasonixEffortSessionResult))
+ if !ok {
+ t.Fatal("parseACPEffortOption found no effort option in the reasonix capture")
+ }
+ if option.ConfigID != "effort" {
+ t.Errorf("ConfigID = %q, want effort (the id set_config_option needs)", option.ConfigID)
+ }
+ if got := strings.Join(option.values(), ","); got != "auto,disabled,low,high,max" {
+ t.Errorf("values = %q, want all five advertised levels in order", got)
+ }
+ if option.CurrentValue != "max" {
+ t.Errorf("CurrentValue = %q, want max", option.CurrentValue)
+ }
+ // Labels come from the backend's own `name` so the picker reads the way
+ // reasonix's own UI does, rather than a Title-cased guess.
+ if option.Choices[1].Label != "Disabled" {
+ t.Errorf("Choices[1].Label = %q, want Disabled", option.Choices[1].Label)
+ }
+}
+
+// TestParseACPEffortOptionSnakeCase covers the runtimes that emit snake_case
+// keys; the model parser already accepts both spellings and this must match.
+func TestParseACPEffortOptionSnakeCase(t *testing.T) {
+ t.Parallel()
+ raw := json.RawMessage(`{"config_options":[{"id":"thought_level","current_value":"high",` +
+ `"options":[{"value":"low","name":"Low"},{"value":"high","name":"High"}]}]}`)
+ option, ok := parseACPEffortOption(raw)
+ if !ok {
+ t.Fatal("snake_case config_options was not recognised")
+ }
+ if option.ConfigID != "thought_level" || option.CurrentValue != "high" {
+ t.Errorf("option = %+v, want thought_level/high", option)
+ }
+}
+
+// TestParseACPEffortOptionAbsent pins the Hermes v0.18.2 shape: session/new
+// carries models and modes but no configOptions, so there is no dial to offer.
+func TestParseACPEffortOptionAbsent(t *testing.T) {
+ t.Parallel()
+ for _, raw := range []string{
+ `{"sessionId":"s","models":{"currentModelId":"m","availableModels":[{"modelId":"m"}]},"modes":{}}`,
+ `{"sessionId":"s","configOptions":[{"id":"mode","currentValue":"default","options":[{"value":"default"}]}]}`,
+ `not json at all`,
+ } {
+ if _, ok := parseACPEffortOption(json.RawMessage(raw)); ok {
+ t.Errorf("parseACPEffortOption(%s) reported an effort option where there is none", raw)
+ }
+ }
+}
+
+// TestParseACPEffortOptionUnusableCurrentValue: a currentValue the backend does
+// not also advertise as a choice cannot be offered, so it must not become the
+// default. This is the CodeBuddy `enabled` case in provider-neutral form.
+func TestParseACPEffortOptionUnusableCurrentValue(t *testing.T) {
+ t.Parallel()
+ raw := json.RawMessage(`{"configOptions":[{"id":"effort","currentValue":"enabled",` +
+ `"options":[{"value":"low"},{"value":"high"}]}]}`)
+ option, ok := parseACPEffortOption(raw)
+ if !ok {
+ t.Fatal("expected the effort option to parse")
+ }
+ if option.CurrentValue != "" {
+ t.Errorf("CurrentValue = %q, want empty so the UI shows a generic Default", option.CurrentValue)
+ }
+}
+
+// TestParseACPEffortOptionNeedsAddressableID: an option matched only by
+// category but carrying no id cannot be sent back to set_config_option, so
+// surfacing it would build a picker with no way to apply it.
+func TestParseACPEffortOptionNeedsAddressableID(t *testing.T) {
+ t.Parallel()
+ raw := json.RawMessage(`{"configOptions":[{"category":"thought_level","currentValue":"low",` +
+ `"options":[{"value":"low"},{"value":"high"}]}]}`)
+ if _, ok := parseACPEffortOption(raw); ok {
+ t.Error("an effort option with no id must be ignored, not offered")
+ }
+}
+
+// TestParseACPEffortOptionLabelFallback: a backend that omits `name` still gets
+// a readable picker entry rather than a blank one.
+func TestParseACPEffortOptionLabelFallback(t *testing.T) {
+ t.Parallel()
+ raw := json.RawMessage(`{"configOptions":[{"id":"effort","options":[{"value":"low"}]}]}`)
+ option, ok := parseACPEffortOption(raw)
+ if !ok || len(option.Choices) != 1 {
+ t.Fatalf("option = %+v, ok = %v", option, ok)
+ }
+ if option.Choices[0].Label != "Low" {
+ t.Errorf("Label = %q, want Low", option.Choices[0].Label)
+ }
+}
+
+// ── annotateACPThinkingForSessionModel ───────────────────────────────
+
+// TestAnnotateACPThinkingForSessionModel: the advertised catalog describes the
+// model the session is on and nothing else, so only that model is annotated.
+//
+// reasonix v1.21.5 derives the effort levels from the current model's provider
+// entry (`EffortCapabilityForEntry`), and the vocabularies genuinely differ —
+// `deepseek-v4-flash` has `low`, `deepseek-v4-pro` does not. Copying one
+// model's catalog onto its siblings would offer `low` on pro, and the runtime
+// would refuse it at apply time while the task ran on at the default.
+func TestAnnotateACPThinkingForSessionModel(t *testing.T) {
+ t.Parallel()
+ models := []Model{
+ {ID: "deepseek-v4-flash", Default: true},
+ {ID: "deepseek-v4-pro"},
+ }
+ annotateACPThinkingForSessionModel(models, json.RawMessage(reasonixEffortSessionResult))
+
+ if models[0].Thinking == nil {
+ t.Fatal("the session's current model must carry the advertised catalog")
+ }
+ if len(models[0].Thinking.SupportedLevels) != 5 || models[0].Thinking.DefaultLevel != "max" {
+ t.Errorf("current model thinking = %+v", models[0].Thinking)
+ }
+ if models[1].Thinking != nil {
+ t.Errorf("non-current model got %+v; its real catalog is unknown and must stay nil",
+ models[1].Thinking)
+ }
+}
+
+// TestAnnotateACPThinkingForSessionModelNoDefault: if nothing is marked as the
+// session's current model there is no model the catalog is known to describe,
+// so annotate nothing rather than guessing at the first entry.
+func TestAnnotateACPThinkingForSessionModelNoDefault(t *testing.T) {
+ t.Parallel()
+ models := []Model{{ID: "a"}, {ID: "b"}}
+ annotateACPThinkingForSessionModel(models, json.RawMessage(reasonixEffortSessionResult))
+ for _, m := range models {
+ if m.Thinking != nil {
+ t.Errorf("model %q was annotated with no current model to anchor the catalog", m.ID)
+ }
+ }
+}
+
+// TestAnnotateACPThinkingForSessionModelNoOption: no advertised dial means no
+// picker. A picker that cannot change anything is worse than none.
+func TestAnnotateACPThinkingForSessionModelNoOption(t *testing.T) {
+ t.Parallel()
+ models := []Model{{ID: "m"}}
+ annotateACPThinkingForSessionModel(models, json.RawMessage(`{"sessionId":"s","modes":{}}`))
+ if models[0].Thinking != nil {
+ t.Errorf("Thinking = %+v, want nil when the session advertises no effort option", models[0].Thinking)
+ }
+}
+
+// ── applyACPEffortOption ─────────────────────────────────────────────
+
+type recordedACPCall struct {
+ method string
+ params map[string]any
+}
+
+func recordingACPRequest(reply string, err error) (acpRequestFn, *[]recordedACPCall) {
+ var calls []recordedACPCall
+ fn := func(_ context.Context, method string, params any) (json.RawMessage, error) {
+ p, _ := params.(map[string]any)
+ calls = append(calls, recordedACPCall{method: method, params: p})
+ if err != nil {
+ return nil, err
+ }
+ return json.RawMessage(reply), nil
+ }
+ return fn, &calls
+}
+
+// TestApplyACPEffortOptionSendsAdvertisedID pins the happy path: the configId
+// comes off the session, not a per-runtime constant.
+func TestApplyACPEffortOptionSendsAdvertisedID(t *testing.T) {
+ t.Parallel()
+ echo := `{"configOptions":[{"id":"effort","currentValue":"low","options":[` +
+ `{"value":"low"},{"value":"high"},{"value":"max"}]}]}`
+ request, calls := recordingACPRequest(echo, nil)
+
+ applyACPEffortOption(context.Background(), request, "reasonix", discardLogger(),
+ "ses-1", json.RawMessage(reasonixEffortSessionResult), "low", true)
+
+ if len(*calls) != 1 {
+ t.Fatalf("calls = %+v, want exactly one set_config_option", *calls)
+ }
+ call := (*calls)[0]
+ if call.method != "session/set_config_option" {
+ t.Errorf("method = %q", call.method)
+ }
+ if call.params["configId"] != "effort" {
+ t.Errorf("configId = %v, want effort (reasonix's advertised id)", call.params["configId"])
+ }
+ if call.params["value"] != "low" || call.params["sessionId"] != "ses-1" {
+ t.Errorf("params = %+v", call.params)
+ }
+}
+
+// TestApplyACPEffortOptionSkips covers every case where sending the call would
+// be wrong. None of them may fail the task — the prompt still goes out.
+func TestApplyACPEffortOptionSkips(t *testing.T) {
+ t.Parallel()
+ for _, tc := range []struct {
+ name string
+ sessionResult string
+ level string
+ }{
+ {
+ name: "no persisted level",
+ sessionResult: reasonixEffortSessionResult,
+ level: "",
+ },
+ {
+ name: "session advertises no effort option",
+ sessionResult: `{"sessionId":"s","modes":{}}`,
+ level: "high",
+ },
+ {
+ // A level the server accepted against an older catalog. Sending it
+ // invites a hard error on a call whose failure we swallow.
+ name: "level not advertised by this session",
+ sessionResult: reasonixEffortSessionResult,
+ level: "ultra",
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+ request, calls := recordingACPRequest(`{}`, nil)
+ applyACPEffortOption(context.Background(), request, "reasonix", discardLogger(),
+ "ses-1", json.RawMessage(tc.sessionResult), tc.level, true)
+ if len(*calls) != 0 {
+ t.Errorf("sent %+v, want no request at all", *calls)
+ }
+ })
+ }
+}
+
+// TestApplyACPEffortOptionResumedSessionStillApplies: when session/resume does
+// echo the option back, a level change between turns must take effect rather
+// than being written off as "the session already has one".
+func TestApplyACPEffortOptionResumedSessionStillApplies(t *testing.T) {
+ t.Parallel()
+ echo := `{"configOptions":[{"id":"effort","currentValue":"low","options":[{"value":"low"},{"value":"max"}]}]}`
+ request, calls := recordingACPRequest(echo, nil)
+
+ applyACPEffortOption(context.Background(), request, "reasonix", discardLogger(),
+ "ses-1", json.RawMessage(reasonixEffortSessionResult), "low", true)
+
+ if len(*calls) != 1 {
+ t.Fatalf("calls = %+v, want the level re-applied on resume", *calls)
+ }
+}
+
+// TestApplyACPEffortOptionResumedWithoutOption: ACP does not require resume to
+// re-advertise configOptions. The session keeps the level it was created with,
+// so this is a no-op rather than a failure.
+func TestApplyACPEffortOptionResumedWithoutOption(t *testing.T) {
+ t.Parallel()
+ request, calls := recordingACPRequest(`{}`, nil)
+
+ applyACPEffortOption(context.Background(), request, "reasonix", discardLogger(),
+ "ses-1", json.RawMessage(`{"sessionId":"ses-1"}`), "max", true)
+
+ if len(*calls) != 0 {
+ t.Errorf("sent %+v, want no request when resume advertises no option", *calls)
+ }
+}
+
+// TestApplyACPEffortOptionStaleStateDefersToRuntime: after a model switch the
+// advertised list describes the model the session opened on, not the one it is
+// now running. Testing the level against that list would be testing it against
+// the wrong model, so the check is skipped and the runtime's own answer decides.
+func TestApplyACPEffortOptionStaleStateDefersToRuntime(t *testing.T) {
+ t.Parallel()
+ // `ultra` is absent from the session/new list. With current state that is a
+ // skip; with stale state it must go out and let the runtime rule on it.
+ echo := `{"configOptions":[{"id":"effort","currentValue":"ultra","options":[{"value":"ultra"}]}]}`
+
+ request, calls := recordingACPRequest(echo, nil)
+ applyACPEffortOption(context.Background(), request, "reasonix", discardLogger(),
+ "ses-1", json.RawMessage(reasonixEffortSessionResult), "ultra", false)
+ if len(*calls) != 1 {
+ t.Fatalf("calls = %+v, want the request sent when the advertised list is stale", *calls)
+ }
+ if (*calls)[0].params["value"] != "ultra" {
+ t.Errorf("params = %+v", (*calls)[0].params)
+ }
+
+ // Same input, state known current: the local check short-circuits it.
+ request, calls = recordingACPRequest(echo, nil)
+ applyACPEffortOption(context.Background(), request, "reasonix", discardLogger(),
+ "ses-1", json.RawMessage(reasonixEffortSessionResult), "ultra", true)
+ if len(*calls) != 0 {
+ t.Errorf("sent %+v, want the unadvertised level skipped against fresh state", *calls)
+ }
+}
+
+// TestApplyACPEffortOptionSurvivesUnconfirmedApply pins the Kimi ≤0.28.1 /
+// Hermes shape: set_config_option answers success but the session reports a
+// different level. The task must continue — the read-back exists to log the
+// discrepancy, not to abort.
+func TestApplyACPEffortOptionSurvivesUnconfirmedApply(t *testing.T) {
+ t.Parallel()
+ for _, tc := range []struct {
+ name string
+ reply string
+ err error
+ }{
+ {
+ name: "backend confirms a different level",
+ reply: `{"configOptions":[{"id":"effort","currentValue":"auto","options":[{"value":"auto"},{"value":"max"}]}]}`,
+ },
+ {
+ name: "backend echoes no currentValue",
+ reply: `{"ok":true}`,
+ },
+ {
+ name: "request itself fails",
+ err: errors.New("boom"),
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+ request, calls := recordingACPRequest(tc.reply, tc.err)
+ applyACPEffortOption(context.Background(), request, "reasonix", discardLogger(),
+ "ses-1", json.RawMessage(reasonixEffortSessionResult), "max", true)
+ if len(*calls) != 1 {
+ t.Fatalf("calls = %+v, want the attempt to still have been made", *calls)
+ }
+ })
+ }
+}
+
+// ── Server-side gate ─────────────────────────────────────────────────
+
+// TestACPCatalogProviderGate: reasonix now takes the dynamic path, while an ACP
+// runtime that has not opted in stays closed. Hermes is the guard case — its
+// ACP surface accepts a level and ignores it (MUL-5770), so accepting one here
+// would promise something no code can deliver.
+func TestACPCatalogProviderGate(t *testing.T) {
+ t.Parallel()
+ if !ThinkingControlSupported("reasonix") {
+ t.Error("reasonix should now advertise reasoning control")
+ }
+ for _, level := range []string{"auto", "disabled", "low", "high", "max"} {
+ if !IsKnownThinkingValue("reasonix", level) {
+ t.Errorf("IsKnownThinkingValue(reasonix, %q) = false, want true", level)
+ }
+ }
+ if IsKnownThinkingValue("reasonix", "not a token") {
+ t.Error("malformed tokens must still be rejected")
+ }
+ if ThinkingControlSupported("hermes") || IsKnownThinkingValue("hermes", "high") {
+ t.Error("hermes must stay closed until its ACP surface applies an effort")
+ }
+ // Copilot discovers over ACP but executes through its own CLI, so it must
+ // not be swept in by the generalization.
+ if ThinkingControlSupported("copilot") {
+ t.Error("copilot executes outside ACP; a picker here would do nothing")
+ }
+}
diff --git a/server/pkg/agent/acp_effort_unix_test.go b/server/pkg/agent/acp_effort_unix_test.go
new file mode 100644
index 0000000000..c5c4d461cc
--- /dev/null
+++ b/server/pkg/agent/acp_effort_unix_test.go
@@ -0,0 +1,197 @@
+//go:build !windows
+
+package agent
+
+import (
+ "context"
+ "encoding/json"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+// These cases need a POSIX shell stub, or the CodeBuddy session capture in
+// codebuddy_discovery_fallback_test.go, which is itself !windows. The
+// provider-neutral parser/apply tests stay in acp_effort_test.go so they run
+// on every platform.
+
+// ── CodeBuddy overlay regression ─────────────────────────────────────
+
+// TestCodebuddyOverlaySurvivesGeneralization: CodeBuddy applies the level
+// through `--effort`, not over ACP, so its narrower flag vocabulary must keep
+// filtering the advertised list even though the parser underneath is shared.
+func TestCodebuddyOverlaySurvivesGeneralization(t *testing.T) {
+ t.Parallel()
+ levels, def := parseACPCodebuddyEffort(json.RawMessage(codebuddyACPSessionResult))
+ if strings.Join(levels, ",") != "minimal,low,medium,high,xhigh,max" {
+ t.Errorf("levels = %v, want the six --effort values without `enabled`", levels)
+ }
+ if def != "" {
+ t.Errorf("DefaultLevel = %q, want empty because currentValue was the unusable `enabled`", def)
+ }
+
+ // The same payload through the generic path keeps `enabled`: the overlay is
+ // CodeBuddy's, not everyone's.
+ option, ok := parseACPEffortOption(json.RawMessage(codebuddyACPSessionResult))
+ if !ok || !option.supports("enabled") {
+ t.Error("the shared parser must not apply CodeBuddy's flag whitelist")
+ }
+}
+
+// ── End-to-end discovery ─────────────────────────────────────────────
+
+// reasonixStubFor answers a discovery handshake with the given session/new
+// result and nothing else, which is all model discovery drives.
+func reasonixStubFor(sessionResult string) string {
+ return `#!/bin/sh
+while IFS= read -r line; do
+ id=$(printf '%s' "$line" | sed -n 's/.*"id":\([0-9]*\).*/\1/p')
+ case "$line" in
+ *'"method":"initialize"'*) printf '{"jsonrpc":"2.0","id":%s,"result":{"protocolVersion":1,"agentCapabilities":{}}}\n' "$id" ;;
+ *'"method":"session/new"'*) printf '{"jsonrpc":"2.0","id":%s,"result":` + sessionResult + `}\n' "$id" ;;
+ esac
+done
+`
+}
+
+// TestValidateThinkingLevelReasonix covers the daemon's pre-execution guard.
+// It fails closed on an unknown (provider, model, level), so without a
+// discovered catalog it would silently drop every level and the feature would
+// look wired up while doing nothing.
+func TestValidateThinkingLevelReasonix(t *testing.T) {
+ fakePath := filepath.Join(t.TempDir(), "reasonix")
+ writeTestExecutable(t, fakePath, []byte(reasonixStubFor(reasonixEffortSessionResult)))
+
+ for _, tc := range []struct {
+ model string
+ level string
+ want bool
+ }{
+ {model: "deepseek-v4-flash", level: "max", want: true},
+ // `auto` and `disabled` only survive because the shared parser takes
+ // the advertised list verbatim; CodeBuddy's whitelist would drop them.
+ {model: "deepseek-v4-flash", level: "auto", want: true},
+ {model: "deepseek-v4-flash", level: "disabled", want: true},
+ {model: "deepseek-v4-flash", level: "ultra", want: false},
+ // Empty model resolves to the catalog's Default (the advertised
+ // currentModelId), so a default-model agent still gets its level.
+ {model: "", level: "high", want: true},
+ {model: "no-such-model", level: "high", want: false},
+ } {
+ got, err := ValidateThinkingLevel(context.Background(), "reasonix", fakePath, 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)
+ }
+ }
+}
+
+// reasonixThreeModelSessionResult mirrors the real per-model split in reasonix
+// v1.21.5's `modelReasoningCapabilities`: the session is on `deepseek-v4-flash`,
+// whose catalog includes `low`, while `deepseek-v4-pro` does not support `low`
+// and `glm-4-air` has no effort dial at all. session/new can only describe the
+// model it is on, so the other two must come out with no catalog.
+const reasonixThreeModelSessionResult = `{"sessionId":"ses-reasonix",` +
+ `"models":{"currentModelId":"deepseek-v4-flash",` +
+ `"availableModels":[{"modelId":"deepseek-v4-flash","name":"Flash"},` +
+ `{"modelId":"deepseek-v4-pro","name":"Pro"},{"modelId":"glm-4-air","name":"GLM Air"}]},` +
+ `"configOptions":[` +
+ `{"type":"select","id":"model","name":"Model","category":"model","currentValue":"deepseek-v4-flash",` +
+ `"options":[{"value":"deepseek-v4-flash"},{"value":"deepseek-v4-pro"},{"value":"glm-4-air"}]},` +
+ `{"type":"select","id":"effort","name":"Effort","category":"thought_level","currentValue":"high","options":[` +
+ `{"value":"disabled","name":"Disabled"},{"value":"low","name":"Low"},` +
+ `{"value":"high","name":"High"},{"value":"max","name":"Max"}]}]}`
+
+// TestReasonixPerModelEffortIsNotSharedAcrossModels is the regression for the
+// review finding on the first cut of this feature: the session's catalog was
+// copied onto every model, so `low` — real for flash, absent on pro, and
+// meaningless for GLM — was offered everywhere. The picker showed it,
+// ValidateThinkingLevel waved it through, and the runtime then refused it at
+// apply time while the task quietly ran at the default.
+func TestReasonixPerModelEffortIsNotSharedAcrossModels(t *testing.T) {
+ fakePath := filepath.Join(t.TempDir(), "reasonix")
+ writeTestExecutable(t, fakePath, []byte(reasonixStubFor(reasonixThreeModelSessionResult)))
+
+ models, err := discoverReasonixModels(context.Background(), fakePath)
+ if err != nil {
+ t.Fatalf("discoverReasonixModels: %v", err)
+ }
+ byID := map[string]Model{}
+ for _, m := range models {
+ byID[m.ID] = m
+ }
+
+ // The model the session is on carries the catalog it actually described.
+ flash := byID["deepseek-v4-flash"]
+ if flash.Thinking == nil {
+ t.Fatal("the current model must carry the advertised catalog")
+ }
+ if len(flash.Thinking.SupportedLevels) != 4 {
+ t.Errorf("flash levels = %+v, want the four advertised", flash.Thinking.SupportedLevels)
+ }
+
+ // The others must not inherit it — their real vocabularies differ.
+ for _, id := range []string{"deepseek-v4-pro", "glm-4-air"} {
+ if got := byID[id]; got.Thinking != nil {
+ t.Errorf("model %q inherited %+v; its catalog was never advertised", id, got.Thinking)
+ }
+ }
+
+ // The daemon guard must agree, so a level can never reach a model whose
+ // support we did not observe.
+ for _, tc := range []struct {
+ model string
+ level string
+ want bool
+ }{
+ {model: "deepseek-v4-flash", level: "low", want: true},
+ {model: "deepseek-v4-flash", level: "high", want: true},
+ // The exact bug: `low` is real on flash and absent on pro.
+ {model: "deepseek-v4-pro", level: "low", want: false},
+ // Not even a level pro plausibly supports — we never saw its catalog.
+ {model: "deepseek-v4-pro", level: "high", want: false},
+ {model: "glm-4-air", level: "high", want: false},
+ } {
+ got, err := ValidateThinkingLevel(context.Background(), "reasonix", fakePath, 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)
+ }
+ }
+}
+
+// TestDiscoverReasonixModelsAnnotatesEffort proves the wiring: one ACP
+// handshake yields both the model catalog and the effort catalog, with no
+// reasonix-specific parsing anywhere in the path.
+func TestDiscoverReasonixModelsAnnotatesEffort(t *testing.T) {
+ fakePath := filepath.Join(t.TempDir(), "reasonix")
+ writeTestExecutable(t, fakePath, []byte(reasonixStubFor(reasonixEffortSessionResult)))
+
+ models, err := discoverReasonixModels(context.Background(), fakePath)
+ if err != nil {
+ t.Fatalf("discoverReasonixModels: %v", err)
+ }
+ if len(models) != 2 {
+ t.Fatalf("models = %+v, want 2", models)
+ }
+ for _, m := range models {
+ // Only the session's current model is described by what session/new
+ // advertised; see TestReasonixPerModelEffortIsNotSharedAcrossModels.
+ if !m.Default {
+ if m.Thinking != nil {
+ t.Errorf("model %q inherited a catalog it never advertised: %+v", m.ID, m.Thinking)
+ }
+ continue
+ }
+ if m.Thinking == nil {
+ t.Fatalf("current model %q carries no effort catalog", m.ID)
+ }
+ if len(m.Thinking.SupportedLevels) != 5 || m.Thinking.DefaultLevel != "max" {
+ t.Errorf("model %q: thinking = %+v", m.ID, m.Thinking)
+ }
+ }
+}
diff --git a/server/pkg/agent/models.go b/server/pkg/agent/models.go
index 31129380eb..50e4aa899d 100644
--- a/server/pkg/agent/models.go
+++ b/server/pkg/agent/models.go
@@ -1529,6 +1529,15 @@ func acpConfigOptionCurrentValue(raw json.RawMessage, configID string) (string,
// model configOptions advertised by session/new. Authentication and provider
// configuration remain owned by `reasonix setup`; discovery failure therefore
// falls back to manual model entry like the other ACP runtimes.
+//
+// The same handshake carries the effort selector, so annotate picks it up for
+// free — no second process and no reasonix-specific parser.
+//
+// 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
+// annotateACPThinkingForSessionModel.
func discoverReasonixModels(ctx context.Context, executablePath string) ([]Model, error) {
return discoverACPModels(ctx, executablePath, acpDiscoveryProvider{
defaultBin: "reasonix",
@@ -1536,6 +1545,7 @@ func discoverReasonixModels(ctx context.Context, executablePath string) ([]Model
acpArgs: reasonixACPLaunchArgs(),
tmpdirPrefix: "multica-reasonix-discovery-",
isolatedStateEnv: "REASONIX_STATE_HOME",
+ annotate: annotateACPThinkingForSessionModel,
})
}
diff --git a/server/pkg/agent/reasonix.go b/server/pkg/agent/reasonix.go
index f75fa5a6c9..636cf2a17c 100644
--- a/server/pkg/agent/reasonix.go
+++ b/server/pkg/agent/reasonix.go
@@ -274,6 +274,11 @@ func (b *reasonixBackend) Execute(ctx context.Context, prompt string, opts ExecO
cwd = "."
}
+ // sessionResult is whichever of session/new or session/resume produced
+ // this session. It carries the configOptions that the effort step
+ // below reads, so both branches have to keep hold of it.
+ var sessionResult json.RawMessage
+
if opts.ResumeSessionID != "" {
// Per ACP Session Setup, session/resume accepts mcpServers and
// the runtime re-connects them as part of the resume. Without
@@ -300,6 +305,7 @@ func (b *reasonixBackend) Execute(ctx context.Context, prompt string, opts ExecO
}
return
}
+ sessionResult = result
var changed bool
sessionID, changed = resolveResumedSessionID(opts.ResumeSessionID, result)
if changed {
@@ -319,6 +325,7 @@ func (b *reasonixBackend) Execute(ctx context.Context, prompt string, opts ExecO
resCh <- Result{Status: finalStatus, Error: finalError, DurationMs: time.Since(startTime).Milliseconds()}
return
}
+ sessionResult = result
sessionID = extractACPSessionID(result)
if sessionID == "" {
finalStatus = "failed"
@@ -372,6 +379,19 @@ func (b *reasonixBackend) Execute(ctx context.Context, prompt string, opts ExecO
b.cfg.Logger.Info("reasonix session model set", "model", opts.Model)
}
+ // 3b. Apply a persisted thinking override through whichever effort
+ // option this session advertises. Unlike set_model above this must NOT
+ // fail the task: an effort we could not apply still runs the prompt at
+ // the runtime's own default, which is a degraded result rather than a
+ // wrong one. The helper logs what actually took effect.
+ //
+ // sessionResult stops describing the live session once set_model runs
+ // above, because reasonix derives the effort catalog from the current
+ // model and returns nothing from set_model. Say so, so the helper
+ // trusts the runtime's answer over a stale advertised list.
+ applyACPEffortOption(runCtx, c.request, "reasonix", b.cfg.Logger,
+ sessionID, sessionResult, opts.ThinkingLevel, opts.Model == "")
+
// 4. Send the prompt and wait for PromptResponse. Reasonix loads
// AGENTS.md from cwd, so the daemon deliberately does not duplicate the
// runtime brief in this user message.
diff --git a/server/pkg/agent/reasonix_effort_execute_unix_test.go b/server/pkg/agent/reasonix_effort_execute_unix_test.go
new file mode 100644
index 0000000000..6d31c4ff6b
--- /dev/null
+++ b/server/pkg/agent/reasonix_effort_execute_unix_test.go
@@ -0,0 +1,127 @@
+//go:build unix
+
+package agent
+
+import (
+ "context"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+)
+
+// reasonixEffortExecStub speaks just enough ACP to run one turn, and appends
+// every request it receives to $REASONIX_RPC_LOG so the test can assert what
+// actually went over the wire. set_config_option echoes the refreshed option
+// the way reasonix does, which is what the read-back confirmation reads.
+func reasonixEffortExecStub(sessionResult string) string {
+ return `#!/bin/sh
+while IFS= read -r line; do
+ printf '%s\n' "$line" >> "$REASONIX_RPC_LOG"
+ id=$(printf '%s' "$line" | sed -n 's/.*"id":\([0-9]*\).*/\1/p')
+ case "$line" in
+ *'"method":"initialize"'*)
+ printf '{"jsonrpc":"2.0","id":%s,"result":{"protocolVersion":1,"agentCapabilities":{}}}\n' "$id"
+ ;;
+ *'"method":"session/new"'*)
+ printf '{"jsonrpc":"2.0","id":%s,"result":` + sessionResult + `}\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":"effort","currentValue":"%s","options":[{"value":"auto"},{"value":"disabled"},{"value":"low"},{"value":"high"},{"value":"max"}]}]}}\n' "$id" "$requested"
+ ;;
+ *'"method":"session/prompt"'*)
+ printf '{"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"ses-reasonix","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"pong"}}}}\n'
+ printf '{"jsonrpc":"2.0","id":%s,"result":{"stopReason":"end_turn"}}\n' "$id"
+ exit 0
+ ;;
+ esac
+done
+`
+}
+
+func runReasonixEffortTurn(t *testing.T, sessionResult, level string) (Result, string) {
+ t.Helper()
+ dir := t.TempDir()
+ logPath := filepath.Join(dir, "rpc.log")
+ t.Setenv("REASONIX_RPC_LOG", logPath)
+
+ fakePath := filepath.Join(dir, "reasonix")
+ writeTestExecutable(t, fakePath, []byte(reasonixEffortExecStub(sessionResult)))
+
+ backend, err := New("reasonix", Config{ExecutablePath: fakePath, Logger: discardLogger()})
+ if err != nil {
+ t.Fatalf("New(reasonix): %v", err)
+ }
+ session, err := backend.Execute(context.Background(), "ping", ExecOptions{
+ ThinkingLevel: level,
+ Timeout: 20 * time.Second,
+ })
+ if err != nil {
+ t.Fatalf("Execute: %v", err)
+ }
+ go func() {
+ for range session.Messages {
+ }
+ }()
+ result := <-session.Result
+
+ raw, err := os.ReadFile(logPath)
+ if err != nil {
+ t.Fatalf("read rpc log: %v", err)
+ }
+ return result, string(raw)
+}
+
+// TestReasonixExecuteAppliesThinkingLevel is the acceptance criterion from
+// GitHub #6720 in test form: a persisted level reaches the live session through
+// the option id the session itself advertised, and the turn still completes.
+func TestReasonixExecuteAppliesThinkingLevel(t *testing.T) {
+ result, rpcLog := runReasonixEffortTurn(t, reasonixEffortSessionResult, "high")
+
+ if result.Status != "completed" {
+ t.Fatalf("result = %+v, want a completed turn", result)
+ }
+ if !strings.Contains(rpcLog, `"method":"session/set_config_option"`) {
+ t.Fatalf("no set_config_option reached the runtime; log:\n%s", rpcLog)
+ }
+ if !strings.Contains(rpcLog, `"configId":"effort"`) {
+ t.Errorf("configId was not the advertised `effort`; log:\n%s", rpcLog)
+ }
+ if !strings.Contains(rpcLog, `"value":"high"`) {
+ t.Errorf("the requested level did not reach the runtime; log:\n%s", rpcLog)
+ }
+ // Ordering matters: an effort applied after the prompt would not affect it.
+ if strings.Index(rpcLog, "set_config_option") > strings.Index(rpcLog, "session/prompt") {
+ t.Errorf("effort was applied after the prompt; log:\n%s", rpcLog)
+ }
+}
+
+// TestReasonixExecuteWithoutEffortOption: a runtime build that advertises no
+// effort selector must still run the turn, and must not send a config call it
+// has no id for.
+func TestReasonixExecuteWithoutEffortOption(t *testing.T) {
+ const noEffort = `{"sessionId":"ses-reasonix","models":{"currentModelId":"m","availableModels":[{"modelId":"m"}]}}`
+ result, rpcLog := runReasonixEffortTurn(t, noEffort, "high")
+
+ if result.Status != "completed" {
+ t.Fatalf("result = %+v, want the turn to run at the runtime default", result)
+ }
+ if strings.Contains(rpcLog, "set_config_option") {
+ t.Errorf("sent a config call with no advertised option; log:\n%s", rpcLog)
+ }
+}
+
+// TestReasonixExecuteWithoutThinkingLevel keeps the default path silent: an
+// agent with no persisted effort must not touch the session configuration.
+func TestReasonixExecuteWithoutThinkingLevel(t *testing.T) {
+ result, rpcLog := runReasonixEffortTurn(t, reasonixEffortSessionResult, "")
+
+ if result.Status != "completed" {
+ t.Fatalf("result = %+v", result)
+ }
+ if strings.Contains(rpcLog, "set_config_option") {
+ t.Errorf("an agent with no effort override must not reconfigure the session; log:\n%s", rpcLog)
+ }
+}
diff --git a/server/pkg/agent/thinking.go b/server/pkg/agent/thinking.go
index b0b7e879bc..b2878d3d98 100644
--- a/server/pkg/agent/thinking.go
+++ b/server/pkg/agent/thinking.go
@@ -544,55 +544,30 @@ func annotateCodebuddyThinkingFromACP(models []Model, sessionResult json.RawMess
// parseACPCodebuddyEffort extracts the effort levels and the advertised default
// from an ACP session/new result. Returns no levels when the response carries no
-// recognisable thought_level option, which makes the caller fall back to the
-// static set rather than hiding the thinking picker entirely.
+// recognisable effort option, which makes the caller fall back to the static
+// set rather than hiding the thinking picker entirely.
+//
+// This is the shared parser (parseACPEffortOption) plus CodeBuddy's flag
+// overlay. The overlay stays CodeBuddy-specific on purpose: it exists because
+// this backend applies the level through `--effort` rather than over ACP, so
+// its usable vocabulary is narrower than what its session advertises. Every
+// other runtime takes the advertised list verbatim.
func parseACPCodebuddyEffort(raw json.RawMessage) (levels []string, defaultLevel string) {
- type acpChoice struct {
- Value string `json:"value"`
- }
- type acpOption struct {
- ID string `json:"id"`
- Category string `json:"category"`
- CurrentValue string `json:"currentValue"`
- CurrentValueSnake string `json:"current_value"`
- Options []acpChoice `json:"options"`
- }
- var resp struct {
- ConfigOptions []acpOption `json:"configOptions"`
- ConfigOptionsSnake []acpOption `json:"config_options"`
- }
- if err := json.Unmarshal(raw, &resp); err != nil {
+ option, ok := parseACPEffortOption(raw)
+ if !ok {
return nil, ""
}
- options := resp.ConfigOptions
- if len(options) == 0 {
- options = resp.ConfigOptionsSnake
- }
- for _, opt := range options {
- if !strings.EqualFold(strings.TrimSpace(opt.ID), "thought_level") &&
- !strings.EqualFold(strings.TrimSpace(opt.Category), "thought_level") {
+ for _, choice := range option.Choices {
+ if !codebuddyFlagEffortValues[choice.Value] {
continue
}
- seen := map[string]bool{}
- for _, choice := range opt.Options {
- value := strings.TrimSpace(choice.Value)
- if value == "" || seen[value] || !codebuddyFlagEffortValues[value] {
- continue
- }
- seen[value] = true
- levels = append(levels, value)
- }
- current := strings.TrimSpace(opt.CurrentValue)
- if current == "" {
- current = strings.TrimSpace(opt.CurrentValueSnake)
- }
- // Only echo a default we could actually pass to --effort.
- if codebuddyFlagEffortValues[current] {
- defaultLevel = current
- }
- return levels, defaultLevel
+ levels = append(levels, choice.Value)
+ }
+ // Only echo a default we could actually pass to --effort.
+ if codebuddyFlagEffortValues[option.CurrentValue] {
+ defaultLevel = option.CurrentValue
}
- return nil, ""
+ return levels, defaultLevel
}
// ── Shared validation ────────────────────────────────────────────────
@@ -784,6 +759,42 @@ var thinkingDynamicCatalogProviders = map[string]bool{
"kimi": true,
}
+// acpCatalogThinkingProviders are the ACP runtimes that discover their effort
+// catalog from `session/new` and apply it with `session/set_config_option`.
+// They behave like the dynamic-catalog providers above — the server accepts a
+// well-formed token and the daemon checks it against the discovered catalog —
+// but they are listed separately because membership means something stricter:
+// the runtime's Execute must actually call applyACPEffortOption.
+//
+// Do NOT add a runtime here just because it speaks ACP. Two things have to be
+// true, and neither is implied by the protocol:
+//
+// - Its Execute wires up applyACPEffortOption. Copilot is the counterexample
+// — its discovery runs over ACP but it executes through its own CLI
+// surface (`--acp` is blocked in copilot.go), so a catalog here would
+// render a picker with nothing behind it.
+// - Someone has confirmed the runtime actually threads the setting into its
+// provider request, from its source or a real run. Advertising is not
+// evidence — Hermes accepts set_config_option and ignores it, Kimi ≤0.28.1
+// confirms "on" after being set to "max" — and neither is the read-back in
+// applyACPEffortOption, which only proves the session reports the new
+// value. This list is where that offline verification is recorded; the
+// read-back is runtime diagnostics on top of it.
+var acpCatalogThinkingProviders = map[string]bool{
+ // reasonix v1.21.5: session/new advertises option id `effort` (category
+ // `thought_level`), set_config_option returns the refreshed options, and
+ // the effort reaches the session controller rather than stopping at the
+ // config surface. Its catalog is per model — see
+ // annotateACPThinkingForSessionModel.
+ "reasonix": true,
+}
+
+// usesDynamicThinkingCatalog reports whether a provider's effort vocabulary is
+// owned by a daemon-local catalog rather than a fixed server-side enum.
+func usesDynamicThinkingCatalog(providerType string) bool {
+ return thinkingDynamicCatalogProviders[providerType] || acpCatalogThinkingProviders[providerType]
+}
+
// ThinkingControlSupported reports whether Multica can deliver a per-agent
// reasoning effort to this runtime at all. False means the answer to any
// thinking_level is "no", regardless of the token: the runtime exposes no
@@ -809,7 +820,7 @@ var thinkingDynamicCatalogProviders = map[string]bool{
// when Hermes' ACP surface exposes reasoning; the picker then follows from the
// discovered catalog like every other runtime's.
func ThinkingControlSupported(providerType string) bool {
- if thinkingDynamicCatalogProviders[providerType] {
+ if usesDynamicThinkingCatalog(providerType) {
return true
}
_, ok := providerThinkingEnums[providerType]
@@ -819,9 +830,9 @@ func ThinkingControlSupported(providerType string) bool {
// IsKnownThinkingValue reports whether `value` is a recognised effort
// token for the given provider. Empty string is always accepted (means
// "use runtime default"). Providers with no reasoning control accept
-// only empty; Codex, OpenCode, and Kimi accept well-formed tokens here because
-// their daemon-local catalogs perform the exact per-model check before
-// execution.
+// only empty; Codex, OpenCode, Kimi, and the ACP catalog runtimes accept
+// well-formed tokens here because their daemon-local catalogs perform the
+// exact per-model check before execution.
//
// This is the cheap synchronous gate the server uses on CreateAgent /
// UpdateAgent. Unlike ValidateThinkingLevel it does NOT consult the live
@@ -832,7 +843,7 @@ func IsKnownThinkingValue(providerType, value string) bool {
if value == "" {
return true
}
- if thinkingDynamicCatalogProviders[providerType] {
+ if usesDynamicThinkingCatalog(providerType) {
return isValidDynamicThinkingValue(value)
}
enum, ok := providerThinkingEnums[providerType]