The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep Enter retrying an SSH terminal whose gateway is offline
Teknium71c094f36140
diff --git a/apps/desktop/src/app/right-sidebar/terminal/terminal-gateway.ts b/apps/desktop/src/app/right-sidebar/terminal/terminal-gateway.tsindex 624633190f6..0ce5f22becf 100644--- a/apps/desktop/src/app/right-sidebar/terminal/terminal-gateway.ts+++ b/apps/desktop/src/app/right-sidebar/terminal/terminal-gateway.ts@@ -38,6 +38,11 @@ export function shellGatewayFor(export const defaultTerminalGateway = () =>shellGatewayFor($activeConnectionId.get(), $activeGatewayProfile.get(), $connectionsRegistry.get())+/** The tab's shell rides an SSH gateway's tunnel (only SSH gateways keep a+ * connection id other than This device on a tab). */+export const runsOverSsh = (gateway: TerminalGateway | undefined): boolean =>+ Boolean(gateway && gateway.connectionId !== LOCAL_CONNECTION_ID)+export const terminalGatewayOf = (term: TerminalEntry | undefined): TerminalGateway | undefined =>term?.connectionId ? { connectionId: term.connectionId, ...(term.profile ? { profile: term.profile } : {}) } : undefineddiff --git a/apps/desktop/src/app/right-sidebar/terminal/terminal-session-attempt.ts b/apps/desktop/src/app/right-sidebar/terminal/terminal-session-attempt.tsindex 1c55fb00031..7441e45f962 100644--- a/apps/desktop/src/app/right-sidebar/terminal/terminal-session-attempt.ts+++ b/apps/desktop/src/app/right-sidebar/terminal/terminal-session-attempt.ts@@ -5,7 +5,7 @@ import type { HermesTerminalSession } from '@/global'import { translateNow } from '@/i18n'import { hostHas } from '@/lib/host-capabilities'-import { defaultTerminalGateway, terminalGatewayOf } from './terminal-gateway'+import { defaultTerminalGateway, runsOverSsh, terminalGatewayOf } from './terminal-gateway'import { $terminals, adoptTerminalGateway, markTerminalPersistent, removeExitedTerminal } from './terminals'type TerminalApi = Window['hermesDesktop']['terminal']@@ -282,10 +282,12 @@ export function createSessionAttemptController(} else if (signal === 'expired') {resumeOnly = falsearmRetry(TERMINAL_EXIT_MESSAGES.expired)- } else if (hostHas('retryTerminalSpawn')) {+ } else if (hostHas('retryTerminalSpawn') || runsOverSsh(gateway)) {+ // A browser host or an SSH gateway can come back (host offline,+ // tunnel still connecting): Enter tries again.armRetry(`Terminal failed to start: ${message}. Press Enter to retry.`)} else {- // Native Desktop spawns a local shell: a failed spawn shows its error+ // A local shell on native Desktop: a failed spawn shows its error// and the tab stays closed, as on main. Retrying it fails the same way.setStatus('closed')term.write(`Terminal failed to start: ${message}\r\n`)diff --git a/apps/desktop/src/app/right-sidebar/terminal/use-terminal-session.test.tsx b/apps/desktop/src/app/right-sidebar/terminal/use-terminal-session.test.tsxindex eefa28d78f8..a8efea119c5 100644--- a/apps/desktop/src/app/right-sidebar/terminal/use-terminal-session.test.tsx+++ b/apps/desktop/src/app/right-sidebar/terminal/use-terminal-session.test.tsx@@ -470,3 +470,46 @@ it("native Desktop: xterm's reply to the shell's cursor query is not activity; tawait waitFor(() => expect(saved()).toContain('$ make'), { timeout: 2000 })})++// An SSH gateway tab survives its host going away: after teardown, Enter re-dials the gateway, and+// while the host is still offline each failed start arms Enter again until the host is back.+it('native Desktop: an SSH tab keeps Enter armed while its gateway is offline', async () => {+ let exit: ((payload: { code: null | number; signal: null | string }) => void) | null = null++ const start = vi+ .fn()+ .mockResolvedValueOnce({ connectionId: 'nas', id: 'pty-1', shell: 'ssh' })+ .mockRejectedValueOnce(new Error('NAS is offline'))+ .mockResolvedValueOnce({ connectionId: 'nas', id: 'pty-2', shell: 'ssh' })++ delete window.document.documentElement.dataset.hermesDesktopHost+ ;(window as unknown as { hermesDesktop: unknown }).hermesDesktop = {+ terminal: {+ attach: vi.fn(async () => true),+ cwd: vi.fn(async () => null),+ dispose: vi.fn(async () => true),+ onData: vi.fn(() => () => {}),+ onExit: vi.fn((_id: string, callback: typeof exit) => {+ exit = callback++ return () => {}+ }),+ resize: vi.fn(async () => true),+ start,+ write: vi.fn(async () => true)+ }+ }+ const id = createTerminal('/work', { connectionId: 'nas', profile: 'default' })+ render(<Harness id={id} />)+ await waitFor(() => expect(screen.getByText('open')).toBeTruthy())++ act(() => exit!({ code: null, signal: 'disconnected' }))+ act(() => emulator.input('\r'))+ await waitFor(() => expect(emulator.output).toContain('Terminal failed to start: NAS is offline. Press Enter to retry.'))+ expect(screen.getByText('closed')).toBeTruthy()++ act(() => emulator.input('\r'))+ await waitFor(() => expect(screen.getByText('open')).toBeTruthy())+ expect(start).toHaveBeenCalledTimes(3)+ expect(start.mock.calls[2][0]).toMatchObject({ connectionId: 'nas', profile: 'default' })+})