Skip to content

The agent that grows with you

fix(desktop): error card 'Switch provider' opens the live session model menu

teknium174c2439af266
diff --git a/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsx b/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsx
index 48b97aef5f8..20c7da63822 100644
--- a/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsx
@@ -20,6 +20,12 @@ import { Thread } from '.'
const requestFreshSession = vi.hoisted(() => vi.fn())
const startManualProviderOAuth = vi.hoisted(() => vi.fn())
+const requestModelMenuToggle = vi.hoisted(() => vi.fn<() => boolean>(() => true))
+
+vi.mock('@/app/chat/composer/focus', async importOriginal => ({
+ ...(await importOriginal<Record<string, unknown>>()),
+ requestModelMenuToggle: () => requestModelMenuToggle()
+}))
vi.mock('@/store/profile', async importOriginal => ({
...(await importOriginal<Record<string, unknown>>()),
@@ -42,6 +48,7 @@ afterEach(() => {
cleanup()
requestFreshSession.mockClear()
startManualProviderOAuth.mockClear()
+ requestModelMenuToggle.mockReset().mockReturnValue(true)
})
function userMessage(): ThreadMessage {
@@ -329,6 +336,44 @@ describe('rejected API key recovery', () => {
})
})
+describe('switch provider on a live session (#95066)', () => {
+ const billingFailure = () =>
+ failedMessage({ code: 'billing', layer: 'billing', provider: 'openai-codex', retryable: false }, 'HTTP 429: quota')
+
+ it('opens the live session model menu instead of leaving the chat for Settings', async () => {
+ render(
+ <MemoryRouter>
+ <LocationProbe />
+ <Harness assistant={billingFailure()} />
+ </MemoryRouter>
+ )
+
+ const button = await screen.findByRole('button', { name: 'Switch provider' })
+ const before = screen.getByTestId('location').textContent
+
+ button.click()
+
+ expect(requestModelMenuToggle).toHaveBeenCalledTimes(1)
+ // Still on the chat: the pick lands on THIS session through model.switch.
+ expect(screen.getByTestId('location').textContent).toBe(before)
+ })
+
+ it('falls back to Settings → Models only when no chat surface is on screen', async () => {
+ requestModelMenuToggle.mockReturnValue(false)
+ render(
+ <MemoryRouter>
+ <LocationProbe />
+ <Harness assistant={billingFailure()} />
+ </MemoryRouter>
+ )
+
+ ;(await screen.findByRole('button', { name: 'Switch provider' })).click()
+
+ expect(requestModelMenuToggle).toHaveBeenCalledTimes(1)
+ await waitFor(() => expect(screen.getByTestId('location').textContent).toMatch(/\?tab=config:model$/))
+ })
+})
+
describe('expired OAuth grant recovery', () => {
it('explains the expiry and re-runs that provider sign-in in one click', async () => {
render(<Harness assistant={oauthExpiredMessage()} />)
diff --git a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
index b84405ce012..9b5e37d6bee 100644
--- a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
@@ -11,6 +11,7 @@ import { useStore } from '@nanostores/react'
import { type FC, type ReactNode, useCallback, useContext, useMemo, useState } from 'react'
import { useInRouterContext, useNavigate } from 'react-router'
+import { requestModelMenuToggle } from '@/app/chat/composer/focus'
import { useSessionView } from '@/app/chat/session-view'
import { SETTINGS_ROUTE } from '@/app/routes'
import { dispatchedTo } from '@/components/assistant-ui/thread/agent-delivery'
@@ -554,6 +555,32 @@ const SettingsLinkAction: FC<{ icon?: ReactNode; label: string; to: string }> =
)
}
+// "Switch provider" for a provider/endpoint/auth/billing failure: opens the
+// composer pill's LIVE model menu, whose picks go through `model.switch` on
+// this session (use-model-menu-controller.ts) — the same menu the
+// `composer.modelPicker` hotkey toggles. Settings → Models only changes the
+// default for NEW sessions, so it is the fallback for when no chat surface is
+// on screen (requestModelMenuToggle returns false), not the first stop.
+// Targeting follows requestModelMenuToggle: the pane under the pointer, else
+// the active composer — a click on this card puts the pointer in its own pane.
+const SwitchProviderAction: FC<{ label: string }> = ({ label }) => {
+ const navigate = useNavigate()
+
+ const switchProvider = useCallback(() => {
+ triggerHaptic('selection')
+
+ if (!requestModelMenuToggle()) {
+ navigate(`${SETTINGS_ROUTE}?tab=config:model`)
+ }
+ }, [navigate])
+
+ return (
+ <button className="aui-error-action" onClick={switchProvider} type="button">
+ {label}
+ </button>
+ )
+}
+
// Settings → Keys deep link for a rejected API key: `?tab=keys` plus
// `&key=<ENV>` when the descriptor names the env var (keys-settings.tsx
// scrolls to and expands that row). Older backends omit `api_key_env`; the
@@ -788,9 +815,7 @@ const ErrorRecoveryActions: FC = () => {
</button>
</ActionBarPrimitive.Reload>
)}
- {plan.switchProvider && inRouter && (
- <SettingsLinkAction label={copy.errorSwitchProvider} to={`${SETTINGS_ROUTE}?tab=config:model`} />
- )}
+ {plan.switchProvider && inRouter && <SwitchProviderAction label={copy.errorSwitchProvider} />}
{localFolders && (
<button className="aui-error-action" onClick={() => void openLogs()} type="button">
{remoteConnection ? copy.errorOpenDesktopLogs : copy.errorOpenLogs}
diff --git a/apps/desktop/src/lib/error-surface.ts b/apps/desktop/src/lib/error-surface.ts
index c1902eb02c8..e228b5ab068 100644
--- a/apps/desktop/src/lib/error-surface.ts
+++ b/apps/desktop/src/lib/error-surface.ts
@@ -186,7 +186,9 @@ export interface ErrorRecoveryPlan {
signInAgain: boolean
/** Open the free-tier sign-in dialog (free_tier_* codes): signing in is free and lifts the refusal. */
signInFreeTier: boolean
- /** Settings → Models deep link. */
+ /** Open the live session model menu (switches THIS session via
+ * model.switch); Settings → Models deep link fallback when no chat surface
+ * is on screen. */
switchProvider: boolean
}
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index 384416abe8d..52cd6925496 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -537,8 +537,10 @@ generic error toast. The card offers recovery actions matched to the failure:
- **Retry** — re-runs the failed turn in place (hidden when retrying would
deterministically reproduce the failure, e.g. a content-policy rejection).
-- **Switch provider** — jumps to Settings → Models for provider, endpoint,
- auth, and billing failures.
+- **Switch provider** — for provider, endpoint, auth, and billing failures,
+ opens the composer's live model menu so you can move **this chat** to another
+ provider/model right away (Settings → Models only changes the default for new
+ chats). When no chat surface is on screen it falls back to Settings → Models.
- **Open logs** — opens `HERMES_HOME/logs` in your file manager. On a remote
or Cloud connection the button reads **Open Desktop logs**: it opens the
local Desktop-side logs (transport evidence), since the failed turn's