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: recover dashboard threads after failed reads (#9919)
Adam Eivy59dd30b3e209
diff --git a/client/src/components/dashboard/builtins/OpenThreadsWidget.jsx b/client/src/components/dashboard/builtins/OpenThreadsWidget.jsxindex 2c360b4581..ca1b64cbb4 100644--- a/client/src/components/dashboard/builtins/OpenThreadsWidget.jsx+++ b/client/src/components/dashboard/builtins/OpenThreadsWidget.jsx@@ -27,12 +27,12 @@ export default function OpenThreadsWidget() {const [completed, setCompleted] = useState({});// Overdue coloring is local clock state, not a reason to re-read the API.useTimeTick(60000);- const { data, loading } = useSocketResource(+ const { data, loading, error, refetch } = useSocketResource(() => api.listThreads({ status: WIDGET_STATUSES, limit: ROWS, offset: 0 }, { silent: true }),{ events: RESOURCE_EVENTS },);- if (loading && !data) return null;+ const hasResults = data != null;const fetchedRows = Array.isArray(data?.threads) ? data.threads : [];// Retain successful writes over a read that started before completion.@@ -43,19 +43,35 @@ export default function OpenThreadsWidget() {return (<div className="@container bg-port-card border border-port-border rounded-xl p-4 h-full">- <div className="flex items-center justify-between gap-2 mb-3">+ <div className="flex flex-wrap items-center justify-between gap-2 mb-3"><Link to="/brain/threads" className="flex items-center gap-2 hover:text-port-accent"><ListTodo size={16} className="text-gray-500" aria-hidden="true" /><h3 className="text-sm font-semibold text-white">Open Threads</h3></Link>- {total > 0 && <span className="text-xs text-gray-500">{formatCount(total)} open</span>}+ {hasResults && total > 0 && <span className="text-xs text-gray-500">{formatCount(total)} open</span>}</div>- {rows.length === 0 ? (+ {error && (+ <div className="mb-3 space-y-2 text-xs" role="status">+ <p className="text-port-warning">+ {hasResults+ ? 'Showing last-loaded results — threads could not be refreshed.'+ : 'Threads unavailable — your open loops could not be loaded.'}+ </p>+ <div className="flex flex-wrap items-center gap-2">+ <button type="button" onClick={refetch} disabled={loading} className="min-h-11 px-3 rounded-lg border border-port-border text-port-accent disabled:opacity-50">+ {loading ? 'Retrying…' : 'Retry'}+ </button>+ <Link to="/brain/threads" className="text-port-accent hover:underline">Open Brain Threads</Link>+ </div>+ </div>+ )}+ {!hasResults && !error && <p role="status" className="text-xs text-gray-500">Loading threads…</p>}+ {hasResults && (rows.length === 0 ? (<p className="text-xs text-gray-500">{total > 0? 'More open loops are available in Brain.'- : <>No open loops. <Link to="/brain/threads" className="text-port-accent hover:underline">Track one</Link></>}+ : error ? 'No open loops in the last-loaded results.' : <>No open loops. <Link to="/brain/threads" className="text-port-accent hover:underline">Track one</Link></>}</p>) : (<ul className="space-y-2">@@ -80,8 +96,8 @@ export default function OpenThreadsWidget() {);})}</ul>- )}- {total > rows.length && (+ ))}+ {hasResults && total > rows.length && (<Link to="/brain/threads" className="block text-xs text-gray-500 hover:text-port-accent mt-2">+{formatCount(total - rows.length)} more</Link>diff --git a/client/src/components/dashboard/builtins/OpenThreadsWidget.test.jsx b/client/src/components/dashboard/builtins/OpenThreadsWidget.test.jsxindex 4a4ab3606c..975d6816e2 100644--- a/client/src/components/dashboard/builtins/OpenThreadsWidget.test.jsx+++ b/client/src/components/dashboard/builtins/OpenThreadsWidget.test.jsx@@ -18,10 +18,12 @@ import OpenThreadsWidget from './OpenThreadsWidget';const renderWidget = () => render(<MemoryRouter><OpenThreadsWidget /></MemoryRouter>);describe('OpenThreadsWidget', () => {- it('renders nothing until the first list arrives', () => {+ it('keeps navigation and a loading status until the first list arrives', () => {mockUseSocketResource.mockReturnValue({ data: null, loading: true });- const { container } = renderWidget();- expect(container.innerHTML).toBe('');+ renderWidget();+ expect(screen.getByRole('link', { name: 'Open Threads' })).toHaveAttribute('href', '/brain/threads');+ expect(screen.getByRole('status')).toHaveTextContent('Loading threads');+ expect(screen.queryByText(/No open loops/)).toBeNull();});it('asks the server for the first page of open + waiting threads only', () => {@@ -117,6 +119,36 @@ describe('OpenThreadsWidget', () => {expect(api.updateThread).toHaveBeenCalledTimes(2);});+ it('offers retry on initial failure and recovers to genuine empty results', () => {+ const refetch = vi.fn();+ mockUseSocketResource.mockReturnValue({ data: null, loading: false, error: new Error('Unavailable'), refetch });+ const view = renderWidget();+ expect(screen.getByRole('status')).toHaveTextContent('Threads unavailable');+ expect(screen.queryByText(/No open loops/)).toBeNull();+ expect(screen.queryByText(/open$/)).toBeNull();+ expect(screen.getByRole('link', { name: 'Open Brain Threads' })).toHaveAttribute('href', '/brain/threads');+ fireEvent.click(screen.getByRole('button', { name: 'Retry' }));+ expect(refetch).toHaveBeenCalledTimes(1);+ mockUseSocketResource.mockReturnValue({ data: null, loading: true, error: new Error('Unavailable'), refetch });+ view.rerender(<MemoryRouter><OpenThreadsWidget /></MemoryRouter>);+ expect(screen.getByRole('button', { name: 'Retrying…' })).toBeDisabled();+ mockUseSocketResource.mockReturnValue({ data: { total: 0, threads: [] }, loading: false, error: null, refetch });+ view.rerender(<MemoryRouter><OpenThreadsWidget /></MemoryRouter>);+ expect(screen.queryByRole('button', { name: 'Retry' })).toBeNull();+ expect(screen.getByText('Track one')).toBeTruthy();+ });++ it('identifies retained rows and counts as stale after reconciliation failure', () => {+ const refetch = vi.fn();+ mockUseSocketResource.mockReturnValue({ data: { total: 1, threads: [{ id: 'retained', title: 'Retained loop', status: 'open' }] }, loading: false, error: new Error('Unavailable'), refetch });+ renderWidget();+ expect(screen.getByRole('status')).toHaveTextContent('Showing last-loaded results');+ expect(screen.getByText('1 open')).toBeTruthy();+ expect(screen.getByText('Retained loop').closest('a')).toHaveAttribute('href', '/brain/threads?thread=retained');+ fireEvent.click(screen.getByRole('button', { name: 'Retry' }));+ expect(refetch).toHaveBeenCalledTimes(1);+ });+it('offers to track one when the list is empty', () => {mockUseSocketResource.mockReturnValue({ loading: false, data: { total: 0, threads: [] } });renderWidget();