Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(chat): follow model thinking defaults

vastsad5c0b9addd6b
diff --git a/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.ts b/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.ts
index d3095179d..650d6128a 100644
--- a/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.ts
+++ b/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.ts
@@ -1,15 +1,14 @@
-import { useEffect, useMemo, useRef, useState, type KeyboardEvent } from "react";
import type {
Mode,
ProviderPublic,
SessionThinkingLevel,
} from "@pi-desktop/shared";
import {
- initialThinkingLevelForBinding,
imageGenerationBindings,
+ initialThinkingLevelForBinding,
isImageGenerationModel,
} from "@pi-desktop/shared";
-import { useAppStore } from "../../../../stores/app-store";
+import { type KeyboardEvent, useEffect, useMemo, useRef, useState } from "react";
import {
composerModelBinding,
composerModelMatchesQuery,
@@ -21,11 +20,12 @@ import {
providerSearchText,
} from "../../../../lib/provider-display";
import { providerThinkingLevels } from "../../../../lib/session-thinking";
+import { useAppStore } from "../../../../stores/app-store";
import {
+ type ComposerMenuView,
sessionThinkingMenuLevels,
thinkingLevelForProvider,
thinkingProviderForModel,
- type ComposerMenuView,
} from "../model";
import { createLatestCommitQueue } from "../thinking-commit-queue";
@@ -256,7 +256,11 @@ export function useComposerModelMenu({
const nextBinding = candidate.models.find((entry) =>
sameComposerModelId(entry.id, nextModelId),
);
- const nextThinkingLevel = activeSessionId
+ const selectedSameModel =
+ activeSessionId &&
+ candidate.id === provider?.id &&
+ sameComposerModelId(modelId ?? "", nextModelId);
+ const nextThinkingLevel = selectedSameModel
? thinkingLevelForProvider(nextModelProvider, thinkingLevel)
: initialThinkingLevelForBinding(
nextBinding,
diff --git a/apps/desktop/test/composer-model-thinking-menu.test.mjs b/apps/desktop/test/composer-model-thinking-menu.test.mjs
index 53d96fa0a..33ad001ae 100644
--- a/apps/desktop/test/composer-model-thinking-menu.test.mjs
+++ b/apps/desktop/test/composer-model-thinking-menu.test.mjs
@@ -31,6 +31,10 @@ test("model selection returns to the root without closing", () => {
assert.match(composerSource, /setQuery\(""\);[\s\S]*?setView\("root"\)/);
assert.match(composerSource, /const thinkingMenuLevels = sessionThinkingMenuLevels\(availableThinkingLevels\)/);
});
+test("switching models adopts the target default without resetting same-model overrides", () => {
+ assert.match(modelMenuSource, /const selectedSameModel =\s*activeSessionId &&\s*candidate\.id === provider\?\.id &&\s*sameComposerModelId\(modelId \?\? "", nextModelId\);/);
+ assert.match(modelMenuSource, /const nextThinkingLevel = selectedSameModel\s*\?\s*thinkingLevelForProvider\(nextModelProvider, thinkingLevel\)\s*:\s*initialThinkingLevelForBinding\(\s*nextBinding,\s*nextModelProvider\?\.supportedThinkingLevels,\s*\)/);
+});
test("the menu root carries the reasoning slider itself", () => {
// The root view renders the slider and nothing else for the level: there is
// no reasoning entry left to open a list of levels.
diff --git a/apps/desktop/test/thinking-ui.test.mjs b/apps/desktop/test/thinking-ui.test.mjs
index 911f89eca..73ca3af42 100644
--- a/apps/desktop/test/thinking-ui.test.mjs
+++ b/apps/desktop/test/thinking-ui.test.mjs
@@ -183,7 +183,11 @@ test("draft Composer thinking follows the exact model selected in its menu", ()
);
assert.match(
composerSource,
- /const nextThinkingLevel = activeSession[\s\S]*?thinkingLevelForProvider\(nextModelProvider, thinkingLevel\)[\s\S]*?initialThinkingLevelForBinding\(/,
+ /const selectedSameModel =\s*activeSessionId &&\s*candidate\.id === provider\?\.id &&\s*sameComposerModelId\(modelId \?\? "", nextModelId\);/,
+ );
+ assert.match(
+ composerSource,
+ /const nextThinkingLevel = selectedSameModel\s*\?\s*thinkingLevelForProvider\(nextModelProvider, thinkingLevel\)\s*:\s*initialThinkingLevelForBinding\(/,
);
assert.match(composerSource, /const selectedBinding = provider\?\.models\.find/);
assert.match(composerSource, /const draftThinkingLevel = initialThinkingLevelForBinding\(/);
diff --git a/docs/spec/03-runtime/13-model-catalog-and-selection.md b/docs/spec/03-runtime/13-model-catalog-and-selection.md
index 74f8f8256..a478d6e2e 100644
--- a/docs/spec/03-runtime/13-model-catalog-and-selection.md
+++ b/docs/spec/03-runtime/13-model-catalog-and-selection.md
@@ -192,19 +192,25 @@ Each session stores:
- `thinkingLevel` (`off|minimal|low|medium|high|xhigh|max|omit`)
Changing model or thinking level mid-session affects subsequent turns only.
-The stored thinking preference survives restart; the effective request level
-is clamped against the selected model binding's enabled levels at execution
-time, except `omit`, which is preserved on a reasoning model and sends no
-thinking override. An empty binding or a binding containing only `off`
-resolves to `off`.
-
-For a newly created session, the renderer resolves the selected (or app-default)
-model's `ModelBinding`. A reasoning model starts at that binding's
-`defaultThinkingLevel` (`omit` is preserved; other values are clamped onto the
-enabled levels). When the default is unset it falls back to the highest enabled
-level seeded from published `supportedThinkingLevels`. A non-reasoning or
-unknown model starts at `off` until the user enables a non-`off` level. This is
-a creation default only and never rewrites an existing session's stored choice.
+The stored thinking preference survives restart. An explicit switch to a
+different provider/model in Composer resets `thinkingLevel` to the target
+binding's `defaultThinkingLevel`, clamped to its enabled levels; if unset, it
+uses the normal new-session fallback. Selecting the already-active
+provider/model preserves a manually selected level. The effective request
+level remains clamped against the selected model binding's enabled levels at
+execution time, except `omit`, which is preserved on a reasoning model and
+sends no thinking override. An empty binding or a binding containing only
+`off` resolves to `off`.
+
+For a newly created session or explicit model switch, the renderer resolves the
+selected (or app-default) model's `ModelBinding`. A reasoning model starts at
+that binding's `defaultThinkingLevel` (`omit` is preserved; other values are
+clamped onto the enabled levels). When the default is unset it falls back to
+the highest enabled level seeded from published `supportedThinkingLevels`. A
+non-reasoning or unknown model starts at `off` until the user enables a
+non-`off` level. Changing a default in Settings does not rewrite existing
+sessions; an existing session keeps its stored choice until a different model
+is explicitly selected.
Unpinned sessions still advertise that inherited default model's reasoning
capability on session list/get/create/fork/configure. Enrichment does not pin
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 9e52c8678..8ecb322bf 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -2943,8 +2943,9 @@ reasoning-level control.
highest enabled level. Published levels seed a new binding; an explicit
binding can opt into a level the catalog omits. Non-reasoning models and
missing capability metadata start at `off` until a user enables a non-`off`
- level; reopening or reusing an existing session preserves its durable
- selection.
+ level. Reopening an existing session preserves its durable selection;
+ explicitly switching to a different model applies that binding's default,
+ while selecting the already-active model preserves a manually chosen level.
- The model menu lists only enabled, runnable providers with configured model
bindings. Cached or freshly discovered rows may enrich those configured
models, but unconfigured discovery results never appear in the conversation
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 87f50bd4f..48ee4ea1f 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -1865,24 +1865,27 @@ identify the platform validation still needed.
#### E2E-089: Composer model menu opens upward and switches model
-- **Preconditions**: Chat route active; provider configured.
+- **Preconditions**: Chat route active; provider configured with two reasoning
+ models whose binding defaults differ.
- **Steps**: 1) Click the Composer-right model × reasoning chip. 2) Confirm the
menu opens upward from the bottom composer. 3) Enter Model, select a different
- provider/model, and return to the root. 4) Enter Reasoning level and select a
- supported level. 5) Open Settings from the command palette or application menu.
+ provider/model, and return to the root. 4) Confirm its default thinking level,
+ choose another supported level, then reselect the same model. 5) Open Settings
+ from the command palette or application menu.
- **Expected**: The trigger uses a Bot icon while retaining the current model
and reasoning labels. The root shows only Model and Reasoning level entries.
The Model submenu lists enabled runnable providers and only the model bindings
saved for each provider, with each model row visibly indented beneath its provider
heading. Cached or freshly discovered models may supply display names and
metadata for those bindings, but unconfigured discovery results are absent;
- configured IDs remain available when discovery is unavailable. The Reasoning
- level submenu lists only the selected model's published levels. Selecting
- updates the active session model/reasoning configuration without dismissing
- the menu; Settings opens from the command palette/menu. The Composer model
- trigger ellipsizes long IDs. Each option shows one display name only, and
- hovering a long option exposes its complete display name in the tooltip
- without changing the menu layout or adding a visible model ID.
+ configured IDs remain available when discovery is unavailable. The root slider
+ lists the selected model's supported levels. Selecting a different model
+ updates the active session to that binding's default thinking level; selecting
+ the already-active model preserves a manually selected level. Settings opens
+ from the command palette/menu. The Composer model trigger ellipsizes long IDs.
+ Each option shows one display name only, and hovering a long option exposes its
+ complete display name in the tooltip without changing the menu layout or adding
+ a visible model ID.
- **Specs linked**: `04-ux/08-component-spec.md` (§11, model menu),
`03-runtime/13-model-catalog-and-selection.md`
- **Acceptance**: C