Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep failed Brain collection reads distinct from empty results (#10872)
Adam Eivyd84153878b83
diff --git a/client/src/components/brain/tabs/BrainCollectionPagination.test.jsx b/client/src/components/brain/tabs/BrainCollectionPagination.test.jsxindex 165dccab6d..2e457bbaa1 100644--- a/client/src/components/brain/tabs/BrainCollectionPagination.test.jsx+++ b/client/src/components/brain/tabs/BrainCollectionPagination.test.jsx@@ -309,5 +309,75 @@ describe('Brain collection pagination & UI bounds', () => {// Full content rendered in reader paneexpect(screen.getByText(/Detailed reflection that was loaded on demand/)).toBeTruthy();});++ describe('failed collection reads stay distinct from empty results', () => {+ const memoryPage = (ids, nextCursor = null, total = ids.length) => ({+ items: ids.map(id => ({ id, title: `Memory ${id}`, content: 'teaser', contentTruncated: true })),+ total,+ nextCursor+ });+ const unavailable = () => Object.assign(new Error('Service unavailable'), { status: 503 });++ it('shows an unavailable state with working retry on a failed first page, never empty onboarding', async () => {+ api.getBrainMemories.mockRejectedValueOnce(unavailable());+ mountMemory();++ expect(await screen.findByText('Service unavailable')).toBeTruthy();+ expect(screen.getByText('Memories could not be loaded.')).toBeTruthy();+ expect(screen.queryByText(/No memories yet/)).toBeNull();+ expect(api.getBrainMemories).toHaveBeenCalledWith(expect.objectContaining({ silent: true }));++ api.getBrainMemories.mockResolvedValueOnce(memoryPage(['mem-a']));+ fireEvent.click(screen.getByRole('button', { name: 'Retry loading' }));++ await screen.findByText('Memory mem-a');+ expect(screen.queryByText('Service unavailable')).toBeNull();+ expect(screen.queryByText('Memories could not be loaded.')).toBeNull();+ });++ it('still shows normal onboarding after a successful empty read', async () => {+ api.getBrainMemories.mockResolvedValueOnce({ items: [], total: 0, nextCursor: null });+ mountMemory();++ expect(await screen.findByText(/No memories yet/)).toBeTruthy();+ expect(screen.queryByRole('button', { name: 'Retry loading' })).toBeNull();+ });++ it('keeps rows and the continuation when a later page fails, and retries that page', async () => {+ api.getBrainMemories.mockResolvedValueOnce(memoryPage(['mem-1', 'mem-2'], 'cursor_2', 4));+ mountMemory();+ await screen.findByText('Memory mem-1');++ api.getBrainMemories.mockRejectedValueOnce(unavailable());+ fireEvent.click(screen.getByRole('button', { name: 'Load more' }));+ expect(await screen.findByText('Service unavailable')).toBeTruthy();+ expect(screen.getByText('Memory mem-1')).toBeTruthy();+ expect(screen.getByText('Memory mem-2')).toBeTruthy();+ expect(screen.queryByText(/No memories yet/)).toBeNull();++ api.getBrainMemories.mockResolvedValueOnce(memoryPage(['mem-3', 'mem-4'], null, 4));+ fireEvent.click(screen.getByRole('button', { name: 'Retry loading' }));+ await screen.findByText('Memory mem-4');+ expect(api.getBrainMemories).toHaveBeenLastCalledWith(expect.objectContaining({ cursor: 'cursor_2' }));+ expect(screen.getAllByText(/^Memory mem-/)).toHaveLength(4);+ });++ it('keeps rows visible and retryable when a reconnect refresh fails', async () => {+ api.getBrainMemories.mockResolvedValueOnce(memoryPage(['mem-1'], 'cursor_2', 2));+ mountMemory();+ await screen.findByText('Memory mem-1');++ api.getBrainMemories.mockRejectedValueOnce(unavailable());+ await act(async () => { mockSocket.emitEvent('connect'); });+ expect(await screen.findByText('Service unavailable')).toBeTruthy();+ expect(screen.getByText('Memory mem-1')).toBeTruthy();++ api.getBrainMemories.mockResolvedValueOnce(memoryPage(['mem-1'], 'cursor_2', 2));+ fireEvent.click(screen.getByRole('button', { name: 'Retry loading' }));+ await waitFor(() => expect(screen.queryByText('Service unavailable')).toBeNull());+ expect(screen.getByText('Memory mem-1')).toBeTruthy();+ expect(screen.getByRole('button', { name: 'Load more' })).toBeTruthy();+ });+ });});});diff --git a/client/src/components/brain/tabs/MemoryTab.jsx b/client/src/components/brain/tabs/MemoryTab.jsxindex 7a86d82e3f..f654c32c58 100644--- a/client/src/components/brain/tabs/MemoryTab.jsx+++ b/client/src/components/brain/tabs/MemoryTab.jsx@@ -92,32 +92,26 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {}, [searchQuery]);const fetchPage = useCallback(async ({ cursor, signal }) => {- let res;+ // Request failures propagate to usePagedCollection, which keeps loaded rows+ // and the continuation and surfaces a retry control; swallowing them here+ // would turn an outage into an authoritative empty collection. The footer+ // owns the error UI, so the request helper's toast is suppressed.const options = {cursor,search: debouncedSearch || undefined,status: statusFilter || undefined,limit: 25,+ silent: true,signal};-+ let res;switch (activeType) {- case 'people':- res = await api.getBrainPeople(options).catch(() => ({ items: [] }));- break;- case 'projects':- res = await api.getBrainProjects(options).catch(() => ({ items: [] }));- break;- case 'ideas':- res = await api.getBrainIdeas(options).catch(() => ({ items: [] }));- break;- case 'admin':- res = await api.getBrainAdmin(options).catch(() => ({ items: [] }));- break;+ case 'people': res = await api.getBrainPeople(options); break;+ case 'projects': res = await api.getBrainProjects(options); break;+ case 'ideas': res = await api.getBrainIdeas(options); break;+ case 'admin': res = await api.getBrainAdmin(options); break;case 'memories':- default:- res = await api.getBrainMemories(options).catch(() => ({ items: [] }));- break;+ default: res = await api.getBrainMemories(options); break;}const items = Array.isArray(res) ? res : (res.items || res[activeType] || []);@@ -973,7 +967,7 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {<div className="flex items-center justify-center h-32"><BrailleSpinner text="Loading" /></div>- ) : filteredRecords.length === 0 ? (+ ) : filteredRecords.length === 0 && !paged.error ? (<p className="text-gray-500 text-center py-8">{searchQuery? `No matches for "${searchQuery}"`@@ -981,6 +975,11 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {</p>) : (<div>+ {filteredRecords.length === 0 && (+ <p className="text-gray-500 text-center pt-8 pb-2">+ {`${DESTINATIONS[activeType]?.label || 'Records'} could not be loaded.`}+ </p>+ )}{filteredRecords.map(record => (<CollapsibleListItem key={`${activeType}:${record.id}`}removing={removingIds.has(`${activeType}:${record.id}`)}