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 graph detail matched to the selected node (#8624)
[._.]/ Adam Eivyda97e7e81a3b
diff --git a/client/src/components/brain/tabs/BrainGraph.jsx b/client/src/components/brain/tabs/BrainGraph.jsxindex 2df7b9a88d..6388bbc817 100644--- a/client/src/components/brain/tabs/BrainGraph.jsx+++ b/client/src/components/brain/tabs/BrainGraph.jsx@@ -14,6 +14,7 @@ import TouchDragHint from '../../graph3d/TouchDragHint';import EntityCombobox from '../../EntityCombobox';import InlineConfirmRow from '../../ui/InlineConfirmRow';import BrailleSpinner from '../../BrailleSpinner';+import useGraphNodeDetail from '../../../hooks/useGraphNodeDetail';import usePrefersReducedMotion from '../../../hooks/usePrefersReducedMotion';import { formatDateNumeric } from '../../../utils/formatters';@@ -83,7 +84,9 @@ export default function BrainGraph() {const [loading, setLoading] = useState(true);const [subLoading, setSubLoading] = useState(false);const [selectedNode, setSelectedNode] = useState(null);- const [fullRecord, setFullRecord] = useState(null);+ const detailLoader = TYPE_GETTERS[selectedNode?.brainType];+ const detailKey = selectedNode ? JSON.stringify([selectedNode.brainType, selectedNode.id]) : null;+ const fullRecord = useGraphNodeDetail(detailKey, detailLoader, selectedNode?.id);const { theme } = useThemeContext();const [layoutKey, setLayoutKey] = useState(0);const [syncing, setSyncing] = useState(false);@@ -200,19 +203,6 @@ export default function BrainGraph() {// Prose the detail panel renders for the loaded record (see recordBody).const detailBody = recordBody(fullRecord);- // Fetch full brain record when a node is selected- useEffect(() => {- if (!selectedNode) { setFullRecord(null); return; }- let cancelled = false;- const getter = TYPE_GETTERS[selectedNode.brainType];- if (!getter) return;- getter(selectedNode.id).then(record => {- if (!cancelled) setFullRecord(record);- }).catch(() => {- if (!cancelled) setFullRecord(null);- });- return () => { cancelled = true; };- }, [selectedNode]);// A null node clears the selection (an empty-space tap); re-selecting the// current node toggles it off.diff --git a/client/src/components/brain/tabs/BrainGraph.test.jsx b/client/src/components/brain/tabs/BrainGraph.test.jsxindex 98cc1a58f3..a3b1365844 100644--- a/client/src/components/brain/tabs/BrainGraph.test.jsx+++ b/client/src/components/brain/tabs/BrainGraph.test.jsx@@ -7,8 +7,12 @@ import userEvent from '@testing-library/user-event';// The stub deliberately drops `children`: rendering the scene would mount// <bufferGeometry>/<mesh> as unknown DOM elements, and the r3f refs they hand// back are HTMLElements without the three.js geometry API.+let sceneElement = null;vi.mock('@react-three/fiber', () => ({- Canvas: ({ frameloop }) => <div data-testid="graph-canvas" data-frameloop={frameloop} />,+ Canvas: ({ children, frameloop }) => {+ sceneElement = children;+ return <div data-testid="graph-canvas" data-frameloop={frameloop} />;+ },// GraphScene reads the live camera through this; it is never rendered here,// but the named import has to resolve.useThree: () => ({ camera: null, size: { width: 0, height: 0 } }),@@ -281,3 +285,55 @@ describe('recordBody (SongBook nodes, #4105)', () => {expect(recordBody({})).toBe('');});});+++describe('selection detail identity', () => {+ it('removes previous body, tags and dates while another record loads or fails', async () => {+ let rejectNext;+ api.getBrainIdea.mockResolvedValue({ content: 'Alpha private body', tags: ['alpha-tag'], createdAt: '2026-01-02' });+ api.getBrainGoal.mockImplementation(() => new Promise((resolve, reject) => { rejectNext = reject; }));+ await renderGraph();+ await act(async () => { sceneElement.props.onSelect(GRAPH.nodes[0]); });+ expect(screen.getByText('Alpha private body')).toBeInTheDocument();+ expect(screen.getByText('alpha-tag')).toBeInTheDocument();+ await act(async () => { sceneElement.props.onSelect(GRAPH.nodes[1]); });+ expect(screen.queryByText('Alpha private body')).not.toBeInTheDocument();+ expect(screen.queryByText('alpha-tag')).not.toBeInTheDocument();+ expect(screen.queryByText(/Created:/)).not.toBeInTheDocument();+ expect(screen.getByText('second')).toBeInTheDocument();+ await act(async () => { rejectNext(new Error('request failed')); });+ expect(screen.getByText('second')).toBeInTheDocument();+ });++ it('invalidates detail when the same id resolves to a different Brain type', async () => {+ const user = userEvent.setup();+ api.getBrainGraph.mockResolvedValueOnce(GRAPH).mockResolvedValue({+ ...GRAPH, nodes: [{ ...GRAPH.nodes[0], brainType: 'goals', summary: 'Goal summary' }], edges: [],+ });+ api.getBrainGraphSearchIndex.mockResolvedValue({ nodes: [GRAPH.nodes[0]] });+ api.getBrainIdea.mockResolvedValue({ content: 'Original idea body' });+ api.getBrainGoal.mockImplementation(() => new Promise(() => {}));+ await renderGraph();+ await act(async () => { sceneElement.props.onSelect(GRAPH.nodes[0]); });+ expect(screen.getByText('Original idea body')).toBeInTheDocument();+ await user.type(screen.getByPlaceholderText(/search memories/i), 'Alpha');+ await user.click(await screen.findByRole('option', { name: /Alpha/i }));+ expect(screen.queryByText('Original idea body')).not.toBeInTheDocument();+ expect(screen.getByText('Goal summary')).toBeInTheDocument();+ });++ it('discards a superseded late response after selection changes', async () => {+ let resolveIdea;+ api.getBrainIdea.mockImplementation(() => new Promise(resolve => { resolveIdea = resolve; }));+ api.getBrainGoal.mockResolvedValue({ content: 'Goal detail' });+ await renderGraph();+ await act(async () => { sceneElement.props.onSelect(GRAPH.nodes[0]); });+ await act(async () => { sceneElement.props.onSelect(GRAPH.nodes[1]); });+ expect(screen.getByText('Goal detail')).toBeInTheDocument();+ await act(async () => { resolveIdea({ content: 'Late idea detail' }); });+ expect(screen.queryByText('Late idea detail')).not.toBeInTheDocument();+ expect(screen.getByText('Goal detail')).toBeInTheDocument();+ await act(async () => { sceneElement.props.onSelect(null); });+ expect(screen.queryByText('Goal detail')).not.toBeInTheDocument();+ });+});diff --git a/client/src/components/cos/tabs/MemoryGraph.jsx b/client/src/components/cos/tabs/MemoryGraph.jsxindex c7903336af..ccfd00c5c9 100644--- a/client/src/components/cos/tabs/MemoryGraph.jsx+++ b/client/src/components/cos/tabs/MemoryGraph.jsx@@ -8,6 +8,7 @@ import GraphScene, { graphMotionSettings } from '../../graph3d/GraphScene';import useGraphCanvasInteraction from '../../graph3d/useGraphCanvasInteraction';import TouchDragHint from '../../graph3d/TouchDragHint';import BrailleSpinner from '../../BrailleSpinner';+import useGraphNodeDetail from '../../../hooks/useGraphNodeDetail';import usePrefersReducedMotion from '../../../hooks/usePrefersReducedMotion';import { formatDateNumeric } from '../../../utils/formatters';@@ -39,7 +40,7 @@ export default function MemoryGraph() {const [graphData, setGraphData] = useState(null);const [loading, setLoading] = useState(true);const [selectedNode, setSelectedNode] = useState(null);- const [fullMemory, setFullMemory] = useState(null);+ const fullMemory = useGraphNodeDetail(selectedNode?.id ?? null, api.getMemory, selectedNode?.id);const [layoutKey, setLayoutKey] = useState(0);// Mobile-only: the legend auto-shows on a roomy viewport (CSS, not this flag).const [legendOpen, setLegendOpen] = useState(false);@@ -80,17 +81,6 @@ export default function MemoryGraph() {}).filter(Boolean): [];- // Fetch full memory details when a node is selected- useEffect(() => {- if (!selectedNode) { setFullMemory(null); return; }- let cancelled = false;- api.getMemory(selectedNode.id).then(mem => {- if (!cancelled) setFullMemory(mem);- }).catch(() => {- if (!cancelled) setFullMemory(null);- });- return () => { cancelled = true; };- }, [selectedNode]);// A null node clears the selection (an empty-space tap, or a touch pick// that landed on nothing — see useGraphCanvasInteraction); re-selecting thediff --git a/client/src/components/cos/tabs/MemoryGraph.test.jsx b/client/src/components/cos/tabs/MemoryGraph.test.jsxindex fc0dd4d53f..362f2a416e 100644--- a/client/src/components/cos/tabs/MemoryGraph.test.jsx+++ b/client/src/components/cos/tabs/MemoryGraph.test.jsx@@ -213,3 +213,24 @@ describe('edge appearance (graph3d extraction)', () => {expect(memoryEdgeIntensity({ type: 'linked', weight: 1 }, true)).toBe(0.06);});});+++describe('selection detail identity', () => {+ it('shows the new summary while detail is pending and ignores cleared late responses', async () => {+ let resolveNext;+ api.getMemory.mockResolvedValueOnce({ content: 'Alpha memory body', tags: ['alpha-tag'], createdAt: '2026-01-02' })+ .mockImplementationOnce(() => new Promise(resolve => { resolveNext = resolve; }));+ await renderGraph();+ await act(async () => { sceneElement.props.onSelect(GRAPH.nodes[0]); });+ expect(screen.getByText('Alpha memory body')).toBeInTheDocument();+ expect(screen.getByText('alpha-tag')).toBeInTheDocument();+ await act(async () => { sceneElement.props.onSelect(GRAPH.nodes[1]); });+ expect(screen.queryByText('Alpha memory body')).not.toBeInTheDocument();+ expect(screen.queryByText('alpha-tag')).not.toBeInTheDocument();+ expect(screen.queryByText(/Created:/)).not.toBeInTheDocument();+ expect(screen.getByText('second')).toBeInTheDocument();+ await act(async () => { sceneElement.props.onSelect(null); });+ await act(async () => { resolveNext({ content: 'Late memory body' }); });+ expect(screen.queryByText('Late memory body')).not.toBeInTheDocument();+ });+});diff --git a/client/src/hooks/README.md b/client/src/hooks/README.mdindex 9fe46ee1b7..5de234781d 100644--- a/client/src/hooks/README.md+++ b/client/src/hooks/README.md@@ -270,3 +270,5 @@ grep -i "what you want to do" client/src/hooks/README.md| `usePagedCollection` | `usePagedCollection(fetchPage, { enabled })` — bounded cursor pages, deduplication by id, single-flight loading, abort/stale-query protection, retry, reset, and local mutation via setItems. | Growing cursor-based collections; pair with `InfiniteScrollFooter`. || `useGoalOrganize` / `useGoalCreate` | Shared goal suggestion preview, explicit apply, and guarded create flows for both Goals views. | Goals List and Tree views. |++| `useGraphNodeDetail` | Selection-keyed graph record loading with render-time identity gating and late-response disposal. | Brain and CoS graph detail panels. |diff --git a/client/src/hooks/index.js b/client/src/hooks/index.jsindex 6cfb89a165..9bd445943a 100644--- a/client/src/hooks/index.js+++ b/client/src/hooks/index.js@@ -251,3 +251,5 @@ export * from './useSocketResource.js';export * from './useProcessSnapshot.js';export * from './useFableLoomRun.js';++export { default as useGraphNodeDetail } from './useGraphNodeDetail.js';diff --git a/client/src/hooks/useGraphNodeDetail.js b/client/src/hooks/useGraphNodeDetail.jsnew file mode 100644index 0000000000..9d8bb91f97--- /dev/null+++ b/client/src/hooks/useGraphNodeDetail.js@@ -0,0 +1,21 @@+import { useEffect, useState } from 'react';++/** Load a selected graph record without rendering a previous selection's detail. */+export default function useGraphNodeDetail(selectionKey, loader, recordId) {+ const [detail, setDetail] = useState(null);++ useEffect(() => {+ let active = true;+ setDetail(null);+ if (selectionKey != null && loader) {+ Promise.resolve().then(() => loader(recordId)).then(record => {+ if (active) setDetail({ key: selectionKey, record });+ }).catch(() => {+ if (active) setDetail(null);+ });+ }+ return () => { active = false; };+ }, [selectionKey, loader, recordId]);++ return selectionKey != null && loader && detail?.key === selectionKey ? detail.record : null;+}