diff --git a/apps/desktop/electron/remote-lifecycle.test.ts b/apps/desktop/electron/remote-lifecycle.test.ts index 47df3f2fc342..014d5692e250 100644 --- a/apps/desktop/electron/remote-lifecycle.test.ts +++ b/apps/desktop/electron/remote-lifecycle.test.ts @@ -480,6 +480,8 @@ test('connect() respawns when the lockfile pid is dead (killed dashboard)', asyn assert.equal(result.reused, false) assert.equal(result.pid, 888) assert.equal(result.remotePort, 42000) + assert.ok(!ssh.calls.some(command => command.includes('pid=333') && command.includes('print("OWNED"')), + 'a dead pid has no process identity to verify') }) test('connect() respawns when the dashboard is wedged (alive pid, probe fails)', async () => { diff --git a/apps/desktop/electron/remote-lifecycle.ts b/apps/desktop/electron/remote-lifecycle.ts index c649ad50b82d..aec04ed19248 100644 --- a/apps/desktop/electron/remote-lifecycle.ts +++ b/apps/desktop/electron/remote-lifecycle.ts @@ -317,8 +317,8 @@ async function pidIsOurDashboard(ssh, pid, spawnNonce, hermesPath = '') { } // Kill the stale dashboard ONLY if provably ours, then drop the lockfile. -async function cleanupStale(ssh, ownershipId, lock) { - if (lock && await pidIsOurDashboard(ssh, lock.pid, lock.spawnNonce, lock.hermesPath)) { +async function cleanupStale(ssh, ownershipId, lock, pidAlive = true) { + if (pidAlive && lock && await pidIsOurDashboard(ssh, lock.pid, lock.spawnNonce, lock.hermesPath)) { try { const result = (await ssh.exec( `kill ${Number(lock.pid)} && ` + @@ -553,7 +553,7 @@ async function connect(deps) { const lock = await readLockfile(ssh, ownershipId) if (lock) { const pidAlive = await remotePidAlive(ssh, lock.pid) - const owned = await pidIsOurDashboard(ssh, lock.pid, lock.spawnNonce, lock.hermesPath) + const owned = pidAlive && await pidIsOurDashboard(ssh, lock.pid, lock.spawnNonce, lock.hermesPath) const reusable = pidAlive && owned && Boolean(reuseToken) && lock.tokenFingerprint === fingerprintToken(reuseToken) && lock.hermesPath === hermesPath && lock.hermesHome === hermesHome @@ -607,7 +607,7 @@ async function connect(deps) { } } else { assertNotAborted(signal) - await cleanupStale(ssh, ownershipId, lock) + await cleanupStale(ssh, ownershipId, lock, pidAlive) } }