Skip to content

The agent that grows with you

fix: isolate desktop bot relay sender and target profile routes

Teknium4f75b6aae4c5
diff --git a/apps/desktop/src/plugins/hermes-bots/relay.test.ts b/apps/desktop/src/plugins/hermes-bots/relay.test.ts
index 11f8c3c4d8c..3184625b173 100644
--- a/apps/desktop/src/plugins/hermes-bots/relay.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/relay.test.ts
@@ -67,6 +67,7 @@ interface RelayCall {
connectionId: string
method: string
params: Record<string, unknown>
+ route: ProfileRoute
}
function respondWith(handler: (call: RelayCall) => unknown) {
@@ -74,7 +75,7 @@ function respondWith(handler: (call: RelayCall) => unknown) {
;(hostMock.requestProfile as ReturnType<typeof vi.fn>).mockImplementation(
async (target: ProfileRoute, method: string, params: Record<string, unknown>) => {
- const call = { connectionId: target.connectionId, method, params: structuredClone(params ?? {}) }
+ const call = { connectionId: target.connectionId, method, params: structuredClone(params ?? {}), route: structuredClone(target) }
calls.push(call)
@@ -511,6 +512,22 @@ describe('the drain loop wires drain → deliver → reply', () => {
stopBotRelay()
})
+ it('drains every sender profile and delivers on the exact target profile', async () => {
+ const ops = { ...route('a'), profile: 'ops', targetProfile: 'ops' }
+ hostMock.profileRoutes = vi.fn(async () => [route('a'), ops, route('b')])
+ const calls = respondWith(call => {
+ if (call.method === 'bot_relay.outbox.drain') return { envelopes: call.route.profile === 'ops' ? [envelope] : [] }
+ if (call.method === 'bot_relay.deliver') return {status: 'settled', delivery_id: envelope.id, admission_id: 'admission', reply: 'isolated'}
+ return {}
+ })
+ const {startBotRelay, stopBotRelay} = await loadRelay()
+ startBotRelay()
+ await pushAndSettle()
+ expect(calls.find(call => call.method === 'bot_relay.deliver')?.route).toEqual({...route('b'), profile: 'ops', targetProfile: 'ops'})
+ expect(calls.find(call => call.method === 'bot_relay.reply')?.route).toEqual(ops)
+ stopBotRelay()
+ })
+
it('retries the same envelope after pending or lost ACK without replying early', async () => {
let attempts = 0
let drained = false
diff --git a/apps/desktop/src/plugins/hermes-bots/relay.ts b/apps/desktop/src/plugins/hermes-bots/relay.ts
index f793a0fd3f1..961e2823679 100644
--- a/apps/desktop/src/plugins/hermes-bots/relay.ts
+++ b/apps/desktop/src/plugins/hermes-bots/relay.ts
@@ -138,7 +138,7 @@ function syncRelayRetention(connections: RelayConnection[]) {
return
}
- const live = new Set(connections.map(connection => connection.id))
+ const live = new Set(connections.map(connection => JSON.stringify(connection.route)))
for (const [id, release] of [...relayRouteRetentions]) {
if (!live.has(id)) {
@@ -157,8 +157,8 @@ function syncRelayRetention(connections: RelayConnection[]) {
}
for (const connection of connections) {
- if (!relayRouteRetentions.has(connection.id)) {
- relayRouteRetentions.set(connection.id, host.retainProfileSocket(connection.route))
+ if (!relayRouteRetentions.has(JSON.stringify(connection.route))) {
+ relayRouteRetentions.set(JSON.stringify(connection.route), host.retainProfileSocket(connection.route))
}
}
}
@@ -189,13 +189,14 @@ async function relayConnections(): Promise<RelayConnection[]> {
for (const route of Array.isArray(routes) ? routes : []) {
const id = String(route?.connectionId || '')
- if (id && !byConnection.has(id)) {
- byConnection.set(id, route)
+ const key = JSON.stringify(route)
+ if (id && !byConnection.has(key)) {
+ byConnection.set(key, route)
}
}
- return [...byConnection.entries()].map(([id, route]) => ({
- id,
+ return [...byConnection.values()].map(route => ({
+ id: route.connectionId,
route
}))
} catch {
@@ -404,7 +405,7 @@ async function drainRelayOutboxes() {
try {
const res = await host.requestProfile<{ status?: string; delivery_id?: string; admission_id?: string; reply?: string; error?: string; reason?: string }>(
- target.route,
+ { ...target.route, profile: String(envelope.target_profile), targetProfile: String(envelope.target_profile) },
'bot_relay.deliver',
{
id: envelopeId,