fix(desktop): discard dead SSH ownership records

Skip argv ownership verification after the remote PID is already proven dead, then remove only the validated lock/log metadata and continue with a fresh spawn.
This commit is contained in:
yoniebans 2026-07-16 09:54:20 +02:00
parent 195d4557fc
commit 9e13cd125b
2 changed files with 6 additions and 4 deletions

View file

@ -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 () => {

View file

@ -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)
}
}