The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): skip non-primary local bot relay route
KoNit-K9cbc6a5ac0e9
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex f9a065bf32c..c13076c6fe8 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -16164,7 +16164,11 @@ ipcMain.handle('hermes:plugin-profile-routes', async (_event, rawProfileNames) =]}- return buildRegistryProfileRoutes({ agents, sources: registry.connections })+ return buildRegistryProfileRoutes({+ agents,+ primaryConnectionId: registry.primary,+ sources: registry.connections+ })})ipcMain.handle('hermes:ssh-config:hosts', async () => ({ hosts: collectSshConfigHosts() }))ipcMain.handle('hermes:ssh-config:resolve', async (_event, host) => {diff --git a/apps/desktop/electron/plugin-profile-routes.test.ts b/apps/desktop/electron/plugin-profile-routes.test.tsindex 0d12f0f88b9..0aa543aca40 100644--- a/apps/desktop/electron/plugin-profile-routes.test.ts+++ b/apps/desktop/electron/plugin-profile-routes.test.ts@@ -209,6 +209,7 @@ describe('buildRegistryProfileRoutes', () => {{ connectionId: 'homelab', profile: 'research' }],legacyRoutes: [{ connectionId: 'legacy-hash', mode: 'local', profile: 'research', targetProfile: 'research' }],+ primaryConnectionId: 'homelab',sources: [{ id: 'local', kind: 'local', label: 'This device' },{@@ -226,7 +227,13 @@ describe('buildRegistryProfileRoutes', () => {expect(routes).toEqual([{ connectionId: 'local', mode: 'local', profile: 'research', targetProfile: 'research' },- { connectionId: 'homelab', mode: 'remote', profile: 'research', targetProfile: 'remote-research' }+ {+ connectionId: 'homelab',+ mode: 'remote',+ primary: true,+ profile: 'research',+ targetProfile: 'remote-research'+ }])expect(JSON.stringify(routes)).not.toContain('private.lan')expect(JSON.stringify(routes)).not.toContain('id_ed25519')@@ -238,10 +245,13 @@ describe('buildRegistryProfileRoutes', () => {const routes = buildRegistryProfileRoutes({agents: [{ connectionId: 'local', profile: 'barry' }],legacyRoutes: [{ connectionId: 'legacy-hash', mode: 'remote', profile: 'barry', targetProfile: 'default' }],+ primaryConnectionId: 'local',sources: [{ id: 'local', kind: 'local', label: 'This device' }]})- expect(routes).toEqual([{ connectionId: 'local', mode: 'local', profile: 'barry', targetProfile: 'barry' }])+ expect(routes).toEqual([+ { connectionId: 'local', mode: 'local', primary: true, profile: 'barry', targetProfile: 'barry' }+ ])})it('scopes registry-shared remote websocket URLs to the requested profile', () => {diff --git a/apps/desktop/electron/plugin-profile-routes.ts b/apps/desktop/electron/plugin-profile-routes.tsindex d7024cea9be..d8c15a6c4eb 100644--- a/apps/desktop/electron/plugin-profile-routes.ts+++ b/apps/desktop/electron/plugin-profile-routes.ts@@ -20,6 +20,8 @@ export interface EffectiveSshRoute {export interface OpaqueProfileRoute {connectionId: stringmode: 'local' | 'remote'+ /** Present only when this route belongs to the window's authoritative primary connection. */+ primary?: trueprofile: stringtargetProfile: string}@@ -39,6 +41,7 @@ interface RegistryProfileRouteSource {interface BuildRegistryProfileRoutesOptions {agents: RegistryProfileRouteAgent[]legacyRoutes?: OpaqueProfileRoute[]+ primaryConnectionId?: stringsources: RegistryProfileRouteSource[]}@@ -257,6 +260,7 @@ export async function buildOpaqueProfileRoutes({*/export function buildRegistryProfileRoutes({agents,+ primaryConnectionId,sources}: BuildRegistryProfileRoutesOptions): OpaqueProfileRoute[] {const sourceById = new Map(sources.map(source => [source.id, source]))@@ -278,6 +282,7 @@ export function buildRegistryProfileRoutes({routes.push({connectionId: source.id,mode: 'local',+ ...(source.id === primaryConnectionId ? { primary: true } : {}),profile,targetProfile: profile})@@ -288,6 +293,7 @@ export function buildRegistryProfileRoutes({routes.push({connectionId: source.id,mode: 'remote',+ ...(source.id === primaryConnectionId ? { primary: true } : {}),profile,targetProfile: source.kind === 'ssh' && source.remoteProfile ? normalizeProfile(source.remoteProfile) : profile})diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.tsindex 3f5f96c6c5c..9beb8e2d39a 100644--- a/apps/desktop/src/global.d.ts+++ b/apps/desktop/src/global.d.ts@@ -911,6 +911,8 @@ export interface DesktopPluginProfileRoute {// across sources.connectionId: stringmode: 'local' | 'remote'+ // Electron's authoritative registry primary. Absent on older shells.+ primary?: trueprofile: stringtargetProfile: string}diff --git a/apps/desktop/src/plugins/hermes-bots/relay.test.ts b/apps/desktop/src/plugins/hermes-bots/relay.test.tsindex 503be2cc6ec..03114db9651 100644--- a/apps/desktop/src/plugins/hermes-bots/relay.test.ts+++ b/apps/desktop/src/plugins/hermes-bots/relay.test.ts@@ -72,11 +72,15 @@ vi.mock('./data', () => ({const RELAY_PUSH_DEBOUNCE_MS = 250const RELAY_DRAIN_INTERVAL_MS = 30_000-const route = (id: string): ProfileRoute => ({+const route = (+ id: string,+ options: { mode?: ProfileRoute['mode']; primary?: true; profile?: string } = {}+): ProfileRoute => ({connectionId: id,- mode: 'remote',- profile: 'default',- targetProfile: 'default'+ mode: options.mode ?? 'remote',+ ...(options.primary === true ? { primary: true } : {}),+ profile: options.profile ?? 'default',+ targetProfile: options.profile ?? 'default'})/** Every RPC through one table, recording what each connection was asked. */@@ -359,6 +363,65 @@ describe('the 30s drain does not open a gateway socket with nothing to deliver (})describe('relay-route socket retention (#93594)', () => {+ it('does not poll or retain the non-primary local source of a remote-primary Desktop', async () => {+ hostMock.profileRoutes = vi.fn(async () => [+ route('remote-primary', { primary: true }),+ route('remote-primary', { primary: true, profile: 'research' }),+ route('local', { mode: 'local' }),+ route('local', { mode: 'local', profile: 'research' })+ ])+ const pins = trackRetention()+ const calls = respondWith(() => ({ envelopes: [] }))+ const { startBotRelay, stopBotRelay } = await loadRelay()++ startBotRelay()+ await vi.advanceTimersByTimeAsync(0)+ await pushAndSettle()++ expect(calls).toHaveLength(0)+ expect(pins).toHaveLength(0)++ stopBotRelay()+ })++ it('preserves local-primary, multi-remote, and fail-open peer sets', async () => {+ for (const routes of [+ [route('local', { mode: 'local', primary: true }), route('remote-peer')],+ [route('remote-primary', { primary: true }), route('remote-peer')],+ [route('remote-primary'), route('local', { mode: 'local' })],+ [route('remote-primary', { primary: true }), route('local', { mode: 'local', primary: true })],+ [+ route('remote-primary', { primary: true }),+ route('remote-primary', { profile: 'research' }),+ route('local', { mode: 'local' })+ ],+ [+ route('remote-primary', { primary: true }),+ route('local', { mode: 'local' }),+ route('unexpected-local', { mode: 'local' })+ ],+ [+ route('remote-primary', { primary: true }),+ { ...route('remote-peer'), primary: false } as unknown as ProfileRoute,+ route('local', { mode: 'local' })+ ]+ ]) {+ hostMock.profileRoutes = vi.fn(async () => routes)+ const pins = trackRetention()+ const calls = respondWith(() => ({ envelopes: [] }))+ const { startBotRelay, stopBotRelay } = await loadRelay()++ startBotRelay()+ await vi.advanceTimersByTimeAsync(0)+ await pushAndSettle()++ expect(new Set(calls.map(call => call.connectionId))).toEqual(new Set(routes.map(item => item.connectionId)))+ expect(pins.map(pin => pin.route.connectionId)).toEqual([...new Set(routes.map(item => item.connectionId))])++ stopBotRelay()+ }+ })+it('pins each connection ONCE across many drain ticks', async () => {const pins = trackRetention()diff --git a/apps/desktop/src/plugins/hermes-bots/relay.ts b/apps/desktop/src/plugins/hermes-bots/relay.tsindex 5b53a9b464a..957bc386030 100644--- a/apps/desktop/src/plugins/hermes-bots/relay.ts+++ b/apps/desktop/src/plugins/hermes-bots/relay.ts@@ -131,6 +131,60 @@ interface RelayAgentRow {title: string}+/** Remove the mandatory local registry source only when Electron identifies+ * one unambiguous REMOTE primary. Older or inconsistent route inventories+ * fail open to the prior peer set. Distinct remote peers always remain. */+function relayEligibleRoutes(routes: ProfileRoute[]): ProfileRoute[] {+ const routesByConnection = new Map<string, ProfileRoute[]>()++ for (const route of routes) {+ if (+ !route ||+ typeof route.connectionId !== 'string' ||+ !route.connectionId ||+ (route.mode !== 'local' && route.mode !== 'remote') ||+ (route.primary !== undefined && route.primary !== true)+ ) {+ return routes+ }++ const grouped = routesByConnection.get(route.connectionId) || []++ grouped.push(route)+ routesByConnection.set(route.connectionId, grouped)+ }++ const primaryGroups = [...routesByConnection.entries()].filter(([, grouped]) =>+ grouped.some(route => route.primary === true)+ )++ if (primaryGroups.length !== 1) {+ return routes+ }++ const [primaryId, primaryRoutes] = primaryGroups[0]++ if (primaryRoutes.some(route => route.mode !== 'remote' || route.primary !== true)) {+ return routes+ }++ const localGroups = [...routesByConnection.entries()].filter(([, grouped]) =>+ grouped.some(route => route.mode === 'local')+ )++ if (+ localGroups.length !== 1 ||+ localGroups[0][1].some(route => route.mode !== 'local') ||+ localGroups[0][0] === primaryId+ ) {+ return routes+ }++ const localId = localGroups[0][0]++ return routes.filter(route => route.connectionId !== localId)+}+/** A queued cross-connection message drained from a gateway's outbox. */interface RelayEnvelope {id?: string@@ -193,10 +247,11 @@ async function relayConnections(): Promise<RelayConnection[]> {}try {- const routes = await host.profileRoutes()+ const rawRoutes = await host.profileRoutes()+ const routes = relayEligibleRoutes(Array.isArray(rawRoutes) ? rawRoutes : [])const byConnection = new Map<string, ProfileRoute>()- for (const route of Array.isArray(routes) ? routes : []) {+ for (const route of routes) {const id = String(route?.connectionId || '')if (id && !byConnection.has(id)) {diff --git a/apps/desktop/src/plugins/hermes-bots/types.ts b/apps/desktop/src/plugins/hermes-bots/types.tsindex 2e0021c8e76..2fdfea88713 100644--- a/apps/desktop/src/plugins/hermes-bots/types.ts+++ b/apps/desktop/src/plugins/hermes-bots/types.ts@@ -25,6 +25,8 @@ export interface SidebarRowLabels {export interface ProfileRoute {connectionId: stringmode: 'local' | 'remote'+ /** Electron's authoritative registry primary. Absent on older shells. */+ primary?: trueprofile: stringtargetProfile: string}diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex 4e0ec3e9e6e..fd148c8cc34 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -210,6 +210,8 @@ const $focusedSessionProfile = computed(export interface PluginProfileRoute {connectionId: stringmode: 'local' | 'remote'+ /** Electron's authoritative registry primary. Absent on older shells. */+ primary?: true/** Desktop profile used to select the connection route. */profile: string/** Backend Hermes profile served by that route. */