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 a retry state when universe run history cannot load (#12484)
[._.]/ Adam Eivy3041930aa2e5
diff --git a/client/src/components/universeBuilder/RenderTab.jsx b/client/src/components/universeBuilder/RenderTab.jsxindex e82fd1803f..88b65d226c 100644--- a/client/src/components/universeBuilder/RenderTab.jsx+++ b/client/src/components/universeBuilder/RenderTab.jsx@@ -16,7 +16,7 @@ import { totalVariationCount, countCanonWithContent } from '../../lib/universeBuexport default function RenderTab({draft, setRenderPin, selectedId, bucketsByKind, renderOpts, setRenderOpts,availableBackends, defaultMode, imageModels, availableLoras = [],- handleRender, rendering, runs,+ handleRender, rendering, runs, runsStatus = 'ready', onRetryRuns,}) {const currentModel = useMemo(() => imageModels.find((m) => m.id === renderOpts.modelId),@@ -275,9 +275,31 @@ export default function RenderTab({</div></section>- {selectedId && runs.length > 0 && (+ {selectedId && (<section className="bg-port-card border border-port-border rounded p-4"><h2 className="text-sm font-semibold text-white mb-2">Recent runs</h2>+ {runsStatus === 'error' && (+ <div role="alert" className="flex items-center justify-between gap-2 text-sm text-port-error mb-2">+ <span>+ {runs.length > 0+ ? 'Could not refresh run history. Showing the last loaded runs.'+ : 'Could not load run history.'}+ </span>+ <button+ type="button"+ onClick={onRetryRuns}+ className="px-2 py-1 text-xs border border-port-border rounded text-white hover:bg-port-border/40 whitespace-nowrap"+ >+ Retry+ </button>+ </div>+ )}+ {runsStatus === 'loading' && runs.length === 0 && (+ <p className="text-sm text-gray-500 flex items-center gap-2"><Loader2 size={14} className="animate-spin" /> Loading runs…</p>+ )}+ {runsStatus === 'ready' && runs.length === 0 && (+ <p className="text-sm text-gray-500">No renders yet.</p>+ )}<ul className="flex flex-col gap-1">{runs.map((r) => (<li key={r.id} className="flex items-center justify-between text-sm text-gray-300 border-b border-port-border/40 py-1.5">diff --git a/client/src/components/universeBuilder/RenderTab.test.jsx b/client/src/components/universeBuilder/RenderTab.test.jsxnew file mode 100644index 0000000000..9dcba54bb4--- /dev/null+++ b/client/src/components/universeBuilder/RenderTab.test.jsx@@ -0,0 +1,52 @@+import { fireEvent, render, screen } from '@testing-library/react';+import { MemoryRouter } from 'react-router';+import { describe, expect, it, vi } from 'vitest';+import RenderTab from './RenderTab';++vi.mock('../imageGen/ImageGenSettingsForm', () => ({ default: () => null }));+vi.mock('../imageGen/RecordRenderPinRow', () => ({ default: () => null }));++const baseProps = {+ draft: { categories: {}, compositeSheets: [], characters: [], places: [], objects: [] },+ setRenderPin: vi.fn(),+ selectedId: 'u1',+ bucketsByKind: {},+ renderOpts: {},+ setRenderOpts: vi.fn(),+ availableBackends: [],+ defaultMode: 'local',+ imageModels: [],+ handleRender: vi.fn(),+ rendering: false,+};++const renderTab = (props) => render(+ <MemoryRouter><RenderTab {...baseProps} {...props} /></MemoryRouter>,+);++describe('RenderTab run history', () => {+ it('shows a persistent error with Retry when history failed to load', () => {+ const onRetryRuns = vi.fn();+ renderTab({ runs: [], runsStatus: 'error', onRetryRuns });+ expect(screen.getByRole('alert').textContent).toMatch(/Could not load run history/);+ expect(screen.queryByText('No renders yet.')).toBeNull();+ fireEvent.click(screen.getByRole('button', { name: 'Retry' }));+ expect(onRetryRuns).toHaveBeenCalledTimes(1);+ });++ it('keeps last-known rows beside a stale notice on a failed refresh', () => {+ renderTab({+ runs: [{ id: 'r1', createdAt: '2026-01-01T00:00:00.000Z', promptCount: 2, collectionId: 'c1' }],+ runsStatus: 'error',+ onRetryRuns: vi.fn(),+ });+ expect(screen.getByRole('alert').textContent).toMatch(/last loaded runs/);+ expect(screen.getByText('Open collection →')).toBeTruthy();+ });++ it('shows a distinct empty state for a successful empty history', () => {+ renderTab({ runs: [], runsStatus: 'ready', onRetryRuns: vi.fn() });+ expect(screen.getByText('No renders yet.')).toBeTruthy();+ expect(screen.queryByRole('alert')).toBeNull();+ });+});diff --git a/client/src/components/universeBuilder/UniverseBuilderPage.jsx b/client/src/components/universeBuilder/UniverseBuilderPage.jsxindex d0fa0e424c..3960c46732 100644--- a/client/src/components/universeBuilder/UniverseBuilderPage.jsx+++ b/client/src/components/universeBuilder/UniverseBuilderPage.jsx@@ -157,6 +157,8 @@ export default function UniverseBuilder() {removeCategory,removeStyleReference,runs,+ runsStatus,+ retryRuns,saving,setRenderPin,setCanonDirty,@@ -699,6 +701,8 @@ export default function UniverseBuilder() {handleRender={handleRender}rendering={rendering}runs={runs}+ runsStatus={runsStatus}+ onRetryRuns={retryRuns}/>)}diff --git a/client/src/hooks/useUniverseDraft.js b/client/src/hooks/useUniverseDraft.jsindex e39a52eff1..46f42e9e24 100644--- a/client/src/hooks/useUniverseDraft.js+++ b/client/src/hooks/useUniverseDraft.js@@ -86,6 +86,8 @@ const emptyPendingCanon = () => ({ characters: [], places: [], objects: [] });* and create/update/delete flows. LLM expansion/refinement and rendering stay* separate consumers of this contract.*/+export const RUNS_STATUS = { LOADING: 'loading', READY: 'ready', ERROR: 'error' };+export default function useUniverseDraft({ selectedId, goToWorld }) {const [universes, setWorlds] = useState([]);const [loading, setLoading] = useState(true);@@ -106,6 +108,9 @@ export default function useUniverseDraft({ selectedId, goToWorld }) {const [targetPin, setTargetPin] = useState(null);const [draft, setDraft] = useState(createEmptyUniverseDraft);const [runs, setRuns] = useState([]);+ // History read state, bound to the universe it was requested for. A failed+ // read must not look like an empty history, so it is tracked apart from `runs`.+ const [runsStatus, setRunsStatus] = useState(RUNS_STATUS.READY);const [pendingDeleteId, setPendingDeleteId] = useState(null);const [newCategoryName, setNewCategoryName] = useState('');const [canonDirty, setCanonDirty] = useState(false);@@ -231,14 +236,10 @@ export default function useUniverseDraft({ selectedId, goToWorld }) {const empty = createEmptyUniverseDraft();setDraft(empty);markDraftSaved(empty);- setRuns([]);return undefined;}let cancelled = false;- Promise.all([- getUniverse(selectedId).catch(() => null),- listWorldRuns(selectedId).catch(() => []),- ]).then(async ([fetched, nextRuns]) => {+ getUniverse(selectedId).catch(() => null).then(async (fetched) => {if (cancelled) return;// This body predates a mutation we already have confirmed — re-read rather// than apply it. The second read is issued after that mutation's response,@@ -272,11 +273,37 @@ export default function useUniverseDraft({ selectedId, goToWorld }) {setDraft(hydrated);markDraftSaved(hydrated);}- setRuns(nextRuns);});return () => { cancelled = true; };}, [selectedId, universeIsStale, noteUniverseUpdated]);+ // Run history loads independently of the draft so Retry never re-hydrates+ // (and so never clobbers) unsaved edits. Results are dropped unless they+ // still belong to the current selection and the latest request.+ const runsRequestRef = useRef(0);+ const loadRuns = useCallback(async (id) => {+ const request = ++runsRequestRef.current;+ setRunsStatus(RUNS_STATUS.LOADING);+ const fetched = await listWorldRuns(id).catch(() => null);+ if (!mountedRef.current || request !== runsRequestRef.current || selectedIdRef.current !== id) return;+ if (fetched) setRuns(fetched);+ setRunsStatus(fetched ? RUNS_STATUS.READY : RUNS_STATUS.ERROR);+ }, [mountedRef]);+ const retryRuns = useCallback(() => {+ if (selectedIdRef.current) loadRuns(selectedIdRef.current);+ }, [loadRuns]);++ useEffect(() => {+ // Rows from the previous universe must never show under the new one.+ setRuns([]);+ if (!selectedId) {+ runsRequestRef.current += 1;+ setRunsStatus(RUNS_STATUS.READY);+ return;+ }+ loadRuns(selectedId);+ }, [selectedId, loadRuns]);+const handleSave = async () => {if (!draft.name?.trim()) {toast.error('Name is required');@@ -766,6 +793,8 @@ export default function useUniverseDraft({ selectedId, goToWorld }) {removeCategory,removeStyleReference,runs,+ runsStatus,+ retryRuns,saving,setRenderPin,setCanonDirty,diff --git a/client/src/hooks/useUniverseDraft.test.jsx b/client/src/hooks/useUniverseDraft.test.jsxindex 64420e4bc1..339c714cf6 100644--- a/client/src/hooks/useUniverseDraft.test.jsx+++ b/client/src/hooks/useUniverseDraft.test.jsx@@ -157,6 +157,50 @@ describe('useUniverseDraft', () => {expect(result.current.isDraftDirty()).toBe(false);});+ describe('run history load state', () => {+ it('reports a failed history read as an error, not an empty history, and retries without touching the draft', async () => {+ apiMocks.listWorldRuns.mockRejectedValueOnce(new Error('boom'));+ const { result } = renderDraft();+ await waitFor(() => expect(result.current.runsStatus).toBe('error'));+ await waitFor(() => expect(result.current.draft.id).toBe('u1'));+ expect(result.current.runs).toEqual([]);++ act(() => result.current.updateDraft({ premise: 'Unsaved premise' }));+ const getCalls = apiMocks.getUniverse.mock.calls.length;+ await act(async () => { result.current.retryRuns(); });+ await waitFor(() => expect(result.current.runsStatus).toBe('ready'));+ expect(result.current.runs).toEqual([{ id: 'run-1' }]);+ expect(result.current.draft.premise).toBe('Unsaved premise');+ expect(apiMocks.getUniverse.mock.calls.length).toBe(getCalls);+ });++ it('keeps same-record rows when a refresh fails', async () => {+ const { result } = renderDraft();+ await waitFor(() => expect(result.current.runsStatus).toBe('ready'));+ apiMocks.listWorldRuns.mockRejectedValueOnce(new Error('boom'));+ await act(async () => { result.current.retryRuns(); });+ await waitFor(() => expect(result.current.runsStatus).toBe('error'));+ expect(result.current.runs).toEqual([{ id: 'run-1' }]);+ });++ it('drops a late history response for a universe that is no longer selected', async () => {+ let resolveOld;+ apiMocks.listWorldRuns.mockImplementation((id) => (id === 'u1'+ ? new Promise((resolve) => { resolveOld = resolve; })+ : Promise.reject(new Error('boom'))));+ const goToWorld = vi.fn();+ const { result, rerender } = renderHook(+ ({ selectedId }) => useUniverseDraft({ selectedId, goToWorld }),+ { initialProps: { selectedId: 'u1' } },+ );+ rerender({ selectedId: 'u2' });+ await waitFor(() => expect(result.current.runsStatus).toBe('error'));+ await act(async () => { resolveOld([{ id: 'stale-run' }]); });+ expect(result.current.runs).toEqual([]);+ expect(result.current.runsStatus).toBe('error');+ });+ });+// A failed fetch and an empty response must not land in the same state. The refresh()// fan-out used to `.catch(() => [])` / `.catch(() => ({}))` every call, so a transient// failure was indistinguishable from a real empty answer — and for settings it was