Skip to content

The agent that grows with you

fix(webapp): boot on the served profile; park and grey unserved profiles

Adolanium8bfff4e2739e
diff --git a/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx b/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
index 08699e9616b..9072c602603 100644
--- a/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
+++ b/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
@@ -54,6 +54,7 @@ import { FleetGatewayMenuGroup } from './fleet-gateway-menu-group'
import { buildRestGroups, type FleetAgent, fleetRouteKey } from './fleet-rail'
import { useLocalDeviceSwitch } from './local-device-switch'
import { ProfileLaunchContextMenu } from './profile-launch-menu'
+import { UnservedProfileNote, useUnservedProfiles } from './unserved-profiles'
import { useFleetRoster } from './use-fleet-roster'
import { useProfilePrewarm } from './use-profile-prewarm'
import { useProfileRailRefreshOnActive } from './use-profile-rail-refresh-on-active'
@@ -85,6 +86,7 @@ export function ProfileSwitcher({ compact = false }: { compact?: boolean }) {
const { dialog: localDeviceDialog, request: requestLocalDevice } = useLocalDeviceSwitch()
useFleetRoster(multipleConnections)
+ const unserved = useUnservedProfiles(profiles)
// The Webapp always takes this dropdown in place of the rail's squares
// (profile-switcher.tsx), so there it keeps the list fresh the same way and
// carries the rail's right-click launch menu. Native Desktop's picker is main's.
@@ -225,6 +227,7 @@ export function ProfileSwitcher({ compact = false }: { compact?: boolean }) {
label={profileLabel(profile)}
launchMenu={browserHost}
name={profile.name}
+ unserved={unserved.has(normalizeProfileKey(profile.name))}
/>
))}
{/* Nothing to widen to with one profile: the ALL view only exists
@@ -298,23 +301,33 @@ interface ProfileItemProps {
/** Wrap the row in the rail's right-click launch menu (the Webapp's picker). */
launchMenu: boolean
name: string
+ /** Listed by its gateway but not served (the Webapp): shown, never picked, since the pick is refused. */
+ unserved: boolean
}
-function ProfileItem({ color, connectionId, isDefault, label, launchMenu, name }: ProfileItemProps) {
+function ProfileItem({ color, connectionId, isDefault, label, launchMenu, name, unserved }: ProfileItemProps) {
const { cancelPrewarm, notePointerMove, startPrewarm } = useProfilePrewarm(name, prewarmProfilePick)
const row = (
<DropdownMenuRadioItem
className="min-w-0"
+ disabled={unserved}
onPointerEnter={startPrewarm}
onPointerLeave={cancelPrewarm}
onPointerMove={notePointerMove}
value={name}
>
<span className="flex min-w-0 items-center gap-1.5">
- <ProfileGlyph aria-hidden="true" color={color} isDefault={isDefault} name={name} />
+ <ProfileGlyph
+ aria-hidden="true"
+ className={cn(unserved && 'grayscale')}
+ color={color}
+ isDefault={isDefault}
+ name={name}
+ />
<span className="truncate">{label}</span>
</span>
+ {unserved && <UnservedProfileNote />}
</DropdownMenuRadioItem>
)
diff --git a/apps/desktop/src/app/chat/sidebar/profile-menu-unserved.test.tsx b/apps/desktop/src/app/chat/sidebar/profile-menu-unserved.test.tsx
new file mode 100644
index 00000000000..274a5a0dbc9
--- /dev/null
+++ b/apps/desktop/src/app/chat/sidebar/profile-menu-unserved.test.tsx
@@ -0,0 +1,188 @@
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { atom } from 'nanostores'
+import { afterEach, beforeEach, expect, it, vi } from 'vitest'
+
+import type { DesktopAgentRoster } from '@/global'
+
+import { ProfileSwitcher } from './profile-dropdown-switcher'
+import { ProfileRail } from './profile-switcher'
+
+// The Webapp's gateway lists every installed profile and serves only some of them; its roster marks
+// the rest `reachable: false`, and picking one is refused. The profile menus read that roster and show
+// such a profile as unavailable, the way the Bots pane does, instead of failing after the click. Only
+// the bridge's roster is stubbed, so the menus' own read of it is covered.
+
+vi.hoisted(() => {
+ // The bridge marks the page before the rail module decides it is always condensed.
+ window.document.documentElement.dataset.hermesDesktopHost = 'browser'
+})
+
+const selectProfile = vi.fn()
+const setShowAllProfiles = vi.fn()
+
+vi.mock('react-router', () => ({ useNavigate: () => vi.fn() }))
+
+vi.mock('@/i18n', () => ({
+ useI18n: () => ({
+ locale: 'en',
+ t: {
+ common: { cancel: 'Cancel', delete: 'Delete' },
+ profiles: {
+ actions: 'Actions',
+ allProfiles: 'All profiles',
+ color: 'Color…',
+ colorFor: 'Color',
+ connectGateway: 'Manage gateways…',
+ editSoul: 'Edit SOUL.md…',
+ exportMenu: 'Export profile…',
+ fleet: { onGateway: (name: string, gateway: string) => `${name} · ${gateway}` },
+ importProfile: 'Import profile…',
+ manageProfiles: 'Manage profiles…',
+ newProfile: 'New profile',
+ notServedHere: 'Not served here',
+ openInNewWindow: 'Open in new window',
+ renameMenu: 'Rename…',
+ remoteOverride: { badge: (host: string) => `Runs on ${host}`, menuItem: 'Connect to a remote host…' },
+ setAsDefault: 'Set as default',
+ showAllProfiles: 'Show all profiles',
+ status: {
+ needsInput: (count: number) => `${count} needs input`,
+ unread: (count: number) => `${count} unread`,
+ working: (count: number) => `${count} working`
+ },
+ switchConnectionFailed: (name: string) => `Could not connect to ${name}`,
+ switchToProfile: (name: string) => `Switch to ${name}`,
+ title: 'Profiles'
+ }
+ }
+ })
+}))
+
+vi.mock('@/store/profile', () => ({
+ $activeGatewayProfile: atom('solo'),
+ $profileColors: atom({}),
+ $profileCreateRequest: atom(0),
+ $profileOrder: atom([]),
+ $profiles: atom([
+ { is_default: true, name: 'default' },
+ { is_default: false, name: 'research' },
+ { is_default: false, name: 'solo' }
+ ]),
+ $profileScope: atom('solo'),
+ $showAllProfiles: atom(false),
+ ALL_PROFILES: '__all__',
+ normalizeProfileKey: (name: string) => name,
+ prewarmProfilePick: vi.fn(),
+ profileLabel: (profile: { name: string }) => profile.name,
+ refreshActiveProfile: vi.fn().mockResolvedValue(undefined),
+ selectProfile: (name: string) => selectProfile(name),
+ setProfileColor: vi.fn(),
+ setProfileOrder: vi.fn(),
+ setShowAllProfiles: (value: boolean) => setShowAllProfiles(value),
+ sortByProfileOrder: (profiles: unknown[]) => profiles
+}))
+
+vi.mock('@/store/connections', () => ({
+ $activeConnectionId: atom<null | string>('local'),
+ $connectionsRegistry: atom(null),
+ $hasMultipleConnections: atom(false),
+ selectConnection: vi.fn()
+}))
+
+vi.mock('@/store/profile-share', () => ({ runExportProfileFlow: vi.fn(), runImportProfileFlow: vi.fn() }))
+vi.mock('./use-profile-prewarm', () => ({
+ useProfilePrewarm: () => ({ cancelPrewarm: vi.fn(), notePointerMove: vi.fn(), startPrewarm: vi.fn() })
+}))
+vi.mock('@/hermes', () => ({ getProfileSoul: vi.fn().mockResolvedValue({ content: '' }), updateProfileSoul: vi.fn() }))
+vi.mock('@/components/chat/code-editor', () => ({ CodeEditor: () => null }))
+vi.mock('../../profiles/create-profile-dialog', () => ({ CreateProfileDialog: () => null }))
+vi.mock('../../profiles/delete-profile-dialog', () => ({ DeleteProfileDialog: () => null }))
+vi.mock('../../profiles/rename-profile-dialog', () => ({ RenameProfileDialog: () => null }))
+
+/** A gateway launched as `solo` that serves no other profile, as the Webapp bridge reports it. */
+function standaloneRoster(): DesktopAgentRoster {
+ const agent = (profile: string, served: boolean) => ({
+ connectionId: 'local',
+ connectionKind: 'local' as const,
+ connectionLabel: 'localhost:9119',
+ handle: profile === 'default' ? 'hermes' : profile,
+ profile,
+ targetProfile: profile,
+ ...(served ? {} : { reachable: false })
+ })
+
+ return {
+ agents: [agent('default', false), agent('research', false), agent('solo', true)],
+ primaryConnectionId: 'local',
+ sources: [{ connectionId: 'local', kind: 'local', label: 'localhost:9119', reachable: true }]
+ }
+}
+
+const getAgentRoster = vi.fn(async () => standaloneRoster())
+
+beforeEach(() => {
+ Object.assign(window, { hermesDesktop: { getAgentRoster } })
+})
+
+afterEach(() => {
+ cleanup()
+ vi.clearAllMocks()
+ Reflect.deleteProperty(window, 'hermesDesktop')
+ window.document.documentElement.dataset.hermesDesktopHost = 'browser'
+})
+
+async function openMenu(trigger: HTMLElement) {
+ await act(async () => {
+ fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false, pointerType: 'mouse' })
+ await Promise.resolve()
+ })
+}
+
+async function expectUnavailable(name: string) {
+ // Greyed and not selectable, with the reason in its name, the way the Bots pane names an unavailable bot.
+ const row = await screen.findByRole('menuitemradio', { name: `${name}, Not served here` })
+
+ expect(row.getAttribute('aria-disabled')).toBe('true')
+
+ await act(async () => {
+ fireEvent.click(row)
+ await Promise.resolve()
+ })
+
+ expect(selectProfile).not.toHaveBeenCalled()
+}
+
+it('the statusbar profile menu shows the profiles its gateway does not serve as unavailable', async () => {
+ render(<ProfileSwitcher compact />)
+ await openMenu(screen.getByRole('button', { name: 'Profiles: solo' }))
+
+ await expectUnavailable('research')
+ await expectUnavailable('default')
+
+ expect(screen.getByRole('menuitemradio', { name: 'solo' }).getAttribute('aria-disabled')).toBeNull()
+ expect(getAgentRoster).toHaveBeenCalled()
+})
+
+it("the rail's profile menu shows them the same way, and its home pill offers no switch to an unserved default", async () => {
+ render(<ProfileRail />)
+
+ // The home pill would switch to default, which this gateway refuses: it toggles the all-profiles view instead.
+ fireEvent.click(await screen.findByRole('button', { name: 'All profiles' }))
+ expect(screen.queryByRole('button', { name: 'Switch to default' })).toBeNull()
+ expect(setShowAllProfiles).toHaveBeenCalledWith(true)
+
+ await openMenu(screen.getByRole('button', { name: 'Profiles' }))
+ await expectUnavailable('research')
+ expect(screen.getByRole('menuitemradio', { name: 'solo' }).getAttribute('aria-disabled')).toBeNull()
+})
+
+it('native Desktop with one gateway reads no roster for the menu and marks nothing', async () => {
+ delete window.document.documentElement.dataset.hermesDesktopHost
+ render(<ProfileSwitcher compact />)
+ await openMenu(screen.getByRole('button', { name: 'Profiles: solo' }))
+
+ const research = await screen.findByRole('menuitemradio', { name: 'research' })
+
+ expect(research.getAttribute('aria-disabled')).toBeNull()
+ expect(getAgentRoster).not.toHaveBeenCalled()
+})
diff --git a/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx b/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
index 4f0a2ba35b8..377f089576f 100644
--- a/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
+++ b/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
@@ -108,6 +108,7 @@ import { buildRestGroups, countRestAgents, type FleetAgent, type FleetGroup, fle
import { useLocalDeviceSwitch } from './local-device-switch'
import { ProfileLaunchContextMenu, ProfileLaunchMenuSection } from './profile-launch-menu'
import { ProfileRemoteOverrideDialog } from './profile-remote-override-dialog'
+import { UnservedProfileNote, useUnservedProfiles } from './unserved-profiles'
import { useFleetRoster } from './use-fleet-roster'
import { useProfilePrewarm } from './use-profile-prewarm'
import { useProfileRailRefreshOnActive } from './use-profile-rail-refresh-on-active'
@@ -123,6 +124,13 @@ const PROFILE_DROPDOWN_THRESHOLD = 13
// surface (drag, hold-to-recolor), and in a browser tab they read as chrome.
const ALWAYS_CONDENSED = isBrowserHostedDesktop()
+// The home pill's profile when the multi-profile rail shows one: the default profile. A gateway that
+// does not serve default (one launched as another profile, in the Webapp) refuses the switch, so the
+// pill is then the plain all toggle, as on a gateway without a default.
+function servedHomeProfile(defaultProfile: ProfileInfo | undefined, unserved: ReadonlySet<string>) {
+ return defaultProfile && !unserved.has(normalizeProfileKey(defaultProfile.name)) ? defaultProfile : undefined
+}
+
// The threshold counts the whole fleet: fourteen squares are fourteen squares
// wherever they live.
function railCondensed(profileCount: number, restGroups: readonly FleetGroup[]): boolean {
@@ -238,6 +246,7 @@ export function ProfileRail() {
const { dialog: localDeviceDialog, request: requestLocalDevice } = useLocalDeviceSwitch()
useFleetRoster(multipleConnections)
+ const unserved = useUnservedProfiles(profiles)
const connections = registry?.connections
@@ -390,6 +399,7 @@ export function ProfileRail() {
const isAll = scope === ALL_PROFILES
const activeKey = normalizeProfileKey(gatewayProfile)
const defaultProfile = profiles.find(profile => profile.is_default)
+ const homeProfile = servedHomeProfile(defaultProfile, unserved)
const onDefault = !isAll && activeKey === 'default'
const named = sortByProfileOrder(
@@ -549,16 +559,16 @@ export function ProfileRail() {
Hidden until a second profile exists. */}
{!fleet &&
multiProfile &&
- (defaultProfile ? (
+ (homeProfile ? (
// On default → toggle to all. Anywhere else (all view or a named
// profile) → return to default. So leaving a profile never lands on all.
<ProfilePill
active={isAll || onDefault}
connectionId={activeConnectionId ?? undefined}
glyph={isAll ? 'layers' : 'home'}
- label={onDefault ? p.showAllProfiles : p.switchToProfile(profileLabel(defaultProfile))}
- onSelect={() => (onDefault ? setShowAllProfiles(true) : selectProfile(defaultProfile.name))}
- profile={defaultProfile.name}
+ label={onDefault ? p.showAllProfiles : p.switchToProfile(profileLabel(homeProfile))}
+ onSelect={() => (onDefault ? setShowAllProfiles(true) : selectProfile(homeProfile.name))}
+ profile={homeProfile.name}
/>
) : (
<ProfilePill active={isAll} glyph="layers" label={p.allProfiles} onSelect={() => setShowAllProfiles(true)} />
@@ -594,6 +604,7 @@ export function ProfileRail() {
// only door; every at-rest group already lists its own (#106017, #131632).
profiles={fleet && defaultProfile ? [defaultProfile, ...named] : named}
restGroups={restGroups}
+ unserved={unserved}
/>
</div>
) : (
@@ -887,7 +898,8 @@ function ProfileDropdown({
onSelect,
onSelectRest,
profiles,
- restGroups
+ restGroups,
+ unserved
}: {
activeKey: null | string
colors: Record<string, string>
@@ -901,6 +913,8 @@ function ProfileDropdown({
profiles: ProfileInfo[]
// Fleet: the other gateways' agents, each under its own section header.
restGroups: readonly FleetGroup[]
+ /** Profiles the gateway lists but does not serve (the Webapp): shown, never picked. */
+ unserved: ReadonlySet<string>
}) {
const { t } = useI18n()
const p = t.profiles
@@ -957,6 +971,7 @@ function ProfileDropdown({
key={profile.name}
label={profileLabel(profile)}
name={profile.name}
+ unserved={unserved.has(normalizeProfileKey(profile.name))}
/>
))}
</DropdownMenuRadioGroup>
@@ -991,7 +1006,8 @@ function ProfileDropdownItem({
hideStatus,
isDefault,
label,
- name
+ name,
+ unserved
}: {
color: null | string
connectionId: null | string
@@ -1001,6 +1017,7 @@ function ProfileDropdownItem({
isDefault: boolean
label: string
name: string
+ unserved: boolean
}) {
const { t } = useI18n()
const p = t.profiles
@@ -1012,17 +1029,25 @@ function ProfileDropdownItem({
<ProfileLaunchContextMenu connectionId={connectionId} label={label} profile={name}>
<DropdownMenuRadioItem
className="min-w-0"
+ disabled={unserved}
onPointerEnter={startPrewarm}
onPointerLeave={cancelPrewarm}
onPointerMove={notePointerMove}
value={name}
>
<span className="flex min-w-0 items-center gap-1.5">
- <ProfileGlyph aria-hidden="true" color={color} isDefault={isDefault} name={name} />
+ <ProfileGlyph
+ aria-hidden="true"
+ className={cn(unserved && 'grayscale')}
+ color={color}
+ isDefault={isDefault}
+ name={name}
+ />
<span className="truncate">{label}</span>
{summary && !hideStatus && <ProfileStatusDot summary={summary} />}
</span>
{statusText && <span className="sr-only">{`, ${statusText}`}</span>}
+ {unserved && <UnservedProfileNote />}
</DropdownMenuRadioItem>
</ProfileLaunchContextMenu>
)
diff --git a/apps/desktop/src/app/chat/sidebar/unserved-profiles.tsx b/apps/desktop/src/app/chat/sidebar/unserved-profiles.tsx
new file mode 100644
index 00000000000..7bfc9155253
--- /dev/null
+++ b/apps/desktop/src/app/chat/sidebar/unserved-profiles.tsx
@@ -0,0 +1,62 @@
+import { useEffect, useState } from 'react'
+
+import { useI18n } from '@/i18n'
+import { isBrowserHostedDesktop } from '@/lib/platform'
+import { normalizeProfileKey } from '@/store/profile'
+import type { ProfileInfo } from '@/types/hermes'
+
+const NONE: ReadonlySet<string> = new Set()
+
+/**
+ * Profiles the Webapp's gateway lists but does not serve, so picking one is refused. Its roster marks
+ * them `reachable: false`, the flag the Bots pane greys a bot on. Re-read whenever the menu's profile
+ * list is (every list read sets a new array: mount, focus, gateway open), so both come from the same
+ * moment. Kept out of the fleet roster ($fleetRoster), whose agents feed fleet-only consumers a
+ * one-gateway Webapp must not join. Native Desktop reads nothing: its rosters never carry the flag.
+ */
+export function useUnservedProfiles(profiles: readonly ProfileInfo[]): ReadonlySet<string> {
+ const [unserved, setUnserved] = useState(NONE)
+
+ useEffect(() => {
+ const roster = isBrowserHostedDesktop() ? window.hermesDesktop?.getAgentRoster : undefined
+
+ if (!roster || !profiles.length) {
+ return
+ }
+
+ let live = true
+
+ // A failed read keeps the last marks, as the bridge keeps its last served set.
+ void roster()
+ .then(({ agents, primaryConnectionId }) => {
+ if (live) {
+ const own = agents.filter(agent => agent.connectionId === primaryConnectionId)
+ setUnserved(new Set(own.filter(agent => agent.reachable === false).map(agent => normalizeProfileKey(agent.profile))))
+ }
+ })
+ .catch(() => undefined)
+
+ return () => {
+ live = false
+ }
+ }, [profiles])
+
+ return unserved
+}
+
+/** What an unserved row says beside its name; the row itself is disabled and greyed. Its accessible
+ * name reads `<profile>, <note>` the way a row's status does (one text node, so the comma's space
+ * survives name computation). */
+export function UnservedProfileNote() {
+ const { t } = useI18n()
+ const note = t.profiles.notServedHere
+
+ return (
+ <>
+ <span aria-hidden="true" className="ml-auto shrink-0 pl-2 text-[0.6875rem] text-(--ui-text-tertiary)">
+ {note}
+ </span>
+ <span className="sr-only">{`, ${note}`}</span>
+ </>
+ )
+}
diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-boot-webapp-profile.test.tsx b/apps/desktop/src/app/gateway/hooks/use-gateway-boot-webapp-profile.test.tsx
index 5e5cd427e7e..9ebc9526fe8 100644
--- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot-webapp-profile.test.tsx
+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot-webapp-profile.test.tsx
@@ -227,3 +227,19 @@ it('picking a profile the gateway does not serve is refused with the reason and
expect(FakeWebSocket.instances).toHaveLength(1)
expect(mints.map(url => url.searchParams.get('profile'))).toEqual([null])
})
+
+it('a refused pick is final: the store does not redial the profile the gateway does not serve', async () => {
+ installed = ['default', 'research', 'solo']
+ served = ['default', 'research']
+ await bootWebappTab('/?profile=research#/')
+ const dials = vi.spyOn(window.hermesDesktop!, 'getGatewayWsUrl')
+
+ await expect(ensureGatewayProfile('solo')).rejects.toThrow('This gateway does not serve profile "solo"')
+ // Well past the redial ladder's ceiling: every scheduled redial would have run by now.
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(120_000)
+ })
+
+ expect(dials.mock.calls.filter(([profile]) => profile === 'solo')).toHaveLength(1)
+ expect(FakeWebSocket.instances).toHaveLength(1)
+})
diff --git a/apps/desktop/src/i18n/ar_command_center.ts b/apps/desktop/src/i18n/ar_command_center.ts
index 7ee5750254b..aae936ad02b 100644
--- a/apps/desktop/src/i18n/ar_command_center.ts
+++ b/apps/desktop/src/i18n/ar_command_center.ts
@@ -400,6 +400,7 @@ export const arCommandCenter = {
exportNeedsHost: name => `لا يمكن للمتصفح حفظ أرشيف الملف الشخصي. على مضيف Hermes، شغّل: hermes profile export ${name}`,
allProfiles: 'كل الملفات الشخصية',
showAllProfiles: 'إظهار كل الملفات الشخصية',
+ notServedHere: 'غير متاح هنا',
switchToProfile: name => `التبديل إلى ${name}`,
switchToConnection: name => `التبديل إلى ${name}`,
switchConnectionFailed: name => `تعذّر الاتصال بـ ${name}`,
diff --git a/apps/desktop/src/i18n/de.ts b/apps/desktop/src/i18n/de.ts
index 81ae8f25ad6..4d764110426 100644
--- a/apps/desktop/src/i18n/de.ts
+++ b/apps/desktop/src/i18n/de.ts
@@ -3208,6 +3208,7 @@ export const deOverrides = {
exportNeedsHost: name => `Der Browser kann kein Profilarchiv speichern. Führe auf dem Hermes-Host aus: hermes profile export ${name}`,
allProfiles: 'Alle Profile',
showAllProfiles: 'Alle Profile anzeigen',
+ notServedHere: 'Hier nicht bereitgestellt',
switchToProfile: name => `Zu ${name} wechseln`,
switchToConnection: name => `Zu ${name} wechseln`,
switchConnectionFailed: name => `Keine Verbindung zu ${name} möglich`,
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index e8d90bbcff7..98f16031fa4 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -2773,6 +2773,7 @@ export const en: Translations = {
exportNeedsHost: name => `The browser can't save a profile archive. On the Hermes host, run: hermes profile export ${name}`,
allProfiles: 'All profiles',
showAllProfiles: 'Show all profiles',
+ notServedHere: 'Not served here',
switchToProfile: name => `Switch to ${name}`,
switchToConnection: name => `Switch to ${name}`,
switchConnectionFailed: name => `Could not connect to ${name}`,
diff --git a/apps/desktop/src/i18n/es.ts b/apps/desktop/src/i18n/es.ts
index 57e1a495bdb..a7e33bfc430 100644
--- a/apps/desktop/src/i18n/es.ts
+++ b/apps/desktop/src/i18n/es.ts
@@ -3197,6 +3197,7 @@ export const esOverrides = {
exportNeedsHost: name => `El navegador no puede guardar un archivo de perfil. En el host de Hermes, ejecuta: hermes profile export ${name}`,
allProfiles: 'Todos los perfiles',
showAllProfiles: 'Mostrar todos los perfiles',
+ notServedHere: 'No se ofrece aquí',
switchToProfile: name => `Cambiar a ${name}`,
switchToConnection: name => `Cambiar a ${name}`,
switchConnectionFailed: name => `No se pudo conectar a ${name}`,
diff --git a/apps/desktop/src/i18n/fr.ts b/apps/desktop/src/i18n/fr.ts
index 32515b80141..12cc2d2fe42 100644
--- a/apps/desktop/src/i18n/fr.ts
+++ b/apps/desktop/src/i18n/fr.ts
@@ -3213,6 +3213,7 @@ export const frOverrides = {
exportNeedsHost: name => `Le navigateur ne peut pas enregistrer une archive de profil. Sur l'hôte Hermes, exécutez : hermes profile export ${name}`,
allProfiles: 'Tous les profils',
showAllProfiles: 'Afficher tous les profils',
+ notServedHere: 'Non proposé ici',
switchToProfile: name => `Basculer vers ${name}`,
switchToConnection: name => `Basculer vers ${name}`,
switchConnectionFailed: name => `Impossible de se connecter à ${name}`,
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 05db72758b0..28b7274c02d 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -1782,6 +1782,7 @@ export const jaOverrides = {
exportNeedsHost: name => `ブラウザーではプロファイルのアーカイブを保存できません。Hermes ホストで次を実行してください: hermes profile export ${name}`,
allProfiles: 'すべてのプロファイル',
showAllProfiles: 'すべてのプロファイルを表示',
+ notServedHere: 'ここでは提供されていません',
switchToProfile: name => `${name} に切り替え`,
switchToConnection: name => `${name} に切り替え`,
switchConnectionFailed: name => `${name} に接続できませんでした`,
diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.ts
index 8e91e823293..5612b62e502 100644
--- a/apps/desktop/src/i18n/ru.ts
+++ b/apps/desktop/src/i18n/ru.ts
@@ -2074,6 +2074,7 @@ export const ruOverrides = {
exportNeedsHost: name => `Браузер не может сохранить архив профиля. На хосте Hermes выполните: hermes profile export ${name}`,
allProfiles: 'Все профили',
showAllProfiles: 'Показать все профили',
+ notServedHere: 'Здесь не обслуживается',
switchToProfile: name => `Переключиться на ${name}`,
switchToConnection: name => `Переключиться на ${name}`,
switchConnectionFailed: name => `Не удалось подключиться к ${name}`,
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 4ce6eb6f189..9d7f1b3bad0 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -2442,6 +2442,7 @@ catalog: CatalogTranslations
exportNeedsHost: (name: string) => string
allProfiles: string
showAllProfiles: string
+ notServedHere: string
switchToProfile: (name: string) => string
switchToConnection: (name: string) => string
switchConnectionFailed: (name: string) => string
diff --git a/apps/desktop/src/i18n/zh-hant_command_center.ts b/apps/desktop/src/i18n/zh-hant_command_center.ts
index 483d40fc27b..f864a607386 100644
--- a/apps/desktop/src/i18n/zh-hant_command_center.ts
+++ b/apps/desktop/src/i18n/zh-hant_command_center.ts
@@ -323,6 +323,7 @@ export const zhHantCommandCenter = {
exportNeedsHost: name => `瀏覽器無法儲存設定檔封存。請在 Hermes 主機上執行:hermes profile export ${name}`,
allProfiles: '全部設定檔',
showAllProfiles: '顯示全部設定檔',
+ notServedHere: '此處未提供',
switchToProfile: name => `切換至 ${name}`,
switchToConnection: name => `切換至 ${name}`,
switchConnectionFailed: name => `無法連線至 ${name}`,
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index d41e5010b7a..0a69b127540 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -2692,6 +2692,7 @@ export const zhOverrides = {
exportNeedsHost: name => `浏览器无法保存配置档案归档。请在 Hermes 主机上运行:hermes profile export ${name}`,
allProfiles: '全部配置档案',
showAllProfiles: '显示全部配置档案',
+ notServedHere: '此处未提供',
switchToProfile: name => `切换到 ${name}`,
switchToConnection: name => `切换到 ${name}`,
switchConnectionFailed: name => `无法连接到 ${name}`,
diff --git a/apps/desktop/src/lib/browser-connection.ts b/apps/desktop/src/lib/browser-connection.ts
index 8d0e3d3a17f..99b111f3ef1 100644
--- a/apps/desktop/src/lib/browser-connection.ts
+++ b/apps/desktop/src/lib/browser-connection.ts
@@ -2,7 +2,7 @@ import { LOCAL_CONNECTION_ID } from '@hermes/shared'
import type { HermesApiRequest, HermesConnection } from '@/global'
import { webappSignInRequired } from '@/lib/browser-launch-session'
-import { createServedProfiles } from '@/lib/browser-served-profiles'
+import { createServedProfiles, UnservedProfileError } from '@/lib/browser-served-profiles'
import {
type AudioSocketPath,
type BrowserBootstrap,
@@ -108,7 +108,7 @@ export function createBrowserConnectionBridge({ api, bootstrap }: BrowserConnect
const getGatewayWsUrl = async (profile?: null | string) => {
// Its ticket would mint, then the gateway would close the dial (4403) without a reason to show.
if (!reachesSocket(profile)) {
- throw new Error(`This gateway does not serve profile "${profile?.trim()}", so this tab cannot open it.`)
+ throw new UnservedProfileError((profile ?? '').trim())
}
try {
diff --git a/apps/desktop/src/lib/browser-served-profiles.ts b/apps/desktop/src/lib/browser-served-profiles.ts
index 01cc597ef89..b80444d3cfb 100644
--- a/apps/desktop/src/lib/browser-served-profiles.ts
+++ b/apps/desktop/src/lib/browser-served-profiles.ts
@@ -9,6 +9,18 @@ const SERVED_SET_READ_TIMEOUT_MS = 5_000
const profileKey = (profile?: null | string) => profile?.trim() || 'default'
+/**
+ * The tab refused to open a socket for a profile its gateway does not serve. No redial can change
+ * the answer, since serving the profile takes a change on the gateway, so the store parks the dial
+ * on it until the next explicit open asks again.
+ */
+export class UnservedProfileError extends Error {
+ constructor(readonly profile: string) {
+ super(`This gateway does not serve profile "${profile}", so this tab cannot open it.`)
+ this.name = 'UnservedProfileError'
+ }
+}
+
/**
* The profiles the gateway serving this tab answers for. `/api/profiles` lists every installed
* profile, but the tab's one socket reaches only the gateway's own profile and, on a multiplexer,
diff --git a/apps/desktop/src/lib/platform.ts b/apps/desktop/src/lib/platform.ts
index 5c1339ae32e..bdbb2953998 100644
--- a/apps/desktop/src/lib/platform.ts
+++ b/apps/desktop/src/lib/platform.ts
@@ -68,3 +68,13 @@ export function isBrowserHostedDesktop() {
return document.documentElement.dataset.hermesDesktopHost === 'browser' ||
(!window.hermesDesktop && hasBrowserHostBootstrap())
}
+
+/**
+ * The profile the renderer's gateway route starts on, before boot adopts its primary. A browser
+ * host's boot adopts the profile its server runs as, and requests that name the tab's profile can
+ * go out before that: on `default` they would name a profile a gateway launched as another one may
+ * not serve, and it refuses them (`profile_mismatch`). Native Desktop starts on `default`.
+ */
+export function initialGatewayProfile(): string {
+ return (isBrowserHostedDesktop() && browserLaunchProfile()) || 'default'
+}
diff --git a/apps/desktop/src/store/gateway-dial-failures.ts b/apps/desktop/src/store/gateway-dial-failures.ts
new file mode 100644
index 00000000000..7e7d0e369d2
--- /dev/null
+++ b/apps/desktop/src/store/gateway-dial-failures.ts
@@ -0,0 +1,21 @@
+// Dial failures the secondary redial ladder (store/gateway.ts reconnectSecondary)
+// treats as permanent for a scoped socket.
+
+// Electron's getConnectionFor rejects with `No connection with id "…"` when
+// the registry entry is gone. That is a permanent condition for the scoped
+// socket, unlike transient transport errors.
+export function isMissingConnectionError(error: unknown): boolean {
+ const message = error instanceof Error ? error.message : String(error ?? '')
+
+ return message.includes('No connection with id')
+}
+
+// Electron's spawn guard (assertLocalProfileCanStart) rejects with these when
+// the profile's directory is gone or its DELETE is still in flight. For a
+// renderer socket that condition is permanent: the backend it reconnects to
+// can never come back, and every retry hammers the guard (#88769).
+export function isMissingProfileError(error: unknown): boolean {
+ const message = error instanceof Error ? error.message : String(error ?? '')
+
+ return message.includes('no longer exists') || message.includes('is being deleted')
+}
diff --git a/apps/desktop/src/store/gateway.ts b/apps/desktop/src/store/gateway.ts
index c83afe99fdf..dc82cef6ce8 100644
--- a/apps/desktop/src/store/gateway.ts
+++ b/apps/desktop/src/store/gateway.ts
@@ -14,6 +14,7 @@ import { canonicalOwnerProfile } from '@/api/canonical-protocol'
import type { HermesConnection } from '@/global'
import { HermesGateway, setApiRequestConnection } from '@/hermes'
import { translateNow } from '@/i18n'
+import { UnservedProfileError } from '@/lib/browser-served-profiles'
import {
decideLivenessForceClose,
LIVENESS_PROBE_TIMEOUT_MS,
@@ -22,12 +23,14 @@ import {
import { isMissingRpcMethod } from '@/lib/gateway-rpc'
import { traceIdentityChange } from '@/lib/identity-trace'
import { isPermanentLocalGatewayEnsureError } from '@/lib/local-gateway-ensure-failure'
+import { initialGatewayProfile } from '@/lib/platform'
import {
isTimeoutError,
RECONNECT_ATTEMPT_TIMEOUT_MS,
SOURCE_SWITCH_DIAL_TIMEOUT_MS,
withTimeout
} from '@/lib/with-timeout'
+import { isMissingConnectionError, isMissingProfileError } from '@/store/gateway-dial-failures'
import { notifyError, RECOVERY_ACTIONS } from '@/store/notifications'
import { markNativeNotifyBaseline } from '@/store/notify-baseline'
import { setConnection, setGatewayState } from '@/store/session'
@@ -246,8 +249,8 @@ function createRegistryState(): GatewayRegistryState {
primaryGateway: null,
primaryConnectionId: null,
primaryConnectionMode: null,
- primaryProfile: 'default',
- activeKey: 'default',
+ primaryProfile: initialGatewayProfile(),
+ activeKey: initialGatewayProfile(),
activationEpoch: 0,
secondaries: new Map<string, Secondary>(),
reauthFailures: new Map(),
@@ -266,7 +269,7 @@ function createRegistryState(): GatewayRegistryState {
// the split-brain where an eviction re-pointed activeKey at the primary
// while the profile atom kept naming the evicted bot routed every
// "loki" session.resume to the default backend (#89206 wake failures).
- $activeProfile: atom<string>('default')
+ $activeProfile: atom<string>(initialGatewayProfile())
}
}
@@ -838,6 +841,12 @@ async function openSecondary(entry: Secondary): Promise<void> {
clearTimer(entry)
}
+ // Parked here, where every dial lands, so not even the first scheduled redial runs.
+ if (error instanceof UnservedProfileError) {
+ entry.wantOpen = false
+ clearTimer(entry)
+ }
+
throw error
} finally {
if (entry.connectPromise === pending) {
@@ -1023,25 +1032,6 @@ async function reconnectSecondary(entry: Secondary): Promise<void> {
}
}
-// Electron's getConnectionFor rejects with `No connection with id "…"` when
-// the registry entry is gone. That is a permanent condition for the scoped
-// socket, unlike transient transport errors.
-function isMissingConnectionError(error: unknown): boolean {
- const message = error instanceof Error ? error.message : String(error ?? '')
-
- return message.includes('No connection with id')
-}
-
-// Electron's spawn guard (assertLocalProfileCanStart) rejects with these when
-// the profile's directory is gone or its DELETE is still in flight. For a
-// renderer socket that condition is permanent: the backend it reconnects to
-// can never come back, and every retry hammers the guard (#88769).
-function isMissingProfileError(error: unknown): boolean {
- const message = error instanceof Error ? error.message : String(error ?? '')
-
- return message.includes('no longer exists') || message.includes('is being deleted')
-}
-
function createSecondary(profile: string, connectionId: null | string = null): Secondary {
const gateway = new HermesGateway()
const scope = registryBackendScopeKey(connectionId, profile)
diff --git a/apps/desktop/src/store/profile-launch-native.test.ts b/apps/desktop/src/store/profile-launch-native.test.ts
new file mode 100644
index 00000000000..def93a0963b
--- /dev/null
+++ b/apps/desktop/src/store/profile-launch-native.test.ts
@@ -0,0 +1,21 @@
+import { afterAll, expect, it, vi } from 'vitest'
+
+import { activeGatewayProfileKey } from '@/store/gateway'
+import { $activeGatewayProfile } from '@/store/profile'
+
+// The twin of profile-launch-webapp.test.ts: only a browser host starts on its server's profile.
+// Electron's preload installs the bridge before any renderer module evaluates, so native Desktop
+// starts on `default` even if a page global names another profile.
+vi.hoisted(() => {
+ Object.assign(window, { __HERMES_DASHBOARD_PROFILE__: 'solo', hermesDesktop: {} })
+})
+
+afterAll(() => {
+ Reflect.deleteProperty(window, '__HERMES_DASHBOARD_PROFILE__')
+ Reflect.deleteProperty(window, 'hermesDesktop')
+})
+
+it('native Desktop starts on default', () => {
+ expect($activeGatewayProfile.get()).toBe('default')
+ expect(activeGatewayProfileKey()).toBe('default')
+})
diff --git a/apps/desktop/src/store/profile-launch-webapp.test.ts b/apps/desktop/src/store/profile-launch-webapp.test.ts
new file mode 100644
index 00000000000..ffc4ea3cd53
--- /dev/null
+++ b/apps/desktop/src/store/profile-launch-webapp.test.ts
@@ -0,0 +1,39 @@
+import { afterAll, expect, it, vi } from 'vitest'
+
+import { getApiRequestProfile } from '@/hermes'
+import { syncApprovalModeForProfile } from '@/store/approval-mode'
+import { activeGatewayProfileKey, requestGatewayForProfile, setPrimaryGateway } from '@/store/gateway'
+import { $activeGatewayProfile } from '@/store/profile'
+
+// A Webapp tab's one socket answers for the profile its gateway runs as, and the gateway refuses a
+// request naming a profile it does not serve (`profile_mismatch`). Boot requests that name the tab's
+// profile (approval mode, model options, the pet, shared metrics, setup checks) can go out before boot
+// adopts the primary, so the renderer must start on the gateway's own profile, not on `default`. The
+// page the gateway serves sets these globals before any module evaluates (web_server_dashboard.py).
+type PageGlobals = { __HERMES_DASHBOARD_PROFILE__?: string; __HERMES_UI_SURFACE__?: string }
+
+vi.hoisted(() => {
+ Object.assign(window, { __HERMES_DASHBOARD_PROFILE__: 'solo', __HERMES_UI_SURFACE__: 'webapp' })
+})
+
+afterAll(() => {
+ const page = window as Window & PageGlobals
+ delete page.__HERMES_DASHBOARD_PROFILE__
+ delete page.__HERMES_UI_SURFACE__
+})
+
+it('a Webapp tab starts on the profile its gateway runs as, so a boot request names that profile', async () => {
+ expect($activeGatewayProfile.get()).toBe('solo')
+ expect(activeGatewayProfileKey()).toBe('solo')
+ expect(getApiRequestProfile()).toBe('solo')
+
+ // The status bar's approval-mode read, as it runs on the tab's socket once it opens.
+ const request = vi.fn(async () => ({ value: 'manual' }))
+ setPrimaryGateway({ connectionState: 'open', request } as never, $activeGatewayProfile.get())
+ await syncApprovalModeForProfile(
+ (method, params) => requestGatewayForProfile($activeGatewayProfile.get(), method, params),
+ $activeGatewayProfile.get()
+ )
+
+ expect(request).toHaveBeenCalledWith('config.get', { key: 'approvals.mode', profile: 'solo' })
+})
diff --git a/apps/desktop/src/store/profile.ts b/apps/desktop/src/store/profile.ts
index b570b856c81..bdff27e8847 100644
--- a/apps/desktop/src/store/profile.ts
+++ b/apps/desktop/src/store/profile.ts
@@ -3,7 +3,7 @@ import { atom, batch, computed } from 'nanostores'
import type { HermesConnection } from '@/global'
import { getProfiles, hermesApi, setApiRequestProfile, STARTUP_REQUEST_TIMEOUT_MS } from '@/hermes'
-import { isBrowserHostedDesktop } from '@/lib/platform'
+import { initialGatewayProfile, isBrowserHostedDesktop } from '@/lib/platform'
import { sortByProfileOrder as sortProfilesByOrder } from '@/lib/profile-order'
import { invalidateProfileScopedQueries } from '@/lib/query-client'
import {
@@ -288,13 +288,15 @@ export async function switchProfile(name: string): Promise<void> {
// gateway to that profile's backend (spawned on demand by the Electron pool).
// A single-profile user never triggers a swap, so their path is unchanged.
-// The profile the live gateway WebSocket is currently connected to. Initialized
-// to the primary (window) backend's profile on boot. The gateway registry
+// The profile the live gateway WebSocket is currently connected to. Starts on
+// the registry's own initial route (initialGatewayProfile: a browser host's
+// serving profile, else default) and follows the primary (window) backend's
+// profile once boot adopts it. The gateway registry
// mirrors its own route into this atom via the onActiveRouteChanged callback
// (wired in use-gateway-boot's configureGatewayRegistry), so registry-internal
// eviction fallbacks (connection removal, profile delete) can never
// leave this naming a profile the active socket no longer serves (#89206).
-export const $activeGatewayProfile = atom<string>('default')
+export const $activeGatewayProfile = atom<string>(initialGatewayProfile())
// Profile for the NEXT new chat (chosen via the new-chat picker). null = primary
// / default, so single-profile users are unaffected.