Skip to content

The agent that grows with you

fix(desktop): clear dead remote update markers on SSH startup

686f6c617ceda46ba43a
diff --git a/apps/desktop/electron/managed-ssh-update.test.ts b/apps/desktop/electron/managed-ssh-update.test.ts
index b44f883ce1d..adef9261f09 100644
--- a/apps/desktop/electron/managed-ssh-update.test.ts
+++ b/apps/desktop/electron/managed-ssh-update.test.ts
@@ -399,9 +399,13 @@ test.runIf(process.platform !== 'win32').each([0, 23])(
const log: string = await readFile(logPath, 'utf8')
assert.match(stdout, /MANAGED_UPDATE_STARTED/)
- assert.equal(stderr, '')
+ assert.match(log, /managed-update start pid=/)
+ assert.match(log, new RegExp(`managed-update exit rc=${exitCode}`))
assert.equal(status, String(exitCode), `updater output: ${log}`)
- assert.deepEqual(log.trimEnd().split('\n'), ['update', '--yes', home, CORRELATION, 'default', home, logPath])
+ const logLines: string[] = log.trimEnd().split('\n')
+ assert.match(logLines.shift() ?? '', /managed-update start pid=/)
+ assert.match(logLines.pop() ?? '', new RegExp(`managed-update exit rc=${exitCode}`))
+ assert.deepEqual(logLines, ['update', '--yes', home, CORRELATION, 'default', home, logPath])
assert.equal((await stat(statusPath)).mode & 0o777, 0o600)
assert.equal(
(await readdir(home)).some((name: string): boolean => name.endsWith('.tmp')),
@@ -412,7 +416,6 @@ test.runIf(process.platform !== 'win32').each([0, 23])(
}
}
)
-
test('Windows managed launcher starts a hidden child and leaves exit 75 to the external coordinator', () => {
const command = buildWindowsManagedUpdateLaunch(
{
diff --git a/apps/desktop/electron/managed-ssh-update.ts b/apps/desktop/electron/managed-ssh-update.ts
index d7eb59765e6..c87796d11d0 100644
--- a/apps/desktop/electron/managed-ssh-update.ts
+++ b/apps/desktop/electron/managed-ssh-update.ts
@@ -236,13 +236,15 @@ function buildPosixManagedUpdateLaunch(target: RemoteUpdateTarget, correlationId
`${launcherWord} update --yes`
const inner =
- `set +e; if [ -r "/proc/$$/stat" ]; then ` +
+ `set +e; echo "managed-update start pid=$$ $(date -u +%Y-%m-%dT%H:%M:%SZ)" >&2; ` +
+ `if [ -r "/proc/$$/stat" ]; then ` +
`intent_creation="linux:$(awk '{print $22}' "/proc/$$/stat")"; ` +
`else intent_creation="darwin:$(ps -o lstart= -p "$$" | sed 's/^ *//')"; fi; ` +
`intent_tmp=${intentWord}."$$".tmp; ` +
`printf '{"correlation":"%s","pid":%s,"creation":"%s"}' ${shq(correlation)} "$$" "$intent_creation" > "$intent_tmp" && ` +
`mv -f "$intent_tmp" ${intentWord} || exit 70; ` +
`${updateCommand}; rc=$?; ` +
+ `echo "managed-update exit rc=$rc $(date -u +%Y-%m-%dT%H:%M:%SZ)" >&2; ` +
`if [ "$rc" -ne ${UPDATE_EXIT_INDEPENDENT_HANDOFF} ] && [ ! -e ${statusWord} ]; then ` +
`tmp=${statusWord}."$$".tmp; umask 077; ` +
`printf "%s" "$rc" > "$tmp" && mv -f "$tmp" ${statusWord}; fi; ` +
diff --git a/apps/desktop/electron/remote-lifecycle.test.ts b/apps/desktop/electron/remote-lifecycle.test.ts
index 78b3132aed6..7ce4dcf388b 100644
--- a/apps/desktop/electron/remote-lifecycle.test.ts
+++ b/apps/desktop/electron/remote-lifecycle.test.ts
@@ -184,6 +184,8 @@ test('POSIX relaunch gate permits absent/dead markers and normalizes named-profi
assert.match(commands[0], /home\.parent\.name/)
assert.match(commands[0], /profiles/)
assert.match(commands[0], /\.hermes-update-in-progress/)
+ assert.match(commands[0], /marker\.unlink/)
+ assert.match(commands[0], /\/proc\/%d\/cmdline/)
})
test('POSIX relaunch gate rechecks after token upload immediately before process creation', async () => {
diff --git a/apps/desktop/electron/remote-lifecycle.ts b/apps/desktop/electron/remote-lifecycle.ts
index a2f0783443d..4b734dc805d 100644
--- a/apps/desktop/electron/remote-lifecycle.ts
+++ b/apps/desktop/electron/remote-lifecycle.ts
@@ -300,6 +300,11 @@ from pathlib import Path
home=Path(os.path.expanduser(sys.argv[1]))
if home.parent.name=='profiles':home=home.parent.parent
marker=home/'.hermes-update-in-progress'
+def clear():
+ try:marker.unlink()
+ except FileNotFoundError:pass
+ except OSError:pass
+ print('CLEAR');raise SystemExit
try:
with marker.open('rb') as stream:raw=stream.read(257)
except FileNotFoundError:
@@ -319,15 +324,20 @@ except ValueError:
try:
os.kill(owner,0)
except ProcessLookupError:
- print('CLEAR')
+ clear()
except PermissionError:
- print('LIVE:'+str(owner))
+ print('LIVE:'+str(owner));raise SystemExit
except OSError as error:
- if error.errno==errno.ESRCH:print('CLEAR')
- elif error.errno==errno.EPERM:print('LIVE:'+str(owner))
- else:print('UNCERTAIN')
-else:
- print('LIVE:'+str(owner))
+ if error.errno==errno.ESRCH:clear()
+ elif error.errno==errno.EPERM:print('LIVE:'+str(owner));raise SystemExit
+ else:print('UNCERTAIN');raise SystemExit
+try:
+ cmd=open('/proc/%d/cmdline'%owner,'rb').read().replace(b'\0',b' ')
+except OSError:
+ cmd=b''
+if cmd and b'update' not in cmd:
+ clear()
+print('LIVE:'+str(owner))
`
/**