The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): defer global default flip until manual provider connect is confirmed
chelsealongf8b272b90ef2
diff --git a/apps/desktop/src/components/onboarding/index.tsx b/apps/desktop/src/components/onboarding/index.tsxindex 66e9f9030d1..18e6459030d 100644--- a/apps/desktop/src/components/onboarding/index.tsx+++ b/apps/desktop/src/components/onboarding/index.tsx@@ -244,13 +244,13 @@ export function DesktopOnboardingOverlay({const reduce = typeof window !== 'undefined' && window.matchMedia?.('(prefers-reduced-motion: reduce)').matchesif (reduce) {- confirmOnboardingModel(ctx)+ void confirmOnboardingModel(ctx)return}setLeaving(true)- window.setTimeout(() => confirmOnboardingModel(ctx), ONBOARDING_EXIT_MS)+ window.setTimeout(() => void confirmOnboardingModel(ctx), ONBOARDING_EXIT_MS)}// The free-tier intro's three doors share one exit: consume the notice, playdiff --git a/apps/desktop/src/store/onboarding-owner.test.ts b/apps/desktop/src/store/onboarding-owner.test.tsindex 55e7bb15ae7..ef244eb7f61 100644--- a/apps/desktop/src/store/onboarding-owner.test.ts+++ b/apps/desktop/src/store/onboarding-owner.test.ts@@ -135,7 +135,12 @@ it.each(['device_code', 'pkce'] as const)(expect(ctx.requestGateway).not.toHaveBeenCalledWith('reload.env')expect(ctx.requestGateway).toHaveBeenCalledWith('setup.runtime_check', { provider: 'openai-codex' })await setOnboardingModel('other-fixture-model', 'openai-codex')- expect(requests.filter(request => request.path === '/api/model/set')).toHaveLength(2)+ // Manual flows defer the global-default flip to the confirm card (#102829):+ // completeWithModelConfirm skips its early persist, so the only /api/model/set+ // is the explicit Change pick (persisted on Begin via confirmOnboardingModel+ // when nothing changes). Owner pinning is what this test guards: every write+ // still carries the flow's initiating owner below.+ expect(requests.filter(request => request.path === '/api/model/set')).toHaveLength(1)expect(requests.some(request => request.path.includes(flow === 'pkce' ? '/submit' : '/poll/'))).toBe(true)expectOwnerRequests()}diff --git a/apps/desktop/src/store/onboarding.test.ts b/apps/desktop/src/store/onboarding.test.tsindex 3215e89f00f..f95c28b0386 100644--- a/apps/desktop/src/store/onboarding.test.ts+++ b/apps/desktop/src/store/onboarding.test.ts@@ -8,6 +8,7 @@ import type { OAuthProvider } from '@/types/hermes'import {$desktopOnboarding,completeDesktopOnboarding,+ confirmOnboardingModel,type DesktopOnboardingState,type OnboardingContext,refreshOnboarding,@@ -158,7 +159,11 @@ describe('refreshOnboarding', () => {await startProviderOAuth(makeOAuthProvider('fixture'), ctx)await vi.waitFor(() => expect($desktopOnboarding.get().flow.status).toBe('confirming_model'), { timeout: 5000 })expect(requests.slice(startAt).some(r => r.path.includes('/poll/'))).toBe(true)- expect(requests.slice(startAt).some(r => r.path === '/api/model/set')).toBe(true)+ // Manual flows defer the global-default flip to the confirm card (#102829):+ // no /api/model/set lands between the OAuth poll and the confirm card.+ // Lifetime/profile pinning is still asserted: everything that DID fire+ // stayed on the initiating profile.+ expect(requests.slice(startAt).some(r => r.path === '/api/model/set')).toBe(false)expect(requests.slice(startAt).every(r => r.profile === 'beta')).toBe(true)} finally {closeManualOnboarding()@@ -645,6 +650,136 @@ describe('OAuth onboarding', () => {})})+describe('manual onboarding (Settings / Add provider on an already-configured install)', () => {+ beforeEach(() => {+ window.localStorage.clear()+ $desktopOnboarding.set(baseState())+ })++ afterEach(() => {+ window.localStorage.clear()+ $desktopOnboarding.set(baseState())+ vi.restoreAllMocks()+ })++ it('does not flip the global default until the user confirms on the confirm card', async () => {+ const model = 'nous/hermes-5'+ const calls: { body?: unknown; path: string }[] = []++ installApiMock(async ({ body, path }: { body?: unknown; path: string }) => {+ calls.push({ body, path })++ if (path === '/api/providers/oauth/nous/submit') {+ return { ok: true, status: 'approved' }+ }++ if (path.startsWith('/api/model/options')) {+ return { providers: [{ name: 'Nous Portal', slug: 'nous', models: [model] }] }+ }++ if (path.startsWith('/api/model/recommended-default?')) {+ return { provider: 'nous', model, free_tier: false }+ }++ if (path === '/api/model/set') {+ return { ok: true, provider: 'nous', model, gateway_tools: [] }+ }++ throw new Error(`unexpected api path: ${path}`)+ })++ const requestGateway: OnboardingContext['requestGateway'] = async (method, params) => {+ if (method === 'reload.env') {+ return {} as never+ }++ if (method === 'setup.status') {+ return { provider_configured: true } as never+ }++ if (method === 'setup.runtime_check') {+ // Still validated against the just-connected provider, not the+ // (unchanged) config default — this is what makes deferring the+ // persist safe.+ expect(params).toEqual({ provider: 'nous' })++ return { ok: true } as never+ }++ throw new Error(`unexpected gateway method: ${method}`)+ }++ // The user already has a working, different default configured — the+ // exact scenario from the bug report (anthropic default, connecting Nous+ // Portal as an *additional* provider from Settings).+ $desktopOnboarding.set(+ baseState({+ manual: true,+ flow: {+ status: 'awaiting_user',+ provider: makeOAuthProvider('nous', 'Nous Portal'),+ start: {+ auth_url: 'https://portal.example/auth',+ expires_in: 600,+ flow: 'pkce',+ session_id: 'portal-session'+ },+ code: 'fresh-code'+ },+ requested: true+ })+ )++ await submitOnboardingCode(onboardingContext(requestGateway))++ const state = $desktopOnboarding.get()+ expect(state.flow.status).toBe('confirming_model')++ // OAuth succeeded and the confirm card is showing the new provider's+ // model, but nothing has been written to config yet.+ expect(calls.some(c => c.path === '/api/model/set')).toBe(false)++ // Dismissing here (closeManualOnboarding) leaves the previous default+ // untouched precisely because this call never fires.+ })++ it('persists the confirmed model only when the user clicks Begin', async () => {+ const model = 'nous/hermes-5'+ const calls: { body?: unknown; path: string }[] = []++ installApiMock(async ({ body, path }: { body?: unknown; path: string }) => {+ calls.push({ body, path })++ if (path === '/api/model/set') {+ return { ok: true, provider: 'nous', model, gateway_tools: [] }+ }++ throw new Error(`unexpected api path: ${path}`)+ })++ $desktopOnboarding.set(+ baseState({+ manual: true,+ configured: true,+ flow: {+ status: 'confirming_model',+ providerSlug: 'nous',+ currentModel: model,+ label: 'Nous Portal',+ saving: false+ }+ })+ )++ const onCompleted = vi.fn()+ await confirmOnboardingModel({ requestGateway: vi.fn(), onCompleted })++ const assign = calls.find(c => c.path === '/api/model/set')+ expect(assign?.body).toMatchObject({ scope: 'main', provider: 'nous', model })+ expect(onCompleted).toHaveBeenCalledTimes(1)+ })+})+describe('saveOnboardingLocalEndpoint', () => {beforeEach(() => {window.localStorage.clear()diff --git a/apps/desktop/src/store/onboarding.ts b/apps/desktop/src/store/onboarding.tsindex f3e7b861279..f8f5f13aa2f 100644--- a/apps/desktop/src/store/onboarding.ts+++ b/apps/desktop/src/store/onboarding.ts@@ -449,10 +449,19 @@ async function completeWithModelConfirm(return}- if (defaults) {- // Persist the chosen provider/model before the runtime gate so a stale- // config provider (e.g. anthropic from a prior failed setup) cannot make- // setup.runtime_check validate the wrong backend after a fresh OAuth login.+ // Manual connect (Settings / model picker "Add provider" on an already-+ // configured install): the global default must NOT change until the user+ // explicitly confirms a model on the confirm card. checkRuntime below+ // already passes preferredSlugs[0] as requestedProvider, so the runtime+ // gate can validate the just-connected provider without persisting first.+ // confirmOnboardingModel persists on Begin instead.+ const manual = $desktopOnboarding.get().manual++ if (defaults && !manual) {+ // First-run only: persist the chosen provider/model before the runtime+ // gate so a stale config provider (e.g. anthropic from a prior failed+ // setup) cannot make setup.runtime_check validate the wrong backend+ // after a fresh OAuth login. There's no prior default to protect here.try {const res = await setMainModelAssignment({@@ -1366,17 +1375,38 @@ export async function setOnboardingModel(model: string, providerSlug: string, la}}-// User clicked "Start chatting" on the confirm card. Finalizes onboarding-// — the model was already persisted by completeWithModelConfirm (or by-// setOnboardingModel if they changed it), so all that's left is to mark-// onboarding done and unblock the rest of the app.-export function confirmOnboardingModel(ctx: OnboardingContext) {- const { flow } = $desktopOnboarding.get()+// User clicked "Start chatting" on the confirm card. First-run: the model+// was already persisted by completeWithModelConfirm (or by setOnboardingModel+// if they changed it), so this only marks onboarding done. Manual connect+// (Settings / "Add provider"): completeWithModelConfirm deliberately skipped+// the persist so the previous default survives a dismiss, so this is where+// the picked model finally gets written — the user just confirmed it.+export async function confirmOnboardingModel(ctx: OnboardingContext) {+ const { flow, manual } = $desktopOnboarding.get()if (flow.status !== 'confirming_model') {return}+ if (manual) {+ // Best-effort: the overlay is already on its way out (cinematic exit+ // choreography in the caller isn't gated on this), so a failure here is+ // reported and swallowed rather than left blocking — same as the rest of+ // this file's non-blocking gateway calls. The alternative (silently+ // keeping the previous default) is still safer than the bug this fixes.+ try {+ const res = await setMainModelAssignment(+ { provider: flow.providerSlug, model: flow.currentModel },+ undefined,+ { skipConfirmPrompt: true }+ )++ notifyGatewayTools(res.gateway_tools)+ } catch (error) {+ notifyError(error, 'Could not save the selected model.')+ }+ }+// No success toast here: the confirm-model screen already showed "<provider>// connected." notifyReady is reserved for completion paths that SKIP this// screen (no-default fallthrough, local endpoint) so feedback isn't lost.