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: show Brain graph load failures with a retry action (#9891)
Adam Eivyc052d2604f96
diff --git a/client/src/components/brain/tabs/BrainGraph.jsx b/client/src/components/brain/tabs/BrainGraph.jsxindex 6388bbc817..99a136ec0d 100644--- a/client/src/components/brain/tabs/BrainGraph.jsx+++ b/client/src/components/brain/tabs/BrainGraph.jsx@@ -82,6 +82,9 @@ export const recordBody = (record) => {export default function BrainGraph() {const [graphData, setGraphData] = useState(null);const [loading, setLoading] = useState(true);+ const [overviewError, setOverviewError] = useState(false);+ const overviewRequest = useRef(0);+ const overviewPending = useRef(false);const [subLoading, setSubLoading] = useState(false);const [selectedNode, setSelectedNode] = useState(null);const detailLoader = TYPE_GETTERS[selectedNode?.brainType];@@ -107,19 +110,43 @@ export default function BrainGraph() {const focusId = currentFocusId(focusTrail);- // Initial load: bounded overview + lightweight search index + embedding gaps.+ // Mount and retry share request ownership; cleanup invalidates late responses.+ const loadOverview = useCallback(async () => {+ if (overviewPending.current) return;+ overviewPending.current = true;+ const request = ++overviewRequest.current;+ setLoading(true);+ setOverviewError(false);+ try {+ const graph = await api.getBrainGraph({}, { silent: true });+ if (request === overviewRequest.current) setGraphData(graph);+ } catch {+ if (request === overviewRequest.current) setOverviewError(true);+ } finally {+ if (request === overviewRequest.current) {+ overviewPending.current = false;+ setLoading(false);+ }+ }+ }, []);++ useEffect(() => {+ loadOverview();+ return () => {+ overviewRequest.current += 1;+ overviewPending.current = false;+ };+ }, [loadOverview]);++ // Optional reads must not delay or replace the overview.useEffect(() => {let cancelled = false;- Promise.all([- api.getBrainGraph().catch(() => null),- api.getBrainGraphSearchIndex().catch(() => ({ nodes: [] })),- api.getEmbeddingsStatus().catch(() => null)- ]).then(([graph, index, status]) => {- if (cancelled) return;- setGraphData(graph);- setSearchIndex(index?.nodes || []);- setEmbeddingStatus(status);- }).finally(() => { if (!cancelled) setLoading(false); });+ api.getBrainGraphSearchIndex({ silent: true }).catch(() => null).then(index => {+ if (!cancelled) setSearchIndex(index?.nodes || []);+ });+ api.getEmbeddingsStatus({ silent: true }).catch(() => null).then(status => {+ if (!cancelled) setEmbeddingStatus(status);+ });return () => { cancelled = true; };}, []);@@ -285,6 +312,17 @@ export default function BrainGraph() {);}+ if (overviewError) {+ return (+ <div className="text-center py-12 space-y-3">+ <p role="alert" className="text-port-error">Could not load the Brain graph. Please try again.</p>+ <button type="button" onClick={loadOverview} className="min-h-[44px] px-4 py-2 rounded-lg bg-port-accent text-white">+ Retry+ </button>+ </div>+ );+ }+if (!graphData?.nodes?.length) {return (<div className="text-center py-12 text-gray-500">diff --git a/client/src/components/brain/tabs/BrainGraph.test.jsx b/client/src/components/brain/tabs/BrainGraph.test.jsxindex 04c1e5e4cc..b3e2a4832c 100644--- a/client/src/components/brain/tabs/BrainGraph.test.jsx+++ b/client/src/components/brain/tabs/BrainGraph.test.jsx@@ -1,4 +1,5 @@import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';+import { StrictMode } from 'react';import { render, screen, act } from '@testing-library/react';import userEvent from '@testing-library/user-event';@@ -83,6 +84,63 @@ afterEach(() => {window.matchMedia = originalMatchMedia;});+describe('overview loading outcomes', () => {+ it('keeps a failed read visible and retries once without reloading optional data', async () => {+ const user = userEvent.setup();+ let resolveRetry;+ api.getBrainGraph.mockRejectedValueOnce(new Error('Unavailable'))+ .mockImplementationOnce(() => new Promise(resolve => { resolveRetry = resolve; }));+ await renderGraph();++ expect(screen.getByRole('alert')).toHaveTextContent('Could not load the Brain graph');+ expect(screen.queryByText(/No brain entities/)).not.toBeInTheDocument();+ expect(api.getBrainGraph).toHaveBeenCalledWith({}, { silent: true });+ await user.click(screen.getByRole('button', { name: 'Retry' }));+ expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument();+ expect(api.getBrainGraph).toHaveBeenCalledTimes(2);+ await act(async () => { resolveRetry(GRAPH); });++ expect(screen.getByTestId('graph-canvas')).toBeInTheDocument();+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();+ expect(api.getBrainGraphSearchIndex).toHaveBeenCalledTimes(1);+ expect(api.getEmbeddingsStatus).toHaveBeenCalledTimes(1);+ });++ it('shows the empty message only for a successful empty overview', async () => {+ api.getBrainGraph.mockResolvedValue({ nodes: [], edges: [] });+ await renderGraph();+ expect(screen.getByText(/No brain entities to graph/)).toBeInTheDocument();+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();+ expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument();+ });++ it('renders the overview while optional reads are pending and preserves it when they reject', async () => {+ let rejectIndex, rejectStatus;+ api.getBrainGraphSearchIndex.mockImplementation(() => new Promise((_, reject) => { rejectIndex = reject; }));+ api.getEmbeddingsStatus.mockImplementation(() => new Promise((_, reject) => { rejectStatus = reject; }));+ await renderGraph();+ expect(screen.getByTestId('graph-canvas')).toBeInTheDocument();+ await act(async () => {+ rejectIndex(new Error('Unavailable'));+ rejectStatus(new Error('Unavailable'));+ });+ expect(screen.getByTestId('graph-canvas')).toBeInTheDocument();+ expect(screen.queryByText(/No brain entities/)).not.toBeInTheDocument();+ });++ it('drops an obsolete mount response after effect cleanup', async () => {+ let resolveObsolete;+ api.getBrainGraph.mockImplementationOnce(() => new Promise(resolve => { resolveObsolete = resolve; }))+ .mockResolvedValueOnce(GRAPH);+ render(<StrictMode><BrainGraph /></StrictMode>);+ await act(async () => {});+ expect(screen.getByTestId('graph-canvas')).toBeInTheDocument();+ await act(async () => { resolveObsolete({ nodes: [], edges: [] }); });+ expect(screen.getByTestId('graph-canvas')).toBeInTheDocument();+ expect(screen.queryByText(/No brain entities/)).not.toBeInTheDocument();+ });+});+describe('reduced motion', () => {it('reads the system preference and renders the canvas on demand', async () => {window.matchMedia = vi.fn(() => ({diff --git a/client/src/services/apiBrain.js b/client/src/services/apiBrain.jsindex 624fe32c67..8584b3f0d8 100644--- a/client/src/services/apiBrain.js+++ b/client/src/services/apiBrain.js@@ -363,9 +363,9 @@ export const getBrainGraph = ({ focus, limit } = {}, options = {}) => {return request(`/brain/graph${qs ? `?${qs}` : ''}`, options);};// Lightweight {id,label,brainType} list of every node, for the search box.-export const getBrainGraphSearchIndex = () => request('/brain/graph/search-index');+export const getBrainGraphSearchIndex = (options = {}) => request('/brain/graph/search-index', options);// Count of active records missing an embedding (powers "Embed missing").-export const getEmbeddingsStatus = () => request('/brain/embeddings/status');+export const getEmbeddingsStatus = (options = {}) => request('/brain/embeddings/status', options);// Brain - Bridge Sync (brain data to CoS memory system).// refresh:true re-embeds already-mapped records to heal memory entries that