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.
This commit is contained in:
engineer
2026-06-01 16:26:13 -07:00
parent 14e858a402
commit a5364668db

View File

@@ -185,12 +185,25 @@ export const useSessions = create<SessionsState>((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