fix(wsl): show Connecting instead of a stale read error while a WSL host starts

After Start, a WSL host can take tens of seconds to boot and update its server. The editor,
file tree and source control dropped the stopped notice as soon as the host left 'stopped'
and showed the error from the read that failed while it was down, telling the user to go to
Settings. They now keep the notice up as 'Connecting to <distro>…', and the editor's retry
waits for the WSL host and reloads the file when it answers, as it already did for SSH.
This commit is contained in:
Neil
2026-11-11 19:09:11 -08:00
parent a0d34074ea
commit e294f48c43
13 changed files with 292 additions and 30 deletions
@@ -6,7 +6,7 @@ import { formatFileLoadErrorMessage } from './file-load-error-copy'
import { displayIpcErrorMessage } from '@/runtime/errors/ipc-error'
import { isFileTooLargeCodeMessage } from '../../../../shared/file-write/file-write-disk-precondition'
import { WORKTREE_HOST_UNRESOLVED_CODE } from './editor-panel-content-types'
import { useStoppedWslHost } from '../wsl-host-stopped/use-stopped-wsl-host'
import { useWslHostReadOutage } from '../wsl-host-stopped/use-stopped-wsl-host'
import { WslHostStoppedNotice } from '../wsl-host-stopped/WslHostStoppedNotice'
// Localize by machine code; stored English remains readable for logs without coupling upstream state checks to UI language.
@@ -39,20 +39,21 @@ export function EditorFileLoadErrorView({
}: {
message: string
code?: string
/** The file's workspace; a stopped WSL host there gets Start instead of this error. */
/** The file's workspace; a stopped or still-connecting WSL host there gets its notice instead of this error. */
worktreeId?: string
onRetry: () => void
/** Reloads after Start without asking to wake again: the click already booted the host. */
onHostStarted?: () => void
}): React.JSX.Element {
const t = useTranslate()
const stoppedWslHost = useStoppedWslHost(worktreeId)
if (stoppedWslHost) {
const wslHostOutage = useWslHostReadOutage(worktreeId)
if (wslHostOutage) {
return (
<div className="flex h-full items-center justify-center bg-editor-surface p-6 text-sm">
<WslHostStoppedNotice
environmentId={stoppedWslHost.environmentId}
distro={stoppedWslHost.distro}
environmentId={wslHostOutage.environmentId}
distro={wslHostOutage.distro}
connecting={wslHostOutage.connecting}
size="sm"
onStarted={onHostStarted}
/>
@@ -1,6 +1,9 @@
import { useEffect, useRef, type Dispatch, type MutableRefObject, type SetStateAction } from 'react'
import type { OpenFile } from '@/store/slices/editor/types/open-file'
import { useWorktreeHostConnection } from '@/lib/workspace/ownership/worktree-host-connection-phase'
import { selectWorkspaceRuntimeEnvironmentId } from '@/lib/workspace/ownership/workspace-runtime-environment'
import { useAppStateValue } from '@/store/retained-views/app-state-view'
import type { WslHostConnectionState } from '../../../../shared/wsl-host-types'
import { displayIpcErrorMessage } from '@/runtime/errors/ipc-error'
import { hasRuntimeRpcErrorCode } from '../../../../shared/runtime-rpc-error-code'
import { isFileTooLargeMessage } from '../../../../shared/file-write/file-write-disk-precondition'
@@ -60,6 +63,24 @@ export function shouldRetryFileLoadError(message: string, code?: string): boolea
)
}
/**
* A WSL host's connection in the SSH phase's terms, so a read that failed while it was down waits
* for it and retries once it answers. Null for any other host.
*/
export function wslHostRetryConnection(
environmentId: string | null,
state: WslHostConnectionState | undefined
): { targetId: string; connecting: boolean; connectedEpoch: string | null } | null {
if (!environmentId || state === undefined) {
return null
}
return {
targetId: `wsl:${environmentId}`,
connecting: state === 'connecting' || state === 'reconnecting',
connectedEpoch: state === 'ready' ? `wsl:${environmentId}` : null
}
}
export function useEditorPanelFileLoadRetry({
activeFile,
fileContents,
@@ -76,9 +97,16 @@ export function useEditorPanelFileLoadRetry({
? fileContents[activeFileLoadRetryId]?.loadErrorCode
: undefined
const hostConnection = useWorktreeHostConnection(activeFile?.worktreeId ?? null)
const hostTargetId = hostConnection.targetId
const hostConnecting = hostConnection.phase === 'connecting'
const connectedHostEpoch = hostConnection.connectedEpoch
const wslEnvironmentId = useAppStateValue((state) =>
selectWorkspaceRuntimeEnvironmentId(state, activeFile?.worktreeId)
)
const wslHostState = useAppStateValue((state) =>
wslEnvironmentId ? state.wslHostStatuses[wslEnvironmentId]?.state : undefined
)
const wslHost = wslHostRetryConnection(wslEnvironmentId, wslHostState)
const hostTargetId = wslHost?.targetId ?? hostConnection.targetId
const hostConnecting = wslHost?.connecting ?? hostConnection.phase === 'connecting'
const connectedHostEpoch = wslHost ? wslHost.connectedEpoch : hostConnection.connectedEpoch
const seenHostRef = useRef({ targetId: hostTargetId, connectedEpoch: connectedHostEpoch })
useEffect(() => {
@@ -0,0 +1,115 @@
// @vitest-environment happy-dom
import { act, useRef, useState } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { OpenFile } from '@/store/slices/editor/types/open-file'
import type { WslHostConnectionState } from '../../../../shared/wsl-host-types'
import type { FileContent } from './editor-panel-content-types'
const host = vi.hoisted((): { state: string | undefined } => ({ state: undefined }))
vi.mock(
'@/lib/workspace/ownership/worktree-host-connection-phase',
() => import('./local-host-test-fixture')
)
vi.mock('@/lib/workspace/ownership/workspace-runtime-environment', () => ({
selectWorkspaceRuntimeEnvironmentId: () => 'wsl-env'
}))
vi.mock('@/store/retained-views/app-state-view', () => ({
useAppStateValue: <T,>(select: (state: unknown) => T): T =>
select({
wslHostStatuses: host.state
? { 'wsl-env': { environmentId: 'wsl-env', distro: 'demo', state: host.state } }
: {}
})
}))
import { useEditorPanelFileLoadRetry, wslHostRetryConnection } from './useEditorPanelFileLoadRetry'
const FILE: OpenFile = {
id: 'file-1',
filePath: '/home/orca/demo/app/main.go',
relativePath: 'main.go',
worktreeId: 'repo::/home/orca/demo/app',
language: 'go',
isDirty: false,
mode: 'edit'
}
const UNREACHABLE = 'Could not connect to the remote Orca runtime.'
function Probe({ loadFileContent }: { loadFileContent: () => Promise<void> }): null {
const [fileContents, setFileContents] = useState<Record<string, FileContent>>({
[FILE.id]: { content: '', isBinary: false, loadError: UNREACHABLE }
})
const openFilesRef = useRef([FILE])
const fileLoadRetryAttemptsRef = useRef<Record<string, number>>({ [FILE.id]: 3 })
useEditorPanelFileLoadRetry({
activeFile: FILE,
fileContents,
fileLoadRetryAttemptsRef,
loadFileContent,
openFilesRef,
setFileContents
})
return null
}
describe('useEditorPanelFileLoadRetry on a WSL host', () => {
let container: HTMLDivElement
let root: Root
beforeEach(() => {
vi.useFakeTimers()
container = document.createElement('div')
root = createRoot(container)
})
afterEach(() => {
act(() => root.unmount())
vi.useRealTimers()
})
const render = (loadFileContent: () => Promise<void>): void =>
act(() => root.render(<Probe loadFileContent={loadFileContent} />))
it('waits while the host connects, then reloads once it answers', async () => {
const loadFileContent = vi.fn(async () => {})
host.state = 'connecting'
render(loadFileContent)
await act(async () => {
await vi.advanceTimersByTimeAsync(10_000)
})
expect(loadFileContent).not.toHaveBeenCalled()
host.state = 'ready'
render(loadFileContent)
expect(loadFileContent).toHaveBeenCalledWith(
FILE.filePath,
FILE.id,
FILE.worktreeId,
FILE.relativePath
)
})
})
describe('wslHostRetryConnection', () => {
it.each<[WslHostConnectionState, boolean, string | null]>([
['connecting', true, null],
['reconnecting', true, null],
['ready', false, 'wsl:env-1'],
['distro-stopped', false, null],
['failed', false, null]
])('%s', (state, connecting, connectedEpoch) => {
expect(wslHostRetryConnection('env-1', state)).toEqual({
targetId: 'wsl:env-1',
connecting,
connectedEpoch
})
})
it('is null for a host that is not a WSL host', () => {
expect(wslHostRetryConnection(null, undefined)).toBeNull()
expect(wslHostRetryConnection('ssh-env', undefined)).toBeNull()
})
})
@@ -41,7 +41,7 @@ import { useFileExplorerBackgroundMenu } from './use-file-explorer-background-me
import { useFileExplorerNameFilter } from './use-file-explorer-name-filter'
import { useFileExplorerTreePaneState } from '../tree/use-file-explorer-tree-pane-state'
import { useWslHostUnavailableReason } from '../../../../runtime/hosts/wsl/wsl-host-availability'
import { useStoppedWslHost } from '../../../wsl-host-stopped/use-stopped-wsl-host'
import { useWslHostReadOutage } from '../../../wsl-host-stopped/use-stopped-wsl-host'
import { useTranslate } from '@/i18n/use-translate'
import { useUiLanguageRevision } from '@/i18n/use-ui-language-revision'
@@ -57,7 +57,7 @@ function FileExplorerFiles(): React.JSX.Element {
runtimeEnvironmentIdOrLocalUnlessTwin(s, activeWorktreeId)
)
const wslHostUnavailable = useWslHostUnavailableReason(activeWorktreeId)
const stoppedWslHost = useStoppedWslHost(activeWorktreeId)
const stoppedWslHost = useWslHostReadOutage(activeWorktreeId)
const activeWorktree = useActiveWorktree()
const activeRepo = useRepoById(activeWorktree?.repoId ?? null)
// Why: a folder workspace has no repo row, so only the catalog owner names its SSH host.
@@ -17,7 +17,7 @@ import type { useFileExplorerSelection } from '../selection/useFileExplorerSelec
import type { useFileExplorerTree } from './useFileExplorerTree'
import type { useFileExplorerTreePaneState } from './use-file-explorer-tree-pane-state'
import type { WslHostUnavailableReason } from '../../../../runtime/hosts/wsl/wsl-host-availability'
import type { StoppedWslHost } from '../../../wsl-host-stopped/use-stopped-wsl-host'
import type { WslHostReadOutage } from '../../../wsl-host-stopped/use-stopped-wsl-host'
type FileExplorerFilesTreePaneProps = {
activeRepo: Repo | null
@@ -39,7 +39,7 @@ type FileExplorerFilesTreePaneProps = {
handleExplorerBackgroundContextMenuCapture: (event: React.MouseEvent<HTMLDivElement>) => void
handleExplorerBackgroundDoubleClick: (event: React.MouseEvent<HTMLDivElement>) => void
wslHostUnavailable?: WslHostUnavailableReason | null
stoppedWslHost?: StoppedWslHost | null
stoppedWslHost?: WslHostReadOutage | null
}
export function FileExplorerFilesTreePane({
@@ -7,7 +7,7 @@ import {
getWslHostsTurnedOffLabel,
getWslHostsTurnOnLabel
} from '../../../sidebar/wsl-host-row-status'
import type { StoppedWslHost } from '../../../wsl-host-stopped/use-stopped-wsl-host'
import type { WslHostReadOutage } from '../../../wsl-host-stopped/use-stopped-wsl-host'
import { WslHostStoppedNotice } from '../../../wsl-host-stopped/WslHostStoppedNotice'
type FileExplorerTreeStatusProps = {
@@ -18,8 +18,8 @@ type FileExplorerTreeStatusProps = {
emptyMessage?: string
/** The workspace's WSL host is turned off: offer the switch instead of a read error. */
wslHostsTurnedOff?: boolean
/** The workspace's WSL host is stopped: offer Start instead of a read error. */
stoppedWslHost?: StoppedWslHost | null
/** The workspace's WSL host is stopped or still connecting: its notice instead of a read error. */
stoppedWslHost?: WslHostReadOutage | null
onWslHostStarted?: () => void
}
@@ -62,6 +62,7 @@ export function FileExplorerTreeStatus({
<WslHostStoppedNotice
environmentId={stoppedWslHost.environmentId}
distro={stoppedWslHost.distro}
connecting={stoppedWslHost.connecting}
className="h-full text-[11px]"
onStarted={onWslHostStarted}
/>
@@ -7,7 +7,7 @@ import { ConflictSummaryCard, OperationBanner } from './conflict-status-cards'
import { EmptyState } from './empty-state'
import { StatusRetryButton } from './status-retry-button'
import { TooManyChangesBanner } from './too-many-changes-banner'
import { useStoppedWslHost } from '../../../wsl-host-stopped/use-stopped-wsl-host'
import { useWslHostReadOutage } from '../../../wsl-host-stopped/use-stopped-wsl-host'
import { WslHostStoppedNotice } from '../../../wsl-host-stopped/WslHostStoppedNotice'
import { useSourceControlScope } from '../panel/worktree-scope'
import { shortRefLabel } from '../../../../../../shared/source-control/short-ref-label'
@@ -62,8 +62,8 @@ export function SourceControlContentStatus({
filterQuery: string
}): React.JSX.Element {
const t = useTranslate()
// Why: a stopped host can't answer git, so its read error or "clean" result is not the workspace's.
const stoppedWslHost = useStoppedWslHost(worktreeId)
// Why: a stopped or still-connecting host can't answer git, so its read error or "clean" result is not the workspace's.
const stoppedWslHost = useWslHostReadOutage(worktreeId)
// Folder sections keep to the plain message and Retry; raw Git output stays in the worktree's own panel.
const showRawStatusError = useSourceControlScope() === null
return (
@@ -72,6 +72,7 @@ export function SourceControlContentStatus({
<WslHostStoppedNotice
environmentId={stoppedWslHost.environmentId}
distro={stoppedWslHost.distro}
connecting={stoppedWslHost.connecting}
className="py-6 text-xs"
/>
)}
@@ -0,0 +1,36 @@
// @vitest-environment happy-dom
import { act } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
vi.mock('@/runtime/hosts/wsl/wsl-host-user-start', () => ({
startWslHostAndReloadProjects: vi.fn(async () => true)
}))
import { WslHostStoppedNotice } from './WslHostStoppedNotice'
describe('WslHostStoppedNotice', () => {
let container: HTMLDivElement
let root: Root
beforeEach(() => {
container = document.createElement('div')
root = createRoot(container)
})
afterEach(() => act(() => root.unmount()))
it('offers Start while the host is stopped', () => {
act(() => root.render(<WslHostStoppedNotice environmentId="env" distro="demo" />))
expect(container.textContent).toContain('demo is stopped')
expect(container.querySelector('button')?.textContent).toBe('Start')
})
it('shows Connecting with no Start while the host boots', () => {
act(() => root.render(<WslHostStoppedNotice environmentId="env" distro="demo" connecting />))
expect(container.textContent).toContain('Connecting to demo…')
expect(container.querySelector('[data-wsl-host-connecting]')).not.toBeNull()
expect(container.querySelector('button')).toBeNull()
})
})
@@ -7,16 +7,21 @@ import { useTranslate } from '@/i18n/use-translate'
import { cn } from '@/lib/class-names'
import { startWslHostAndReloadProjects } from '@/runtime/hosts/wsl/wsl-host-user-start'
/** "<distro> is stopped" with Start, where a surface would otherwise show a read error. Only the click boots (E9). */
/**
* "<distro> is stopped" with Start, where a surface would otherwise show a read error. Only the click
* boots (E9). `connecting` swaps in "Connecting to <distro>…" while it boots, so the stale error never shows.
*/
export function WslHostStoppedNotice({
environmentId,
distro,
connecting = false,
size = 'xs',
className,
onStarted
}: {
environmentId: string
distro: string
connecting?: boolean
size?: 'xs' | 'sm'
className?: string
onStarted?: () => void
@@ -48,15 +53,26 @@ export function WslHostStoppedNotice({
className="mb-1 size-7 text-muted-foreground"
data-wsl-host-stopped-icon=""
/>
<span>
{t('components.native-chat.hostOutage.stopped', '{{distro}} is stopped', {
distro
})}
</span>
<Button type="button" size={size} disabled={starting} onClick={start}>
{starting ? <Loader2 className="animate-spin" /> : null}
{t('components.native-chat.hostOutage.start', 'Start')}
</Button>
{connecting ? (
<span className="flex items-center gap-1.5" data-wsl-host-connecting="">
<Loader2 className="size-3.5 animate-spin" />
{t('components.native-chat.hostOutage.connecting', 'Connecting to {{distro}}…', {
distro
})}
</span>
) : (
<>
<span>
{t('components.native-chat.hostOutage.stopped', '{{distro}} is stopped', {
distro
})}
</span>
<Button type="button" size={size} disabled={starting} onClick={start}>
{starting ? <Loader2 className="animate-spin" /> : null}
{t('components.native-chat.hostOutage.start', 'Start')}
</Button>
</>
)}
</div>
)
}
@@ -1,11 +1,16 @@
import { useAppStateValue } from '@/store/retained-views/app-state-view'
import { useMemo } from 'react'
import type { AppState } from '@/store/types'
import { selectStoppedWslDistro } from '@/runtime/hosts/wsl/wsl-host-stopped-status'
import {
selectConnectingWslDistro,
selectStoppedWslDistro
} from '@/runtime/hosts/wsl/wsl-host-stopped-status'
import { selectWorkspaceRuntimeEnvironmentId } from '../../lib/workspace/ownership/workspace-runtime-environment'
import { selectWslHostEnvironmentUnavailableReason } from '../../runtime/hosts/wsl/wsl-host-availability'
export type StoppedWslHost = { environmentId: string; distro: string }
/** A host a read surface waits on instead of showing its read error; `connecting` once Start (or a reconnect) is under way. */
export type WslHostReadOutage = StoppedWslHost & { connecting: boolean }
/** A stopped distro Start can boot; a host that cannot run (turned off, server files missing) keeps its own notice. */
export function selectStartableStoppedWslDistro(
@@ -40,3 +45,27 @@ export function useStoppedWslHost(worktreeId: string | null | undefined): Stoppe
[environmentId, distro]
)
}
/**
* For surfaces that mask a read error: a read that failed while the host was down stays stale
* until the host answers, so a connecting host keeps the notice up instead of that error.
*/
export function useWslHostReadOutage(
worktreeId: string | null | undefined
): WslHostReadOutage | null {
const stopped = useStoppedWslHost(worktreeId)
const environmentId = useAppStateValue((state) =>
selectWorkspaceRuntimeEnvironmentId(state, worktreeId)
)
const connectingDistro = useAppStateValue((state) =>
selectConnectingWslDistro(state, environmentId)
)
return useMemo(() => {
if (stopped) {
return { ...stopped, connecting: false }
}
return environmentId && connectingDistro
? { environmentId, distro: connectingDistro, connecting: true }
: null
}, [stopped, environmentId, connectingDistro])
}
+1
View File
@@ -21169,6 +21169,7 @@
"reconnect": "Reconnect",
"stopped": "{{distro}} is stopped",
"start": "Start",
"connecting": "Connecting to {{distro}}…",
"startFailed": "Couldn’t start {{distro}}. Check it in Settings → Remote Orca Servers.",
"unverifiable": "Orca couldn't check whether {{distro}} is running",
"startToSend": "Start {{distro}} to send.",
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'
import type { WslHostConnectionState } from '../../../../../shared/wsl-host-types'
import { selectConnectingWslDistro, selectStoppedWslDistro } from './wsl-host-stopped-status'
const stateWith = (state: WslHostConnectionState) => ({
wslHostStatuses: { env: { environmentId: 'env', distro: 'demo', state, detail: null } }
})
describe('selectConnectingWslDistro', () => {
it.each<[WslHostConnectionState, string | null]>([
['connecting', 'demo'],
['reconnecting', 'demo'],
['ready', null],
['distro-stopped', null],
['failed', null]
])('%s', (state, expected) => {
expect(selectConnectingWslDistro(stateWith(state), 'env')).toBe(expected)
})
it('is null for an unknown host and never overlaps stopped', () => {
expect(selectConnectingWslDistro(stateWith('connecting'), 'other')).toBeNull()
expect(selectConnectingWslDistro(stateWith('connecting'), null)).toBeNull()
expect(selectStoppedWslDistro(stateWith('connecting'), 'env')).toBeNull()
})
})
@@ -9,6 +9,15 @@ export function selectStoppedWslDistro(
return status?.state === 'distro-stopped' ? status.distro : null
}
/** The distro of a WSL host still connecting, such as after Start while it boots or updates its server. */
export function selectConnectingWslDistro(
state: Pick<AppState, 'wslHostStatuses'>,
environmentId: string | null | undefined
): string | null {
const status = environmentId ? state.wslHostStatuses[environmentId] : undefined
return status?.state === 'connecting' || status?.state === 'reconnecting' ? status.distro : null
}
/**
* Whether a pane shows the stopped distro's Start card. A pane whose create failed has no server
* yet and is still the workspace's; one on another server, or a host that cannot run, keeps its own