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.
This commit is contained in:
Neil
2026-11-13 06:45:52 -08:00
committed by GitHub
parent 5e6fcd30f3
commit 4d6041ff71
5 changed files with 49 additions and 8 deletions
@@ -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<string[]>((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])
@@ -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) {
@@ -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<string | null>(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 &&
@@ -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
@@ -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<string>()
/** 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<void> {
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. */