diff --git a/packages/ui/src/components/session/SessionSidebar.tsx b/packages/ui/src/components/session/SessionSidebar.tsx index 3ea80c83..86813fe4 100644 --- a/packages/ui/src/components/session/SessionSidebar.tsx +++ b/packages/ui/src/components/session/SessionSidebar.tsx @@ -320,6 +320,7 @@ export const SessionSidebar: React.FC = ({ const liveSessions = useAllLiveSessions(); const isVSCode = React.useMemo(() => isVSCodeRuntime(), []); const hasLoadedGlobalSessions = useGlobalSessionsStore((state) => state.hasLoaded); + const hasAuthoritativeGlobalSessions = useGlobalSessionsStore((state) => state.status === 'ready'); const globalActiveSessions = useGlobalSessionsStore((state) => state.activeSessions); const archivedSessions = useGlobalSessionsStore((state) => state.archivedSessions); const currentSessionId = useSessionUIStore((state) => state.currentSessionId); @@ -539,7 +540,7 @@ export const SessionSidebar: React.FC = ({ const { scheduleCollapsedProjectsPersist } = useSidebarPersistence({ isVSCode, - hasLoadedGlobalSessions, + hasAuthoritativeGlobalSessions, safeStorage, keys: { sessionExpanded: SESSION_EXPANDED_STORAGE_KEY, diff --git a/packages/ui/src/components/session/sidebar/hooks/useSidebarPersistence.ts b/packages/ui/src/components/session/sidebar/hooks/useSidebarPersistence.ts index 13519d9a..3a4a2146 100644 --- a/packages/ui/src/components/session/sidebar/hooks/useSidebarPersistence.ts +++ b/packages/ui/src/components/session/sidebar/hooks/useSidebarPersistence.ts @@ -33,7 +33,7 @@ const LEGACY_EXPANSION_CONTEXT_PREFIXES = [ type Args = { isVSCode: boolean; - hasLoadedGlobalSessions: boolean; + hasAuthoritativeGlobalSessions: boolean; safeStorage: SafeStorageLike; keys: Keys; sessions: Session[]; @@ -49,7 +49,7 @@ type Args = { export const useSidebarPersistence = (args: Args) => { const { isVSCode, - hasLoadedGlobalSessions, + hasAuthoritativeGlobalSessions, safeStorage, keys, sessions, @@ -151,14 +151,14 @@ export const useSidebarPersistence = (args: Args) => { }, [keys.projectCollapse, keys.sessionExpanded, keys.sessionExpandedLegacy, safeStorage, setCollapsedProjects, setExpandedParents]); React.useEffect(() => { - if (!hasLoadedGlobalSessions) { + if (!hasAuthoritativeGlobalSessions) { return; } setPinnedSessionIds((prev) => { return prunePinnedSessionIds(sessions, prev); }); - }, [hasLoadedGlobalSessions, sessions, setPinnedSessionIds]); + }, [hasAuthoritativeGlobalSessions, sessions, setPinnedSessionIds]); React.useEffect(() => { try { diff --git a/packages/ui/src/stores/useGlobalSessionsStore.ts b/packages/ui/src/stores/useGlobalSessionsStore.ts index 2599e608..7acfd763 100644 --- a/packages/ui/src/stores/useGlobalSessionsStore.ts +++ b/packages/ui/src/stores/useGlobalSessionsStore.ts @@ -420,7 +420,10 @@ export const useGlobalSessionsStore = create((set, get) => // instance — drop it. return { activeSessions: [], archivedSessions: [] }; } - set((state) => applySnapshot(state, nextActiveSessions, nextArchivedSessions, 'ready')); + const status = activeResult.status === 'fulfilled' && archivedResult.status === 'fulfilled' + ? 'ready' + : 'error'; + set((state) => applySnapshot(state, nextActiveSessions, nextArchivedSessions, status)); return { activeSessions: nextActiveSessions, archivedSessions: nextArchivedSessions }; } catch (error) { if (generation !== loadGeneration) {