Skip to content

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

fix: surface loading and error state for the Story Builder session list (#3906)

[._.]/ Adam Eivyc6813b145844
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index c9b74c7b91..fc8f494a8e 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -39,6 +39,8 @@
## Changed
+- A failed "Continue a story" fetch on the Story Builder index no longer looks like your saved stories were deleted. The list swallowed its own error and fell back to an empty array, and an empty array renders nothing — so a dropped connection or a restarting server left the sidebar section silently gone, with no indication anything had failed and no way to try again short of a reload. The section now reserves itself while the fetch is in flight with three pulsing placeholder rows, and on failure renders an error banner naming the error with a Retry button that re-runs the fetch and restores the list. Only a successful, genuinely empty list still hides the section.
+
- `restorePostgres` now has tests for the three paths a PostgreSQL restore can go wrong on. A missing `psql` binary surfaces as a spawn `'error'` event rather than a `'close'`, so without its listener the restore promise would never settle and the UI would hang — the suite now drives that emit and pins the `{ status: 'failed', reason: 'restore_error' }` result. The `--single-transaction` / `ON_ERROR_STOP=1` pair is what makes a failed replay roll back instead of leaving the live database half-dropped, so both flags (and the `-v` flag's actual value, not just its presence) are asserted, along with the `portos` PGPASSWORD default and an explicit `PGPASSWORD` overriding it. A `manifest.json` that exists but is unparseable reads as absent — `readJSONFile` returns its `null` default, so hash verification is skipped and the restore proceeds; that is now pinned in both the dry-run and real-restore directions, so changing it to a hard failure has to be a deliberate decision.
- The Story Builder's footer "Next >" button now says why it can't be clicked. It was inert whenever the active step was unlocked or had gone stale, but carried no tooltip and no accessible description — and since the step rail beside it is deliberately un-gated, a dead Next read as a bug rather than as guidance. It now carries a `title` plus a screen-reader hint naming the actual blocker ("Lock this step to advance to the next step." vs. "An upstream step changed — re-lock this step to advance."), and uses `aria-disabled` instead of `disabled` so keyboard and screen-reader users can still reach the button and hear the reason.
diff --git a/client/src/pages/StoryBuilder.jsx b/client/src/pages/StoryBuilder.jsx
index 474c973c88..417c9a136c 100644
--- a/client/src/pages/StoryBuilder.jsx
+++ b/client/src/pages/StoryBuilder.jsx
@@ -158,6 +158,13 @@ function StoryBuilderIndex() {
// of auto-creating a fresh universe. The create schema already accepts it.
const onrampUniverseId = searchParams.get('universeId') || undefined;
const [sessions, setSessions] = useState([]);
+ // `sessionsLoading` / `sessionsError` keep "still fetching" and "the fetch
+ // failed" distinct from "you genuinely have no saved stories" — collapsing
+ // all three into an empty array made a failed list look like a deletion
+ // (#3906). `sessionsReloadTick` re-runs the effect for the Retry button.
+ const [sessionsLoading, setSessionsLoading] = useState(true);
+ const [sessionsError, setSessionsError] = useState(null);
+ const [sessionsReloadTick, setSessionsReloadTick] = useState(0);
const [mode, setMode] = useState('seed');
const [title, setTitle] = useState('');
const [seedIdea, setSeedIdea] = useState('');
@@ -170,8 +177,21 @@ function StoryBuilderIndex() {
const [remixIngredients, setRemixIngredients] = useState([]);
useEffect(() => {
- listStorySessions({ silent: true }).then(setSessions).catch(() => setSessions([]));
- }, []);
+ let cancelled = false;
+ setSessionsLoading(true);
+ setSessionsError(null);
+ listStorySessions({ silent: true })
+ .then((list) => {
+ if (cancelled) return;
+ setSessions(Array.isArray(list) ? list : []);
+ })
+ .catch((err) => {
+ if (cancelled) return;
+ setSessionsError(err?.message || 'Failed to load your saved stories');
+ })
+ .finally(() => { if (!cancelled) setSessionsLoading(false); });
+ return () => { cancelled = true; };
+ }, [sessionsReloadTick]);
// Consume the remix handoff once at mount, then clear the history state so a
// refresh doesn't re-seed (mirrors CatalogIngest's prefill-consume pattern).
@@ -295,10 +315,39 @@ function StoryBuilderIndex() {
)}
</section>
- {sessions.length > 0 && (
+ {/* Rendered while loading and on failure too — an empty sidebar during a
+ failed fetch reads as "my saved stories were deleted" (#3906). Only a
+ successful, genuinely-empty list hides the section. */}
+ {(sessionsLoading || sessionsError || sessions.length > 0) && (
<section className="space-y-2">
<h2 className="font-semibold text-gray-300">Continue a story</h2>
- {sessions.map((s) => (
+ {sessionsLoading ? (
+ <div className="space-y-2" role="status" aria-busy="true" aria-label="Loading your stories">
+ {['w-2/3', 'w-1/2', 'w-1/3'].map((w) => (
+ <div key={w} className="bg-port-card border border-port-border rounded-lg px-4 py-3 animate-pulse">
+ <div className={`h-4 rounded bg-port-border ${w}`} />
+ </div>
+ ))}
+ </div>
+ ) : sessionsError ? (
+ <Banner
+ tone="error"
+ icon={AlertTriangle}
+ size="md"
+ title="Couldn’t load your saved stories"
+ actions={(
+ <button
+ type="button"
+ onClick={() => setSessionsReloadTick((t) => t + 1)}
+ className="inline-flex items-center gap-1.5 text-xs px-2 py-1 rounded border border-port-border text-gray-300 hover:text-white"
+ >
+ <RefreshCw className="w-3 h-3" aria-hidden="true" /> Retry
+ </button>
+ )}
+ >
+ {sessionsError}
+ </Banner>
+ ) : sessions.map((s) => (
<Link
key={s.id} to={`/story-builder/${s.id}/${s.currentStep || 'idea'}`}
className="flex items-center justify-between gap-2 bg-port-card border border-port-border rounded-lg px-4 py-3 hover:border-port-accent"
diff --git a/client/src/pages/StoryBuilder.test.jsx b/client/src/pages/StoryBuilder.test.jsx
index a9b87864d4..089f76fc2f 100644
--- a/client/src/pages/StoryBuilder.test.jsx
+++ b/client/src/pages/StoryBuilder.test.jsx
@@ -187,6 +187,46 @@ describe('StoryBuilder — index', () => {
expect(screen.getByText('Import a finished work')).toBeTruthy();
});
+ it('session list: shows a loading skeleton until the fetch resolves, then the sessions (#3906)', async () => {
+ let resolveList;
+ api.listStorySessions.mockReturnValue(new Promise((res) => { resolveList = res; }));
+
+ renderAt('/story-builder');
+
+ expect(await screen.findByLabelText('Loading your stories')).toBeTruthy();
+ await act(async () => { resolveList([{ id: 'stb-1', title: 'Example Story', currentStep: 'idea' }]); });
+
+ await waitFor(() => expect(screen.queryByLabelText('Loading your stories')).toBeNull());
+ expect(screen.getByText('Example Story')).toBeTruthy();
+ });
+
+ it('session list: a failed fetch shows an error banner with Retry, and Retry restores the list (#3906)', async () => {
+ const { fireEvent } = await import('@testing-library/react');
+ api.listStorySessions.mockRejectedValueOnce(new Error('Network is down'));
+
+ renderAt('/story-builder');
+
+ // The section stays visible with the failure named — not silently blank.
+ expect(await screen.findByText('Couldn’t load your saved stories')).toBeTruthy();
+ expect(screen.getByText('Network is down')).toBeTruthy();
+ expect(screen.getByText('Continue a story')).toBeTruthy();
+
+ api.listStorySessions.mockResolvedValue([{ id: 'stb-2', title: 'Recovered Story', currentStep: 'plotArc' }]);
+ await act(async () => { fireEvent.click(screen.getByRole('button', { name: /Retry/i })); });
+
+ await waitFor(() => expect(screen.getByText('Recovered Story')).toBeTruthy());
+ expect(screen.queryByText('Couldn’t load your saved stories')).toBeNull();
+ expect(api.listStorySessions).toHaveBeenCalledTimes(2);
+ });
+
+ it('session list: a successful but empty list hides the section entirely (#3906)', async () => {
+ api.listStorySessions.mockResolvedValue([]);
+ renderAt('/story-builder');
+ await screen.findByLabelText('Universe / story name');
+ await waitFor(() => expect(screen.queryByLabelText('Loading your stories')).toBeNull());
+ expect(screen.queryByText('Continue a story')).toBeNull();
+ });
+
it('remix handoff: hydrates selected ingredients into chips + a prefilled seed, and forwards the ids on create', async () => {
const { fireEvent } = await import('@testing-library/react');
api.listCatalogIngredientsByIds.mockResolvedValue([