Skip to content

The agent that grows with you

fix(desktop): group replies carry the gateway install_id so (you) survives differing connection labels

teknium149d134036a2c
diff --git a/apps/desktop/src/plugins/hermes-bots/data.ts b/apps/desktop/src/plugins/hermes-bots/data.ts
index d5fcd31711c..5646b75f31d 100644
--- a/apps/desktop/src/plugins/hermes-bots/data.ts
+++ b/apps/desktop/src/plugins/hermes-bots/data.ts
@@ -1290,6 +1290,7 @@ export function annotateBotSource(bot: RosterRow, sources: GatewaySource[] | nul
...bot,
connectionKind: bot.connectionKind || source.kind,
connectionLabel: bot.connectionLabel || source.label,
+ ...(source.installId ? { installId: source.installId } : {}),
sourceError: source.error || null,
sourceMissing: false,
sourceReachable: source.reachable
diff --git a/apps/desktop/src/plugins/hermes-bots/group-membership.ts b/apps/desktop/src/plugins/hermes-bots/group-membership.ts
index e8a4a87d06f..53d290395f5 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-membership.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-membership.ts
@@ -65,7 +65,15 @@ export function groupMemberKey(member: GroupMember): string {
export function groupMemberAuthor(member: GroupMember): GroupMessageAuthor {
const source = member.connectionLabel || member.connectionId
- return { kind: 'member', name: member.name, ...(source ? { source } : {}) }
+ // `source` is this Desktop's label for the connection; `gateway` is the
+ // backend's own install_id, identical on every Desktop that reaches it —
+ // the token the self test matches on when both sides carry it.
+ return {
+ kind: 'member',
+ name: member.name,
+ ...(source ? { source } : {}),
+ ...(member.installId ? { gateway: member.installId } : {})
+ }
}
/** Marks a session key as thread-scoped. Pre-thread rooms stored ONE session
diff --git a/apps/desktop/src/plugins/hermes-bots/group-round-prompt.ts b/apps/desktop/src/plugins/hermes-bots/group-round-prompt.ts
index 372873691a0..a1fe1991a1f 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-round-prompt.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-round-prompt.ts
@@ -20,7 +20,8 @@ function relabelMemberControlFrames(text: string) {
/** Viewer identity for a room-log line. A bare string is the local, unsourced
* profile name (legacy call sites and single-connection jobs). */
export type GroupChatLineViewer =
- string | (Pick<GroupMember, 'name'> & Partial<Pick<GroupMember, 'connectionId' | 'connectionLabel' | 'remoteSource'>>)
+ | string
+ | (Pick<GroupMember, 'name'> & Partial<Pick<GroupMember, 'connectionId' | 'connectionLabel' | 'installId' | 'remoteSource'>>)
/** Room-log line as a member sees it: `Name (user): …` / `Name: …` /
* `Name (you): …`. */
@@ -87,6 +88,14 @@ function isGroupChatSelf(from: GroupMessageAuthor, viewer: GroupChatLineViewer):
return false
}
+ // Gateway identity first: the install_id is the same token on every
+ // Desktop, while `source` is whatever THIS Desktop labelled the connection
+ // (two Desktops calling one gateway "Central" / "Studio" agree here and
+ // disagree below). Only decisive when both sides carry it.
+ if (from.gateway && typeof viewer !== 'string' && viewer?.installId) {
+ return from.gateway === viewer.installId
+ }
+
const speakerSource = from.source || ''
// An unsourced same-name line is local by the room's resolution rule
diff --git a/apps/desktop/src/plugins/hermes-bots/group-rounds.test.ts b/apps/desktop/src/plugins/hermes-bots/group-rounds.test.ts
index e9fbff508e5..65527f5f96d 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-rounds.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-rounds.test.ts
@@ -187,6 +187,29 @@ describe('routing', () => {
formatGroupChatLine(reply as GroupMessage, { connectionId: 'mbp', connectionLabel: 'MBP', name: 'default', remoteSource: true })
).not.toContain('(you)')
})
+
+ // Two Desktops label the same gateway differently ("Central" here, "Studio"
+ // there): the reply's gateway install_id, not the label, decides `(you)`.
+ it('matches self on the gateway install_id when Desktops label the connection differently', async () => {
+ const room = await loadRoom({ turn: () => 'Central here.' })
+ const { formatGroupChatLine } = await import('./group-round-prompt')
+ const local: GroupMember = { connectionId: 'central', connectionLabel: 'Central', installId: 'gw-1', name: 'default', title: '' }
+
+ room.rounds.sendToGroupChat('Core', [local], '@hermes status?')
+ await settle(room, 'Core')
+
+ const reply = log(room, 'Core').find(entry => entry.from.kind === 'member') as GroupMessage
+
+ expect(reply.from).toEqual({ kind: 'member', name: 'default', source: 'Central', gateway: 'gw-1' })
+ // The other Desktop's view of the SAME gateway under its own label.
+ expect(
+ formatGroupChatLine(reply, { connectionId: 'c9', connectionLabel: 'Studio', installId: 'gw-1', name: 'default', remoteSource: true })
+ ).toContain('(you)')
+ // …and a different gateway that happens to share the label is not self.
+ expect(
+ formatGroupChatLine(reply, { connectionId: 'c2', connectionLabel: 'Central', installId: 'gw-2', name: 'default', remoteSource: true })
+ ).not.toContain('(you)')
+ })
})
describe('round lifecycle', () => {
diff --git a/apps/desktop/src/plugins/hermes-bots/types.ts b/apps/desktop/src/plugins/hermes-bots/types.ts
index c5eff2606d9..b00cc12be87 100644
--- a/apps/desktop/src/plugins/hermes-bots/types.ts
+++ b/apps/desktop/src/plugins/hermes-bots/types.ts
@@ -98,6 +98,10 @@ export interface RosterRow {
ghost?: boolean
handle?: string
has_avatar?: boolean
+ /** The connection's backend identity (/api/status `install_id`) when the
+ * roster source has seen it — stable across Desktops, unlike `connectionId`
+ * / `connectionLabel`, which are THIS Desktop's names for the connection. */
+ installId?: string
last_session?: SessionPreview | null
remoteSource?: boolean
route?: ProfileRoute
@@ -124,6 +128,7 @@ export type GroupMember = Pick<
| 'display_name'
| 'ghost'
| 'handle'
+ | 'installId'
| 'name'
| 'remoteSource'
| 'route'
@@ -146,8 +151,14 @@ export interface Attachment {
export interface GroupMessageAuthor {
kind: 'member' | 'user'
name: string
- /** Connection label, present when the speaker lives on another machine. */
+ /** Connection label (`connectionLabel || connectionId`) — this Desktop's
+ * name for the speaker's connection; display-only. */
source?: string
+ /** The speaker's gateway identity (/api/status `install_id`): the same
+ * token on every Desktop, so a mirrored entry passes the self test whatever
+ * the reader labelled that connection. Absent when the source never
+ * reported one. */
+ gateway?: string
}
export interface GroupMessage {
@@ -299,6 +310,8 @@ export interface GatewaySource {
connectionId: string
count?: number
error?: null | string
+ /** Backend identity (/api/status `install_id`) when the enumeration saw it. */
+ installId?: string
kind?: string
label?: string
reachable?: boolean