Skip to content

The agent that grows with you

fix(desktop): stop a stale reasoning wire level from labelling the composer

kokhlo33bb9f5b3a1c
diff --git a/apps/desktop/src/store/model-presets.ts b/apps/desktop/src/store/model-presets.ts
index ea9fc837eef..f2ecc241ec3 100644
--- a/apps/desktop/src/store/model-presets.ts
+++ b/apps/desktop/src/store/model-presets.ts
@@ -75,7 +75,7 @@ export async function applyModelPreset(
} else if (ctx.sessionId) {
sessionTileDelegate()?.updateSession(ctx.sessionId, state => ({
...state,
- ...(effort !== undefined ? { reasoningEffort: effort } : {}),
+ ...(effort !== undefined ? { reasoningEffort: effort, reasoningEffortWire: '' } : {}),
...(fast !== undefined ? { fast } : {})
}))
}
diff --git a/apps/desktop/src/store/reasoning-effort-wire-scope.test.ts b/apps/desktop/src/store/reasoning-effort-wire-scope.test.ts
new file mode 100644
index 00000000000..dd632285863
--- /dev/null
+++ b/apps/desktop/src/store/reasoning-effort-wire-scope.test.ts
@@ -0,0 +1,100 @@
+import { beforeEach, describe, expect, it } from 'vitest'
+
+import {
+ $currentModel,
+ $currentProvider,
+ $currentReasoningEffort,
+ $currentReasoningEffortWire,
+ setCurrentModel,
+ setCurrentModelTransient,
+ setCurrentProvider,
+ setCurrentProviderTransient,
+ setCurrentReasoningEffort,
+ setCurrentReasoningEffortWire
+} from './session'
+
+/** The gateway's clamp for one (provider, model, effort) triple. */
+const stampWire = (wire: string) => setCurrentReasoningEffortWire(wire)
+
+describe('reasoning-effort wire scope', () => {
+ beforeEach(() => {
+ setCurrentModel('')
+ setCurrentProvider('')
+ setCurrentReasoningEffort('')
+ stampWire('')
+ })
+
+ it('drops the wire stamp when the model changes, so a stale arrow is not presented as confirmed', () => {
+ // The old route clamped `xhigh` up for its own vocabulary; the pill read
+ // "XHigh→Max" even though no route can send that pair.
+ setCurrentModel('gpt-6.1-sol')
+ setCurrentProvider('openai-codex')
+ setCurrentReasoningEffort('xhigh')
+ stampWire('max')
+
+ expect($currentReasoningEffortWire.get()).toBe('max')
+
+ // A different model clamps a different set, so the stamp no longer describes
+ // this session's route.
+ setCurrentModel('gpt-6.1-luna')
+
+ expect($currentReasoningEffortWire.get()).toBe('')
+ // The pick itself is untouched — only the route claim is withdrawn.
+ expect($currentReasoningEffort.get()).toBe('xhigh')
+ })
+
+ it('drops the wire stamp when the provider changes', () => {
+ setCurrentModel('gpt-6.1-sol')
+ setCurrentProvider('openai-codex')
+ setCurrentReasoningEffort('xhigh')
+ stampWire('max')
+
+ setCurrentProvider('openrouter')
+
+ expect($currentReasoningEffortWire.get()).toBe('')
+ })
+
+ it('keeps a confirmed stamp when the same model or provider is re-set', () => {
+ setCurrentModel('gpt-6.1-sol')
+ setCurrentProvider('openai-codex')
+ setCurrentReasoningEffort('ultra')
+ stampWire('max')
+
+ // Re-stamping the identical selection describes the same route.
+ setCurrentModel('gpt-6.1-sol')
+ setCurrentProvider('openai-codex')
+
+ expect($currentReasoningEffortWire.get()).toBe('max')
+ })
+
+ it('accepts a functional updater without clearing the stamp on a no-op', () => {
+ setCurrentModel('gpt-6.1-sol')
+ setCurrentReasoningEffort('ultra')
+ stampWire('max')
+
+ setCurrentModel(current => current)
+
+ expect($currentModel.get()).toBe('gpt-6.1-sol')
+ expect($currentReasoningEffortWire.get()).toBe('max')
+
+ setCurrentModel(() => 'gpt-6.1-luna')
+
+ expect($currentModel.get()).toBe('gpt-6.1-luna')
+ expect($currentReasoningEffortWire.get()).toBe('')
+ })
+
+ it('keeps the stamp across a heartbeat that mirrors the runtime model', () => {
+ setCurrentModel('gpt-6.1-sol')
+ setCurrentProvider('openai-codex')
+ setCurrentReasoningEffort('ultra')
+ stampWire('max')
+
+ // The periodic `session.info` heartbeat pushes the resolved route without
+ // claiming the composer selection. It does not change the route, so it must
+ // not withdraw a confirmed clamp — otherwise the pill flickers on every beat.
+ setCurrentModelTransient($currentModel.get())
+ setCurrentProviderTransient($currentProvider.get())
+
+ expect($currentReasoningEffortWire.get()).toBe('max')
+ })
+})
diff --git a/apps/desktop/src/store/session.ts b/apps/desktop/src/store/session.ts
index 5a323aa89cb..6ab273a49bb 100644
--- a/apps/desktop/src/store/session.ts
+++ b/apps/desktop/src/store/session.ts
@@ -1638,7 +1638,17 @@ export const setBusy = (next: Updater<boolean>) => updateAtom($busy, next)
export const setAwaitingResponse = (next: Updater<boolean>) => updateAtom($awaitingResponse, next)
export const setCurrentModel = (next: Updater<string>) => {
+ const previous = $currentModel.get()
updateAtom($currentModel, next)
+
+ if ($currentModel.get() !== previous) {
+ // The wire level belongs to one (provider, model, effort) triple, and a
+ // different model clamps a different set. Carrying the old route's stamp
+ // makes the pill present a stale escalation as a confirmed one, so drop it
+ // and let the next `session.info` re-stamp.
+ $currentReasoningEffortWire.set('')
+ }
+
const key = composerSelectionKey(COMPOSER_MODEL_KEY)
if (key !== null) {
@@ -1647,7 +1657,13 @@ export const setCurrentModel = (next: Updater<string>) => {
}
export const setCurrentProvider = (next: Updater<string>) => {
+ const previous = $currentProvider.get()
updateAtom($currentProvider, next)
+
+ if ($currentProvider.get() !== previous) {
+ $currentReasoningEffortWire.set('')
+ }
+
const key = composerSelectionKey(COMPOSER_PROVIDER_KEY)
if (key !== null) {