The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a slow onboarding start waits for the backend instead of timing out
alt-glitch82d8a2e959c8
diff --git a/apps/desktop/src/components/onboarding/first-run/kickoff.test.ts b/apps/desktop/src/components/onboarding/first-run/kickoff.test.tsindex 9ba6c461fdb..e0fe906ff4a 100644--- a/apps/desktop/src/components/onboarding/first-run/kickoff.test.ts+++ b/apps/desktop/src/components/onboarding/first-run/kickoff.test.ts@@ -1,9 +1,10 @@import type { OnboardingStartResult } from '@hermes/shared'import { beforeEach, describe, expect, it, vi } from 'vitest'-import { $chatOnboardingSolo, $introView } from '@/store/onboarding-intro'+import { BACKEND_BOOT_WAIT_TIMEOUT_MS } from '@/lib/with-timeout'+import { $chatOnboardingSolo, $introStartExit, $introView } from '@/store/onboarding-intro'import { $onboardingPhase } from '@/store/onboarding-phase'-import { startOnboarding } from '@/store/onboarding-run'+import { type OnboardingRequest, startOnboarding } from '@/store/onboarding-run'import { $activeSessionId, $connection, $selectedStoredSessionId } from '@/store/session'import { $introCopy } from './intro'@@ -52,4 +53,26 @@ describe('first-run kickoff', () => {// A blank chat plays main's intro copy; the backend's greeting row replaces it.expect($introCopy.get()).toBe('playing')})++ it('waits on a slow start with no deadline, and the way out fails it', async () => {+ vi.useFakeTimers()+ const deadlines: (number | undefined)[] = []++ // A cold start that answers only when abandoned.+ const slow: OnboardingRequest = async <T>(...[, , timeoutMs, signal]: Parameters<OnboardingRequest>): Promise<T> => {+ deadlines.push(timeoutMs)++ return new Promise<T>((_resolve, reject) => signal?.addEventListener('abort', () => reject(new Error('aborted'))))+ }++ const opening = startOnboarding(slow, adopt, { ensureProfile, intro: firstRunIntro() })+ await vi.advanceTimersByTimeAsync(BACKEND_BOOT_WAIT_TIMEOUT_MS)+ $introStartExit.get()?.()+ vi.useRealTimers()++ expect(await opening).toBe(false)+ expect(deadlines).toEqual([0])+ expect($introView.get()).toBe('off')+ expect($onboardingPhase.get()).toBe('failed')+ })})diff --git a/apps/desktop/src/components/onboarding/first-run/kickoff.ts b/apps/desktop/src/components/onboarding/first-run/kickoff.tsindex e619dcb9d2b..4144f9a1751 100644--- a/apps/desktop/src/components/onboarding/first-run/kickoff.ts+++ b/apps/desktop/src/components/onboarding/first-run/kickoff.ts@@ -20,10 +20,10 @@ function hasAssistantWords(runtimeId: null | string): boolean {/*** Main's first-run start around `onboarding.start`: the boot overlay holds, the window takes the demo* layout once the start answers, and the intro opens once the returned chat is the one on screen.- * Past the boot budget the starting screen offers a way out; the chat then stays closed this launch.+ * `onboarding.start` has no deadline: past the boot budget the starting screen offers a way out, which+ * fails the start (`failed` below) so the chat stays closed this launch.*/export function firstRunIntro(): OnboardingIntroHooks {- let abandoned = falselet offerExit: ReturnType<typeof setTimeout> | undefinedconst clearExit = () => {@@ -32,29 +32,14 @@ export function firstRunIntro(): OnboardingIntroHooks {}return {- starting: () => {+ starting: abandon => {startIntro()$introTurnSent.set(false)- offerExit = setTimeout(- () =>- $introStartExit.set(() => {- abandoned = true- clearExit()- failIntro()- }),- BACKEND_BOOT_WAIT_TIMEOUT_MS- )+ offerExit = setTimeout(() => $introStartExit.set(abandon), BACKEND_BOOT_WAIT_TIMEOUT_MS)},started: () => {clearExit()-- if (abandoned) {- return false- }-openDemoLayout()-- return true},opened: (started: OnboardingStartResult) => {const runtimeId = $activeSessionId.get()diff --git a/apps/desktop/src/store/onboarding-run.ts b/apps/desktop/src/store/onboarding-run.tsindex 6b04341a71e..c0ea7f1b705 100644--- a/apps/desktop/src/store/onboarding-run.ts+++ b/apps/desktop/src/store/onboarding-run.ts@@ -20,7 +20,15 @@ import { ensureGatewayProfile } from './profile'import { $connection, $selectedStoredSessionId } from './session'import type { SetupBeatToolResult } from './setup-beat'-export type OnboardingRequest = GatewayRequester+export type OnboardingRequest = <T = unknown>(+ method: string,+ params?: Parameters<GatewayRequester>[1],+ timeoutMs?: number,+ signal?: AbortSignal+) => Promise<T>++// A cold first boot answers onboarding.start late; the intro's way-out offer bounds the wait instead.+const NO_DEADLINE = 0/** Opens a stored session on screen, replacing the route (`useSessionActions().resumeSession`). */export type OnboardingResume = (storedId: string, replaceRoute?: boolean) => Promise<void>@@ -92,10 +100,11 @@ async function factsSource(request: OnboardingRequest): Promise<'local' | 'remot/** The first-run intro around a start (`components/onboarding/first-run/kickoff.ts`). */export interface OnboardingIntroHooks {- /** Before `onboarding.start`: the boot overlay holds. */- starting: () => void- /** The start answered, the chat not open yet. False: the user went on without setup, so it stays closed. */- started: (started: OnboardingStartResult) => boolean+ /** Before `onboarding.start`: the boot overlay holds. `abandon`: the user went on without setup; the+ * start fails and the chat stays closed. */+ starting: (abandon: () => void) => void+ /** The start answered, the chat not open yet. */+ started: (started: OnboardingStartResult) => void/** The chat is the one on screen. */opened: (started: OnboardingStartResult) => voidfailed: () => void@@ -117,23 +126,21 @@ export async function startOnboarding($onboardingPhase.set('shown')$onboardingEnded.set(null)$onboardingChatSeen.set(false)- intro?.starting()++ const abandon = new AbortController()+ intro?.starting(() => abandon.abort())try {await ensureProfile(ONBOARDING_PROFILE)- const started = await request<OnboardingStartResult>('onboarding.start', {- facts_source: await factsSource(request),- locale: getRuntimeI18nLocale(),- rerun- })-- if (intro && !intro.started(started)) {- $onboardingSession.set(null)- $onboardingPhase.set('failed')+ const started = await request<OnboardingStartResult>(+ 'onboarding.start',+ { facts_source: await factsSource(request), locale: getRuntimeI18nLocale(), rerun },+ NO_DEADLINE,+ abandon.signal+ )- return false- }+ intro?.started(started)// The chat is on screen before the run names it, so the presence never sees a gap.await resume(started.stored_session_id, true)@@ -142,7 +149,11 @@ export async function startOnboarding(return true} catch (error) {- console.warn('[onboarding] could not start', error)+ // Going on without setup is the user's choice, not an error.+ if (!abandon.signal.aborted) {+ console.warn('[onboarding] could not start', error)+ }+$onboardingSession.set(null)$onboardingPhase.set('failed')intro?.failed()