The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): retain local startup profile across SSH switches
kim-miramac2ec568333d
diff --git a/apps/desktop/src/store/profile-select-source.test.ts b/apps/desktop/src/store/profile-select-source.test.tsindex 9adcfcb6d93..703723cc0af 100644--- a/apps/desktop/src/store/profile-select-source.test.ts+++ b/apps/desktop/src/store/profile-select-source.test.ts@@ -97,8 +97,17 @@ describe('selectProfile startup preference (#79886)', () => {beforeEach(() => {rememberProfile.mockClear()++ const getConnection = vi.fn(async () => ({ mode: 'local' }))++ const getConnectionConfig = vi.fn(async () => ({ mode: 'local' }))+;(globalThis as { window?: unknown }).window = {- hermesDesktop: { profile: { remember: rememberProfile } }+ hermesDesktop: {+ getConnection,+ getConnectionConfig,+ profile: { remember: rememberProfile }+ }}})@@ -139,4 +148,60 @@ describe('selectProfile startup preference (#79886)', () => {await vi.waitFor(() => expect(ensureGatewayForAgent).toHaveBeenCalledWith('mini', 'researcher'))expect(rememberProfile).not.toHaveBeenCalled()})++ it('remembers an already-active local profile after returning from All Profiles', async () => {+ activeGatewayConnectionId.mockReturnValue(null)+ $activeGatewayProfile.set('tilly')++ selectProfile('tilly')++ await vi.waitFor(() => expect(rememberProfile).toHaveBeenCalledWith('tilly'))+ })++ it('keeps local startup persistence when the backend descriptor lookup fails', async () => {+ activeGatewayConnectionId.mockReturnValue(null)++ const getConnection = vi.fn(async () => {+ throw new Error('descriptor unavailable')+ })++ const getConnectionConfig = vi.fn(async () => ({ mode: 'local' }))++ ;(globalThis as { window?: unknown }).window = {+ hermesDesktop: {+ getConnection,+ getConnectionConfig,+ profile: { remember: rememberProfile }+ }+ }++ selectProfile('tilly')++ await vi.waitFor(() => expect(ensureGatewayForProfile).toHaveBeenCalledWith('tilly'))+ await vi.waitFor(() => expect(rememberProfile).toHaveBeenCalledWith('tilly'))+ })++ it('does not replace the local startup preference for a profile SSH override', async () => {+ activeGatewayConnectionId.mockReturnValue(null)++ const getConnection = vi.fn(async () => ({ mode: 'remote', remoteKind: 'ssh' }))++ const getConnectionConfig = vi.fn(async () => ({ mode: 'ssh' }))++ ;(globalThis as { window?: unknown }).window = {+ hermesDesktop: {+ getConnection,+ getConnectionConfig,+ profile: { remember: rememberProfile }+ }+ }++ selectProfile('macmini-hermes')++ await vi.waitFor(() => expect(ensureGatewayForProfile).toHaveBeenCalledWith('macmini-hermes'))+ await vi.waitFor(() => expect(getConnection).toHaveBeenCalledWith('macmini-hermes'))+ await new Promise(resolve => setTimeout(resolve, 0))++ expect(rememberProfile).not.toHaveBeenCalled()+ })})diff --git a/apps/desktop/src/store/profile.ts b/apps/desktop/src/store/profile.tsindex 869c96b8da5..1dbcfdfea11 100644--- a/apps/desktop/src/store/profile.ts+++ b/apps/desktop/src/store/profile.ts@@ -784,9 +784,11 @@ export function selectProfile(name: string): void {// preference.const onPrimary = activeGatewayConnectionId() == null- void activateOnCurrentSource(target)- .then(() => {- if (onPrimary) {+ const shouldRememberStartupProfile = onPrimary ? isLocalDesktopProfile(target) : Promise.resolve(false)++ void Promise.all([activateOnCurrentSource(target), shouldRememberStartupProfile])+ .then(([, shouldRemember]) => {+ if (shouldRemember) {return window.hermesDesktop?.profile?.remember(target)}@@ -799,6 +801,28 @@ export function selectProfile(name: string): void {})}+// Resolve persistence from the saved per-profile Desktop route, rather than the+// live backend descriptor. A descriptor lookup is intentionally best-effort:+// failure must not discard a successful local selection's startup preference.+// Conversely, `ssh`, `remote`, and `cloud` here are per-profile overrides and+// must never replace the local Desktop startup profile.+async function isLocalDesktopProfile(target: string): Promise<boolean> {+ const getConnectionConfig = window.hermesDesktop?.getConnectionConfig++ if (!getConnectionConfig) {+ return true+ }++ try {+ return (await getConnectionConfig(target)).mode === 'local'+ } catch {+ // Preserve the pre-fix local-primary behavior when Electron's config bridge+ // is temporarily unavailable. The next successful config read will still+ // exclude any remote override.+ return true+ }+}+// Route a profile pick at the source the user is LOOKING at. $profiles is the// active gateway's list, so a pick made while a remote registry source is live// names one of THAT source's profiles and must keep its connection id. The