From 76af834dddb480fa867c625c70f9fa93090636bf Mon Sep 17 00:00:00 2001 From: Kavyrocom Date: Mon, 24 Aug 2026 06:20:54 +0000 Subject: [PATCH] fix(desktop): route ambient SSH profile deletion to remote --- apps/desktop/src/sdk/index.ts | 22 ++++++++++++++++++-- apps/desktop/src/sdk/profile-routing.test.ts | 14 +++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.ts index 59f01962d6..74a5735719 100644 --- a/apps/desktop/src/sdk/index.ts +++ b/apps/desktop/src/sdk/index.ts @@ -617,6 +617,17 @@ export const host = { } const targetProfile = route?.targetProfile || name + // A name-only call is ambient, not local: Bot Mode's active SSH roster + // rows deliberately use the ambient gateway door and therefore carry no + // explicit owner route. Preserve the active registry connection so the + // profile teardown and DELETE both land on the VPS instead of retiring the + // unrelated local pool and leaving the warmed remote backend to recreate + // the deleted profile. + const ambientConnectionId = route ? null : String(activeGatewayConnectionId() || '').trim() + + const ambientRemoteConnectionId = ambientConnectionId && ambientConnectionId !== 'local' + ? ambientConnectionId + : null if (!name) { throw new Error('deleteProfile: profile name required') @@ -637,11 +648,18 @@ export const host = { // A hover-warmed Bot Mode row owns a retained renderer socket. Retire it // before Electron stops the profile backend so the socket closure cannot // schedule a reconnect that resurrects the deleted profile. - if (!route || route.mode === 'local') { + if (route?.mode === 'local' || (!route && !ambientRemoteConnectionId)) { retireLocalProfileGateways(targetProfile) } - await deleteProfile(targetProfile, route ? { connectionId: route.connectionId, profile: route.profile } : undefined) + await deleteProfile( + targetProfile, + route + ? { connectionId: route.connectionId, profile: route.profile } + : ambientRemoteConnectionId + ? { connectionId: ambientRemoteConnectionId, profile: name } + : undefined + ) // The profile rail paints from the shared $profiles cache; without a // refresh the deleted profile's badge survives and clicking it starts a diff --git a/apps/desktop/src/sdk/profile-routing.test.ts b/apps/desktop/src/sdk/profile-routing.test.ts index 78dae20be4..71237762d0 100644 --- a/apps/desktop/src/sdk/profile-routing.test.ts +++ b/apps/desktop/src/sdk/profile-routing.test.ts @@ -108,6 +108,7 @@ const { openSession: openSessionCore } = await import('@/app/open-session') const { deleteProfile } = await import('@/hermes') const { + activeGatewayConnectionId, openGatewayForAgent, openGatewayForProfile, requestGatewayForAgent, @@ -152,6 +153,7 @@ const profile = (name: string): ProfileInfo => ({ afterEach(() => { vi.clearAllMocks() + vi.mocked(activeGatewayConnectionId).mockReturnValue('local') $activeGatewayProfile.set('remote-worker') $gatewaySwapTarget.set(null) setMockAtom($focusedRuntimeId, null) @@ -189,6 +191,18 @@ describe('connection-aware plugin host APIs', () => { expect(refreshProfiles).toHaveBeenCalled() }) + it('pins an ambient SSH profile delete to the active connection and target profile', async () => { + vi.mocked(activeGatewayConnectionId).mockReturnValue('ssh-vps') + + await host.deleteProfile('worker') + + expect(retireLocalProfileGateways).not.toHaveBeenCalled() + expect(deleteProfile).toHaveBeenCalledWith('worker', { + connectionId: 'ssh-vps', + profile: 'worker' + }) + }) + it('refreshes the profile inventory before asking Electron for routes', async () => { const getProfileRoutes = vi.fn(async () => [ { connectionId: 'connection-local', mode: 'local', profile: 'desktop-primary', targetProfile: 'desktop-primary' },