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.
This commit is contained in:
Chris Scott committed 2026-10-25 17:48:50 -04:00
1 parent d26ab578f0
commit 48d9bed4cc
6 files changed
+51 -39

No files matched your search

@@ -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}
<LocationProbe />
@@ -123,10 +123,10 @@ function Harness({
)
}
function renderAt(search: string, docked = true, onDeleteActiveSession?: () => void) {
function renderAt(search: string, docked = true, deleteActiveSessionPath?: string) {
return render(
<MemoryRouter initialEntries={[`/repos/1/sessions/ses_1${search}`]}>
<Harness docked={docked} onDeleteActiveSession={onDeleteActiveSession} />
<Harness docked={docked} deleteActiveSessionPath={deleteActiveSessionPath} />
</MemoryRouter>,
)
}
@@ -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',
}),
)
})
@@ -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 ? <RepoMcpContent open directory={repoDirectory} /> : null
if (tool === 'walkthrough') return sessionId ? <ChangesWalkthroughView /> : null
if (tool === 'sessions') {
return <SessionsPanelBody docked={docked} onClose={closePanel} onDeleteActiveSession={onDeleteActiveSession} />
return <SessionsPanelBody docked={docked} onClose={closePanel} deleteActiveSessionPath={deleteActiveSessionPath} />
}
if (tool === 'terminal') {
return terminalWorkspaceTarget
@@ -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()
})
})
})
@@ -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,
+1 -1
View File
@@ -1025,7 +1025,7 @@ export function SessionDetail() {
walkthroughSourceRequest={walkthroughSourceRequest}
walkthroughModel={modelRef}
walkthroughOnOpenSession={handleChildSessionClick}
onDeleteActiveSession={isRemoteServer ? handleCloseSession : undefined}
deleteActiveSessionPath={isRemoteServer ? remoteProjectBackPath : undefined}
/>
)}
</div>
@@ -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 () => {