Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(agents): bound the CLI-caps wait so a hung RPC can never block an agent relaunch

enes543fb03c365f
diff --git a/src/core/claude-cli.ts b/src/core/claude-cli.ts
index d07b6c782..e775894de 100644
--- a/src/core/claude-cli.ts
+++ b/src/core/claude-cli.ts
@@ -42,19 +42,14 @@ async function probe(): Promise<ClaudeCliCaps> {
/**
* The local Claude CLI's capabilities. Memoized for the process lifetime: `claude --version`
- * spawns a login shell + node, and the answer only changes when the user upgrades the CLI (a
- * relaunch — or a manual `refresh` — picks that up). Never rejects.
+ * spawns a login shell + node, and the answer only changes when the user upgrades the CLI (which a
+ * relaunch picks up). Never rejects.
*/
export function claudeCliCaps(): Promise<ClaudeCliCaps> {
if (!cached) cached = probe()
return cached
}
-/** Drop the memo so the next call re-probes (used by the tests; also survives a CLI upgrade). */
-export function resetClaudeCliCaps(): void {
- cached = null
-}
-
/** Wire the probe onto the platform's RPC surface (Electron ipcMain / server WS-RPC alike). */
export function registerClaudeCliIpc(): void {
platform().handle(IPC.claudeCliCaps, () => claudeCliCaps())
diff --git a/src/renderer/state/permissionMode.test.ts b/src/renderer/state/permissionMode.test.ts
index 0fb8d0d5b..2228541fe 100644
--- a/src/renderer/state/permissionMode.test.ts
+++ b/src/renderer/state/permissionMode.test.ts
@@ -26,7 +26,7 @@ const SSH_SERVER = { id: 's1', label: 'box', host: 'box', user: 'me' } as unknow
beforeEach(() => {
useProjects.getState().hydrate({ version: 2, activeProjectId: '', projects: [] })
useSettings.setState({ settings: { ...DEFAULT_SETTINGS }, hydrated: false })
- useSshConn.setState({ byProject: {} })
+ useSshConn.setState({ byProject: {}, autoPermByProject: {} })
resetClaudeCliCapsForTests()
mockCliCaps(MODERN)
})
@@ -185,4 +185,23 @@ describe('ensureActivePermissionMode', () => {
await expect(ensureActivePermissionMode()).resolves.toBe('manual')
expect(await ensureClaudeCliCaps()).toEqual(UNKNOWN_CLAUDE_CLI_CAPS)
})
+
+ it('never hangs on a probe that never answers (Server Edition: WS-RPC has no timeout)', async () => {
+ // A dropped socket between send and response leaves the RPC promise unsettled forever. The
+ // relaunch awaits this, so it must time out into the fail-open bare command instead.
+ vi.useFakeTimers()
+ try {
+ ;(globalThis as { window?: unknown }).window = {
+ nodeTerminal: { claude: { cliCaps: () => new Promise<never>(() => {}) } }
+ }
+ resetClaudeCliCapsForTests()
+ activeProject()
+
+ const pending = ensureActivePermissionMode()
+ await vi.advanceTimersByTimeAsync(3000)
+ await expect(pending).resolves.toBe('manual')
+ } finally {
+ vi.useRealTimers()
+ }
+ })
})
diff --git a/src/renderer/state/permissionMode.ts b/src/renderer/state/permissionMode.ts
index aec897f0b..40a52f723 100644
--- a/src/renderer/state/permissionMode.ts
+++ b/src/renderer/state/permissionMode.ts
@@ -16,14 +16,32 @@ import { useSshConn } from './sshConn'
let caps: ClaudeCliCaps = UNKNOWN_CLAUDE_CLI_CAPS
let capsPromise: Promise<ClaudeCliCaps> | null = null
-/** Kick off (or join) the local CLI probe. Never rejects. Called once at boot; awaited by any
- * launch path that can run before boot settles (a cold-restored agent node). */
+/** How long a launch may wait on the probe before giving up on it and using the bare command. */
+const CAPS_WAIT_MS = 3000
+
+/**
+ * Kick off (or join) the local CLI probe. Never rejects, and never takes longer than
+ * `CAPS_WAIT_MS`. Called once at boot; awaited by any launch path that can run before boot settles
+ * (a cold-restored agent node).
+ *
+ * The timeout is what makes "a launch is never blocked on the probe" true BY CONSTRUCTION. On the
+ * desktop the IPC round-trip is bounded by the main-process probe, but in the Server Edition the
+ * call goes over WS-RPC, which neither times out nor rejects its pending requests when the socket
+ * drops — a drop between send and response would leave this promise (and the memo) unsettled
+ * forever, and with it the agent relaunch that awaits it. On timeout we resolve to the caps we
+ * have (unknown ⇒ no `auto` flag ⇒ bare command); a late answer still lands in `caps`, so the
+ * NEXT launch picks it up.
+ */
export function ensureClaudeCliCaps(): Promise<ClaudeCliCaps> {
if (!capsPromise) {
- capsPromise = Promise.resolve()
+ const probe = Promise.resolve()
.then(() => window.nodeTerminal.claude.cliCaps())
.then((c) => (caps = c ?? UNKNOWN_CLAUDE_CLI_CAPS))
.catch(() => UNKNOWN_CLAUDE_CLI_CAPS)
+ const timeout = new Promise<ClaudeCliCaps>((resolve) =>
+ setTimeout(() => resolve(caps), CAPS_WAIT_MS)
+ )
+ capsPromise = Promise.race([probe, timeout])
}
return capsPromise
}