From 4afe08f4945284e4646583955f0f3e7a9fdca8fc Mon Sep 17 00:00:00 2001 From: Al Zilla Date: Mon, 17 Aug 2026 13:22:49 -0600 Subject: [PATCH] fix(desktop): retry failed SSH Bot Mode inventory after cooldown A first inventory miss used to stick forever as a seeded default until the user hit Test. Retry after 60s; a successful cache still never re-probes, and Test still forces an immediate refresh. --- .../electron/connection-registry.test.ts | 8 ++++++++ apps/desktop/electron/connection-registry.ts | 20 +++++++++++++++++++ apps/desktop/electron/main.ts | 17 ++++++++++++---- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/apps/desktop/electron/connection-registry.test.ts b/apps/desktop/electron/connection-registry.test.ts index d0b67a39ef..786b8e68b1 100644 --- a/apps/desktop/electron/connection-registry.test.ts +++ b/apps/desktop/electron/connection-registry.test.ts @@ -28,6 +28,7 @@ import { REGISTRY_VERSION, rememberSshEnumeration, removeConnection, + shouldRetrySshInventory, resolveRegistryLocalRoute, setPrimaryConnection, shouldDeferLocalEnumeration, @@ -224,6 +225,13 @@ test('rememberSshEnumeration: live list wins, cache then seed default', () => { }) }) +test('shouldRetrySshInventory: first try, cooldown, then retry; cache never retries', () => { + assert.equal(shouldRetrySshInventory(false, null, 1_000), true) + assert.equal(shouldRetrySshInventory(false, 1_000, 30_000, 60_000), false) + assert.equal(shouldRetrySshInventory(false, 1_000, 61_000, 60_000), true) + assert.equal(shouldRetrySshInventory(true, 1_000, 120_000, 60_000), false) +}) + test('parseRemoteProfileListing: Mini/Spark dirs become roster names and drop rollbacks', () => { const listed = parseRemoteProfileListing( ['bob', 'dixie', 'goose', 'rambo', 'bob.rollback-old', '.hidden', '', 'not a name'].join('\n') diff --git a/apps/desktop/electron/connection-registry.ts b/apps/desktop/electron/connection-registry.ts index 4da82c9384..b888e85ef6 100644 --- a/apps/desktop/electron/connection-registry.ts +++ b/apps/desktop/electron/connection-registry.ts @@ -284,6 +284,26 @@ export function rememberSshEnumeration( return enumeration } +/** Whether an undialed SSH source should be inventoried again. Cached + * successes never retry. Failures retry after `retryAfterMs` so a cold box + * does not stay seeded as `default` until the user hits Test. */ +export function shouldRetrySshInventory( + hasCache: boolean, + lastAttemptMs: null | number | undefined, + nowMs: number, + retryAfterMs = 60_000 +): boolean { + if (hasCache) { + return false + } + + if (lastAttemptMs == null) { + return true + } + + return nowMs - lastAttemptMs >= retryAfterMs +} + const PROFILE_NAME_RE = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/ /** Turn `ls ~/.hermes/profiles` output into roster names. Always includes diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts index 3afe067eb1..ec15ce3920 100644 --- a/apps/desktop/electron/main.ts +++ b/apps/desktop/electron/main.ts @@ -106,6 +106,7 @@ import { resolveRegistryLocalRoute, setPrimaryConnection, shouldDeferLocalEnumeration, + shouldRetrySshInventory, updateEligibility, upsertConnection } from './connection-registry' @@ -12420,7 +12421,7 @@ ipcMain.handle('hermes:connections:test', async (_event, id) => { }) if (result?.reachable) { - sshInventoryAttempted.delete(entry.id) + sshInventoryAttemptedAt.delete(entry.id) sshRosterCache.delete(entry.id) await probeSshProfileInventory(entry) } @@ -12492,14 +12493,22 @@ ipcMain.handle('hermes:connections:test', async (_event, id) => { // descriptor serves the enumeration like any remote. Last-known SSH profile // lists are reused so switching the window back to local does not empty Bot Mode. const sshRosterCache = new Map() -const sshInventoryAttempted = new Set() +const sshInventoryAttemptedAt = new Map() +const SSH_INVENTORY_RETRY_MS = 60_000 async function probeSshProfileInventory(connection) { - if (sshRosterCache.has(connection.id) || sshInventoryAttempted.has(connection.id)) { + if ( + !shouldRetrySshInventory( + sshRosterCache.has(connection.id), + sshInventoryAttemptedAt.get(connection.id), + Date.now(), + SSH_INVENTORY_RETRY_MS + ) + ) { return } - sshInventoryAttempted.add(connection.id) + sshInventoryAttemptedAt.set(connection.id, Date.now()) const sshConfig = normalizeSshConfig({ mode: 'ssh',