Repository navigation
fix(wsl-host): a pane parked by a stopped host reopens once Start brings the host back #36784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| vi.mock('@/store', () => ({ | ||
| useAppStore: { | ||
| getState: () => { | ||
| throw new Error('These transport fixtures must not read app-store ownership') | ||
| } | ||
| } | ||
| })) | ||
|
|
||
| import { wslHostStoppedMessage } from '../../../../shared/wsl-host-stopped-message' | ||
| import { flushAsyncTicks } from './pty-connection-test-async' | ||
| import { | ||
| createRemoteRuntimeTransportMocks, | ||
| type MultiplexSubscriptionCallbacks | ||
| } from './remote-runtime-pty-transport-test-harness' | ||
|
|
||
| const ORIGINAL_ID = 'remote:env-1@@terminal-1' | ||
|
|
||
| let callbacks: MultiplexSubscriptionCallbacks = null | ||
| let resolvedHandle = 'terminal-1' | ||
| const { runtimeCall, latestSubscribePayload, emitSnapshot, resetRemoteRuntimeTransport } = | ||
| createRemoteRuntimeTransportMocks({ | ||
| getCallbacks: () => callbacks, | ||
| setCallbacks: (value) => { | ||
| callbacks = value | ||
| }, | ||
| getResolvedPaneHandle: () => resolvedHandle, | ||
| setResolvedPaneHandle: (value) => { | ||
| resolvedHandle = value | ||
| } | ||
| }) | ||
|
|
||
| beforeEach(resetRemoteRuntimeTransport) | ||
|
|
||
| async function completeAttach(): Promise<void> { | ||
| await vi.waitFor(() => expect(latestSubscribePayload()).toBeDefined()) | ||
| const { streamId } = latestSubscribePayload() | ||
| callbacks?.onResponse({ ok: true, result: { type: 'subscribed', streamId } }) | ||
| emitSnapshot(streamId, 'prompt$ ') | ||
| } | ||
|
|
||
| /** Every runtime call is refused the way main refuses one for a stopped distro, until `start()`. */ | ||
| function stoppedHost(): { start: () => void } { | ||
| let stopped = true | ||
| const call = runtimeCall.getMockImplementation() | ||
| runtimeCall.mockImplementation(async (request: { method: string }) => { | ||
| if (stopped) { | ||
| throw new Error( | ||
| `Error invoking remote method 'runtimeEnvironments:call': Error: ${wslHostStoppedMessage('Ubuntu')}` | ||
| ) | ||
| } | ||
| return call?.(request) | ||
| }) | ||
| return { | ||
| start: () => { | ||
| stopped = false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| describe('a restored remote pane whose host was stopped', () => { | ||
| it.each(['connect', 'attach'] as const)( | ||
| 'reopens by %s once the host is running again, though its own retry has nothing armed', | ||
| async (entry) => { | ||
| const host = stoppedHost() | ||
| const { createRemoteRuntimePtyTransport } = await import('./remote-runtime-pty-transport') | ||
| const transport = createRemoteRuntimePtyTransport('env-1', { | ||
| worktreeId: 'wt-1', | ||
| tabId: 'tab-1', | ||
| leafId: 'pane:1' | ||
| }) | ||
| const onError = vi.fn() | ||
| if (entry === 'connect') { | ||
| void transport.connect({ url: '', sessionId: ORIGINAL_ID, callbacks: { onError } }) | ||
| } else { | ||
| transport.attach({ existingPtyId: ORIGINAL_ID, cols: 80, rows: 24, callbacks: { onError } }) | ||
| } | ||
| await vi.waitFor(() => expect(onError).toHaveBeenCalled()) | ||
| await flushAsyncTicks() | ||
| expect(transport.getPtyId()).toBeNull() | ||
|
|
||
| host.start() | ||
| // The refusal armed nothing, so the pane's own retry cannot bring it back. | ||
| expect(transport.retryRecovery?.()).toBe(false) | ||
| expect(transport.reopenAfterHostReturned?.()).toBe(true) | ||
| await completeAttach() | ||
|
|
||
| await vi.waitFor(() => expect(transport.getPtyId()).toBe(ORIGINAL_ID)) | ||
| // Connected now: a second host return does not open it again. | ||
| expect(transport.reopenAfterHostReturned?.()).toBe(false) | ||
| transport.destroy?.() | ||
| } | ||
| ) | ||
|
|
||
| it('leaves a pane that is still connecting to its own path', async () => { | ||
| const { createRemoteRuntimePtyTransport } = await import('./remote-runtime-pty-transport') | ||
| const transport = createRemoteRuntimePtyTransport('env-1', { worktreeId: 'wt-1' }) | ||
| expect(transport.reopenAfterHostReturned?.()).toBe(false) | ||
| void transport.connect({ url: '', sessionId: ORIGINAL_ID, callbacks: {} }) | ||
| expect(transport.reopenAfterHostReturned?.()).toBe(false) | ||
| transport.destroy?.() | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,9 @@ export function useRetryPanesWhenWslHostReturns( | |
| ownerEnvironmentId: string | null, | ||
| /** The owner's WSL host state, from the caller's own subscription (no listener of its own). */ | ||
| status: WslHostConnectionState | undefined, | ||
| paneTransports: { readonly current: ReadonlyMap<number, PtyTransport> } | ||
| paneTransports: { readonly current: ReadonlyMap<number, PtyTransport> }, | ||
| /** Clears the stop's own error from the panes; their old refusal is no longer true. */ | ||
| onHostReturned?: () => void | ||
| ): void { | ||
| const stoppedHost = useRef<string | null>(null) | ||
| useEffect(() => { | ||
|
|
@@ -22,14 +24,18 @@ export function useRetryPanesWhenWslHostReturns( | |
| return | ||
| } | ||
| stoppedHost.current = null | ||
| onHostReturned?.() | ||
| for (const transport of paneTransports.current.values()) { | ||
| // The card's rule: a pane with no server yet is still the workspace's; one on another never met this stop. | ||
| const paneEnvironmentId = transport.getRuntimeEnvironmentId | ||
| ? transport.getRuntimeEnvironmentId() | ||
| : ownerEnvironmentId | ||
| if (paneEnvironmentId == null || paneEnvironmentId === ownerEnvironmentId) { | ||
| transport.retryRecovery?.() | ||
| // Why both: a refused connect left the pane idle, with no retry armed to resume. | ||
| if (!transport.retryRecovery?.()) { | ||
| transport.reopenAfterHostReturned?.() | ||
| } | ||
| } | ||
| } | ||
| }, [status, ownerEnvironmentId, paneTransports]) | ||
| }, [status, ownerEnvironmentId, paneTransports, onHostReturned]) | ||
|
Comment on lines
+27
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { | ||
| isWslHostStoppedErrorLine, | ||
| withoutWslHostStoppedLines, | ||
| wslHostStoppedMessage | ||
| } from './wsl-host-stopped-message' | ||
|
|
||
| const IPC_WRAPPER = "Error invoking remote method 'runtimeEnvironments:call': Error: " | ||
|
|
||
| describe('the stopped WSL host refusal', () => { | ||
| it('matches the line its own message produces, with or without the IPC wrapper', () => { | ||
| const line = wslHostStoppedMessage('Ubuntu') | ||
| expect(isWslHostStoppedErrorLine(line, 'Ubuntu')).toBe(true) | ||
| expect(isWslHostStoppedErrorLine(`${IPC_WRAPPER}${line}`, 'Ubuntu')).toBe(true) | ||
| }) | ||
|
|
||
| it.each(['', IPC_WRAPPER])( | ||
| 'keeps an unrelated line of a mixed error (wrapper: %j)', | ||
| (wrapper) => { | ||
| const error = `${wrapper}${wslHostStoppedMessage('Ubuntu')}\nPaste failed.` | ||
| expect(withoutWslHostStoppedLines(error, 'Ubuntu')).toBe('Paste failed.') | ||
| } | ||
| ) | ||
|
|
||
| it('clears an error that was only the refusal', () => { | ||
| expect(withoutWslHostStoppedLines(wslHostStoppedMessage('Ubuntu'), 'Ubuntu')).toBeNull() | ||
| }) | ||
|
|
||
| it('keeps another, still-stopped distro’s refusal', () => { | ||
| const other = wslHostStoppedMessage('Debian') | ||
| expect(isWslHostStoppedErrorLine(other, 'Ubuntu')).toBe(false) | ||
| expect(withoutWslHostStoppedLines(other, 'Ubuntu')).toBe(other) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // The refusal a runtime call meets when its WSL host's distro was stopped; the renderer clears it once the host returns. | ||
| export function wslHostStoppedMessage(distro: string): string { | ||
| return `${distro} is stopped. To start it, click Start or open a new terminal in one of its projects.` | ||
| } | ||
|
|
||
| /** True for an error line carrying this distro's refusal, with or without an IPC wrapper around it. */ | ||
| export function isWslHostStoppedErrorLine(line: string, distro: string): boolean { | ||
| return line.includes(wslHostStoppedMessage(distro)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Match the complete distro refusal. If both |
||
| } | ||
|
|
||
| /** The error without the distro's refusal lines; null when nothing else was on it. */ | ||
| export function withoutWslHostStoppedLines(error: string, distro: string): string | null { | ||
| const kept = error | ||
| .split('\n') | ||
| .filter((line) => !isWslHostStoppedErrorLine(line, distro)) | ||
| .join('\n') | ||
| return kept.length > 0 ? kept : null | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reset refusal deduplication when clearing the displayed refusal.
If reopening meets the same stopped-host refusal before attachment succeeds, the transport still has the first refusal in
surfacedErrorMessages. The cleanup removes the displayed error, butsurfaceErrorMessagesuppresses the new refusal. The pane can remain offline without showing why. Clear the matching transport error state when this callback removes its refusal, before attempting reopening. (raw.githubusercontent.com)