Skip to content

The agent that grows with you

fix(desktop): sign-in waits for the local-model choice through a restart before connecting

alt-glitch2f2fd13c9c62
diff --git a/apps/desktop/src/components/onboarding/onboarding-end.test.tsx b/apps/desktop/src/components/onboarding/onboarding-end.test.tsx
index a20d1c54944..7a640b0e9f5 100644
--- a/apps/desktop/src/components/onboarding/onboarding-end.test.tsx
+++ b/apps/desktop/src/components/onboarding/onboarding-end.test.tsx
@@ -1,6 +1,9 @@
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import type { HermesConnection } from '@/global'
+import { writeKey } from '@/lib/storage'
+import { $localModelOfferPending, LOCAL_MODEL_PENDING_KEY } from '@/store/local-model-offer'
import { $localSetupEligibility } from '@/store/local-setup-offer'
import { markOnboardingDecided } from '@/store/onboarding-presence'
import { $onboardingSettleFrom } from '@/store/onboarding-run'
@@ -28,22 +31,24 @@ const MODEL: LocalCatalogModel = {
fit_summary: 'runs at its full 256K context'
}
+const LOCAL: HermesConnection = {
+ baseUrl: 'http://127.0.0.1:1',
+ isFullscreen: false,
+ logs: [],
+ mode: 'local',
+ nativeOverlayWidth: 0,
+ token: '',
+ windowButtonPosition: null,
+ wsUrl: 'ws://127.0.0.1:1'
+}
+
beforeEach(() => {
vi.useFakeTimers()
// The quiet check: a focused, visible window with the boot onboarding check answered.
vi.spyOn(window.document, 'hasFocus').mockReturnValue(true)
vi.spyOn(window.document, 'visibilityState', 'get').mockReturnValue('visible')
markOnboardingDecided()
- $connection.set({
- baseUrl: 'http://127.0.0.1:1',
- isFullscreen: false,
- logs: [],
- mode: 'local',
- nativeOverlayWidth: 0,
- token: '',
- windowButtonPosition: null,
- wsUrl: 'ws://127.0.0.1:1'
- })
+ $connection.set(LOCAL)
// Set after the connection, whose change drops the cached answer.
$localSetupEligibility.set({ checkedAt: Date.now(), fit: { model: MODEL }, reason: 'test' })
})
@@ -86,4 +91,19 @@ describe('OnboardingEnd', () => {
await act(() => vi.advanceTimersByTimeAsync(SETTLED_MS))
expect(screen.getByText(TITLE)).toBeTruthy()
})
+
+ it('keeps sign-in waiting through a restart that mounts before the connection is up', async () => {
+ writeKey(LOCAL_MODEL_PENDING_KEY, String(Date.now()))
+ $connection.set(null)
+ $localModelOfferPending.set(true)
+
+ render(<OnboardingEnd />)
+ await act(() => vi.advanceTimersByTimeAsync(0))
+ expect($localModelOfferPending.get()).toBe(true)
+
+ // The machine it connects to cannot run a local model: now the sign-in offer may go first.
+ act(() => $connection.set({ ...LOCAL, mode: 'remote' }))
+ await act(() => vi.advanceTimersByTimeAsync(0))
+ expect($localModelOfferPending.get()).toBe(false)
+ })
})
diff --git a/apps/desktop/src/components/onboarding/onboarding-end.tsx b/apps/desktop/src/components/onboarding/onboarding-end.tsx
index 640898ad8b1..f9eaa6f9337 100644
--- a/apps/desktop/src/components/onboarding/onboarding-end.tsx
+++ b/apps/desktop/src/components/onboarding/onboarding-end.tsx
@@ -20,7 +20,7 @@ import {
LOCAL_MODEL_OFFERED_KEY,
LOCAL_MODEL_PENDING_KEY
} from '@/store/local-model-offer'
-import { readLocalSetupEligibility } from '@/store/local-setup-offer'
+import { readConnectedLocalSetupEligibility, readLocalSetupEligibility } from '@/store/local-setup-offer'
import { $onboardingSettleFrom } from '@/store/onboarding-run'
import { requestRoute } from '@/store/recovery-requests'
import type { LocalCatalogModel } from '@/types/hermes'
@@ -53,8 +53,8 @@ export function OnboardingEnd() {
$localModelOfferPending.set(true)
// A machine that cannot run a local model (or cannot be read) gets no offer, so the sign-in offer
- // stops waiting.
- void readLocalSetupEligibility().then(
+ // stops waiting. Before the connection is up nothing is known yet, so it keeps waiting until it is.
+ void readConnectedLocalSetupEligibility().then(
({ fit }) => !fit && $localModelOfferPending.set(false),
() => $localModelOfferPending.set(false)
)
diff --git a/apps/desktop/src/store/local-setup-offer.ts b/apps/desktop/src/store/local-setup-offer.ts
index 1b449af5f9c..4b115dc997d 100644
--- a/apps/desktop/src/store/local-setup-offer.ts
+++ b/apps/desktop/src/store/local-setup-offer.ts
@@ -74,6 +74,22 @@ export function readLocalSetupEligibility(): Promise<Eligibility> {
return cached && !cached.transient ? Promise.resolve(cached) : refreshLocalSetupEligibility()
}
+/** The answer once a connection is up: before that there is no machine to read, so it waits for one. */
+export function readConnectedLocalSetupEligibility(): Promise<Eligibility> {
+ if ($connection.get()?.mode) {
+ return readLocalSetupEligibility()
+ }
+
+ return new Promise(resolve => {
+ const stop = $connection.listen(connection => {
+ if (connection?.mode) {
+ stop()
+ resolve(readLocalSetupEligibility())
+ }
+ })
+ })
+}
+
/** Read again, keeping the current answer on screen until the new one lands. */
export function refreshLocalSetupEligibility(): Promise<Eligibility> {
const mode = $connection.get()?.mode ?? null