Skip to content

The agent that grows with you

fix(desktop): an end sent while the onboarding chat opens is not missed, and its card goes too

alt-glitch5648d3d465e9
diff --git a/apps/desktop/src/store/onboarding-run.test.ts b/apps/desktop/src/store/onboarding-run.test.ts
index ee7af0d0113..2c7df972500 100644
--- a/apps/desktop/src/store/onboarding-run.test.ts
+++ b/apps/desktop/src/store/onboarding-run.test.ts
@@ -21,15 +21,17 @@ const ensureProfile = async (): Promise<void> => undefined
// What resumeSession does for the test: the stored chat becomes the one on screen.
const resume = vi.fn(async (storedId: string) => $selectedStoredSessionId.set(storedId))
-function backend(state: { eligible: boolean; run: boolean }) {
+// `runId`: the run onboarding.state reports open; null once something ended it.
+function backend(state: { eligible: boolean; run: boolean }, runId: null | string = 'run-1') {
const calls: string[] = []
const started = { resumed: false, run_id: 'run-1', session_id: 'rt-1', stored_session_id: 'st-1' }
+ const read = { ...state, run_id: runId, session_id: runId && 'st-1' }
const request = async <T,>(method: string): Promise<T> => {
calls.push(method)
// SAFETY: the fake answers onboarding.state and onboarding.start with their contract result shapes.
- return (method === 'onboarding.state' ? state : started) as T
+ return (method === 'onboarding.state' ? read : started) as T
}
return { calls, request }
@@ -53,7 +55,8 @@ describe('onboarding run', () => {
await decideOnboarding(request, resume, { ensureProfile })
stop()
- expect(calls).toEqual(['onboarding.state', 'onboarding.start'])
+ // The last read checks for an end sent while the chat was opening.
+ expect(calls).toEqual(['onboarding.state', 'onboarding.start', 'onboarding.state'])
expect(resume).toHaveBeenCalledWith('st-1', true)
expect($onboardingDecided.get()).toBe(true)
expect(clear).not.toContain(true)
@@ -105,6 +108,13 @@ describe('onboarding run', () => {
$sessionTiles.set([])
})
+ it('ends a run that ended while its chat was opening', async () => {
+ const { request } = backend({ eligible: true, run: true }, null)
+
+ await startOnboarding(request, resume, { ensureProfile })
+ await vi.waitFor(() => expect($onboardingEnded.get()).toBe('skipped'))
+ })
+
it('ends a run the backend no longer has open when it re-reads the state', 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 b02185f9d79..63aa7d02c17 100644
--- a/apps/desktop/src/store/onboarding-run.ts
+++ b/apps/desktop/src/store/onboarding-run.ts
@@ -22,10 +22,10 @@ import { ackFreeTierNotice } from './free-tier'
import { clearFreeTierIntro } from './onboarding'
import { $onboardingPhase } from './onboarding-phase'
import { markOnboardingDecided, ONBOARDING_DECIDE_DEADLINE_MS, setOnboardingSurfaceActive } from './onboarding-presence'
-import { $onboardingSession } from './onboarding-session'
+import { $onboardingSession, isOnboardingChat } from './onboarding-session'
import { ensureGatewayProfile, newSessionInProfile } from './profile'
import { $connection, $gatewayState, $selectedStoredSessionId } from './session'
-import { dropSetupBeat } from './setup-beat'
+import { $setupBeatRequests, dropSetupBeat } from './setup-beat'
export type OnboardingRequest = <T = unknown>(
method: string,
@@ -240,10 +240,15 @@ export function noteOnboardingEnded({ outcome, run_id }: OnboardingEndedPayload)
return
}
- dropSetupBeat(session.runtimeId)
+ dropRunCards()
endOnboarding(outcome === 'done' ? 'done' : 'skipped')
}
+// The run's card waits under the chat's current runtime id, which a reconnect replaces.
+function dropRunCards(): void {
+ Object.keys($setupBeatRequests.get()).filter(isOnboardingChat).forEach(dropSetupBeat)
+}
+
/** An end this window missed (a reconnect, a backend restart): the run it shows is no longer the run
* in progress. */
export async function reconcileOnboarding(request: OnboardingRequest): Promise<void> {
@@ -256,6 +261,7 @@ export async function reconcileOnboarding(request: OnboardingRequest): Promise<v
const state = await request<OnboardingRunStateResult>('onboarding.state')
if ($onboardingSession.get() === session && state.run_id !== session.runId) {
+ dropRunCards()
endOnboarding('skipped')
}
}
@@ -275,4 +281,7 @@ function watchRunEnd(request: OnboardingRequest): void {
offGateway()
window.removeEventListener('focus', check)
}
+
+ // An end sent while the chat was opening found no session here to end.
+ check()
}