diff --git a/src/renderer/src/components/terminal-pane/TerminalErrorToast.test.ts b/src/renderer/src/components/terminal-pane/TerminalErrorToast.test.ts index c46df0e72..03bb896eb 100644 --- a/src/renderer/src/components/terminal-pane/TerminalErrorToast.test.ts +++ b/src/renderer/src/components/terminal-pane/TerminalErrorToast.test.ts @@ -1,5 +1,58 @@ import { describe, expect, it } from 'vitest' -import { shouldOfferDaemonRestart } from './TerminalErrorToast' +import { + isSshReconnectOwnedTerminalError, + shouldOfferDaemonRestart, + stripSshReconnectOwnedErrorLines +} from './TerminalErrorToast' + +const SSH_FAILURE = + "SSH connection failed: Error invoking remote method 'ssh:connect': Error: Relay package for linux-x64 not found locally." + +describe('isSshReconnectOwnedTerminalError', () => { + it('matches raw ssh:connect failures and inactive-host messages', () => { + expect( + isSshReconnectOwnedTerminalError( + "SSH connection failed: Error invoking remote method 'ssh:connect': Error: Relay package for linux-x64 not found locally." + ) + ).toBe(true) + expect( + isSshReconnectOwnedTerminalError( + 'SSH connection is not active. Use the reconnect dialog or Settings to connect.' + ) + ).toBe(true) + }) + + it('leaves unrelated terminal errors for the toast', () => { + expect(isSshReconnectOwnedTerminalError('Paste failed.')).toBe(false) + expect(isSshReconnectOwnedTerminalError('node-pty: open_slave failed: EMFILE')).toBe(false) + }) +}) + +describe('stripSshReconnectOwnedErrorLines', () => { + it('clears an error that is only SSH reconnect text', () => { + expect(stripSshReconnectOwnedErrorLines(SSH_FAILURE)).toBeNull() + }) + + it('keeps an unrelated error that precedes the SSH failure', () => { + expect(stripSshReconnectOwnedErrorLines(`Paste failed.\n${SSH_FAILURE}`)).toBe('Paste failed.') + }) + + it('keeps an unrelated error that follows the SSH failure', () => { + expect(stripSshReconnectOwnedErrorLines(`${SSH_FAILURE}\nPaste failed.`)).toBe('Paste failed.') + }) + + it('drops every SSH-owned line but preserves the rest', () => { + expect( + stripSshReconnectOwnedErrorLines( + `${SSH_FAILURE}\nPaste failed.\nSSH connection is not active. Use the reconnect dialog.` + ) + ).toBe('Paste failed.') + }) + + it('leaves an error with no SSH text untouched', () => { + expect(stripSshReconnectOwnedErrorLines('Paste failed.')).toBe('Paste failed.') + }) +}) describe('shouldOfferDaemonRestart', () => { it('matches stale daemon node-pty install failures', () => { diff --git a/src/renderer/src/components/terminal-pane/TerminalErrorToast.tsx b/src/renderer/src/components/terminal-pane/TerminalErrorToast.tsx index a71cd8816..7289dba79 100644 --- a/src/renderer/src/components/terminal-pane/TerminalErrorToast.tsx +++ b/src/renderer/src/components/terminal-pane/TerminalErrorToast.tsx @@ -1,5 +1,7 @@ import { translate } from '@/i18n/i18n' const SSH_PREFIX = 'SSH connection is not active' +// Produced by pty-connection.ts reportError() when a PTY reattach can't reach its SSH host. +const SSH_CONNECT_FAILURE_PREFIX = 'SSH connection failed' const STALE_NODE_PTY_DAEMON_MARKERS = [ "Daemon's node-pty install is gone", 'node-pty: posix_spawn failed: ENOENT' @@ -13,6 +15,21 @@ function isSshError(error: string): boolean { return error.startsWith(SSH_PREFIX) } +/** A single error line the SSH reconnect banner already covers — hide instead of stacking under/over it. */ +export function isSshReconnectOwnedTerminalError(error: string): boolean { + return error.startsWith(SSH_CONNECT_FAILURE_PREFIX) || error.startsWith(SSH_PREFIX) +} + +// Why: onPtyError aggregates errors into one newline-joined string, so classify per line — +// drop only the reconnect-owned lines and keep any unrelated error, regardless of order. +export function stripSshReconnectOwnedErrorLines(error: string): string | null { + const kept = error + .split('\n') + .filter((line) => !isSshReconnectOwnedTerminalError(line)) + .join('\n') + return kept.length > 0 ? kept : null +} + export function shouldOfferDaemonRestart(error: string): boolean { return [STALE_NODE_PTY_DAEMON_MARKERS, STALE_DAEMON_CWD_MARKERS].some((markers) => markers.every((marker) => error.includes(marker)) diff --git a/src/renderer/src/components/terminal-pane/TerminalPane.tsx b/src/renderer/src/components/terminal-pane/TerminalPane.tsx index a7543e8df..ef95aaa5a 100644 --- a/src/renderer/src/components/terminal-pane/TerminalPane.tsx +++ b/src/renderer/src/components/terminal-pane/TerminalPane.tsx @@ -56,7 +56,7 @@ import { useEffectiveMacOptionAsAlt } from '@/lib/keyboard-layout/use-effective- import { useTerminalFontZoom } from './useTerminalFontZoom' import CloseTerminalDialog, { type CloseTerminalDialogCopyKind } from './CloseTerminalDialog' import { MobileDriverOverlay } from './MobileDriverOverlay' -import { TerminalErrorToast } from './TerminalErrorToast' +import { stripSshReconnectOwnedErrorLines, TerminalErrorToast } from './TerminalErrorToast' import { TerminalSessionStateSaveFailureDialog } from './TerminalSessionStateSaveFailureDialog' import TerminalContextMenu from './TerminalContextMenu' import TerminalPaneHeaderOverlay from './TerminalPaneHeaderOverlay' @@ -2779,6 +2779,18 @@ export default function TerminalPane({ sshReconnectStatus && sshReconnectStatus !== 'connected' ) + // Why: while the reconnect banner owns recovery, strip only the SSH-owned lines from the + // (possibly aggregated) error, so a later successful connect can't flash the raw ssh:connect + // failure and any unrelated error still surfaces after reconnect. + useEffect(() => { + if (!showSshReconnectOverlay || terminalError == null) { + return + } + const kept = stripSshReconnectOwnedErrorLines(terminalError) + if (kept !== terminalError) { + setTerminalError(kept) + } + }, [showSshReconnectOverlay, terminalError]) const menuPaneHasCustomTitle = contextMenu.menuPaneId !== null && Boolean(paneTitles[contextMenu.menuPaneId]) const chatLeafStillMounted = chatLeafId @@ -2889,13 +2901,15 @@ export default function TerminalPane({ }) }} /> - {terminalError && isActive && ( + {/* Why: the reconnect banner already owns SSH recovery UX; the z-50 error + toast was painting over it (same bottom strip) with the raw ssh:connect failure. */} + {terminalError && isActive && !showSshReconnectOverlay ? ( setTerminalError(null)} onRestartDaemon={() => daemonActions.setPending('restart')} /> - )} + ) : null} {/* Why: portal into the pane so the banner stacks above the xterm canvas (sibling mount painted under WebGL). */} {showSshReconnectOverlay && sshReconnectTargetId && sshReconnectStatus ? managedPanes.map((pane) =>