From 48d9bed4cc987967d09772a9257c5594c808c735 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Sun, 25 Oct 2026 17:48:50 -0400 Subject: [PATCH] fix(sessions): route remote session deletion through the picker navigation Replace the picker's onDeleteActiveSession callback override with a deleteActiveSessionPath destination that goes through the shared open() helper. Deleting the open remote session from the floating panel no longer races a history-back close against the project navigation, and the docked panel stays open on the remote project page like local deletion does. --- .../navigation/ToolSidePanel.test.tsx | 19 +++++++------- .../components/navigation/ToolSidePanel.tsx | 16 ++++++------ .../hooks/useSessionPickerNavigation.test.tsx | 26 ++++++++++++++----- .../src/hooks/useSessionPickerNavigation.ts | 15 +++++------ frontend/src/pages/SessionDetail.tsx | 2 +- .../__tests__/SessionDetail.remote.test.tsx | 12 ++++----- 6 files changed, 51 insertions(+), 39 deletions(-) diff --git a/frontend/src/components/navigation/ToolSidePanel.test.tsx b/frontend/src/components/navigation/ToolSidePanel.test.tsx index b9e824e3..7c30c1b3 100644 --- a/frontend/src/components/navigation/ToolSidePanel.test.tsx +++ b/frontend/src/components/navigation/ToolSidePanel.test.tsx @@ -95,10 +95,10 @@ function LocationProbe() { function Harness({ docked, - onDeleteActiveSession, + deleteActiveSessionPath, }: { docked: boolean - onDeleteActiveSession?: () => void + deleteActiveSessionPath?: string }) { const panel = useToolPanel(docked) return ( @@ -115,7 +115,7 @@ function Harness({ selectedFilePath="src/a.ts" repoDirectory="/repo" onSkillLoaded={() => {}} - onDeleteActiveSession={onDeleteActiveSession} + deleteActiveSessionPath={deleteActiveSessionPath} /> ) : null} @@ -123,10 +123,10 @@ function Harness({ ) } -function renderAt(search: string, docked = true, onDeleteActiveSession?: () => void) { +function renderAt(search: string, docked = true, deleteActiveSessionPath?: string) { return render( - + , ) } @@ -621,14 +621,15 @@ describe('ToolSidePanel', () => { } }) - it('forwards the delete override to the session picker', async () => { - const onDeleteActiveSession = vi.fn() - renderAt('?panel=sessions', true, onDeleteActiveSession) + it('forwards the delete destination to the session picker', async () => { + renderAt('?panel=sessions', true, '/servers/srv_kitchen/projects?directory=%2Fapp') await screen.findByText('route-session-picker') expect(sessionPickerMocks.useSessionPickerNavigation).toHaveBeenLastCalledWith( - expect.objectContaining({ onDeleteActiveSession }), + expect.objectContaining({ + deleteActiveSessionPath: '/servers/srv_kitchen/projects?directory=%2Fapp', + }), ) }) diff --git a/frontend/src/components/navigation/ToolSidePanel.tsx b/frontend/src/components/navigation/ToolSidePanel.tsx index e8bb3203..a5627508 100644 --- a/frontend/src/components/navigation/ToolSidePanel.tsx +++ b/frontend/src/components/navigation/ToolSidePanel.tsx @@ -165,18 +165,18 @@ function useFloatingPanelDismiss( interface SessionsPanelBodyProps { docked: boolean onClose: () => void - onDeleteActiveSession?: () => void + deleteActiveSessionPath?: string } /** * Session picker shown in the tool panel. While docked, choosing a session keeps the panel open on * the destination; as an overlay sheet the choice replaces the entry behind it and closes the panel. */ -function SessionsPanelBody({ docked, onClose, onDeleteActiveSession }: SessionsPanelBodyProps) { +function SessionsPanelBody({ docked, onClose, deleteActiveSessionPath }: SessionsPanelBodyProps) { const navigation = useSessionPickerNavigation({ mode: docked ? 'panel' : 'replace', onClose, - onDeleteActiveSession, + deleteActiveSessionPath, }) return ( @@ -220,10 +220,10 @@ interface ToolSidePanelProps { walkthroughModel?: ModelRef | null walkthroughOnOpenSession?: (id: string) => void /** - * Replaces the session picker's default behaviour after the open session is deleted; the session - * page passes its close handler on linked-server routes. + * Path the session picker opens after the open session is deleted; the session page passes the + * remote project path on linked-server routes. */ - onDeleteActiveSession?: () => void + deleteActiveSessionPath?: string } interface RailButtonProps { @@ -289,7 +289,7 @@ export function ToolSidePanel({ walkthroughSourceRequest, walkthroughModel, walkthroughOnOpenSession, - onDeleteActiveSession, + deleteActiveSessionPath, }: ToolSidePanelProps) { const { activeTool, toggleTool, closePanel } = panel const location = useLocation() @@ -359,7 +359,7 @@ export function ToolSidePanel({ if (tool === 'mcp') return repoDirectory ? : null if (tool === 'walkthrough') return sessionId ? : null if (tool === 'sessions') { - return + return } if (tool === 'terminal') { return terminalWorkspaceTarget diff --git a/frontend/src/hooks/useSessionPickerNavigation.test.tsx b/frontend/src/hooks/useSessionPickerNavigation.test.tsx index f9b4cbaa..29889932 100644 --- a/frontend/src/hooks/useSessionPickerNavigation.test.tsx +++ b/frontend/src/hooks/useSessionPickerNavigation.test.tsx @@ -161,23 +161,23 @@ describe('useSessionPickerNavigation', () => { expect(onClose).not.toHaveBeenCalled() }) - it('calls only the delete override when one is supplied', () => { - const onDeleteActiveSession = vi.fn() + it('opens the delete destination with the panel param and keeps the picker open', () => { const { result, onClose, location } = renderPickerNavigation( ['/servers/srv_kitchen/sessions/a?panel=sessions'], - { mode: 'panel', onDeleteActiveSession }, + { mode: 'panel', deleteActiveSessionPath: '/servers/srv_kitchen/projects?directory=%2Fapp' }, ) act(() => { result.current.onDeleteActiveSession() }) - expect(onDeleteActiveSession).toHaveBeenCalledTimes(1) - expect(location()).toBe('/servers/srv_kitchen/sessions/a?panel=sessions POP') + expect(location()).toBe( + '/servers/srv_kitchen/projects?directory=%2Fapp&panel=sessions PUSH', + ) expect(onClose).not.toHaveBeenCalled() }) - it('does nothing when deleting without an override outside a repo route', () => { + it('does nothing when deleting without a destination outside a repo route', () => { const { result, onClose, location } = renderPickerNavigation( ['/servers/srv_kitchen/sessions/a?panel=sessions'], { mode: 'panel' }, @@ -250,5 +250,19 @@ describe('useSessionPickerNavigation', () => { expect(location()).toBe('/repos/1/sessions/b REPLACE') expect(onClose).not.toHaveBeenCalled() }) + + it('replaces the entry with the delete destination without closing or going back', () => { + const { result, onClose, location } = renderPickerNavigation( + ['/servers/srv_kitchen/sessions/a?panel=sessions'], + { mode: 'replace', deleteActiveSessionPath: '/servers/srv_kitchen/projects?directory=%2Fapp' }, + ) + + act(() => { + result.current.onDeleteActiveSession() + }) + + expect(location()).toBe('/servers/srv_kitchen/projects?directory=%2Fapp REPLACE') + expect(onClose).not.toHaveBeenCalled() + }) }) }) diff --git a/frontend/src/hooks/useSessionPickerNavigation.ts b/frontend/src/hooks/useSessionPickerNavigation.ts index 18bc6258..70fc1239 100644 --- a/frontend/src/hooks/useSessionPickerNavigation.ts +++ b/frontend/src/hooks/useSessionPickerNavigation.ts @@ -20,8 +20,8 @@ export interface SessionPickerNavigationOptions { */ mode: 'push' | 'replace' | 'panel' onClose: () => void - /** Replaces the default delete behaviour of returning to the current repo's session list. */ - onDeleteActiveSession?: () => void + /** Where to go after the open session is deleted, instead of the current repo's session list. */ + deleteActiveSessionPath?: string } export interface SessionPickerNavigation { @@ -39,13 +39,13 @@ export interface SessionPickerNavigation { * where the picker stays open. An assistant session keeps `?assistant=1` when the chosen session * belongs to the current repo. * - * @param options Navigation mode, the picker's close callback, and an optional delete override. + * @param options Navigation mode, the picker's close callback, and an optional delete destination. * @returns Handlers for selecting sessions and repos and for following a prepared path. */ export function useSessionPickerNavigation({ mode, onClose, - onDeleteActiveSession: deleteActiveSessionOverride, + deleteActiveSessionPath, }: SessionPickerNavigationOptions): SessionPickerNavigation { const navigate = useNavigate() const { pathname, search } = useLocation() @@ -95,9 +95,8 @@ export function useSessionPickerNavigation({ ) const onDeleteActiveSession = useCallback(() => { - if (deleteActiveSessionOverride) { - if (!isPanelMode) onClose() - deleteActiveSessionOverride() + if (deleteActiveSessionPath) { + open(deleteActiveSessionPath) return } if (currentRepoId === null) { @@ -107,7 +106,7 @@ export function useSessionPickerNavigation({ open(getSessionListPath(currentRepoId, isAssistantSession, repoTab)) }, [ currentRepoId, - deleteActiveSessionOverride, + deleteActiveSessionPath, isAssistantSession, isPanelMode, onClose, diff --git a/frontend/src/pages/SessionDetail.tsx b/frontend/src/pages/SessionDetail.tsx index 6240127a..01a0be91 100644 --- a/frontend/src/pages/SessionDetail.tsx +++ b/frontend/src/pages/SessionDetail.tsx @@ -1025,7 +1025,7 @@ export function SessionDetail() { walkthroughSourceRequest={walkthroughSourceRequest} walkthroughModel={modelRef} walkthroughOnOpenSession={handleChildSessionClick} - onDeleteActiveSession={isRemoteServer ? handleCloseSession : undefined} + deleteActiveSessionPath={isRemoteServer ? remoteProjectBackPath : undefined} /> )} diff --git a/frontend/src/pages/__tests__/SessionDetail.remote.test.tsx b/frontend/src/pages/__tests__/SessionDetail.remote.test.tsx index 050ea710..dfd00473 100644 --- a/frontend/src/pages/__tests__/SessionDetail.remote.test.tsx +++ b/frontend/src/pages/__tests__/SessionDetail.remote.test.tsx @@ -539,21 +539,19 @@ describe('SessionDetail remote server mode', () => { }) it('deletes the active remote session from the tool panel', async () => { - const { capturedPathname, capturedSearch } = renderRemoteSession() + renderRemoteSession() await waitFor(() => { expect(screen.getByTestId('message-thread')).toBeInTheDocument() }) const panelProps = mocks.ToolSidePanel.mock.calls.at(-1)?.[0] as - | { onDeleteActiveSession?: () => void } + | { deleteActiveSessionPath?: string } | undefined - act(() => { - panelProps?.onDeleteActiveSession?.() - }) - expect(capturedPathname.current).toBe('/servers/srv_kitchen/projects') - expect(capturedSearch.current).toBe('?directory=%2Fhome%2Fme%2Fapp') + expect(panelProps?.deleteActiveSessionPath).toBe( + '/servers/srv_kitchen/projects?directory=%2Fhome%2Fme%2Fapp', + ) }) it('shows a loader until the session directory is available', async () => {