Skip to content

The agent that grows with you

fix(desktop): a failed onboarding start returns the window to its launch profile

alt-glitchd59c943abb54
diff --git a/apps/desktop/src/store/onboarding-run.test.ts b/apps/desktop/src/store/onboarding-run.test.ts
index a1e4b902fa9..d54a9ffe5ab 100644
--- a/apps/desktop/src/store/onboarding-run.test.ts
+++ b/apps/desktop/src/store/onboarding-run.test.ts
@@ -10,6 +10,7 @@ import {
skipOnboarding,
startOnboarding
} from './onboarding-run'
+import { $activeGatewayProfile } from './profile'
import { $connection, $selectedStoredSessionId } from './session'
const ensureProfile = async (): Promise<void> => undefined
@@ -90,6 +91,16 @@ describe('onboarding run', () => {
expect($onboardingEnded.get()).toBeNull()
})
+ it('returns the window to the profile it launched on when the start fails', async () => {
+ $activeGatewayProfile.set('work')
+ const switched = vi.fn(async (_profile: string) => undefined)
+ const refuse = async (): Promise<never> => Promise.reject(new Error('backend down'))
+
+ expect(await startOnboarding(refuse, resume, { ensureProfile: switched })).toBe(false)
+ expect(switched.mock.calls).toEqual([['default'], ['work']])
+ $activeGatewayProfile.set('default')
+ })
+
it('keeps the run when the backend refuses the skip', async () => {
const { request } = backend({ eligible: true, run: true })
await startOnboarding(request, resume, { ensureProfile })
diff --git a/apps/desktop/src/store/onboarding-run.ts b/apps/desktop/src/store/onboarding-run.ts
index c0ea7f1b705..369f5d9ac04 100644
--- a/apps/desktop/src/store/onboarding-run.ts
+++ b/apps/desktop/src/store/onboarding-run.ts
@@ -14,9 +14,10 @@ import { atom, computed } from 'nanostores'
import { getRuntimeI18nLocale } from '@/i18n/runtime'
import type { GatewayRequester } from '@/lib/yolo-session'
+import { activeGatewayConnectionId } from './gateway'
import { $onboardingPhase } from './onboarding-phase'
import { markOnboardingDecided, setOnboardingSurfaceActive } from './onboarding-presence'
-import { ensureGatewayProfile } from './profile'
+import { $activeGatewayProfile, ensureGatewayAgent, ensureGatewayProfile } from './profile'
import { $connection, $selectedStoredSessionId } from './session'
import type { SetupBeatToolResult } from './setup-beat'
@@ -51,6 +52,14 @@ export const $onboardingSettleFrom = atom<null | number>(null)
// The backend runs onboarding in its root profile whichever profile the app was on.
const ONBOARDING_PROFILE = 'default'
+/** The profile (and registry source) the window was on before the run moved it to the default profile. */
+interface LaunchSource {
+ connectionId: null | string
+ profile: string
+}
+
+let launch: LaunchSource | null = null
+
/** The run's chat has been on screen at least once; until then a route still opening is not a leave. */
const $onboardingChatSeen = atom(false)
@@ -129,6 +138,7 @@ export async function startOnboarding(
const abandon = new AbortController()
intro?.starting(() => abandon.abort())
+ launch = { connectionId: activeGatewayConnectionId(), profile: $activeGatewayProfile.get() }
try {
await ensureProfile(ONBOARDING_PROFILE)
@@ -157,11 +167,27 @@ export async function startOnboarding(
$onboardingSession.set(null)
$onboardingPhase.set('failed')
intro?.failed()
+ await returnToLaunchProfile(ensureProfile)
return false
}
}
+// Like main's failed kickoff: the window goes back to where it was before the switch.
+async function returnToLaunchProfile(ensureProfile: (profile: string) => Promise<void>): Promise<void> {
+ if (!launch) {
+ return
+ }
+
+ const { connectionId, profile } = launch
+
+ try {
+ await (connectionId ? ensureGatewayAgent(connectionId, profile) : ensureProfile(profile))
+ } catch (error) {
+ console.warn('[onboarding] could not return to the launch profile', error)
+ }
+}
+
let decision: null | Promise<void> = null
/**