Skip to content

The agent that grows with you

fix(desktop): two profiles of one connection are not relay peers

Teknium0731a22eb9be
diff --git a/apps/desktop/src/plugins/hermes-bots/relay.test.ts b/apps/desktop/src/plugins/hermes-bots/relay.test.ts
index 88e05303c6b..5e5053b8aec 100644
--- a/apps/desktop/src/plugins/hermes-bots/relay.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/relay.test.ts
@@ -380,8 +380,18 @@ describe('relay-route socket retention (#93594)', () => {
await vi.advanceTimersByTimeAsync(0)
await pushAndSettle()
- // Only the sole remaining connection's one-time roster clear goes out; the local source is never polled.
- expect(calls).toEqual([{ connectionId: 'remote-primary', method: 'bot_relay.roster.sync', params: { agents: [] } }])
+ // Only the sole remaining connection's one-time roster clear goes out — once per profile
+ // route, since each profile home holds its own roster; the local source is never polled.
+ // Two profiles of one connection are not peers: no profiles.list, nothing pinned.
+ expect(calls).toEqual([
+ { connectionId: 'remote-primary', method: 'bot_relay.roster.sync', params: { agents: [] }, route: route('remote-primary', { primary: true }) },
+ {
+ connectionId: 'remote-primary',
+ method: 'bot_relay.roster.sync',
+ params: { agents: [] },
+ route: route('remote-primary', { primary: true, profile: 'research' })
+ }
+ ])
expect(pins).toHaveLength(0)
stopBotRelay()
@@ -419,7 +429,11 @@ describe('relay-route socket retention (#93594)', () => {
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))])
+ // One profiles.list per connection, however many of its profiles are routed.
+ const lists = calls.filter(call => call.method === 'profiles.list').map(call => call.connectionId)
+ expect(lists.sort()).toEqual([...new Set(routes.map(item => item.connectionId))].sort())
+ // Every eligible profile route (its own socket scope and outbox) is pinned exactly once.
+ expect(pins.map(pin => pin.route)).toEqual(routes)
stopBotRelay()
}
diff --git a/apps/desktop/src/plugins/hermes-bots/relay.ts b/apps/desktop/src/plugins/hermes-bots/relay.ts
index d5a5df8a48f..12e1d3b0a4f 100644
--- a/apps/desktop/src/plugins/hermes-bots/relay.ts
+++ b/apps/desktop/src/plugins/hermes-bots/relay.ts
@@ -254,7 +254,9 @@ function releaseRelayRetention() {
relayRouteRetentions.clear()
}
-/** One representative route per reachable connection id. */
+/** Every relay-eligible profile route, once each. The canonical gateway keeps a
+ * roster and an outbox per profile home, so drain/roster/pins are per ROUTE;
+ * the peer set (is there anything to relay between?) is per connection id. */
async function relayConnections(): Promise<RelayConnection[]> {
if (typeof host.profileRoutes !== 'function' || typeof host.requestProfile !== 'function') {
return []
@@ -284,6 +286,11 @@ async function relayConnections(): Promise<RelayConnection[]> {
}
}
+/** Distinct connections among the relay routes: profiles of one connection are not peers. */
+function peerCount(connections: RelayConnection[]): number {
+ return new Set(connections.map(connection => connection.id)).size
+}
+
/** Human label per connection id, from the registry — the only place that has one.
* A `host.profileRoutes()` route carries identity alone, so without this the roster a
* peer gateway shows its bots ("@chii on 127-0-0-1-9119", tools/bot_mode_probe.py) and
@@ -407,14 +414,14 @@ async function syncRelayRosters() {
return
}
- if (connections.length < 2) {
+ if (peerCount(connections) < 2) {
// Nothing to relay — but the gateways that remain still hold the last
// pushed roster, so a departed machine's agents would stay in every
// bot's prompt (and as message_agent targets) until a second connection
// reappears. Push the now-empty roster once per sole connection so it
// forgets it — a replacement sole connection has never been told. An
// empty route list (registry not loaded yet) must not spend the clear.
- if (connections.length === 1 && connections[0].id !== relay.rosterClearedFor) {
+ if (peerCount(connections) === 1 && connections[0].id !== relay.rosterClearedFor) {
const cleared = await Promise.all(
connections.map(async connection => {
if (!isCurrent()) {
@@ -446,8 +453,10 @@ async function syncRelayRosters() {
relay.rosterClearedFor = null
const agentsByConnection = new Map<string, RelayAgentRow[]>()
+ // One profiles.list per connection: its routes share a socket and answer one profile set.
+ const firstRoutes = connections.filter((connection, index) => connections.findIndex(other => other.id === connection.id) === index)
await Promise.all(
- connections.map(async connection => {
+ firstRoutes.map(async connection => {
const agents = await relayAgentsOn(connection, labels)
if (!isCurrent()) {
@@ -535,9 +544,9 @@ async function drainRelayOutboxes() {
// Retention follows the relay-eligible set: with fewer than two
// connections there is nothing to relay, so nothing stays pinned.
- syncRelayRetention(connections.length >= 2 ? connections : [])
+ syncRelayRetention(peerCount(connections) >= 2 ? connections : [])
- if (connections.length < 2) {
+ if (peerCount(connections) < 2) {
return
}