Skip to content

The agent that grows with you

fix(desktop): a native terminal that fails to start shows main's error and no retry

emozilla0efe24fdffd2
diff --git a/apps/desktop/src/app/right-sidebar/terminal/terminal-session-attempt.ts b/apps/desktop/src/app/right-sidebar/terminal/terminal-session-attempt.ts
index 2b4514d74a5..a70b0f67d3f 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
@@ -2,6 +2,7 @@ import type { Terminal } from '@xterm/xterm'
import type { RefObject } from 'react'
import type { HermesTerminalSession } from '@/global'
+import { isBrowserHostedDesktop } from '@/lib/platform'
import { $terminals, markTerminalPersistent, removeExitedTerminal } from './terminals'
@@ -68,8 +69,9 @@ export interface SessionAttemptController {
}
// One shell attachment per terminal tab at a time. Each start supersedes the
-// previous attempt; an attempt that fails, disconnects or loses its persistent
-// stream arms Enter to start (or resume) the next one in the same scrollback.
+// previous attempt; an attempt that disconnects or loses its persistent stream,
+// or a browser-host start that fails, arms Enter to start (or resume) the next
+// one in the same scrollback.
export function createSessionAttemptController(
id: string,
{
@@ -242,14 +244,18 @@ export function createSessionAttemptController(
release()
const expired = error && typeof error === 'object' && 'signal' in error && error.signal === 'expired'
+ const message = error instanceof Error ? error.message : String(error)
if (expired) {
resumeOnly = false
armRetry(TERMINAL_EXIT_MESSAGES.expired)
+ } else if (isBrowserHostedDesktop()) {
+ armRetry(`Terminal failed to start: ${message}. Press Enter to retry.`)
} else {
- armRetry(
- `Terminal failed to start: ${error instanceof Error ? error.message : String(error)}. Press Enter to retry.`
- )
+ // Native Desktop spawns a local shell: 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.tsx
index fa8614c4b88..19e889218a9 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
@@ -345,3 +345,34 @@ it('keeps a signed-out tab and says to sign in again instead of reconnecting', a
expect($desktopBoot.get().error).toBe(WEBAPP_LAUNCH_REQUIRED)
$desktopBoot.set({ ...$desktopBoot.get(), error: null, visible: false })
})
+
+// Native Desktop's shell is a local process (node-pty over IPC). A failed spawn prints main's error
+// line and leaves the tab closed: no retry hint, and Enter starts no second shell.
+it('native Desktop: a failed start shows main\'s error and Enter does not start another shell', async () => {
+ const start = vi.fn().mockRejectedValue(new Error('spawn /bin/nope ENOENT'))
+
+ delete window.document.documentElement.dataset.hermesDesktopHost
+ ;(window as unknown as { hermesDesktop: unknown }).hermesDesktop = {
+ terminal: {
+ attach: vi.fn(),
+ cwd: vi.fn(async () => null),
+ dispose: vi.fn(async () => true),
+ onData: vi.fn(() => () => {}),
+ onExit: vi.fn(() => () => {}),
+ resize: vi.fn(async () => true),
+ start,
+ write: vi.fn(async () => true)
+ }
+ }
+ const id = createTerminal('/work')
+ render(<Harness id={id} />)
+
+ await waitFor(() => expect(emulator.output).toContain('Terminal failed to start: spawn /bin/nope ENOENT\r\n'))
+ expect(screen.getByText('closed')).toBeTruthy()
+ expect(emulator.output).not.toMatch(/Press Enter/)
+
+ act(() => emulator.input('\r'))
+ await act(async () => {})
+ expect(start).toHaveBeenCalledTimes(1)
+ expect(screen.getByText('closed')).toBeTruthy()
+})