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.
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user