From 187e5b2b956a5fdc367397b6063b2be17d88e0a7 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 17 Aug 2026 11:19:33 -0700 Subject: [PATCH] fix(desktop): stop phantom local default on remote-gateway desktops; keep the main agent named Hermes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to #88523/#88542 from a community report (main agent listed twice, both rows unnamed @default handles). Two distinct bugs, both specific to remote-gateway-primary desktops: 1. Phantom "This device" default (electron): the roster enumeration dialed ensureRegistryBackend for the registry's local entry unconditionally. On a remote-primary desktop that forces resolveRegistryLocalRoute into the forced-local branch — SPAWNING a local backend the user never asked for. That backend enumerates a `default` profile, so a second default agent appears AND the duplicate-handle rule forces -device suffixes onto the real one. New shouldDeferLocalEnumeration() treats the forced-local route as connect-on-demand (same courtesy as undialed SSH sources): the local entry only enumerates when it is the delegate route (local-primary desktops, byte-identical behavior) or a forced-local child is already pooled (the user opened one). 2. Main agent renamed to a connection label (plugin): displayName keyed the "show the connection label for a default row" rule off sourceScoped — which annotation also sets on ACTIVE-source rows. A remote-gateway user's main agent rendered as an IP-derived label (or bare handle) instead of "Hermes"/their title. Key it off remoteSource: only THIN rows from another source trade the friendly name for their source label. Tests: shouldDeferLocalEnumeration route matrix (delegate always enumerates; forced-local defers until a conn:local:: child exists; bare-key remote descriptor doesn't count), displayName regression (active default stays Hermes/title; thin remote default still shows its source label). --- .../electron/connection-registry.test.ts | 23 +++++++++++++++++++ apps/desktop/electron/connection-registry.ts | 22 ++++++++++++++++++ apps/desktop/electron/main.ts | 20 ++++++++++++++++ .../desktop/src/plugins/hermes-bots/plugin.js | 7 +++++- .../tests/multi-source-roster.test.mjs | 9 +++++++- 5 files changed, 79 insertions(+), 2 deletions(-) diff --git a/apps/desktop/electron/connection-registry.test.ts b/apps/desktop/electron/connection-registry.test.ts index 9e6ce7665f..736a673851 100644 --- a/apps/desktop/electron/connection-registry.test.ts +++ b/apps/desktop/electron/connection-registry.test.ts @@ -28,6 +28,7 @@ import { removeConnection, resolveRegistryLocalRoute, setPrimaryConnection, + shouldDeferLocalEnumeration, uniqueLabel, updateEligibility, upsertConnection @@ -159,6 +160,28 @@ test('registry local route: a per-profile remote override also forces local', () assert.deepEqual(route, { delegate: false, poolKey: 'conn:local::research' }) }) +// --- shouldDeferLocalEnumeration (roster's connect-on-demand for 'local') --- + +test('local enumeration: delegate route (local-primary desktop) always enumerates', () => { + const route = resolveRegistryLocalRoute('default', {}) + + assert.equal(shouldDeferLocalEnumeration(route, []), false) + assert.equal(shouldDeferLocalEnumeration(route, ['conn:local::default']), false) +}) + +test('local enumeration: forced-local route defers until a local child exists (remote-primary desktop)', () => { + // Remote-gateway-only desktops: enumerating "This device" here would SPAWN + // a local backend the user never asked for — a phantom `default` agent + // that duplicates their real one and forces -device handles onto it. + const route = resolveRegistryLocalRoute('default', { globalRemote: true }) + + assert.equal(shouldDeferLocalEnumeration(route, []), true) + // The v1 remote descriptor cached at the BARE profile key is not a local child. + assert.equal(shouldDeferLocalEnumeration(route, ['default', 'research']), true) + // Once the user has genuinely opened a forced-local child, it enumerates. + assert.equal(shouldDeferLocalEnumeration(route, ['conn:local::default']), false) +}) + // --- buildAgentRoster (union roster + @name-device rule) --- test('roster: unique profiles keep bare handles; duplicates get @name-device', () => { diff --git a/apps/desktop/electron/connection-registry.ts b/apps/desktop/electron/connection-registry.ts index a49fba76e2..2781631b44 100644 --- a/apps/desktop/electron/connection-registry.ts +++ b/apps/desktop/electron/connection-registry.ts @@ -211,6 +211,28 @@ export function resolveRegistryLocalRoute( return { delegate: true, poolKey: profileKey } } +/** + * Whether the roster enumeration should SKIP the registry's local entry as + * connect-on-demand. True when the local source is the forced-local route + * (primary resolves remote — enumerating would spawn a local backend the + * user never asked for, minting a phantom `default` agent and forcing + * -device handles onto the real one) AND no forced-local child is already + * pooled. Pure — main.ts feeds it the live route + pool keys. + */ +export function shouldDeferLocalEnumeration( + route: RegistryLocalRoute, + poolKeys: Iterable, + connectionId: string = LOCAL_CONNECTION_ID +): boolean { + if (route.delegate) { + return false + } + + const prefix = backendScopePrefix(connectionId) + + return ![...poolKeys].some(key => String(key).startsWith(prefix)) +} + // ── Union agent roster ────────────────────────────────────────────────────── export interface ConnectionAgents { diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts index e1da6f7fbf..340111ef11 100644 --- a/apps/desktop/electron/main.ts +++ b/apps/desktop/electron/main.ts @@ -103,6 +103,7 @@ import { removeConnection, resolveRegistryLocalRoute, setPrimaryConnection, + shouldDeferLocalEnumeration, updateEligibility, upsertConnection } from './connection-registry' @@ -12490,6 +12491,25 @@ async function enumerateRegistryAgentSources(registry = readDesktopConnectionsRe return { connection, profiles: null, error: 'connect-on-demand' } } + // Same connect-on-demand courtesy for the forced-local path: when the + // primary route is remote, enumerating "This device" would SPAWN a + // local backend this user has never asked for — a phantom `default` + // agent that also forces -device handle disambiguation onto the real + // one (remote-gateway-only desktops showed their main agent twice, + // Aug 17 2026). Enumerate the local source only when it is the + // delegate route (local-primary desktops, unchanged behavior) or a + // forced-local child is ALREADY pooled (the user opened one). + if (connection.kind === 'local') { + const localRoute = resolveRegistryLocalRoute('default', { + globalRemote: globalRemoteActive(), + profileRemoteOverride: Boolean(profileHasRemoteOverride(primaryProfileKey())) + }) + + if (shouldDeferLocalEnumeration(localRoute, backendPool.keys(), connection.id)) { + return { connection, profiles: null, error: 'connect-on-demand' } + } + } + const descriptor: any = await ensureRegistryBackend(connection.id, null) const body: any = await getJsonForBackend(descriptor, '/api/profiles', { timeoutMs: 8_000 }) diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.js index b3d7c1d06b..1881622a08 100644 --- a/apps/desktop/src/plugins/hermes-bots/plugin.js +++ b/apps/desktop/src/plugins/hermes-bots/plugin.js @@ -2482,7 +2482,12 @@ async function prepareBotSource(bot, pinnedChat) { } function displayName(bot, meta) { - if (bot?.sourceScoped && (bot.name || '').trim().toLowerCase() === 'default' && bot.connectionLabel) { + // Only THIN rows from another source trade the friendly name for their + // connection label — the active gateway's own default must keep reading + // "Hermes". Annotated active rows carry sourceScoped too, and keying this + // off sourceScoped renamed the user's main agent to an IP-derived label + // (community report, Aug 17 2026). + if (bot?.remoteSource && (bot.name || '').trim().toLowerCase() === 'default' && bot.connectionLabel) { return bot.connectionLabel } 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 643df47633..7f9a09f23f 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 @@ -240,8 +240,15 @@ test('default rows use source identity without borrowing another source title', assert.equal(metaFor(remote, metadata), null) assert.equal(name(remote, metaFor(remote, metadata)), 'Personal') - assert.equal(name(active, metadata.default), 'Personal') assert.equal(key(remote), 'personal::default') + + // The ACTIVE gateway's own default is the user's main agent — annotation + // (sourceScoped + connection fields) must NOT rename it to a connection + // label. Titled: the title wins. Untitled: it stays "Hermes". Regression: + // remote-gateway desktops showed the main agent as an IP-derived label + // with no shortname (Aug 17 2026 report). + assert.equal(name(active, metadata.default), 'Active workspace') + assert.equal(name(active, undefined), 'Hermes') }) test('botHandle: precomputed multi-source handle wins; default stays hermes', () => {