Skip to content

The agent that grows with you

fix(desktop): the creating desktop backfills section names onto bots filed before names rode along

teknium1996c18274b2f
diff --git a/apps/desktop/src/plugins/hermes-bots/roster-pane.tsx b/apps/desktop/src/plugins/hermes-bots/roster-pane.tsx
index a92dde9b798..842dcdf227f 100644
--- a/apps/desktop/src/plugins/hermes-bots/roster-pane.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/roster-pane.tsx
@@ -51,7 +51,7 @@ import { botNeedsHandleLabel, rosterGatewayOptions } from './roster-sections'
import { botWorkspaceOwnerKey, setBotsWorkspaceOwner } from './routing'
import { activeBots, useTurnBusy } from './row-helpers'
import type { BotMeta, GatewaySource, GroupMember, RosterActivityFilter, RosterKindFilter, RosterRow } from './types'
-import { $botSections, $draggingBot, adoptBotSectionsFromMeta, type SectionDialogState } from './user-sections'
+import { $botSections, $draggingBot, adoptBotSectionsFromMeta, backfillBotSectionNames, type SectionDialogState } from './user-sections'
import { useEscapeCancelsBotDrag } from './user-sections-ui'
// ── roster pane ──────────────────────────────────────────────────────────────
@@ -293,9 +293,13 @@ export function BotsPane() {
// Sections made on ANOTHER desktop arrive as id + name on each member's
// ui_meta; rebuild the records this machine has never seen so the roster
- // draws the same folders instead of a flat list (#114355).
+ // draws the same folders instead of a flat list (#114355). Then the reverse:
+ // members filed here before names rode along carry only the id — stamp the
+ // name from this machine's records so other desktops can rebuild them too.
+ // Each stamp is a one-time write: once sectionName is set it is skipped.
useEffect(() => {
adoptBotSectionsFromMeta(roster, allMeta)
+ backfillBotSectionNames(roster, allMeta)
}, [roster, allMeta])
// React Query can briefly report neither loading nor data while the plugin
diff --git a/apps/desktop/src/plugins/hermes-bots/user-sections.test.ts b/apps/desktop/src/plugins/hermes-bots/user-sections.test.ts
index 50946da4ad3..68e2680bb2c 100644
--- a/apps/desktop/src/plugins/hermes-bots/user-sections.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/user-sections.test.ts
@@ -43,6 +43,7 @@ import type { RosterRow } from './types'
import {
$botSections,
adoptBotSectionsFromMeta,
+ backfillBotSectionNames,
createBotSection,
deleteBotSection,
groupRowsBySection,
@@ -150,6 +151,28 @@ describe('user sections', () => {
expect($botSections.get()).toEqual([{ id: 'sec-clients', name: 'Customers' }])
})
+ it('the desktop that knows a section backfills the name onto members filed before names rode along', async () => {
+ // This machine made "Clients" before sectionName existed: the record is
+ // local, the members carry only the id. Another desktop cannot rebuild
+ // the section from that — so stamp the name here, once per member.
+ $botSections.set([{ id: 'sec-clients', name: 'Clients' }])
+ const meta = {
+ nanox: { sectionId: 'sec-clients' },
+ scout: { sectionId: 'sec-clients', sectionName: 'Clients' }, // already stamped
+ ghost: { sectionId: 'sec-unknown' } // nobody here knows that section: nothing to stamp
+ }
+ $botMeta.set(meta)
+
+ expect(backfillBotSectionNames([bot('nanox'), bot('scout'), bot('ghost')], meta).map(b => b.name)).toEqual(['nanox'])
+ await vi.waitFor(() => expect(saveBotMeta).toHaveBeenCalledTimes(1))
+ expect(saveBotMeta).toHaveBeenCalledWith(bot('nanox'), { sectionId: 'sec-clients', sectionName: 'Clients' })
+
+ // The write set the name, so the next roster pass has nothing left to do.
+ saveBotMeta.mockClear()
+ expect(backfillBotSectionNames([bot('nanox'), bot('scout'), bot('ghost')], $botMeta.get())).toEqual([])
+ expect(saveBotMeta).not.toHaveBeenCalled()
+ })
+
it('renaming re-stamps the members so the new name reaches other desktops', async () => {
const section = createBotSection('Clients', [bot('nanox')])!
await vi.waitFor(() => expect($botMeta.get().nanox?.sectionName).toBe('Clients'))
diff --git a/apps/desktop/src/plugins/hermes-bots/user-sections.ts b/apps/desktop/src/plugins/hermes-bots/user-sections.ts
index fe02e448bf1..a547b7467a2 100644
--- a/apps/desktop/src/plugins/hermes-bots/user-sections.ts
+++ b/apps/desktop/src/plugins/hermes-bots/user-sections.ts
@@ -172,6 +172,36 @@ export function adoptBotSectionsFromMeta(roster: RosterRow[], metaByName: Record
}
}
+/**
+ * The other half of adoptBotSectionsFromMeta: bots filed before the name rode
+ * along carry only `sectionId`, and a desktop that never made that section
+ * has nothing to rebuild it from. So the desktop that DOES know the section —
+ * usually the one that created it — stamps the name onto every such member
+ * through the same one-write-per-profile path filing uses. Returns the members
+ * being stamped. Runs once per member: the write sets `sectionName`, so the
+ * next roster pass finds nothing to do. Members of a section nobody here
+ * knows are left alone — there is no name to give them.
+ */
+export function backfillBotSectionNames(roster: RosterRow[], metaByName: Record<string, BotMeta>): RosterRow[] {
+ const known = new Set($botSections.get().map(s => s.id))
+ const bySection = new Map<string, RosterRow[]>()
+
+ for (const bot of roster || []) {
+ const meta = bot ? botRosterMeta(bot, metaByName) : null
+ const id = meta?.sectionId ? String(meta.sectionId) : null
+
+ if (id && known.has(id) && !String(meta?.sectionName || '').trim()) {
+ bySection.set(id, [...(bySection.get(id) || []), bot])
+ }
+ }
+
+ for (const [id, members] of bySection) {
+ void moveBotsToSection(members, id)
+ }
+
+ return [...bySection.values()].flat()
+}
+
/**
* Delete the section only. Its members are not deleted and not hidden — they
* fall back to Unassigned, which is the whole reason membership lives on the
diff --git a/website/docs/user-guide/bot-mode.md b/website/docs/user-guide/bot-mode.md
index 47a9a5c72fa..c2a4d0839da 100644
--- a/website/docs/user-guide/bot-mode.md
+++ b/website/docs/user-guide/bot-mode.md
@@ -41,7 +41,7 @@ Sections are folders you make yourself — **Clients**, **Team**, whatever fits
- **Rename, reorder, or delete** a section from its heading's right-click menu (or the **⋯** that appears on hover); double-click a heading to rename. Headings fold like the gateway headings do.
- **Deleting a section never deletes Bots** — they return to **Unassigned**, and the toast offers **Undo**. No confirmation is asked.
-Membership — the section's id **and name** — is stored in each Bot's profile metadata (`ui_meta`), so a Bot's section follows it to every desktop connected to that backend: a second desktop rebuilds the section headings from its members the first time it loads the roster, and a rename made on one desktop reaches the others the same way. The section list itself (order, empty sections) is kept per desktop, so deleting a section on one machine leaves an empty heading on the others until you delete it there too. Bots filed before this shipped carry only the id; re-file them once (or rename the section) to stamp the name. When the roster shows more than one gateway, sections nest inside each gateway's bucket.
+Membership — the section's id **and name** — is stored in each Bot's profile metadata (`ui_meta`), so a Bot's section follows it to every desktop connected to that backend: a second desktop rebuilds the section headings from its members the first time it loads the roster, and a rename made on one desktop reaches the others the same way. The section list itself (order, empty sections) is kept per desktop, so deleting a section on one machine leaves an empty heading on the others until you delete it there too. Bots filed before names rode along carry only the id; the desktop that created the section stamps the name onto them automatically the next time its roster loads, and other desktops pick the section up from there. When the roster shows more than one gateway, sections nest inside each gateway's bucket.
## Creating a Bot