From 2cb42da56d9ac08556fbda0bbe736d38c748cc86 Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 11 Nov 2026 00:41:45 -0800 Subject: [PATCH] fix(cloud): re-opening a workspace from its row mid-suspend shows Waking too (W2 P2) Left during the sleep, then clicked back: activation selects it, then (before its panes mount) marks it asleep and holds the read-only view again, and records the wake, so its panes wait for the wake instead of attaching to a VM going down. --- .../activation/sidebar-worktree-activation.ts | 21 +++++++++++++--- .../lib/worktree-sleep-wake-request.test.ts | 25 +++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/lib/workspace/activation/sidebar-worktree-activation.ts b/src/renderer/src/lib/workspace/activation/sidebar-worktree-activation.ts index 431e50f3b4e..58a9cc0430f 100644 --- a/src/renderer/src/lib/workspace/activation/sidebar-worktree-activation.ts +++ b/src/renderer/src/lib/workspace/activation/sidebar-worktree-activation.ts @@ -30,6 +30,8 @@ import { releaseWorktreeSleepView } from '@/lib/worktree-sleep-view' import { requestWakeAfterSleep } from '@/lib/worktree-sleep-wake-request' +import { markWorktreeSleepIntent } from '@/lib/worktree-sleep-intent' +import { holdActiveCloudSleepView } from '@/components/sidebar/workspace-actions/sleep/workspace-sleep-view-hold' /** Coded failures render through the catalog; a thrown IPC error only has its message. */ async function settleLifecycleCall( @@ -62,10 +64,21 @@ export async function activateWorktreeFromSidebar( }) return { ok: true } } - // "Wake to continue" (or opening it) while main is already suspending its VM: the VM must go - // down before it can wake, so it shows as waking from now and wakes once the sleep ends (the - // sleep follower does that). Opening it now would show dead panes with no cover meanwhile. - if (isWorktreeSleepViewHeld(worktreeId) && isWorktreeSuspendCommitted(worktreeId)) { + // "Wake to continue", or opening it again from its row, while main is already suspending its VM: + // the VM must go down before it can wake, so it shows as waking from now and wakes once the + // sleep ends (the sleep follower does that). Opening it now would show dead panes meanwhile. + if (isWorktreeSuspendCommitted(worktreeId)) { + if (!isWorktreeSleepViewHeld(worktreeId)) { + // Left and come back: select it, then (before its panes mount) keep it asleep and on + // screen read-only, as when it went to sleep, so its panes wait instead of reattaching. + activateAndRevealWorktree(worktreeId, { + navigationIntent: 'user-open', + revealInSidebar: false, + ...(executionHostId ? { executionHostId } : {}) + }) + markWorktreeSleepIntent(worktreeId) + holdActiveCloudSleepView(worktreeId) + } requestWakeAfterSleep(worktreeId, Date.now()) return { ok: true } } diff --git a/src/renderer/src/lib/worktree-sleep-wake-request.test.ts b/src/renderer/src/lib/worktree-sleep-wake-request.test.ts index 58693cdad36..5054f067ea4 100644 --- a/src/renderer/src/lib/worktree-sleep-wake-request.test.ts +++ b/src/renderer/src/lib/worktree-sleep-wake-request.test.ts @@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const mocks = vi.hoisted(() => ({ beginWorkspaceWake: vi.fn(), activateAndRevealWorktree: vi.fn(), + holdActiveCloudSleepView: vi.fn(() => true), resumeWorkspace: vi.fn() })) @@ -13,6 +14,9 @@ vi.mock('@/components/terminal-pane/input/wake-input-buffer', () => ({ beginWorkspaceWake: mocks.beginWorkspaceWake, endWorkspaceWake: vi.fn() })) +vi.mock('@/components/sidebar/workspace-actions/sleep/workspace-sleep-view-hold', () => ({ + holdActiveCloudSleepView: mocks.holdActiveCloudSleepView +})) vi.mock('@/lib/workspace/activation/worktree-activation', () => ({ activateAndRevealFolderWorkspace: vi.fn(), activateAndRevealWorktree: mocks.activateAndRevealWorktree @@ -34,6 +38,7 @@ import { resetWorktreeSleepViewForTests } from './worktree-sleep-view' import { activateWorktreeFromSidebar } from './workspace/activation/sidebar-worktree-activation' +import { forgetWorktreeSleepIntent, hasWorktreeSleepIntent } from './worktree-sleep-intent' const WS = 'cloud-wt' const PRESS = 1_800_000_000_000 @@ -45,6 +50,7 @@ beforeEach(() => { afterEach(() => { resetWakeAfterSleepForTests() resetWorktreeSleepViewForTests() + forgetWorktreeSleepIntent(WS) vi.unstubAllGlobals() cleanup() }) @@ -88,6 +94,25 @@ describe('wake pressed while main suspends the VM', () => { expect(mocks.resumeWorkspace).not.toHaveBeenCalled() }) + it('re-opening it from its row after leaving mid-sleep selects it, kept asleep, and waits', async () => { + // Left during the sleep: the read-only hold ended with the selection. + markWorktreeSuspendCommitted(WS) + await expect(activateWorktreeFromSidebar(WS)).resolves.toEqual({ ok: true }) + expect(mocks.activateAndRevealWorktree).toHaveBeenCalledWith( + WS, + expect.objectContaining({ navigationIntent: 'user-open' }) + ) + // Selecting clears sleep intent; it is put back (and the view held) right after, before any + // pane mounts, so the panes wait for the wake instead of attaching to a VM going down. + expect(hasWorktreeSleepIntent(WS)).toBe(true) + expect(mocks.holdActiveCloudSleepView).toHaveBeenCalledWith(WS) + expect(mocks.holdActiveCloudSleepView.mock.invocationCallOrder[0]).toBeGreaterThan( + mocks.activateAndRevealWorktree.mock.invocationCallOrder[0] + ) + expect(hasWakeAfterSleepRequest(WS)).toBe(true) + expect(mocks.resumeWorkspace).not.toHaveBeenCalled() + }) + it('opening it before the suspend is committed still wakes the ordinary way', async () => { holdWorktreeSleepView(WS) mocks.resumeWorkspace.mockResolvedValue({ ok: true })