Skip to content

The agent that grows with you

fix(desktop): an ssh connection learns its backend install id, so two addresses for one machine collapse

John Paul Soliva82e147ffb83e
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 8e7162fb687..0db0c5e22f1 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -15796,6 +15796,14 @@ async function probeSshProfileInventory(connection) {
if (profiles.length > 0) {
sshRosterCache.set(connection.id, profiles)
}
+
+ // Backend identity, on the session we already have open: without it an ssh connection has no
+ // install id at all, so two addresses for one machine never collapse into one roster row
+ // (#88828 wired this for remote/local only, through /api/status).
+ connectionInstallIds.set(connection.id, {
+ id: await remoteLifecycle.readRemoteInstallId(ssh),
+ ts: Date.now()
+ })
} catch (error: any) {
sshRememberLog(`[ssh] profile inventory failed for ${connection.id}: ${error?.message || error}`)
} finally {
@@ -15848,7 +15856,14 @@ async function enumerateRegistryAgentSources(registry = readDesktopConnectionsRe
// (ECONNRESET / liveness probe drop).
if (connection.kind === 'ssh') {
await probeSshProfileInventory(connection)
- raw = { connection, profiles: null, error: 'connect-on-demand' }
+ // The inventory probe learns the backend's install id on its own session; carrying it
+ // here is what lets two ssh addresses for one machine collapse to one row.
+ raw = {
+ connection,
+ profiles: null,
+ error: 'connect-on-demand',
+ installId: connectionInstallIds.get(connection.id)?.id
+ }
} else {
// Same connect-on-demand courtesy for the forced-local path: when
// the primary route is remote, enumerating "This device" would
diff --git a/apps/desktop/electron/remote-lifecycle.test.ts b/apps/desktop/electron/remote-lifecycle.test.ts
index 9e380116474..e8723467115 100644
--- a/apps/desktop/electron/remote-lifecycle.test.ts
+++ b/apps/desktop/electron/remote-lifecycle.test.ts
@@ -30,6 +30,7 @@ import {
probeRemotePlatform,
PROTOCOL_VERSION,
readLockfile,
+ readRemoteInstallId,
READY_RE,
remotePidAlive,
remoteSupportsSshOwnership,
@@ -237,6 +238,52 @@ test('POSIX relaunch gate rechecks after token upload immediately before process
)
})
+test('readRemoteInstallId reads the backend identity without spawning a dashboard or minting one', async () => {
+ const ssh = fakeSsh([
+ [/HERMES_HOME/, '/Users/zillajr/.hermes\n'],
+ [/cat .*install_id/, '0f8a1c2b3d4e5f60718293a4b5c6d7e8\n']
+ ])
+
+ assert.equal(await readRemoteInstallId(ssh), '0f8a1c2b3d4e5f60718293a4b5c6d7e8')
+ // Read-only: identity is the install's to mint, never a visiting client's.
+ assert.equal(
+ ssh.calls.some(cmd => /serve|dashboard|>\s*\S*install_id|tee|uuidgen/.test(cmd)),
+ false
+ )
+})
+
+test('readRemoteInstallId reports the INSTALL root id for a profile-pinned home', async () => {
+ // The whole point of the id: two ssh connections to one machine — one pinned at a profile,
+ // one at the root — must report the SAME backend so their roster rows collapse.
+ const pinned = fakeSsh([
+ [/HERMES_HOME/, '/Users/zillajr/.hermes/profiles/dixie\n'],
+ [/cat .*install_id/, '0f8a1c2b3d4e5f60718293a4b5c6d7e8\n']
+ ])
+
+ assert.equal(await readRemoteInstallId(pinned), '0f8a1c2b3d4e5f60718293a4b5c6d7e8')
+ assert.equal(
+ pinned.calls.some(cmd => cmd.includes('/Users/zillajr/.hermes/install_id')),
+ true
+ )
+ assert.equal(
+ pinned.calls.some(cmd => cmd.includes('/profiles/dixie/install_id')),
+ false
+ )
+})
+
+test('readRemoteInstallId reports no id rather than a bad one', async () => {
+ for (const payload of ['', 'not-an-id\n', 'ABCDEF\n', '0f8a1c2b3d4e5f60718293a4b5c6d7e8extra\n']) {
+ const ssh = fakeSsh([
+ [/HERMES_HOME/, '/Users/zillajr/.hermes\n'],
+ [/cat .*install_id/, payload]
+ ])
+
+ // An older backend (or one that has never been started) simply has no identity: the roster
+ // falls back to a per-connection key, exactly as before.
+ assert.equal(await readRemoteInstallId(ssh), undefined, payload)
+ }
+})
+
test('listRemoteHermesProfiles inventories Mini-style profile dirs without spawning a dashboard', async () => {
const ssh = fakeSsh([
[/HERMES_HOME/, '/Users/zillajr/.hermes\n'],
diff --git a/apps/desktop/electron/remote-lifecycle.ts b/apps/desktop/electron/remote-lifecycle.ts
index a6e00240eda..414080bab2f 100644
--- a/apps/desktop/electron/remote-lifecycle.ts
+++ b/apps/desktop/electron/remote-lifecycle.ts
@@ -389,6 +389,31 @@ async function listRemoteHermesProfiles(ssh) {
return parseRemoteProfileListing(listing)
}
+async function readRemoteInstallId(ssh) {
+ // The stable backend identity the roster collapses on (`hermes_cli/install_identity.py`:
+ // `<install root>/install_id`, opaque hex). Read from the INSTALL root, so an ssh connection
+ // pinned to `<root>/profiles/<name>` reports the same id as one pointed at the root — they are
+ // one backend. Read-only: a missing file is left missing (minting identity is the install's job,
+ // never a visiting client's) and simply means "no id", exactly as an older backend reports.
+ const root = remoteInstallRoot(assertSafeRemoteHome(await probeRemoteHermesHome(ssh)))
+ const file = expandRemotePath(`${root}/install_id`)
+ let out = ''
+
+ try {
+ out = await ssh.exec(`if [ -f ${file} ]; then cat ${file}; fi`)
+ } catch (cause) {
+ const error: any = new Error('Could not read the remote Hermes install id.')
+ error.kind = 'transient-transport-error'
+ error.cause = cause
+ throw error
+ }
+
+ const id = String(out || '').trim().split('\n').pop()?.trim().toLowerCase() ?? ''
+
+ // Same shape check the minting side guarantees; anything else is not an identity.
+ return /^[0-9a-f]{32}$/.test(id) ? id : undefined
+}
+
function assertSafeRemoteHome(home) {
const value = String(home || '').trim()
@@ -1740,6 +1765,7 @@ export {
probeRemotePlatform,
PROTOCOL_VERSION,
readLockfile,
+ readRemoteInstallId,
READY_RE,
REMOTE_LOCK_DIR,
remotePidAlive,