The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): stop a lost readiness race re-arming the first-run picker
Brooklyn Nicholsona6faf23851a0
diff --git a/apps/desktop/src/components/onboarding/index.tsx b/apps/desktop/src/components/onboarding/index.tsxindex 1bd1649ea8e..b86978f93ad 100644--- a/apps/desktop/src/components/onboarding/index.tsx+++ b/apps/desktop/src/components/onboarding/index.tsx@@ -305,8 +305,13 @@ export function DesktopOnboardingOverlay({const current = $desktopOnboarding.get()return (+ // `!== true` rather than `=== false`: an UNRESOLVED readiness state+ // (a boot round whose probes both timed out) is left at `null`+ // instead of being written down as unconfigured, and it needs this+ // tick to settle too — otherwise the overlay sits on its+ // "starting" header with nothing left to re-check it.!current.manual &&- current.configured === false &&+ current.configured !== true &¤t.flow.status === 'idle' &¤t.mode === 'oauth' &&!current.localEndpointdiff --git a/apps/desktop/src/store/onboarding.test.ts b/apps/desktop/src/store/onboarding.test.tsindex 7e73f3ce94b..da0e77c767f 100644--- a/apps/desktop/src/store/onboarding.test.ts+++ b/apps/desktop/src/store/onboarding.test.ts@@ -7,6 +7,7 @@ import type { OAuthProvider } from '@/types/hermes'import {$desktopOnboarding,+ completeDesktopOnboarding,type DesktopOnboardingState,type OnboardingContext,refreshOnboarding,@@ -273,6 +274,45 @@ describe('refreshOnboarding', () => {}})+ it('leaves configured unknown on a boot fallback instead of erasing the cache', async () => {+ const notifySpy = vi.spyOn(notifications, 'notify')++ installApiMock(vi.fn())+ // Cold launch, no onboarded cache yet: `configured` is UNKNOWN, not false.+ // A round that loses the race to a cold/queued backend answers neither+ // probe, and recording that as "no provider" deleted the cache — which+ // re-armed the blocking first-run picker on every launch afterwards.+ $desktopOnboarding.set(baseState({ configured: null, providers: null, requested: false }))++ const ready = await refreshOnboarding(onboardingContext(fallbackTimeoutGateway()))++ expect(ready).toBe(false)+ expect($desktopOnboarding.get().configured).toBeNull()+ expect(window.localStorage.getItem('hermes-desktop-onboarded-v1')).toBeNull()+ // Nothing was ever verified, so there is no outage worth a toast.+ expect(notifySpy).not.toHaveBeenCalled()+ })++ it('keeps a persisted "choose later" when a passive round completes onboarding', () => {+ window.localStorage.setItem('hermes-onboarding-skipped-v1', '1')+ $desktopOnboarding.set(baseState({ configured: null, firstRunSkipped: true }))++ completeDesktopOnboarding()++ expect(window.localStorage.getItem('hermes-onboarding-skipped-v1')).toBe('1')+ expect($desktopOnboarding.get().firstRunSkipped).toBe(true)+ })++ it('clears the skip only when the user actually connected a provider', () => {+ window.localStorage.setItem('hermes-onboarding-skipped-v1', '1')+ $desktopOnboarding.set(baseState({ configured: null, firstRunSkipped: true }))++ completeDesktopOnboarding(true)++ expect(window.localStorage.getItem('hermes-onboarding-skipped-v1')).toBeNull()+ expect($desktopOnboarding.get().firstRunSkipped).toBe(false)+ })+it('enters setup when the selected OpenRouter credential is genuinely empty', async () => {installApiMock(vi.fn())window.localStorage.setItem('hermes-desktop-onboarded-v1', '1')diff --git a/apps/desktop/src/store/onboarding.ts b/apps/desktop/src/store/onboarding.tsindex 64913e8cdce..1176efae6d4 100644--- a/apps/desktop/src/store/onboarding.ts+++ b/apps/desktop/src/store/onboarding.ts@@ -239,9 +239,16 @@ async function checkRuntime(ctx: OnboardingContext, requestedProvider?: string):}function shouldPreserveConfiguredOnFallback(runtime: RuntimeReadinessResult, state: DesktopOnboardingState): boolean {- // Non-authoritative transport fallback only — keep a previously verified- // configured state instead of forcing the blocking onboarding overlay.- return runtime.source === 'fallback' && state.configured === true && !state.requested+ // Non-authoritative transport fallback only: NEITHER probe answered, so the+ // round carries no evidence either way and must never be written down as+ // "unconfigured". This used to require an in-memory `configured === true`,+ // which on a cold launch can only come from the onboarded cache — the very+ // cache an earlier fallback had already deleted. One readiness round that+ // lost the race to a cold/queued backend therefore re-armed the blocking+ // first-run picker on EVERY launch afterwards, on installs with a perfectly+ // good provider. `configured === null` (still unknown) now also holds: the+ // overlay keeps its "starting" header until a probe actually answers.+ return runtime.source === 'fallback' && state.configured !== false && !state.requested}function notifyReady(provider: string) {@@ -441,7 +448,7 @@ async function completeWithModelConfirm(if (!defaults) {// Couldn't get a sensible default — proceed without confirm step.notifyReady(providerLabel)- completeDesktopOnboarding()+ completeDesktopOnboarding(true)ctx.onCompleted?.()return@@ -643,13 +650,21 @@ export function closeManualOnboarding() {})}-export function completeDesktopOnboarding() {+/** `connected` marks the completion paths where a provider sign-in / key save+ * in THIS flow is what finished onboarding. Only those make an earlier+ * "choose later" moot. A passive readiness round must leave the skip alone:+ * clearing it there erased the user's explicit decision, so the next round+ * that came back not-ready was free to raise the blocking picker again — the+ * set/clear flip-flop behind "the setup screen returns on every launch". */+export function completeDesktopOnboarding(connected = false) {clearPoll()dismissNotification('runtime-not-ready')writeCachedConfigured(true)- // A real provider is now connected, so any earlier "choose later" skip is- // moot — clear it so the flag never lingers in a configured install.- writeCachedSkipped(false)++ if (connected) {+ writeCachedSkipped(false)+ }+$desktopOnboarding.set({configured: true,flow: { status: 'idle' },@@ -657,7 +672,7 @@ export function completeDesktopOnboarding() {providers: null,reason: null,requested: false,- firstRunSkipped: false,+ firstRunSkipped: connected ? false : readCachedSkipped(),manual: false,localEndpoint: false,freeTierReady: false@@ -721,16 +736,22 @@ export async function refreshOnboarding(ctx: OnboardingContext, stillWanted?: ()const state = $desktopOnboarding.get()if (shouldPreserveConfiguredOnFallback(runtime, state)) {- // Gateway probes timed out but the user was already configured — don't- // downgrade to the blocking onboarding overlay or claim an error verdict.- // Use the temporary informational notice; recovery clears it early.- notify({- id: 'runtime-not-ready',- kind: 'info',- title: 'Runtime not ready',- message:- 'Hermes Desktop could not verify the running backend on startup. Some features may be unavailable until the gateway is reachable.'- })+ // Gateway probes timed out — don't downgrade to the blocking onboarding+ // overlay or claim an error verdict. Only a previously VERIFIED install+ // losing its backend is worth telling the user about; an unknown state is+ // just a round that landed before the backend could answer, and a notice+ // on every cold launch would be noise. Use the temporary informational+ // notice with a stable id, so repeated calls during an outage dedup and+ // recovery clears it early.+ if (state.configured === true) {+ notify({+ id: 'runtime-not-ready',+ kind: 'info',+ title: 'Runtime not ready',+ message:+ 'Hermes Desktop could not verify the running backend on startup. Some features may be unavailable until the gateway is reachable.'+ })+ }return false}@@ -1214,7 +1235,7 @@ export async function saveOnboardingLocalEndpoint(}notifyReady('Local / custom endpoint')- completeDesktopOnboarding()+ completeDesktopOnboarding(true)ctx.onCompleted?.()return { ok: true }@@ -1297,6 +1318,6 @@ export function confirmOnboardingModel(ctx: OnboardingContext) {// 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.- completeDesktopOnboarding()+ completeDesktopOnboarding(true)ctx.onCompleted?.()}