Skip to content

The agent that grows with you

fix(desktop): only the run's own computer can end onboarding on a re-read

alt-glitch122f5b9eb73f
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
index 3e1b9a50747..25c56d6074c 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
@@ -913,7 +913,12 @@ describe('useComposerSubmit with a setup card waiting in the onboarding chat', (
it('closes the card unanswered and sends the words as the next turn, never into the card turn', () => {
$onboardingPhase.set('shown')
- $onboardingSession.set({ runId: 'run-1', runtimeId: 'runtime-session', storedId: 'stored-session' })
+ $onboardingSession.set({
+ connectionId: null,
+ runId: 'run-1',
+ runtimeId: 'runtime-session',
+ storedId: 'stored-session'
+ })
const respond = parkCard('layout')
const { hook, onSteer, onSubmit, queueCurrentDraft } = renderSubmitHook({
@@ -935,7 +940,12 @@ describe('useComposerSubmit with a setup card waiting in the onboarding chat', (
it('takes words typed on the name card as the name, and sends no message', () => {
$onboardingPhase.set('shown')
- $onboardingSession.set({ runId: 'run-1', runtimeId: 'runtime-session', storedId: 'stored-session' })
+ $onboardingSession.set({
+ connectionId: null,
+ runId: 'run-1',
+ runtimeId: 'runtime-session',
+ storedId: 'stored-session'
+ })
const respond = parkCard('name')
const { clearDraft, hook, onSteer, onSubmit, queueCurrentDraft } = renderSubmitHook({ busy: true, text: 'Sid' })
diff --git a/apps/desktop/src/components/assistant-ui/thread/streaming.test.tsx b/apps/desktop/src/components/assistant-ui/thread/streaming.test.tsx
index b0614e95951..33933f676a6 100644
--- a/apps/desktop/src/components/assistant-ui/thread/streaming.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/streaming.test.tsx
@@ -706,7 +706,7 @@ describe('assistant-ui streaming renderer', () => {
it('keeps streaming reasoning collapsed in the onboarding chat', () => {
$activeSessionId.set('onboarding-chat')
- $onboardingSession.set({ runId: 'run-1', runtimeId: 'onboarding-chat', storedId: 'stored-onboarding' })
+ $onboardingSession.set({ connectionId: null, runId: 'run-1', runtimeId: 'onboarding-chat', storedId: 'stored-onboarding' })
$onboardingPhase.set('shown')
const { container } = render(<RunningReasoningHarness />)
diff --git a/apps/desktop/src/store/onboarding-run.test.ts b/apps/desktop/src/store/onboarding-run.test.ts
index 8c6becec3e7..881d3161e14 100644
--- a/apps/desktop/src/store/onboarding-run.test.ts
+++ b/apps/desktop/src/store/onboarding-run.test.ts
@@ -1,5 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { setPrimaryGatewayConnectionId } from './gateway'
import { $onboardingPhase } from './onboarding-phase'
import { $onboardingDecided, $onboardingSurfaceClear } from './onboarding-presence'
import {
@@ -46,6 +47,7 @@ function backend(state: { eligible: boolean; run: boolean }, runId: null | strin
beforeEach(() => {
// SAFETY: factsSource reads only `mode`; a local connection skips the machine comparison.
$connection.set({ mode: 'local' } as never)
+ setPrimaryGatewayConnectionId('local')
$onboardingPhase.set('idle')
$onboardingEnded.set(null)
$onboardingSettleFrom.set(null)
@@ -153,6 +155,22 @@ describe('onboarding run', () => {
expect($onboardingEnded.get()).toBe('skipped')
})
+ it('keeps the run while the window reads another computer, and re-reads on its own', async () => {
+ const { request } = backend({ eligible: true, run: true })
+ await startOnboarding(request, resume, { ensureProfile })
+
+ // SAFETY: the fake answers onboarding.state with its contract result shape.
+ const noRun = async <T,>(): Promise<T> => ({ eligible: true, run: false, run_id: null, session_id: null }) as T
+
+ setPrimaryGatewayConnectionId('homelab')
+ await reconcileOnboarding(noRun)
+ expect($onboardingPhase.get()).toBe('shown')
+
+ setPrimaryGatewayConnectionId('local')
+ await reconcileOnboarding(noRun)
+ expect($onboardingEnded.get()).toBe('skipped')
+ })
+
it('stays on the default profile when the start fails', async () => {
$activeGatewayProfile.set('work')
const switched = vi.fn(async (_profile: string) => undefined)
diff --git a/apps/desktop/src/store/onboarding-run.ts b/apps/desktop/src/store/onboarding-run.ts
index eecd895b23c..00f4870e429 100644
--- a/apps/desktop/src/store/onboarding-run.ts
+++ b/apps/desktop/src/store/onboarding-run.ts
@@ -19,6 +19,7 @@ import { getRuntimeI18nLocale } from '@/i18n/runtime'
import type { GatewayRequester } from '@/lib/yolo-session'
import { ackFreeTierNotice } from './free-tier'
+import { activeGatewayConnectionId } from './gateway'
import { clearFreeTierIntro } from './onboarding'
import { $onboardingPhase } from './onboarding-phase'
import { markOnboardingDecided, ONBOARDING_DECIDE_DEADLINE_MS, setOnboardingSurfaceActive } from './onboarding-presence'
@@ -130,6 +131,7 @@ export async function startOnboarding(
try {
await ensureProfile(ONBOARDING_PROFILE)
+ const connectionId = activeGatewayConnectionId()
// The request stays alive past the way out: its answer names the run the skip ends.
const started = await request<OnboardingStartResult>(
@@ -148,7 +150,12 @@ export async function startOnboarding(
// The chat is on screen before the run names it, so the presence never sees a gap.
await resume(started.stored_session_id, true)
- $onboardingSession.set({ runId: started.run_id, runtimeId: started.session_id, storedId: started.stored_session_id })
+ $onboardingSession.set({
+ connectionId,
+ runId: started.run_id,
+ runtimeId: started.session_id,
+ storedId: started.stored_session_id
+ })
watchRunEnd(request)
if (intro) {
@@ -255,11 +262,12 @@ export function noteOnboardingEnded({ outcome, run_id }: OnboardingEndedPayload)
}
/** An end this window missed (a reconnect, a backend restart): the run it shows is no longer the run
- * in progress. */
+ * in progress. Only the run's own computer can say so; while the window is on another one, the
+ * reconnect that brings it back re-reads. */
export async function reconcileOnboarding(request: OnboardingRequest): Promise<void> {
const session = $onboardingSession.get()
- if (!session || $onboardingPhase.get() !== 'shown') {
+ if (!session || $onboardingPhase.get() !== 'shown' || activeGatewayConnectionId() !== session.connectionId) {
return
}
diff --git a/apps/desktop/src/store/onboarding-session.ts b/apps/desktop/src/store/onboarding-session.ts
index e47f39546d1..ca7cd952f4c 100644
--- a/apps/desktop/src/store/onboarding-session.ts
+++ b/apps/desktop/src/store/onboarding-session.ts
@@ -4,6 +4,8 @@ import { $onboardingPhase } from './onboarding-phase'
import { $sessionTiles, storedSessionIdForRuntimeId } from './session-states'
export interface OnboardingSession {
+ /** The computer the run lives on (`activeGatewayConnectionId()` at its start); only its backend knows the run. */
+ connectionId: null | string
/** Names the run in `onboarding.ended` and `onboarding.state`. */
runId: string
runtimeId: string
diff --git a/apps/desktop/src/store/parked-card-answers.test.ts b/apps/desktop/src/store/parked-card-answers.test.ts
index 9f5788407ae..a3edc81e909 100644
--- a/apps/desktop/src/store/parked-card-answers.test.ts
+++ b/apps/desktop/src/store/parked-card-answers.test.ts
@@ -59,7 +59,7 @@ describe('parked card answers', () => {
// A run is shown whenever its chat is named (startOnboarding).
$onboardingPhase.set('shown')
- $onboardingSession.set({ runId: 'run-1', runtimeId: 'session-a', storedId: 'stored-a' })
+ $onboardingSession.set({ connectionId: null, runId: 'run-1', runtimeId: 'session-a', storedId: 'stored-a' })
expect($waiting.get()).toBe(true)
expect(answerParkedCard('session-a', 'hello')).toBe(true)
expect(answerParkedCard('session-b', 'hello')).toBe(false)
diff --git a/apps/desktop/src/store/setup-beat.test.ts b/apps/desktop/src/store/setup-beat.test.ts
index dd5e135a43d..5a5aa9d3f14 100644
--- a/apps/desktop/src/store/setup-beat.test.ts
+++ b/apps/desktop/src/store/setup-beat.test.ts
@@ -44,7 +44,7 @@ function parkCard(requestId: string, open = true, beat: 'layout' | 'name' = 'nam
beforeEach(() => {
// A run is shown whenever its chat is named (startOnboarding).
$onboardingPhase.set('shown')
- $onboardingSession.set({ runId: 'run-1', runtimeId: 'rt-1', storedId: 'stored-1' })
+ $onboardingSession.set({ connectionId: null, runId: 'run-1', runtimeId: 'rt-1', storedId: 'stored-1' })
})
afterEach(() => {