Skip to content

The agent that grows with you

fix(bot-relay): peer gateways name each machine by its label, not its connection id

John Paul Solivabfaa0492d2af
diff --git a/apps/desktop/src/plugins/hermes-bots/relay.test.ts b/apps/desktop/src/plugins/hermes-bots/relay.test.ts
index ba8f5e8bd16..98c7f582024 100644
--- a/apps/desktop/src/plugins/hermes-bots/relay.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/relay.test.ts
@@ -434,6 +434,42 @@ describe('the roster loop pushes the OTHER connections’ agents', () => {
stopBotRelay()
})
+ it.each([
+ [{ registry: true }, 'This Mac'],
+ [{ registry: false }, 'a']
+ ])('names the machine by its registry label (%o -> %s)', async ({ registry }, expected) => {
+ // tools/bot_mode_probe.py injects "@handle on <connection_label or connection_id>" into every
+ // bot's roster, and tools/bot_relay.py names the machine the same way when it refuses a target
+ // as offline. The route carries identity only, so the label has to come from the registry —
+ // without it every peer bot addresses its teammates by raw connection id. A Desktop build with
+ // no registry rejects the call, and the id stays.
+ if (registry) {
+ hostMock.connections = vi.fn(async () => [
+ { id: 'a', label: 'This Mac' },
+ { id: 'b', label: 'Noir (cto)' }
+ ])
+ } else {
+ delete hostMock.connections
+ }
+
+ const calls = respondWith(call =>
+ call.method === 'profiles.list' ? { profiles: [{ name: call.connectionId }] } : {}
+ )
+
+ const { startBotRelay, stopBotRelay } = await loadRelay()
+
+ startBotRelay()
+ await vi.advanceTimersByTimeAsync(0)
+
+ const pushedToB = calls.find(call => call.method === 'bot_relay.roster.sync' && call.connectionId === 'b')
+
+ expect(pushedToB?.params.agents).toEqual([
+ expect.objectContaining({ connection_id: 'a', connection_label: expected, profile: 'a' })
+ ])
+
+ stopBotRelay()
+ })
+
it('drops the cached rows of a connection that genuinely disconnected', async () => {
const calls = respondWith(call =>
call.method === 'profiles.list' ? { profiles: [{ name: call.connectionId }] } : {}
diff --git a/apps/desktop/src/plugins/hermes-bots/relay.ts b/apps/desktop/src/plugins/hermes-bots/relay.ts
index 6bcc19373c9..e159ea247d8 100644
--- a/apps/desktop/src/plugins/hermes-bots/relay.ts
+++ b/apps/desktop/src/plugins/hermes-bots/relay.ts
@@ -106,12 +106,11 @@ const relay: RelayLifecycle = {
// exemption). stopBotRelay releases everything.
const relayRouteRetentions = new Map<string, () => void>()
-/** One reachable gateway plus a representative route onto it. The route comes
- * from `host.profileRoutes()`, which carries identity only — the optional
- * label fields are read defensively in relayAgentsOn and never arrive. */
+/** One reachable gateway plus a representative route onto it. The route carries
+ * identity only, so the human label comes from the registry (connectionLabels). */
interface RelayConnection {
id: string
- route: ProfileRoute & { connectionLabel?: string; label?: string }
+ route: ProfileRoute
}
/** One agent as pushed to a peer gateway's relay roster. */
@@ -206,24 +205,46 @@ async function relayConnections(): Promise<RelayConnection[]> {
}
}
+/** 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
+ * its refusal text name machines by raw connection id. A build with no registry rejects
+ * the call, and ids stay. */
+async function connectionLabels(): Promise<Map<string, string>> {
+ if (typeof host.connections !== 'function') {
+ return new Map()
+ }
+
+ try {
+ const rows = await host.connections()
+
+ return new Map(
+ (Array.isArray(rows) ? rows : [])
+ .map(row => [String(row?.id || ''), String(row?.label || '').trim()] as const)
+ .filter(([id, label]) => Boolean(id && label))
+ )
+ } catch {
+ return new Map()
+ }
+}
+
/** The agents living on one connection, as relay roster rows.
* Returns null on FAILURE (transient RPC blip, slow socket) — distinct from
* a genuine empty profile list. Conflating the two would push a fresh union
* roster missing a LIVE connection's agents, and the gateway-side liveness
* check (bot_relay._target_liveness) reads "absent from a fresh roster" as
* definitively offline → false runtime_offline refusals (#93091 item 2). */
-async function relayAgentsOn(connection: RelayConnection): Promise<RelayAgentRow[] | null> {
+async function relayAgentsOn(
+ connection: RelayConnection,
+ labels: Map<string, string>
+): Promise<RelayAgentRow[] | null> {
try {
const res = await host.requestProfile<{ profiles?: RosterRow[] }>(connection.route, 'profiles.list', {
include_sessions: false
})
const profiles = Array.isArray(res?.profiles) ? res.profiles : []
- // TODO(bot-mode-types): neither `connectionLabel` nor `label` can exist on
- // a `host.profileRoutes()` route (connectionId / mode / profile /
- // targetProfile only), so this always falls through to the raw connection
- // id and peer gateways list agents by id instead of the human label.
- const label = String(connection.route?.connectionLabel || connection.route?.label || connection.id)
+ const label = labels.get(connection.id) || connection.id
return profiles
.map(profile => ({
@@ -259,6 +280,7 @@ async function syncRelayRosters() {
try {
const connections = await relayConnections()
+ const labels = await connectionLabels()
if (connections.length < 2) {
// Nothing to relay — but the gateways that remain still hold the last
@@ -297,7 +319,7 @@ async function syncRelayRosters() {
const agentsByConnection = new Map<string, RelayAgentRow[]>()
await Promise.all(
connections.map(async connection => {
- const agents = await relayAgentsOn(connection)
+ const agents = await relayAgentsOn(connection, labels)
if (agents === null) {
// Transient fetch failure: reuse the last good rows for this
diff --git a/website/docs/user-guide/bot-mode.md b/website/docs/user-guide/bot-mode.md
index 5f890bb0654..f571627e8c3 100644
--- a/website/docs/user-guide/bot-mode.md
+++ b/website/docs/user-guide/bot-mode.md
@@ -226,6 +226,8 @@ Every gateway you register in **Settings → Connections** — local, remote URL
- **Rosters propagate on their own.** While the Desktop runs, it periodically tells each connected gateway which agents live on the *other* connections. Every Bot Chat's teammate roster then lists them ("Teammates on OTHER connected machines"), with names, roles, and which machine they're on — and the roster refreshes when agents appear, disappear, or get renamed (capability epoch).
- **`message_agent` reaches them directly.** A Bot on your laptop messages the cloud agent with `message_agent(target="moxie", …)` exactly like a local teammate. If the same handle exists on several machines, disambiguate with `target="moxie@<connection>"` (the tool's error tells the Bot the exact forms). Delivery rides the Desktop: the sending gateway queues the message, the Desktop relays it to the target connection's own gateway, the target Bot runs a turn in its canonical Bot Chat, and the reply comes back to the sender as the same background completion notification local DMs use (the process that waits for it is a Hermes entrypoint, so it starts under `approvals.single_query_mode: deny` — the default for a Bot's one-shot reply turn — too). Messages to different Bots are delivered side by side, so one Bot's long turn never delays another Bot's mail (or ages it past `bot_mode.envelope_ttl_seconds`); messages to the *same* Bot are delivered in order, one turn at a time.
- **The Desktop is the courier.** Cross-connection delivery works while a Desktop that knows both connections is running (it holds the sockets and the credentials — gateways never see each other's auth). If the Desktop is closed mid-delivery, the sender's Bot is told the reply didn't arrive rather than left hanging; a message the Desktop picked up but never handed to the target (it disconnected in between) is offered to the next drain again — once, and only after the Desktop's own delivery deadline (~26 minutes) has passed with no reply, so a slow-but-live turn is never delivered twice. The sender keeps waiting long enough for that second delivery to finish (~52 minutes in all); if it still gets no reply, the sender is told so with reason `delivery_timeout`. While a re-offered message waits for a drain, `bot_mode.envelope_ttl_seconds` applies to it exactly as to a freshly queued one, and the first reply recorded for a message is the one that stands. For always-on machine-to-machine messaging with no Desktop in the loop, register a peer (`hermes peer`, below) — the two routes coexist.
+- **`message_agent` reaches them directly.** A Bot on your laptop messages the cloud agent with `message_agent(target="moxie", …)` exactly like a local teammate. If the same handle exists on several machines, disambiguate with `target="moxie@<connection>"` (the tool's error tells the Bot the exact forms). Each teammate is listed by the machine's name from **Settings → Connections**, so a Bot reads `@moxie on Homelab` rather than a bare connection id. Delivery rides the Desktop: the sending gateway queues the message, the Desktop relays it to the target connection's own gateway, the target Bot runs a turn in its canonical Bot Chat, and the reply comes back to the sender as the same background completion notification local DMs use (the process that waits for it is a Hermes entrypoint, so it starts under `approvals.single_query_mode: deny` — the default for a Bot's one-shot reply turn — too). Messages to different Bots are delivered side by side, so one Bot's long turn never delays another Bot's mail (or ages it past `bot_mode.envelope_ttl_seconds`); messages to the *same* Bot are delivered in order, one turn at a time.
+- **The Desktop is the courier.** Cross-connection delivery works while a Desktop that knows both connections is running (it holds the sockets and the credentials — gateways never see each other's auth). If the Desktop is closed mid-delivery, the sender's Bot is told the reply didn't arrive rather than left hanging. For always-on machine-to-machine messaging with no Desktop in the loop, register a peer (`hermes peer`, below) — the two routes coexist.
- **A remote `default` goes by its title.** Every machine's `default` is `@hermes`, so a remote one is offered — and reachable — under its Bot Mode title instead (a remote `default` titled *CoS Bot* is `@cos-bot`; with no title, `hermes@<connection>`), and a DM it sends arrives signed with that same reply-safe form rather than a bare `@hermes` that would point back at your own default.
- **The 10-minute cap bounds the target's turn, not its handoffs.** A relayed message gives the target Bot 10 minutes to finish its turn. When that turn messages a teammate itself, the delivery process stays alive afterwards — bounded by `terminal.oneshot_completion_wait_seconds` — so the teammate's reply can land in its Bot Chat (and, when it arrives in time, becomes the answer relayed back). That wait is never counted against the cap: a turn that finished is reported to the sender with its answer, not as `delivery_timeout`, and its handoff is left to complete.