Skip to content

The agent that grows with you

fix(desktop): drop Bot Mode rows for removed SSH connections

Al Zilla89877d10a516
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.js
index 823c0bb2f9e..c88d19f72bb 100644
--- a/apps/desktop/src/plugins/hermes-bots/plugin.js
+++ b/apps/desktop/src/plugins/hermes-bots/plugin.js
@@ -2241,10 +2241,11 @@ function mergeMultiSourceRoster(local, union, activeConnectionId, previous = [])
const localProfiles = Array.isArray(local?.profiles) ? local.profiles : []
const agents = Array.isArray(union?.agents) ? union.agents : []
// A live id of null/'' means the window is on the unscoped local backend
- // (host.state.connectionId is null for mode:'local'). Do NOT fall back to
- // registry primary in that case — primary can still say "spark" after the
- // user clicked a local bot, which skipped every Spark row as "active" and
- // invented a This-device shadow of default.
+ // (legacy hosts reported null for mode:'local'; the SDK now reports
+ // 'local'). Do NOT fall back to registry primary when the third argument
+ // was passed — primary can still say "spark" after the user clicked a
+ // local bot, which skipped every Spark row as "active" and invented a
+ // This-device shadow of default.
const liveProvided = arguments.length >= 3
const liveId = String(activeConnectionId || '').trim()
const activeId = liveId || (liveProvided ? '' : String(union?.primaryConnectionId || '').trim())
@@ -2338,6 +2339,12 @@ function mergeMultiSourceRoster(local, union, activeConnectionId, previous = [])
.filter(Boolean)
)
+ const registered = new Set(
+ (Array.isArray(union?.sources) ? union.sources : [])
+ .map(source => String(source?.connectionId || '').trim())
+ .filter(Boolean)
+ )
+
for (const row of previous) {
const connectionId = String(row?.connectionId || '').trim()
const name = String(row?.name || '').trim()
@@ -2347,6 +2354,10 @@ function mergeMultiSourceRoster(local, union, activeConnectionId, previous = [])
continue
}
+ if (registered.size > 0 && !registered.has(connectionId)) {
+ continue
+ }
+
if (omitted.has(connectionId) || !unionSourceIds.has(connectionId)) {
profiles.push({ ...row, remoteSource: true, sourceScoped: true })
present.add(key)
diff --git a/apps/desktop/src/plugins/hermes-bots/tests/multi-source-roster.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/multi-source-roster.test.mjs
index eb1198a22d8..19e0dceaf82 100644
--- a/apps/desktop/src/plugins/hermes-bots/tests/multi-source-roster.test.mjs
+++ b/apps/desktop/src/plugins/hermes-bots/tests/multi-source-roster.test.mjs
@@ -417,6 +417,39 @@ test('merge: previously seen remotes survive a connect-on-demand empty union', (
assert.equal(out.profiles.filter(p => p.name === 'default').length, 1)
})
+test('merge: previous remotes from a removed connection do not resurrect', () => {
+ const { __mergeMultiSourceRoster: merge } = runtime()
+ const previous = [
+ { name: 'default', last_session: { id: 'this-chat' } },
+ {
+ name: 'bob',
+ remoteSource: true,
+ sourceScoped: true,
+ connectionId: 'gone',
+ connectionKind: 'ssh',
+ connectionLabel: 'Gone',
+ handle: 'bob'
+ }
+ ]
+ const local = { profiles: [{ name: 'default', last_session: { id: 'this-chat' } }] }
+ const union = {
+ primaryConnectionId: 'local',
+ agents: [
+ {
+ connectionId: 'local',
+ connectionKind: 'local',
+ connectionLabel: 'This device',
+ profile: 'default',
+ handle: 'default'
+ }
+ ],
+ sources: [{ connectionId: 'local', kind: 'local' }]
+ }
+
+ const out = merge(local, union, 'local', previous)
+ assert.equal(out.profiles.find(p => p.connectionId === 'gone'), undefined)
+})
+
test('displayName: local default stays Hermes; remote default uses the device label', () => {
const { __displayName: name } = runtime()