Skip to content

The agent that grows with you

fix(desktop): retry failed SSH Bot Mode inventory after cooldown

Al Zilla4afe08f49452
diff --git a/apps/desktop/electron/connection-registry.test.ts b/apps/desktop/electron/connection-registry.test.ts
index d0b67a39efb..786b8e68b13 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 4da82c9384f..b888e85ef6e 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 3afe067eb12..ec15ce39204 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<string, string[]>()
-const sshInventoryAttempted = new Set<string>()
+const sshInventoryAttemptedAt = new Map<string, number>()
+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',