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: fence imported-data count reads across source deletion
[._.]/ Adam Eivy67700a8cf4b9
diff --git a/client/src/components/timeline/ManageImportedDataPanel.jsx b/client/src/components/timeline/ManageImportedDataPanel.jsxindex 471c734c62..b2f5127a56 100644--- a/client/src/components/timeline/ManageImportedDataPanel.jsx+++ b/client/src/components/timeline/ManageImportedDataPanel.jsx@@ -22,6 +22,7 @@ export default function ManageImportedDataPanel({ reloadKey, onChanged }) {const mounted = useMounted();useEffect(() => {+ if (pending.current) return;let active = true;const current = ++generation.current;api.getTimelineSources({ silent: true }).then((r) => {@@ -43,6 +44,7 @@ export default function ManageImportedDataPanel({ reloadKey, onChanged }) {generation.current++;setBusy(true);setError(null);+ let confirmedGone = false;const result = await api.eraseTimelineSource(source, { silent: true }).catch(async (err) => {if (!mounted.current) return null;@@ -54,6 +56,7 @@ export default function ManageImportedDataPanel({ reloadKey, onChanged }) {if (!mounted.current || generation.current !== current || !Array.isArray(fresh?.sources)) return null;if (fresh.sources.some(row => row.source === source)) setSources(fresh.sources);else {+ confirmedGone = true;const next = [...fresh.sources];const index = sources.findIndex(row => row.source === source);if (index !== -1) next.splice(Math.min(index, next.length), 0, sources[index]);@@ -63,7 +66,10 @@ export default function ManageImportedDataPanel({ reloadKey, onChanged }) {}return null;});- pending.current = false;+ // A reload requested during deletion must not publish pre-delete counts.+ // Keep its read lane closed through a successful row's collapse.+ generation.current++;+ pending.current = Boolean(result) || confirmedGone;if (!mounted.current) return;setBusy(false);if (!result) return;@@ -73,8 +79,19 @@ export default function ManageImportedDataPanel({ reloadKey, onChanged }) {};const finishRemoval = (source) => {+ pending.current = false;+ const current = ++generation.current;setSources((list) => list.filter((row) => row.source !== source));setRemoving(null);+ // Reconcile counts after the mutation and animation; keep any lost-ack+ // warning visible even when this authoritative read succeeds.+ api.getTimelineSources({ silent: true }).then((fresh) => {+ if (mounted.current && generation.current === current && !pending.current && Array.isArray(fresh?.sources)) {+ setSources(fresh.sources);+ }+ }).catch((err) => {+ if (mounted.current && generation.current === current && !pending.current) setError(err.message || 'Could not load imported data.');+ });onChanged?.();};diff --git a/client/src/components/timeline/ManageImportedDataPanel.test.jsx b/client/src/components/timeline/ManageImportedDataPanel.test.jsxindex 18d957c10c..aa5ab8ce16 100644--- a/client/src/components/timeline/ManageImportedDataPanel.test.jsx+++ b/client/src/components/timeline/ManageImportedDataPanel.test.jsx@@ -27,6 +27,7 @@ it('keeps the confirmed source fixed during deletion and ignores a pre-delete coexpect(screen.getByRole('textbox')).toHaveValue('browser');expect(api.eraseTimelineSource).toHaveBeenCalledTimes(1);expect(api.eraseTimelineSource.mock.calls[0][0]).toBe('browser');+ api.getTimelineSources.mockResolvedValue({ sources: [sources[1]] });await act(async () => { finishDelete({ deleted: 3 }); });await waitFor(() => expect(screen.queryByText('browser')).not.toBeInTheDocument());expect(screen.getByText('discord')).toBeInTheDocument();@@ -36,12 +37,36 @@ it('keeps the confirmed source fixed during deletion and ignores a pre-delete coconst confirm = screen.getByRole('button', { name: 'Confirm delete' });confirm.focus();fireEvent.click(confirm);+ api.getTimelineSources.mockResolvedValue({ sources: [] });await act(async () => { finishDelete({ deleted: 2 }); });await screen.findByText('No imported events.');expect(screen.getByRole('list')).toHaveFocus();});+it('reconciles authoritative counts after deletion without restoring a source from a pending reload', async () => {+ let finishDelete;+ let finishCounts;+ let deleted = false;+ const staleCounts = new Promise(resolve => { finishCounts = resolve; });+ api.eraseTimelineSource.mockImplementationOnce(() => new Promise(resolve => { finishDelete = resolve; }));+ const view = render(<ManageImportedDataPanel reloadKey={0} />);+ await screen.findByText('browser');+ api.getTimelineSources.mockImplementation(() => deleted+ ? Promise.resolve({ sources: [{ source: 'discord', eventCount: 9 }] })+ : staleCounts);+ fireEvent.click(screen.getAllByRole('button', { name: 'Delete' })[0]);+ fireEvent.change(screen.getByRole('textbox'), { target: { value: 'browser' } });+ fireEvent.click(screen.getByRole('button', { name: 'Confirm delete' }));+ view.rerender(<ManageImportedDataPanel reloadKey={1} />);+ await act(async () => { deleted = true; finishDelete({ deleted: 3 }); });+ await waitFor(() => expect(screen.queryByText('browser')).not.toBeInTheDocument());+ await act(async () => { finishCounts({ sources }); });+ expect(screen.queryByText('browser')).not.toBeInTheDocument();+ expect(await screen.findByText('9 events')).toBeInTheDocument();+ expect(api.eraseTimelineSource).toHaveBeenCalledTimes(1);+});+it('retains the row and confirmation and shows a refused deletion', async () => {api.eraseTimelineSource.mockRejectedValueOnce(new Error('Deletion unavailable'));const onChanged = vi.fn();@@ -63,7 +88,7 @@ it('reconciles a lost delete acknowledgement from a fresh read without repeatingapi.eraseTimelineSource.mockRejectedValueOnce(new Error('Response lost'));render(<ManageImportedDataPanel onChanged={onChanged} />);await screen.findByText('browser');- api.getTimelineSources.mockResolvedValueOnce({ sources: [sources[1]] });+ api.getTimelineSources.mockResolvedValue({ sources: [sources[1]] });fireEvent.click(screen.getAllByRole('button', { name: 'Delete' })[0]);fireEvent.change(screen.getByRole('textbox'), { target: { value: 'browser' } });fireEvent.click(screen.getByRole('button', { name: 'Confirm delete' }));