Skip to content

The agent that grows with you

fix(desktop): remember selected profile across restarts

Tilly-YL2952119bce48
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 5f1a03aeca5..48fb22bcadc 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -14105,6 +14105,13 @@ ipcMain.handle('hermes:connection-config:apply', async (_event, payload) => {
})
ipcMain.handle('hermes:profile:get', async () => ({ profile: readActiveDesktopProfile() }))
+// Persistence-only sibling of hermes:profile:set: records the profile the
+// Desktop should boot into next launch WITHOUT tearing down the backend or
+// reloading the window — the rail's live workspace switch already re-homed
+// the gateway (#79886).
+ipcMain.handle('hermes:profile:remember', async (_event, name) => ({
+ profile: writeActiveDesktopProfile(name)
+}))
ipcMain.handle('hermes:profile:set', async (_event, name) => {
const next = writeActiveDesktopProfile(name)
diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.ts
index 402588bc137..300c634ed1f 100644
--- a/apps/desktop/electron/preload.ts
+++ b/apps/desktop/electron/preload.ts
@@ -214,6 +214,7 @@ contextBridge.exposeInMainWorld('hermesDesktop', {
},
profile: {
get: () => ipcRenderer.invoke('hermes:profile:get'),
+ remember: name => ipcRenderer.invoke('hermes:profile:remember', name),
set: name => ipcRenderer.invoke('hermes:profile:set', name)
},
api: request => ipcRenderer.invoke('hermes:api', request),
diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.ts
index 318072588b4..f3e0d0381ed 100644
--- a/apps/desktop/src/global.d.ts
+++ b/apps/desktop/src/global.d.ts
@@ -198,6 +198,9 @@ declare global {
}
profile: {
get: () => Promise<DesktopActiveProfile>
+ // Persists the profile used on the next Desktop launch without
+ // interrupting the live gateway workspace switch.
+ remember: (name: string | null) => Promise<DesktopActiveProfile>
// Persists the desktop's profile choice and relaunches the local
// backend under the new HERMES_HOME (reloads the window). Pass null to
// clear the preference.
diff --git a/apps/desktop/src/store/profile-select-source.test.ts b/apps/desktop/src/store/profile-select-source.test.ts
index 8fe01691121..9adcfcb6d93 100644
--- a/apps/desktop/src/store/profile-select-source.test.ts
+++ b/apps/desktop/src/store/profile-select-source.test.ts
@@ -91,3 +91,52 @@ describe('newSessionInProfile', () => {
expect(ensureGatewayForAgent).not.toHaveBeenCalled()
})
})
+
+describe('selectProfile startup preference (#79886)', () => {
+ const rememberProfile = vi.fn(async (name: null | string) => ({ profile: name }))
+
+ beforeEach(() => {
+ rememberProfile.mockClear()
+ ;(globalThis as { window?: unknown }).window = {
+ hermesDesktop: { profile: { remember: rememberProfile } }
+ }
+ })
+
+ it('remembers the selected workspace for the next Desktop launch', async () => {
+ activeGatewayConnectionId.mockReturnValue(null)
+
+ selectProfile('tilly')
+
+ await vi.waitFor(() => expect(rememberProfile).toHaveBeenCalledWith('tilly'))
+ expect(ensureGatewayForProfile).toHaveBeenCalledWith('tilly')
+ })
+
+ it('waits for gateway activation before replacing the startup preference', async () => {
+ let resolveGateway!: () => void
+
+ activeGatewayConnectionId.mockReturnValue(null)
+ ensureGatewayForProfile.mockImplementationOnce(
+ () =>
+ new Promise<undefined>(resolve => {
+ resolveGateway = () => resolve(undefined)
+ })
+ )
+
+ selectProfile('tilly')
+ await vi.waitFor(() => expect(ensureGatewayForProfile).toHaveBeenCalledWith('tilly'))
+ expect(rememberProfile).not.toHaveBeenCalled()
+
+ resolveGateway()
+
+ await vi.waitFor(() => expect(rememberProfile).toHaveBeenCalledWith('tilly'))
+ })
+
+ it('does not replace the startup preference for a registry-source pick', async () => {
+ activeGatewayConnectionId.mockReturnValue('mini')
+
+ selectProfile('researcher')
+
+ await vi.waitFor(() => expect(ensureGatewayForAgent).toHaveBeenCalledWith('mini', 'researcher'))
+ expect(rememberProfile).not.toHaveBeenCalled()
+ })
+})
diff --git a/apps/desktop/src/store/profile.ts b/apps/desktop/src/store/profile.ts
index 39dba687c13..de71b8138ab 100644
--- a/apps/desktop/src/store/profile.ts
+++ b/apps/desktop/src/store/profile.ts
@@ -692,11 +692,28 @@ export function selectProfile(name: string): void {
// #81094: any other failed switch must be visible too — the profile pill
// stays on the previous profile and the user learns why the backend is
// unreachable.
- void activateOnCurrentSource(target).catch((error: unknown) => {
- if (!notifyRemoteOverrideAuthFailure(target, error)) {
- notifyError(error, `Failed to switch to profile "${target}"`)
- }
- })
+ //
+ // The profile rail is a live workspace switch, so it must not call
+ // profile.set() and reload the window. Once activation succeeds, remember
+ // the selection for the next Desktop launch through the persistence-only
+ // IPC instead (#79886). Registry-source picks name ANOTHER source's
+ // profiles, so only a primary-backend activation updates the startup
+ // preference.
+ const onPrimary = activeGatewayConnectionId() == null
+
+ void activateOnCurrentSource(target)
+ .then(() => {
+ if (onPrimary) {
+ return window.hermesDesktop?.profile?.remember(target)
+ }
+
+ return undefined
+ })
+ .catch((error: unknown) => {
+ if (!notifyRemoteOverrideAuthFailure(target, error)) {
+ notifyError(error, `Failed to switch to profile "${target}"`)
+ }
+ })
}
// Route a profile pick at the source the user is LOOKING at. $profiles is the
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
new file mode 100644
index 00000000000..ae57937ba06
--- /dev/null
+++ b/contributors/emails/[email protected]
@@ -0,0 +1 @@
+Tilly-YL