From a5364668db75209ceaefa38cfa314443c7533dec Mon Sep 17 00:00:00 2001 From: engineer Date: Mon, 1 Jun 2026 16:26:13 -0700 Subject: [PATCH] fix(sessions): create session in the same scope the list reads (#10) Root cause of the empty-sessions-after-connect bug, caught by the now-live E2E smoke: createSession() created via the plain connection client (server CWD), while loadSessions() lists home-scoped when the connection has no explicit directory. When CWD != home the new session was invisible to the list. Fix: createSession now mirrors loadSessions' directory scoping (home-scoped client when no explicit directory), so a freshly created session reliably appears. No change for connections with an explicit directory. Verified by the connect-and-verify-sessions CUA smoke on push. Refs #10. --- src/stores/sessions.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/stores/sessions.ts b/src/stores/sessions.ts index d2f3483..e41e048 100644 --- a/src/stores/sessions.ts +++ b/src/stores/sessions.ts @@ -185,12 +185,25 @@ export const useSessions = create((set, get) => ({ }, createSession: async (title) => { - const client = useConnections.getState().client - if (!client) { + const connState = useConnections.getState() + if (!connState.client) { set({ error: "No active connection" }) return null } + // Create the session in the SAME directory scope that loadSessions reads from. + // loadSessions lists home-scoped sessions when the connection has no explicit + // directory; creating via the plain connection client targets the server's CWD + // instead. When CWD != home the new session was invisible to the list (#10: + // "sessions tab empty after connect / create"). Mirror the list's scoping so a + // freshly created session reliably shows up. + const hasExplicitDirectory = Boolean(connState.activeConnection?.directory) + const home = connState.serverHome + const client = + !hasExplicitDirectory && home + ? connState.clientForDirectory(home) || connState.client + : connState.client + try { const session = await client.session.create({ title }) // Don't optimistically add to sessions list — let loadSessions() handle it