The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): reseed a bare provider pick the default migrated to custom:*
Austin Pickett652fb2eb57de
diff --git a/apps/desktop/src/app/session/hooks/use-model-controls.test.tsx b/apps/desktop/src/app/session/hooks/use-model-controls.test.tsxindex b2c9c84d253..28681b02916 100644--- a/apps/desktop/src/app/session/hooks/use-model-controls.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-model-controls.test.tsx@@ -857,4 +857,61 @@ describe('useModelControls', () => {expect($currentProvider.get()).toBe('custom')expect(getCurrentModelSource()).toBe('manual')})++ // ── Stale native pick superseded by a custom default (#81922) ─────────────+ // `nvidia` -> `custom:nvidia` in config.yaml: the bare slug is the+ // pre-migration spelling of the SAME endpoint (#87035 aliases the two for one+ // catalog row), but shipping it builds the NATIVE provider and silently drops+ // the custom entry's `extra_body` (e.g. `thinking: {type: adaptive}`). The+ // bare slug must yield to the configured default.+ it('reseeds a sticky manual pick the profile default migrated to its custom-provider form (#81922)', async () => {+ vi.mocked(getGlobalModelInfo).mockResolvedValue({ model: 'z-ai/glm-5.2', provider: 'custom:nvidia' })+ setCurrentModel('z-ai/glm-5.2')+ setCurrentProvider('nvidia')+ setCurrentModelSource('manual')++ const { result } = renderHook(() => useModelControls({ queryClient: new QueryClient(), requestGateway: vi.fn() }))++ await act(() => result.current.refreshCurrentModel())++ expect($currentProvider.get()).toBe('custom:nvidia')+ expect($currentModel.get()).toBe('z-ai/glm-5.2')+ // 'default' means the next session.create omits the override entirely, so+ // the gateway resolves config.yaml's custom entry (with its extra_body).+ expect(getCurrentModelSource()).toBe('default')+ })++ it('keeps a manual pick of a different provider while the default is a custom entry', async () => {+ vi.mocked(getGlobalModelInfo).mockResolvedValue({ model: 'z-ai/glm-5.2', provider: 'custom:nvidia' })+ setCurrentModel('claude-sonnet-4-6')+ setCurrentProvider('anthropic')+ setCurrentModelSource('manual')++ const { result } = renderHook(() => useModelControls({ queryClient: new QueryClient(), requestGateway: vi.fn() }))++ await act(() => result.current.refreshCurrentModel())++ expect($currentModel.get()).toBe('claude-sonnet-4-6')+ expect($currentProvider.get()).toBe('anthropic')+ expect(getCurrentModelSource()).toBe('manual')+ })++ it('keeps a manual custom:* pick without consulting the profile default', async () => {+ setCurrentModel('deepseek-v4-flash')+ setCurrentProvider('custom:relay')+ setCurrentModelSource('manual')+ // getGlobalModelInfo is a shared module mock; count only this test's calls.+ vi.mocked(getGlobalModelInfo).mockClear()++ const { result } = renderHook(() => useModelControls({ queryClient: new QueryClient(), requestGateway: vi.fn() }))++ await act(() => result.current.refreshCurrentModel())++ expect($currentModel.get()).toBe('deepseek-v4-flash')+ expect($currentProvider.get()).toBe('custom:relay')+ expect(getCurrentModelSource()).toBe('manual')+ // A provider-class pick can never be shadowed by a custom:<key> default, so+ // the sticky path must not pay for a /api/model/info round trip.+ expect(getGlobalModelInfo).not.toHaveBeenCalled()+ })})diff --git a/apps/desktop/src/app/session/hooks/use-model-controls.ts b/apps/desktop/src/app/session/hooks/use-model-controls.tsindex 9561d9b9099..d66fb84dc92 100644--- a/apps/desktop/src/app/session/hooks/use-model-controls.ts+++ b/apps/desktop/src/app/session/hooks/use-model-controls.ts@@ -7,7 +7,12 @@ import { getGlobalModelInfo } from '@/hermes'import { useI18n } from '@/i18n'import { isBusySessionModelSwitch } from '@/lib/gateway-rpc'import { surfaceModelSwitchConfirm } from '@/lib/guarded-model-switch'-import { moaPickRemoved, modelOptionsQueryKey, requestModelOptions } from '@/lib/model-options'+import {+ customDefaultSupersedesPick,+ moaPickRemoved,+ modelOptionsQueryKey,+ requestModelOptions+} from '@/lib/model-options'import { notifyError } from '@/store/notifications'import { $activeGatewayProfile } from '@/store/profile'import {@@ -110,6 +115,9 @@ export function useModelControls({// only fills an EMPTY selection so a user's pick (plain UI state in// $currentModel) survives the lifecycle refreshes that fire on boot / fresh// draft / session events. A live session owns the footer, so skip entirely.+ // Two provably-stale manual picks are the exception and reseed from the+ // profile default: the virtual `moa` provider (#90244) and a bare provider+ // slug the default has migrated to its `custom:<key>` form (#81922).const refreshCurrentModel = useCallback(async (force = false) => {// A forced profile swap opens a new intent epoch; an older in-flight@@ -135,10 +143,22 @@ export function useModelControls({// `Model · moa: default` forever (#90244).const manualPick = () => Boolean($currentModel.get()) && getCurrentModelSource() === 'manual'- const staleMoaPick = () =>- !force && manualPick() && ($currentProvider.get() || '').trim().toLowerCase() === 'moa'+ const pickProvider = () => ($currentProvider.get() || '').trim()++ const staleMoaPick = () => !force && manualPick() && pickProvider().toLowerCase() === 'moa'++ // A SECOND exception: a bare provider slug can be a stale spelling of a+ // `custom:<key>` profile default (#87035 aliases the two spellings for+ // one endpoint). Shipping the bare form resolves the NATIVE provider and+ // silently drops the entry's `extra_body` (#81922), so the pick must+ // reseed. Only a bare slug qualifies — a pick that already names a+ // provider class is a distinct choice and stays sticky — and the profile+ // default is a backend fact, so this needs the same `getGlobalModelInfo`+ // fetch the empty / default-sourced path already makes.+ const maybeSupersededPick = () =>+ !force && manualPick() && pickProvider() !== '' && !pickProvider().includes(':')- if (manualPick() && !force && !staleMoaPick()) {+ if (manualPick() && !force && !staleMoaPick() && !maybeSupersededPick()) {return}@@ -179,7 +199,10 @@ export function useModelControls({profileRefreshEpochRef.current !== profileRefreshEpoch ||$activeSessionId.get() ||getComposerSelectionGeneration() !== selectionGeneration ||- (manualPick() && !force && !reseedStaleMoa)+ (manualPick() &&+ !force &&+ !reseedStaleMoa &&+ !customDefaultSupersedesPick($currentProvider.get(), result.provider ?? ''))) {return}diff --git a/apps/desktop/src/lib/model-options.test.ts b/apps/desktop/src/lib/model-options.test.tsindex 9ccbf6bb6d5..846cf74cc75 100644--- a/apps/desktop/src/lib/model-options.test.ts+++ b/apps/desktop/src/lib/model-options.test.ts@@ -3,7 +3,13 @@ import { afterEach, describe, expect, it, vi } from 'vitest'import { getGlobalModelOptions } from '@/hermes'-import { catalogProviderMatches, moaPickRemoved, modelOptionsQueryKey, requestModelOptions } from './model-options'+import {+ catalogProviderMatches,+ customDefaultSupersedesPick,+ moaPickRemoved,+ modelOptionsQueryKey,+ requestModelOptions+} from './model-options'const globalOptions = { model: 'hermes-4', provider: 'nous', providers: [] }@@ -257,3 +263,26 @@ describe('moaPickRemoved', () => {expect(moaPickRemoved({ providers: [providers[0]] }, '', 'default')).toBe(false)})})++describe('customDefaultSupersedesPick', () => {+ it('flags a bare pick the default has migrated to its custom-provider form (#81922)', () => {+ // The wire payload for `nvidia` builds the NATIVE provider and drops the+ // custom entry's extra_body; `custom:nvidia` is the same endpoint.+ expect(customDefaultSupersedesPick('nvidia', 'custom:nvidia')).toBe(true)+ expect(customDefaultSupersedesPick(' NVIDIA ', 'Custom:NVIDIA')).toBe(true)+ })++ it('keeps a pick that already names the custom entry, or a different provider', () => {+ expect(customDefaultSupersedesPick('custom:nvidia', 'custom:nvidia')).toBe(false)+ expect(customDefaultSupersedesPick('custom:relay', 'custom:nvidia')).toBe(false)+ expect(customDefaultSupersedesPick('anthropic', 'custom:nvidia')).toBe(false)+ })++ it('never fires for a non-custom default or an empty pick', () => {+ expect(customDefaultSupersedesPick('nvidia', 'nvidia')).toBe(false)+ expect(customDefaultSupersedesPick('custom', 'custom')).toBe(false)+ expect(customDefaultSupersedesPick('nvidia', 'openai-codex')).toBe(false)+ expect(customDefaultSupersedesPick('', 'custom:nvidia')).toBe(false)+ expect(customDefaultSupersedesPick('nvidia', 'custom:')).toBe(false)+ })+})diff --git a/apps/desktop/src/lib/model-options.ts b/apps/desktop/src/lib/model-options.tsindex 0d5bc7ac995..90554c8a41b 100644--- a/apps/desktop/src/lib/model-options.ts+++ b/apps/desktop/src/lib/model-options.ts@@ -64,6 +64,32 @@ export function moaPickRemoved(return !(row?.models ?? []).includes(model)}+/** A bare provider slug is the pre-migration spelling of a custom entry. The+ * catalog aliases `custom:<key>` with the bare config key (#87035), so a pick+ * still carrying `nvidia` and a profile default of `custom:nvidia` name the+ * SAME endpoint — the pick's spelling is simply stale, not a distinct choice.+ * Shipping the bare slug resolves the NATIVE provider instead of the custom+ * entry, silently dropping the entry's `extra_body` (e.g.+ * `thinking: {type: adaptive}`) that the user configured (#81922).+ *+ * Only a bare slug can be superseded: a pick that already names a provider+ * class (`custom:<other>`, `moa`, `openai-codex`) is a different endpoint and+ * keeps the sticky behavior. The bare slug must be the default's own key, so+ * an unrelated manual pick (`anthropic` while the default is `custom:nvidia`)+ * is never clobbered. */+export function customDefaultSupersedesPick(pickProvider: string, defaultProvider: string): boolean {+ const pick = (pickProvider || '').trim().toLowerCase()+ const fallback = (defaultProvider || '').trim().toLowerCase()++ if (!pick || pick === fallback || !fallback.startsWith('custom:')) {+ return false+ }++ const key = fallback.slice('custom:'.length).trim()++ return key.length > 0 && pick === key+}+interface ModelOptionsRequest {/** When false, include ambient/unconfigured providers (onboarding/setup* surfaces). Chat pickers default to true so only explicitly configured