The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): flag a failed cold-start sidebar read instead of reporting an empty list
brooklyn!72bc2f6a4f49
diff --git a/apps/desktop/src/app/session/hooks/use-session-list-actions.test.tsx b/apps/desktop/src/app/session/hooks/use-session-list-actions.test.tsxindex bec573ccd65..4138d2949d1 100644--- a/apps/desktop/src/app/session/hooks/use-session-list-actions.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-session-list-actions.test.tsx@@ -18,6 +18,7 @@ import {$sessionProfilesTruncated,$sessionProfilesUsage,$sessions,+ $sessionsLoadError,$sessionsLoading,setCronSessions,setMessagingPlatformTotals,@@ -25,6 +26,7 @@ import {setMessagingTruncated,setSessionProfilesTruncated,setSessionProfilesUsage,+ setSessionsLoadError,setSessions,setSessionsLoading} from '@/store/session'@@ -119,6 +121,7 @@ beforeEach(() => {setSessionProfilesTruncated({})setSessionProfilesUsage({})setSessionsLoading(false)+ setSessionsLoadError(false)})afterEach(() => {@@ -131,6 +134,71 @@ afterEach(() => {setSessionProfilesTruncated({})setSessionProfilesUsage({})setSessionsLoading(false)+ setSessionsLoadError(false)+})++// #67600: a cold-start read that fails must not render as "No sessions yet".+describe('refreshSessions cold-start load error', () => {+ const failedScan = (storage?: Record<string, 'corrupt'>): SidebarSessionsResponse => ({+ ...sidebar({ sessions: [] }),+ errors: [{ error: 'boom', profile: 'default' }],+ storage+ })++ it('flags a thrown first read and clears the flag once a retry lands rows', async () => {+ listSidebarSessions.mockRejectedValueOnce(new Error('ECONNREFUSED'))+ const { result } = renderHook(() => useSessionListActions({ profileScope: 'default' }))++ await act(async () => {+ await result.current.refreshSessions().catch(() => undefined)+ })++ expect($sessionsLoadError.get()).toBe(true)+ expect($sessionsLoading.get()).toBe(false)++ listSidebarSessions.mockResolvedValueOnce(sidebar({ sessions: [row('a')] }))+ await act(async () => {+ await result.current.refreshSessions()+ })++ expect($sessionsLoadError.get()).toBe(false)+ expect($sessions.get().map(s => s.id)).toEqual(['a'])+ })++ it('flags a reported scan failure that leaves the list empty', async () => {+ listSidebarSessions.mockResolvedValueOnce(failedScan())+ const { result } = renderHook(() => useSessionListActions({ profileScope: 'default' }))++ await act(async () => {+ await result.current.refreshSessions()+ })++ expect($sessionsLoadError.get()).toBe(true)+ })++ it('leaves a corrupt store to its own notice instead of offering retry', async () => {+ listSidebarSessions.mockResolvedValueOnce(failedScan({ default: 'corrupt' }))+ const { result } = renderHook(() => useSessionListActions({ profileScope: 'default' }))++ await act(async () => {+ await result.current.refreshSessions()+ })++ expect($sessionsLoadError.get()).toBe(false)+ })++ it('never flags a failed refresh over rows already on screen', async () => {+ setSessions([row('a')])+ listSidebarSessions.mockRejectedValueOnce(new Error('ECONNREFUSED'))+ const { result } = renderHook(() => useSessionListActions({ profileScope: 'default' }))++ await act(async () => {+ await result.current.refreshSessions().catch(() => undefined)+ })++ expect($sessionsLoadError.get()).toBe(false)+ expect($sessions.get().map(s => s.id)).toEqual(['a'])+ })})describe('refreshSessions identity + loading hygiene', () => {diff --git a/apps/desktop/src/app/session/hooks/use-session-list-actions.ts b/apps/desktop/src/app/session/hooks/use-session-list-actions.tsindex a29f6babea7..f1a73a84009 100644--- a/apps/desktop/src/app/session/hooks/use-session-list-actions.ts+++ b/apps/desktop/src/app/session/hooks/use-session-list-actions.ts@@ -35,6 +35,7 @@ import {setMessagingTruncated,setSessionProfilesTruncated,setSessionProfilesUsage,+ setSessionsLoadError,setSessions,setSessionsLoading} from '@/store/session'@@ -271,6 +272,7 @@ export function useSessionListActions({ profileScope }: UseSessionListActionsArgconst showLoading = $sessions.get().length === 0if (showLoading && shouldPublish()) {+ setSessionsLoadError(false)setSessionsLoading(true)}@@ -323,8 +325,12 @@ export function useSessionListActions({ profileScope }: UseSessionListActionsArgif (owns()) {const recents = result.recents+ const recentsErrors = recents.errors ?? result.errorssetCorruptSessionStores(result.storage)+ // A damaged store already has its own notice; Retry can't repair it.+ const retryableErrors = recentsErrors?.filter(e => !result.storage?.[e.profile])+ setSessionsLoadError(Boolean(showLoading && retryableErrors?.length && recents.sessions.length === 0))// Drop rows the user just deleted/archived: a refresh can race an// in-flight mutation and the backend page still carries the doomed row.@@ -348,7 +354,6 @@ export function useSessionListActions({ profileScope }: UseSessionListActionsArg// top of the rows it already read (the old exact totals ran a COUNT(*)// per profile DB on every refresh). Reference-stable when unchanged so// the sidebar's group memos don't recompute per refresh.- const recentsErrors = recents.errors ?? result.errorssetSessionProfilesTruncated(prev => {const next = keepFailedProfileMeta(prev, recents.profiles_truncated ?? {}, recentsErrors)const prevKeys = Object.keys(prev)@@ -403,6 +408,12 @@ export function useSessionListActions({ profileScope }: UseSessionListActionsArgmessagingErrors?.length ? prev : result.messaging.sessions.length >= MESSAGING_SECTION_LIMIT)}+ } catch (error) {+ if (owns() && showLoading) {+ setSessionsLoadError(true)+ }++ throw error} finally {// Request identity preserves the zero-argument refresh contract across a// failed activation epoch; an explicit owner predicate is stronger anddiff --git a/apps/desktop/src/store/gateway-switch.ts b/apps/desktop/src/store/gateway-switch.tsindex 86b76549020..5c8bef55253 100644--- a/apps/desktop/src/store/gateway-switch.ts+++ b/apps/desktop/src/store/gateway-switch.ts@@ -22,6 +22,7 @@ import {setSelectedStoredSessionId,setSessionProfilesTruncated,setSessionProfilesUsage,+ setSessionsLoadError,setSessions,setSessionsLoading} from '@/store/session'@@ -217,6 +218,7 @@ export function wipeSessionListsForGatewaySwitch(): void {resetLiveSync()$unreadFinishedSessionIds.set([])setSessionsLoading(true)+ setSessionsLoadError(false)resetSessionsLimit()setActiveSessionId(null)diff --git a/apps/desktop/src/store/session.ts b/apps/desktop/src/store/session.tsindex de6b5ab27ba..76a669339a8 100644--- a/apps/desktop/src/store/session.ts+++ b/apps/desktop/src/store/session.ts@@ -947,6 +947,8 @@ export const $sessionProfilesUsage = atom<Record<string, ProfileUsage>>({})* is a damaged store, not deleted history, and the sidebar says so. */export const $corruptSessionStores = atom<string[]>([])export const $sessionsLoading = atom(true)+/** True when the first sidebar read failed before it could populate any rows. */+export const $sessionsLoadError = atom(false)export const $activeSessionId = atom<string | null>(null)export const $selectedStoredSessionId = atom<string | null>(null)export interface ActiveSessionStoredIdRotation {@@ -1313,6 +1315,7 @@ export const setSessionProfilesTruncated = (next: Updater<Record<string, booleanexport const setSessionProfilesUsage = (next: Updater<Record<string, ProfileUsage>>) =>updateAtom($sessionProfilesUsage, next)export const setSessionsLoading = (next: Updater<boolean>) => updateAtom($sessionsLoading, next)+export const setSessionsLoadError = (next: Updater<boolean>) => updateAtom($sessionsLoadError, next)/** Publish the corrupt-store profiles from one sidebar refresh; identity-stable when unchanged. */export function setCorruptSessionStores(storage: Record<string, string> | undefined) {