From 4d6041ff71b2633d07651bd73a4b1ea5fd072431 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 13 Nov 2026 06:45:52 -0800 Subject: [PATCH] fix(cloud): no reconnect banner while a paired workspace goes to sleep (SLEEP-RECONNECT-BANNER) (#705) A paired workspace's going-to-sleep mark was cleared before its sandbox slept through the control plane, and it has no local record that flips to suspended, so while the connection dropped the pane showed 'Reconnecting... Down for N sec'. Paired ids now stay going to sleep until their control-plane sleep and status re-read finish, and the reconnect banner and outage notice hold while a sleep is in progress. --- .../sleep-worktree-flow-paired-copy.test.ts | 28 ++++++++++++++++++- .../sleep/sleep-worktree-flow.ts | 13 +++++++-- .../recovery/TerminalPaneRecoveryPortals.tsx | 5 +++- .../src/lib/orca-cloud/paired-cloud-sleep.ts | 2 +- .../src/lib/orca-cloud/paired-cloud-wake.ts | 9 ++++-- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/components/sidebar/workspace-actions/sleep/sleep-worktree-flow-paired-copy.test.ts b/src/renderer/src/components/sidebar/workspace-actions/sleep/sleep-worktree-flow-paired-copy.test.ts index a99ec607ded..ef4c8b0212c 100644 --- a/src/renderer/src/components/sidebar/workspace-actions/sleep/sleep-worktree-flow-paired-copy.test.ts +++ b/src/renderer/src/components/sidebar/workspace-actions/sleep/sleep-worktree-flow-paired-copy.test.ts @@ -23,7 +23,11 @@ vi.mock('./workspace-sleep-target', () => ({ })) import { seedCloudWorkspaceSnapshot } from '@/lib/orca-cloud/orca-cloud-workspace-store' -import { resetWorktreeSleepViewForTests, sleepCopySave } from '@/lib/worktree-sleep-view' +import { + isWorktreeGoingToSleep, + resetWorktreeSleepViewForTests, + sleepCopySave +} from '@/lib/worktree-sleep-view' import { PAIRED_HOST_SLEEP_TIMEOUT_MS, runSleepWorktrees } from './sleep-worktree-flow' const T0 = 1_800_000_000_000 @@ -61,6 +65,28 @@ describe('runSleepWorktrees on a paired cloud workspace', () => { expect(sleepCopySave(LOCAL)).toBeNull() }) + it('stays going to sleep until the paired sandbox slept, so no reconnect banner shows (SLEEP-RECONNECT-BANNER)', async () => { + let finishPairedSleep: (stillRunning: string[]) => void = () => undefined + let goingDuringPairedSleep: { paired: boolean; local: boolean } | null = null + mocks.sleepPairedCloudSandboxes.mockImplementation( + () => + new Promise((resolve) => { + goingDuringPairedSleep = { + paired: isWorktreeGoingToSleep(PAIRED), + local: isWorktreeGoingToSleep(LOCAL) + } + finishPairedSleep = resolve + }) + ) + const done = runSleepWorktrees([PAIRED, LOCAL]) + await vi.waitFor(() => expect(goingDuringPairedSleep).not.toBeNull()) + // The control plane is still suspending the paired sandbox: it is going to sleep, not down. + expect(goingDuringPairedSleep).toEqual({ paired: true, local: false }) + finishPairedSleep([]) + await done + expect(isWorktreeGoingToSleep(PAIRED)).toBe(false) + }) + it('clears it when the control plane left the paired sandbox running', async () => { mocks.sleepPairedCloudSandboxes.mockResolvedValue([PAIRED]) await runSleepWorktrees([PAIRED]) diff --git a/src/renderer/src/components/sidebar/workspace-actions/sleep/sleep-worktree-flow.ts b/src/renderer/src/components/sidebar/workspace-actions/sleep/sleep-worktree-flow.ts index 66d38cfb72a..03f45b7040f 100644 --- a/src/renderer/src/components/sidebar/workspace-actions/sleep/sleep-worktree-flow.ts +++ b/src/renderer/src/components/sidebar/workspace-actions/sleep/sleep-worktree-flow.ts @@ -102,8 +102,13 @@ export async function runSleepWorktrees( } const { errors, results, vmStillRunningIds, unsleptWorktreeIds } = await sleepWorktreesReportingFailures(worktreeIds, { markChatsAsleep: true }) + // SLEEP-RECONNECT-BANNER: a paired workspace is still going to sleep until its sandbox has slept + // through the control plane below and its status says so (it has no local record that flips). + const pairedIds = new Set(worktreeIds.filter((id) => isPairedCloudWorkspace(id))) for (const id of worktreeIds) { - clearWorktreeGoingToSleep(id) + if (!pairedIds.has(id)) { + clearWorktreeGoingToSleep(id) + } clearWorktreeKeptAwake(id) } // Refused before main started it (nothing stopped) or failed: the workspace is awake. @@ -118,7 +123,11 @@ export async function runSleepWorktrees( const unslept = new Set(unsleptWorktreeIds) const pairedStillRunning = await sleepPairedCloudSandboxes( worktreeIds.filter((id) => !unslept.has(id)) - ) + ).finally(() => { + for (const id of pairedIds) { + clearWorktreeGoingToSleep(id) + } + }) const stillRunningIds = [...vmStillRunningIds, ...pairedStillRunning] // The paired sandbox kept running: no sealed copy is coming either. for (const id of pairedStillRunning) { diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/recovery/TerminalPaneRecoveryPortals.tsx b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/recovery/TerminalPaneRecoveryPortals.tsx index 076661f5454..f3a01df69ae 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/recovery/TerminalPaneRecoveryPortals.tsx +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/recovery/TerminalPaneRecoveryPortals.tsx @@ -228,7 +228,9 @@ export function TerminalPaneRecoveryPortals({ stoppedWslDistro === null && pairingRefusedEnvironmentId === null && !cloudWaking && - !cloudAsleep + !cloudAsleep && + // SLEEP-RECONNECT-BANNER: a sleep the person asked for drops the connection on purpose. + !goingToSleep const serverDown = retryingOutageEnvironmentId !== null const notice = useRemoteServerNoticeClaim(ownerEnvironmentId, serverDown, canSpeak) const [noticeEnvironmentId, setNoticeEnvironmentId] = useState(null) @@ -389,6 +391,7 @@ export function TerminalPaneRecoveryPortals({ // Why stopped panes too: a card flashing over the notice's hold is the overlap this avoids. heldByServer={ cloudWaking || + goingToSleep || (!isolated && !awaitingSignIn && !wslHostUnavailable && diff --git a/src/renderer/src/lib/orca-cloud/paired-cloud-sleep.ts b/src/renderer/src/lib/orca-cloud/paired-cloud-sleep.ts index 719cda346e8..ee1be30e5b2 100644 --- a/src/renderer/src/lib/orca-cloud/paired-cloud-sleep.ts +++ b/src/renderer/src/lib/orca-cloud/paired-cloud-sleep.ts @@ -45,7 +45,7 @@ export async function sleepPairedCloudSandboxes(worktreeIds: readonly string[]): stillRunning.push(id) } else { // The row says Asleep (not Active) now, and opening it wakes it (n38 GATE). - notePairedCloudSlept(id) + await notePairedCloudSlept(id) } } return stillRunning diff --git a/src/renderer/src/lib/orca-cloud/paired-cloud-wake.ts b/src/renderer/src/lib/orca-cloud/paired-cloud-wake.ts index 1f9a9e37899..0f390dacb80 100644 --- a/src/renderer/src/lib/orca-cloud/paired-cloud-wake.ts +++ b/src/renderer/src/lib/orca-cloud/paired-cloud-wake.ts @@ -23,10 +23,13 @@ function notPairedMessage(): string { // Paired rows this desktop put to sleep (their status read may not have caught up yet). const sleptHere = new Set() -/** Paired Sleep succeeded here: its status is re-read now, and an open wakes it even before that. */ -export function notePairedCloudSlept(workspaceId: string): void { +/** + * Paired Sleep succeeded here: its status is re-read now (resolved once read, so the sleep can keep + * saying "going to sleep" until the row says Asleep), and an open wakes it even before that. + */ +export function notePairedCloudSlept(workspaceId: string): Promise { sleptHere.add(workspaceId) - void refreshCloudWorkspaceStatus(workspaceId) + return refreshCloudWorkspaceStatus(workspaceId).catch(() => undefined) } /** How often, and for how long, an explicit wake re-reads status until the VM runs. */