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(ssh): a cancelled install ends the share

reviewfff7a6b31112
diff --git a/docs/hosted-team-relay.md b/docs/hosted-team-relay.md
index 5a7d69f21..88c0afda1 100644
--- a/docs/hosted-team-relay.md
+++ b/docs/hosted-team-relay.md
@@ -283,7 +283,12 @@ again.
installs only for a plan that does not refuse, and bootstraps and resumes only for a ready one.
3. **Confirm.** Cancel changes nothing.
4. **Install**, only when needed, then probe again. The server must now be ready, or the share stops
- with nothing changed.
+ with nothing changed. After an install that exited 0 a not-ready answer gets three probes, 2 s
+ apart, because the restarted service may not answer `team status` at once. **Cancel** during the
+ install ends the share there (the dialog keeps the focus on itself, not on Cancel, so a stray
+ Enter does not stop a long install): no second probe, nothing saved, marked or closed, and the
+ result says "The install was cancelled, so nothing was shared. The host may keep a partly
+ installed nodeterm-server; the next install replaces it."
5. **Save the canvas.**
6. **Mark the project handed off, in progress** (`handedOffTo` with no host yet), and save, so no
later save on this desktop mirrors the project to the host.
diff --git a/src/main/remote-ssh/share-team.test.ts b/src/main/remote-ssh/share-team.test.ts
index 70254cc47..c84db849a 100644
--- a/src/main/remote-ssh/share-team.test.ts
+++ b/src/main/remote-ssh/share-team.test.ts
@@ -237,7 +237,7 @@ describe('share-team handlers', () => {
expect(await deps({ remote: { status: 'absent' } }).h.flushMirror('p')).toEqual({ ok: true, nodeIds: [] })
expect(await deps({ remote: { status: 'ok', content: '{not json' } }).h.flushMirror('p')).toMatchObject({ ok: false })
})
- it('install: one run per project at a time, cancellable, output streamed', async () => {
+ it('install: one run per project at a time, cancellable (answered E_CANCELLED), output streamed', async () => {
let release: (v: { exitCode: number }) => void = () => {}
let seenSignal: AbortSignal | null = null
const { h } = deps({
@@ -255,7 +255,8 @@ describe('share-team handlers', () => {
await h.cancelInstall('p')
expect(seenSignal!.aborted).toBe(true)
release({ exitCode: 143 })
- expect(await first).toEqual({ ok: true, exitCode: 143 })
+ // A cancelled install is never an install that "finished": the share must end there.
+ expect(await first).toEqual({ ok: false, code: 'E_CANCELLED', error: 'The install was cancelled.' })
expect(chunks).toEqual(['installing\n'])
// The slot is free again once the run ends.
const again = h.install('p', () => {})
diff --git a/src/main/remote-ssh/share-team.ts b/src/main/remote-ssh/share-team.ts
index 4c309f957..4493fcf79 100644
--- a/src/main/remote-ssh/share-team.ts
+++ b/src/main/remote-ssh/share-team.ts
@@ -107,6 +107,7 @@ const PROJECT_READ_FAILED = 'Could not read the project file on the host.'
const BAD_JOIN_CODE = 'The server sent an invalid join code.'
const BAD_BOOTSTRAP = 'The server answered bootstrap with a result this build cannot read.'
const BAD_RESUME = 'The server answered resume with a result this build cannot read.'
+const INSTALL_CANCELLED = { ok: false, code: 'E_CANCELLED', error: 'The install was cancelled.' } as const
const NOT_ISSUED = 'Only the invite code Share with team just received can be added without the verification code.'
/** The most of a server-sent sentence shown to the user. */
@@ -255,6 +256,9 @@ export function createShareTeamHandlers(deps: ShareTeamDeps): ShareTeamHandlers
}
try {
const { exitCode } = await deps.runInstall(projectId, SHARE_INSTALL_SCRIPT, chunk, ctrl.signal)
+ // A cancelled run is never "finished": the renderer must end the share, not re-probe a
+ // host that may still read as ready.
+ if (ctrl.signal.aborted) return INSTALL_CANCELLED
return { ok: true, exitCode }
} finally {
installs.delete(projectId)
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 55936d2b9..7fa82f689 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -16984,7 +16984,13 @@ export function Canvas() {
now: () => Date.now()
})
return runShare(
- { api: window.nodeTerminal.shareTeam, confirm: ui.confirm, phase: ui.phase, ...steps },
+ {
+ api: window.nodeTerminal.shareTeam,
+ confirm: ui.confirm,
+ phase: ui.phase,
+ ...steps,
+ wait: (ms) => new Promise<void>((resolve) => setTimeout(resolve, ms))
+ },
{
projectId,
projectName: project.name,
diff --git a/src/renderer/components/ShareTeamDialog.test.tsx b/src/renderer/components/ShareTeamDialog.test.tsx
index b4db93ce7..73fda7368 100644
--- a/src/renderer/components/ShareTeamDialog.test.tsx
+++ b/src/renderer/components/ShareTeamDialog.test.tsx
@@ -99,6 +99,8 @@ describe('ShareTeamDialogBody', () => {
expect(html).toContain('Installing nodeterm-server on the host.')
expect(html).toContain('cloning…')
expect(html).toContain('Cancel')
+ // The panel takes focus, not the Cancel: a stray Enter must not stop a long install.
+ expect(html).not.toContain('data-autofocus')
expect(body({ phase: 'running', step: 'bootstrapping', log: '' })).not.toContain('Cancel')
expect(body({ phase: 'running', step: 'bootstrapping', log: 'cloning…' })).not.toContain('cloning…')
})
@@ -348,6 +350,8 @@ describe('ShareTeamDialog', () => {
act(() => output!('cloning…\n'))
act(() => output!('building…\n'))
expect(document.querySelector('[role="log"]')!.textContent).toBe('cloning…\nbuilding…\n')
+ expect(document.activeElement?.classList.contains('share-team')).toBe(true)
+ expect(document.activeElement).not.toBe(btn('Cancel'))
click(btn('Cancel')!)
expect(api.cancelInstall).toHaveBeenCalledWith('p1')
})
diff --git a/src/renderer/components/ShareTeamDialog.tsx b/src/renderer/components/ShareTeamDialog.tsx
index 338f844aa..64c6652e4 100644
--- a/src/renderer/components/ShareTeamDialog.tsx
+++ b/src/renderer/components/ShareTeamDialog.tsx
@@ -98,10 +98,11 @@ export function ShareTeamDialogBody(p: {
</>
)
// Only the install can be stopped: every later step is short, and stopping one half-way would
- // leave the very state the orchestrator's own undo exists to avoid.
+ // leave the very state the orchestrator's own undo exists to avoid. The panel keeps the focus,
+ // not this button: a stray Enter must not stop a long install.
actions =
s.step === 'installing' ? (
- <button className="confirm__btn" data-autofocus="" onClick={p.onCancelInstall}>
+ <button className="confirm__btn" onClick={p.onCancelInstall}>
Cancel
</button>
) : null
@@ -321,7 +322,7 @@ export function ShareTeamDialog({
setState({ ...s, copied: true })
}
- // The orchestrator's install then answers with a non-zero exit, and that failure is what renders.
+ // The install then answers E_CANCELLED, and the orchestrator ends the share with that failure.
const cancelInstall = (): void => {
try {
window.nodeTerminal.shareTeam.cancelInstall(projectId).catch(() => {})
diff --git a/src/renderer/lib/shareSshTeam.test.ts b/src/renderer/lib/shareSshTeam.test.ts
index a0828e5bf..69d463bde 100644
--- a/src/renderer/lib/shareSshTeam.test.ts
+++ b/src/renderer/lib/shareSshTeam.test.ts
@@ -1,5 +1,14 @@
import { describe, it, expect } from 'vitest'
-import { runShare, classifyTerminals, securityNote, type ShareDeps, type ShareInput } from './shareSshTeam'
+import {
+ runShare,
+ classifyTerminals,
+ securityNote,
+ INSTALL_CANCELLED,
+ INSTALL_REPROBE_ATTEMPTS,
+ INSTALL_REPROBE_GAP_MS,
+ type ShareDeps,
+ type ShareInput
+} from './shareSshTeam'
const READY = { ok: true, probe: { adoptCwd: '/home/alice/proj', teamExists: false } as never, plan: { kind: 'ready' }, paneCommands: { 'term-p': 'npm' } } as const
const BOOT = { ok: true, result: { hostId: 'H', projectId: 'project-9', projectName: 'proj', joinCode: 'nodeterm://join/CODE', hosting: 'up', created: { team: true, owner: true, project: true, share: true } } } as const
@@ -23,7 +32,8 @@ function setup(o: Partial<Record<'probe' | 'flush' | 'bootstrap' | 'kill' | 'res
release: async () => void log.push('release'),
restore: async () => void log.push('restore'),
markHandedOff: async (to) => void log.push(`handed:${to.hostId}:${to.projectId}`),
- join: (code, focus) => void log.push(`join:${focus}`)
+ join: (code, focus) => void log.push(`join:${focus}`),
+ wait: async (ms) => void log.push(`wait:${ms}`)
}
return { deps, log }
}
@@ -346,10 +356,42 @@ describe('runShare', () => {
})
it('an install that does not leave a ready server fails without releasing anything', async () => {
const { deps, log } = setup()
- deps.api.probe = async () => ({ ...READY, plan: { kind: 'install', reason: 'missing' } }) as never
+ deps.api.probe = async () => (log.push('probe'), { ...READY, plan: { kind: 'install', reason: 'missing' } }) as never
expect(await runShare(deps, INPUT)).toMatchObject({ kind: 'failed', step: 'checking-install', reopened: false })
expect(log).not.toContain('release')
expect(log).not.toContain('mark')
+ // The re-probe was given a few chances (the restarted service may not answer at once).
+ expect(log.filter((l) => l === 'probe')).toHaveLength(1 + INSTALL_REPROBE_ATTEMPTS)
+ expect(log.filter((l) => l.startsWith('wait:'))).toEqual(Array(INSTALL_REPROBE_ATTEMPTS - 1).fill(`wait:${INSTALL_REPROBE_GAP_MS}`))
+ })
+ it('a re-probe right after a completed install retries while the server is not ready yet, then shares', async () => {
+ let n = 0
+ const { deps, log } = setup()
+ const notRunning = { ...READY, plan: { kind: 'install', reason: 'not-running' } }
+ deps.api.probe = async () => (log.push('probe'), (n++ < 2 ? notRunning : READY) as never)
+ expect(await runShare(deps, INPUT)).toMatchObject({ kind: 'shared' })
+ expect(log.filter((l) => l === 'probe')).toHaveLength(3)
+ expect(log.indexOf('wait:2000')).toBeGreaterThan(log.indexOf('install'))
+ })
+ it('an install that exited non-zero, or a refusing re-probe, is not retried', async () => {
+ const failedInstall = setup()
+ failedInstall.deps.api.install = async () => ({ ok: true, exitCode: 1 })
+ failedInstall.deps.api.probe = async () => (failedInstall.log.push('probe'), { ...READY, plan: { kind: 'install', reason: 'missing' } }) as never
+ expect(await runShare(failedInstall.deps, INPUT)).toMatchObject({ kind: 'failed', step: 'checking-install' })
+ expect(failedInstall.log.filter((l) => l === 'probe')).toHaveLength(2)
+ let n = 0
+ const refusing = setup()
+ refusing.deps.api.probe = async () =>
+ (refusing.log.push('probe'), (n++ === 0 ? { ...READY, plan: { kind: 'install', reason: 'missing' } } : { ...READY, plan: { kind: 'refuse', reason: 'nope' } })) as never
+ expect(await runShare(refusing.deps, INPUT)).toMatchObject({ kind: 'failed', step: 'checking-install' })
+ expect(refusing.log.filter((l) => l === 'probe')).toHaveLength(2)
+ })
+ it('a cancelled install ends the share: no re-probe, nothing released, killed or bootstrapped', async () => {
+ const { deps, log } = setup({ probe: { ...READY, plan: { kind: 'install', reason: 'missing' } } })
+ deps.api.install = async () => (log.push('install'), { ok: false, code: 'E_CANCELLED', error: 'The install was cancelled.' })
+ expect(await runShare(deps, INPUT)).toEqual({ kind: 'failed', step: 'installing', error: INSTALL_CANCELLED, reopened: false })
+ expect(log.filter((l) => l === 'probe')).toHaveLength(1)
+ expect(log.some((l) => /^(prepare|mark|flush|release|restore|bootstrap|kill|resume|seed|join)/.test(l))).toBe(false)
})
})
diff --git a/src/renderer/lib/shareSshTeam.ts b/src/renderer/lib/shareSshTeam.ts
index 50f31fa60..e64e0b86f 100644
--- a/src/renderer/lib/shareSshTeam.ts
+++ b/src/renderer/lib/shareSshTeam.ts
@@ -108,6 +108,8 @@ export interface ShareDeps {
restore(): Promise<void>
markHandedOff(to: { hostId: string; projectId: string }): Promise<void>
join(joinCode: string, focusProjectId: string): void
+ /** Wait `ms` (the pause between re-probes after an install). */
+ wait(ms: number): Promise<void>
}
const BUSY_STATES = new Set<AgentState>(['working', 'blocked'])
@@ -116,6 +118,13 @@ const isAgentResumable = (id: string | undefined): boolean =>
const errorText = (e: unknown): string => (e instanceof Error ? e.message : String(e))
+/** How often the host is probed after an install that exited 0, and how far apart: the restarted
+ * service can take a moment before its admin socket answers `team status`. */
+export const INSTALL_REPROBE_ATTEMPTS = 3
+export const INSTALL_REPROBE_GAP_MS = 2000
+export const INSTALL_CANCELLED =
+ 'The install was cancelled, so nothing was shared. The host may keep a partly installed nodeterm-server; the next install replaces it.'
+
/** An IPC verb that throws (a dead bridge, a renderer-side bug) reads as an ordinary failed reply,
* so every step below handles exactly one failure shape. */
async function call<T>(fn: () => Promise<ShareReply<T>>): Promise<ShareReply<T>> {
@@ -213,10 +222,20 @@ export async function runShare(deps: ShareDeps, input: ShareInput): Promise<Shar
if (plan.kind === 'install') {
phase('installing')
const installed = await call(() => api.install(projectId))
- // Probe again whatever the install answered: only a ready server lets the share go on, and a
- // failed reply (a dropped stream, say) does not by itself mean the server is not ready.
+ // A cancelled install ends the share here: nothing is released, and the host is not probed
+ // again (it may read as ready, and the user asked to stop).
+ if (!installed.ok && installed.code === 'E_CANCELLED') return failed('installing', INSTALL_CANCELLED, false)
+ // Probe again whatever else the install answered: only a ready server lets the share go on, and
+ // a failed reply (a dropped stream, say) does not by itself mean the server is not ready. After
+ // an install that exited 0 the restarted service may not answer yet, so a not-ready answer gets
+ // a few more tries.
phase('checking-install')
- const again = await call(() => api.probe(projectId, ids))
+ const attempts = installed.ok && installed.exitCode === 0 ? INSTALL_REPROBE_ATTEMPTS : 1
+ let again = await call(() => api.probe(projectId, ids))
+ for (let i = 1; i < attempts && again.ok && again.plan.kind === 'install'; i++) {
+ await deps.wait(INSTALL_REPROBE_GAP_MS)
+ again = await call(() => api.probe(projectId, ids))
+ }
if (!again.ok || again.plan.kind !== 'ready') {
const base = installed.ok
? `The install finished (exit ${installed.exitCode}) but nodeterm-server is not ready on the host.`
diff --git a/src/shared/share-team.ts b/src/shared/share-team.ts
index 5caf5d2c8..a10a63207 100644
--- a/src/shared/share-team.ts
+++ b/src/shared/share-team.ts
@@ -154,7 +154,8 @@ export function sharePlan(p: ShareProbe): SharePlan {
}
/** Every `shareTeam` answer: never a rejection across IPC. `code` is an `E_*` code when the
- * failure has one the renderer branches on (`E_NOT_CONNECTED`, `E_NOT_PROBED`, a server refusal). */
+ * failure has one the renderer branches on (`E_NOT_CONNECTED`, `E_NOT_PROBED`, `E_CANCELLED` for
+ * an install the user stopped, a server refusal). */
export type ShareReply<T> = ({ ok: true } & T) | { ok: false; error: string; code?: string }
/** The probe, the plan it implies, and the command each requested node's pane is running on the