From 62c2eb8aed59dfe8f9a9e37b9cb6f1a56998a2ec Mon Sep 17 00:00:00 2001 From: Chris Scott <> Date: Fri, 16 Oct 2026 20:50:35 +0000 Subject: [PATCH] fix(activity): report failed worktree lookups instead of showing partial session lists --- .../navigation/DesktopSessionTree.test.tsx | 8 ++++++++ .../src/components/navigation/RepoSessionNav.tsx | 2 ++ frontend/src/hooks/useActiveWork.test.tsx | 14 ++++++++++++++ frontend/src/hooks/useActiveWork.ts | 8 ++++++-- frontend/src/hooks/useRepoWorktrees.ts | 7 +++++-- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/navigation/DesktopSessionTree.test.tsx b/frontend/src/components/navigation/DesktopSessionTree.test.tsx index 68797fe0..f028c5cb 100644 --- a/frontend/src/components/navigation/DesktopSessionTree.test.tsx +++ b/frontend/src/components/navigation/DesktopSessionTree.test.tsx @@ -425,6 +425,14 @@ describe('DesktopSessionTree', () => { expect(await screen.findByText('Failed to load sessions')).toBeTruthy() }) + it('shows the error state when the worktree siblings lookup fails', async () => { + getRepoSiblingsMock.mockRejectedValue(new Error('siblings failed')) + + render(, { wrapper: createWrapper(['/repos/1']) }) + + expect(await screen.findByText('Failed to load sessions')).toBeTruthy() + }) + it('creates a session in the repo full path', async () => { const user = userEvent.setup() render(, { wrapper: createWrapper(['/']) }) diff --git a/frontend/src/components/navigation/RepoSessionNav.tsx b/frontend/src/components/navigation/RepoSessionNav.tsx index d24c8d63..926744f6 100644 --- a/frontend/src/components/navigation/RepoSessionNav.tsx +++ b/frontend/src/components/navigation/RepoSessionNav.tsx @@ -206,6 +206,8 @@ function RepoSessionList({ repo, onSelectSession }: RepoSessionListProps) { ) if (siblings.isLoading) return Loading sessions... + if (siblings.isError && siblings.data === undefined) + return Failed to load sessions return } diff --git a/frontend/src/hooks/useActiveWork.test.tsx b/frontend/src/hooks/useActiveWork.test.tsx index e593af44..13b62d2e 100644 --- a/frontend/src/hooks/useActiveWork.test.tsx +++ b/frontend/src/hooks/useActiveWork.test.tsx @@ -241,6 +241,20 @@ describe('useActiveWork', () => { expect(result.current.groups.recent[0].path).toBe('/repos/1/sessions/wt?repoTab=workspaces') }) + it('reports an error when the worktree siblings lookup fails with no cached data', async () => { + const now = Date.now() + mocks.listSessionPage.mockResolvedValue({ + items: [session('wt', now - 500, undefined, '/repo/.worktrees/feature')], + }) + mocks.getRepoSiblings.mockRejectedValue(new Error('siblings failed')) + + const { result } = renderHook(() => useActiveWork(WINDOW_MS), { + wrapper: createWrapper(createQueryClient()), + }) + + await waitFor(() => expect(result.current.isError).toBe(true)) + }) + it('never fetches siblings for an orphan session updated outside the window', async () => { const now = Date.now() mocks.listSessionPage.mockResolvedValue({ diff --git a/frontend/src/hooks/useActiveWork.ts b/frontend/src/hooks/useActiveWork.ts index edfc0f30..5be838ff 100644 --- a/frontend/src/hooks/useActiveWork.ts +++ b/frontend/src/hooks/useActiveWork.ts @@ -259,7 +259,11 @@ export function useActiveWork(windowMs: number): { [now, windowMs, repos, mergedSessions, resolvedParents, resolvedRoots], ) - const { worktrees, isLoading: isWorktreesLoading } = useRepoWorktrees(repos, needsLookup) + const { + worktrees, + isLoading: isWorktreesLoading, + isError: isWorktreesError, + } = useRepoWorktrees(repos, needsLookup) const groups = useMemo( () => @@ -279,6 +283,6 @@ export function useActiveWork(windowMs: number): { return { groups, isLoading: isReposLoading || isSessionsLoading || isWorktreesLoading, - isError: isSessionsError, + isError: isSessionsError || isWorktreesError, } } diff --git a/frontend/src/hooks/useRepoWorktrees.ts b/frontend/src/hooks/useRepoWorktrees.ts index d3ee554c..d0d01bbc 100644 --- a/frontend/src/hooks/useRepoWorktrees.ts +++ b/frontend/src/hooks/useRepoWorktrees.ts @@ -7,12 +7,14 @@ import type { Repo } from '@/api/types' /** * Discovers each repo's worktrees from its siblings while enabled, keyed by directory so a session * running in a worktree resolves to the repo that owns it. Each query is skipped for repos without - * a positive id. `isLoading` is true while any enabled siblings query is still loading. + * a positive id. `isLoading` is true while any enabled siblings query is still loading. `isError` + * is true only when a siblings query has failed with no data, so a failed refetch that still has + * cached data is not an error. */ export function useRepoWorktrees( repos: Repo[], enabled: boolean, -): { worktrees: ActiveWorktree[]; isLoading: boolean } { +): { worktrees: ActiveWorktree[]; isLoading: boolean; isError: boolean } { return useQueries({ queries: repos.map((repo) => ({ queryKey: repoSiblingsQueryKey(repo.id), @@ -23,6 +25,7 @@ export function useRepoWorktrees( combine: (results) => ({ worktrees: buildWorktreeActivity(repos, results), isLoading: results.some((result) => result.isLoading), + isError: results.some((result) => result.isError && result.data === undefined), }), }) }