Skip to content

The agent that grows with you

fix(desktop): skip macOS SSH remotes with a live serve in update-all

Austin Pickett0c266b515050
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 9add01a3345..64f63715912 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -332,9 +332,11 @@ import {
executeManagedRemoteUpdate,
fenceManagedSshBootstrapPublication,
ManagedConnectionUpdateGate,
+ managedSshDrainBlocker,
managedSshRecoveryScopes,
managedSshScopeRole,
managedSshTokenPersistencePlan,
+ managedSshUpdateAllRow,
MAX_MANAGED_SSH_RECOVERY_ATTEMPTS,
recoverManagedSshScopes,
refusedManagedSshUpdate,
@@ -11746,6 +11748,12 @@ async function drainManagedSshScope(scope) {
async function updateManagedSshConnection(source, correlationId) {
const sourceSnapshot = { ...source }
const scopes = await captureManagedSshScopes(sourceSnapshot)
+ const blocker = managedSshDrainBlocker(scopes)
+
+ if (blocker) {
+ return refusedManagedSshUpdate(source.id, correlationId, blocker.message, blocker.reason)
+ }
+
let ephemeral: null | { close: () => Promise<void>; target: RemoteUpdateTarget } = null
let launchAttempted = false
const firstState = scopes.find(scope => scope.state)?.state
@@ -16377,15 +16385,7 @@ ipcMain.handle('hermes:connections:update-all', async (_event, payload) => {
}
if (connection.kind === 'ssh') {
- const result = await requestManagedSshUpdate(connection.id)
-
- return {
- ...base,
- ok: result.ok,
- detail: result.message,
- managed: result,
- ...(result.ok ? {} : { error: result.error || result.outcome })
- }
+ return managedSshUpdateAllRow(base, await requestManagedSshUpdate(connection.id))
}
// Claim-guarded (#90812): coalesce with a concurrent renderer dial
diff --git a/apps/desktop/electron/managed-ssh-update.test.ts b/apps/desktop/electron/managed-ssh-update.test.ts
index 4f263a5942d..b44f883ce1d 100644
--- a/apps/desktop/electron/managed-ssh-update.test.ts
+++ b/apps/desktop/electron/managed-ssh-update.test.ts
@@ -13,10 +13,12 @@ import {
buildWindowsManagedUpdateLaunch,
fenceManagedSshBootstrapPublication,
ManagedConnectionUpdateGate,
+ managedSshDrainBlocker,
managedSshRecoveryDisposition,
managedSshRecoveryScopes,
managedSshScopeRole,
managedSshTokenPersistencePlan,
+ managedSshUpdateAllRow,
MAX_MANAGED_SSH_RECOVERY_ATTEMPTS,
parseRemoteUpdateObservation,
RECEIPT_GRACE_MS,
@@ -1042,3 +1044,36 @@ test('refused result is structured and has no managed scopes to restore', () =>
assert.equal(result.restoreOk, true)
assert.deepEqual(result.scopes, [])
})
+
+test('a live Desktop-owned serve on a macOS remote is a per-row skip, not a batch failure (#124617)', () => {
+ // Darwin cannot bind a signal to the verified PID, so the drain refuses to
+ // stop the serve. Detect that before any scope is touched and report the
+ // connection as skipped instead of an aborted update.
+ const blocker = managedSshDrainBlocker([
+ { profile: 'default', state: { remotePlatform: 'Darwin' } },
+ { profile: 'work', state: null }
+ ])
+
+ assert.equal(blocker?.reason, 'darwin-drain-unsupported')
+ assert.match(blocker?.message || '', /macOS remote \(default\)/)
+
+ const refused = refusedManagedSshUpdate('mac', CORRELATION, blocker!.message, blocker!.reason)
+ const row: any = managedSshUpdateAllRow({ connectionId: 'mac', label: 'Mac', kind: 'ssh' }, refused)
+
+ assert.equal(row.skipped, true)
+ assert.equal(row.reason, 'darwin-drain-unsupported')
+ assert.equal(row.detail, blocker!.message)
+ assert.equal(row.error, undefined)
+})
+
+test('macOS remotes with no live serve and Linux remotes still update', () => {
+ assert.equal(managedSshDrainBlocker([{ profile: 'default', state: null }]), null)
+ assert.equal(managedSshDrainBlocker([{ profile: 'default', state: { remotePlatform: 'Linux' } }]), null)
+
+ const failed = { ...refusedManagedSshUpdate('box', CORRELATION, 'boom'), outcome: 'update-failed' as const }
+ const row: any = managedSshUpdateAllRow({ connectionId: 'box' }, failed)
+
+ assert.equal(row.skipped, undefined)
+ assert.equal(row.ok, false)
+ assert.equal(row.error, 'boom')
+})
diff --git a/apps/desktop/electron/managed-ssh-update.ts b/apps/desktop/electron/managed-ssh-update.ts
index 30af832e6b4..d7eb59765e6 100644
--- a/apps/desktop/electron/managed-ssh-update.ts
+++ b/apps/desktop/electron/managed-ssh-update.ts
@@ -59,6 +59,9 @@ interface ManagedConnectionUpdateResult {
scopes: ManagedUpdateScopeResult[]
error?: string
message?: string
+ // Set when the connection was deliberately not attempted (a known safety
+ // limit, not a failure). Batch callers report it as a per-row skip.
+ skipReason?: string
}
interface ManagedSshScope {
@@ -941,7 +944,7 @@ async function runManagedSshUpdate<TScope extends ManagedSshScope>(
}
}
-function refusedManagedSshUpdate(connectionId: string, correlationId: string, error: string) {
+function refusedManagedSshUpdate(connectionId: string, correlationId: string, error: string, skipReason?: string) {
const message = String(error || 'This connection is not managed by Desktop SSH.')
return {
@@ -955,7 +958,50 @@ function refusedManagedSshUpdate(connectionId: string, correlationId: string, er
receipt: null,
scopes: [],
error: message,
- message
+ message,
+ ...(skipReason ? { skipReason } : {})
+ }
+}
+
+const DARWIN_DRAIN_UNSUPPORTED = 'darwin-drain-unsupported'
+
+// The POSIX drain signals the owned serve only through a pidfd, which binds the
+// signal to the verified process. Darwin has no equivalent, so
+// terminateOwnedDashboardForUpdate deliberately refuses there rather than
+// accept a PID-reuse window. Detect that before touching any scope: cycling
+// forwards only to hit the refusal would disrupt healthy sessions for nothing.
+// A macOS remote with no live Desktop-owned serve needs no drain and updates.
+function managedSshDrainBlocker(
+ scopes: Array<{ profile: string; state?: { remotePlatform?: string } | null }>
+): null | { reason: string; message: string } {
+ const blocked = scopes.filter(scope => scope.state?.remotePlatform === 'Darwin').map(scope => scope.profile)
+
+ if (blocked.length === 0) {
+ return null
+ }
+
+ return {
+ reason: DARWIN_DRAIN_UNSUPPORTED,
+ message:
+ `Skipped: Desktop cannot safely stop its running Hermes serve on this macOS remote (${blocked.join(', ')}). ` +
+ 'Disconnect it, or run `hermes update` on the remote, then retry.'
+ }
+}
+
+// One "Update all instances" row for a managed SSH connection. A deliberate
+// refusal with a skip reason is a skip, not a failure, so it is reported
+// per-row without reading as a broken batch.
+function managedSshUpdateAllRow<TBase extends object>(base: TBase, result: ManagedConnectionUpdateResult) {
+ if (result.skipReason) {
+ return { ...base, ok: false, skipped: true, reason: result.skipReason, detail: result.message, managed: result }
+ }
+
+ return {
+ ...base,
+ ok: result.ok,
+ detail: result.message,
+ managed: result,
+ ...(result.ok ? {} : { error: result.error || result.outcome })
}
}
@@ -1121,12 +1167,14 @@ export {
launchManagedRemoteUpdate,
ManagedConnectionUpdateGate,
type ManagedConnectionUpdateResult,
+ managedSshDrainBlocker,
managedSshRecoveryDisposition,
type ManagedSshRecoveryScope,
managedSshRecoveryScopes,
type ManagedSshScope,
managedSshScopeRole,
managedSshTokenPersistencePlan,
+ managedSshUpdateAllRow,
type ManagedUpdateDeps,
type ManagedUpdateOutcome,
type ManagedUpdateReceiptSummary,
diff --git a/apps/desktop/src/app/settings/connections-registry.tsx b/apps/desktop/src/app/settings/connections-registry.tsx
index b5c7a4406f9..8f204f918e6 100644
--- a/apps/desktop/src/app/settings/connections-registry.tsx
+++ b/apps/desktop/src/app/settings/connections-registry.tsx
@@ -518,6 +518,10 @@ export function ConnectionsRegistrySection() {
notify({ title: row.label, message: row.detail || s.updateAllDone })
} else if (row.skipped && row.reason === 'cloud-managed') {
notify({ title: row.label, message: s.updateSkippedCloud })
+ } else if (row.skipped && row.reason === 'darwin-drain-unsupported' && row.detail) {
+ // A deliberate per-row skip (e.g. a macOS SSH remote whose running
+ // serve Desktop cannot safely stop) — informational, not a failure.
+ notify({ title: row.label, message: row.detail })
} else {
notifyError(new Error(row.error || row.detail || row.reason || row.label), s.updateAllFailed)
}