Skip to content

The agent that grows with you

fix(desktop): peer windows read the onboarding state, so their pickers and offers are not stuck

alt-glitchd2b6af4a99ba
diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsx
index 355455a3b8f..35ba636524b 100644
--- a/apps/desktop/src/app/contrib/wiring.tsx
+++ b/apps/desktop/src/app/contrib/wiring.tsx
@@ -1294,11 +1294,12 @@ export function ContribWiring({ children }: { children: ReactNode }) {
{/* The full real overlay set (mirrors DesktopController's `overlays`). */}
<RemoteDisplayBanner />
{!isAuxiliaryWindow() && <DesktopInstallOverlay />}
- {isMainWindow() && (
+ {!isAuxiliaryWindow() && (
<OnboardingChatGate
enabled={gatewayState === 'open'}
onKickoff={kickoffFirstChat}
requestGateway={ambientRequestGateway}
+ runsIntro={isMainWindow()}
/>
)}
{!isAuxiliaryWindow() && (
diff --git a/apps/desktop/src/components/onboarding-chat/gate.test.tsx b/apps/desktop/src/components/onboarding-chat/gate.test.tsx
new file mode 100644
index 00000000000..194551cb844
--- /dev/null
+++ b/apps/desktop/src/components/onboarding-chat/gate.test.tsx
@@ -0,0 +1,62 @@
+import type { OnboardingStateResult } from '@hermes/shared'
+import { cleanup, render, waitFor } from '@testing-library/react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+// The gate's stores are module singletons; each test loads a fresh window's worth.
+async function loadWindow() {
+ vi.resetModules()
+
+ const [{ OnboardingChatGate }, gate, onboarding] = await Promise.all([
+ import('./gate'),
+ import('@/store/onboarding-gate'),
+ import('@/store/onboarding')
+ ])
+
+ return { OnboardingChatGate, gate, onboarding }
+}
+
+const UNSEEN_STATE: OnboardingStateResult = { eligible: true, intro: 'unseen', failed_starts: 0, profile: 'setup' }
+
+const unseenFirstRun = async <T,>(method: string): Promise<T> => {
+ const reply = method === 'onboarding.state' ? UNSEEN_STATE : {}
+
+ // SAFETY: the gate reads `onboarding.state` as OnboardingStateResult; any other call only awaits the reply.
+ return reply as T
+}
+
+const neverKicksOff = () => new Promise<never>(() => {})
+
+beforeEach(() => {
+ Object.assign(window, { hermesDesktop: { guestOnboardingEnabled: true } })
+})
+
+afterEach(() => {
+ cleanup()
+ Reflect.deleteProperty(window, 'hermesDesktop')
+})
+
+describe('OnboardingChatGate', () => {
+ it('lets a window that does not run the intro open the provider picker once the state is read', async () => {
+ const { OnboardingChatGate, gate, onboarding } = await loadWindow()
+
+ onboarding.requestDesktopOnboarding('No provider configured')
+ render(
+ <OnboardingChatGate enabled onKickoff={neverKicksOff} requestGateway={unseenFirstRun} runsIntro={false} />
+ )
+
+ await waitFor(() => expect(onboarding.$desktopOnboarding.get().requested).toBe(true))
+ expect(gate.$onboardingGate.get().phase).toBe('idle')
+ expect(gate.$setupProfileName.get()).toBe('setup')
+ })
+
+ it('queues the guided first run in the window that runs the intro', async () => {
+ const { OnboardingChatGate, gate, onboarding } = await loadWindow()
+
+ onboarding.requestDesktopOnboarding('No provider configured')
+ render(<OnboardingChatGate enabled onKickoff={neverKicksOff} requestGateway={unseenFirstRun} runsIntro />)
+
+ await waitFor(() => expect(gate.$onboardingStateRead.get()).toBe(true))
+ expect(gate.$onboardingGate.get().phase).toBe('pending')
+ expect(onboarding.$desktopOnboarding.get().requested).toBe(false)
+ })
+})
diff --git a/apps/desktop/src/components/onboarding-chat/gate.tsx b/apps/desktop/src/components/onboarding-chat/gate.tsx
index f614d91774c..505c9edd566 100644
--- a/apps/desktop/src/components/onboarding-chat/gate.tsx
+++ b/apps/desktop/src/components/onboarding-chat/gate.tsx
@@ -22,10 +22,12 @@ interface OnboardingChatGateProps {
enabled: boolean
onKickoff: () => Promise<GuideKickoffResult>
requestGateway: FreeTierRequester
+ /** Only the main window runs the intro. Every window still reads the state: the provider picker,
+ * the free-tier introduction and the usage-stats offer wait on that read (afterOnboardingStateRead). */
+ runsIntro: boolean
}
-/** Mounted in the main window only: secondary windows never run the intro. */
-export function OnboardingChatGate({ enabled, onKickoff, requestGateway }: OnboardingChatGateProps) {
+export function OnboardingChatGate({ enabled, onKickoff, requestGateway, runsIntro }: OnboardingChatGateProps) {
const gate = useStore($onboardingGate)
useEffect(() => {
@@ -37,6 +39,11 @@ export function OnboardingChatGate({ enabled, onKickoff, requestGateway }: Onboa
.then(
state => {
$setupProfileName.set(state.profile ?? null)
+
+ if (!runsIntro) {
+ return
+ }
+
beginOnboardingFlow(state)
if ($onboardingGate.get().guideQueued) {
@@ -46,7 +53,7 @@ export function OnboardingChatGate({ enabled, onKickoff, requestGateway }: Onboa
error => console.warn('[onboarding] state could not be read', error)
)
.finally(markOnboardingStateRead)
- }, [enabled, requestGateway])
+ }, [enabled, requestGateway, runsIntro])
useEffect(() => {
if (!enabled || !isOnboardingEnabled()) {