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: keep Writers Room bible load failures distinct from empty profiles (#12390)

[._.]/ Adam Eivyc663f00d4581
diff --git a/client/src/components/writers-room/BibleSection.jsx b/client/src/components/writers-room/BibleSection.jsx
index ffd52b9f60..b3060bfe6b 100644
--- a/client/src/components/writers-room/BibleSection.jsx
+++ b/client/src/components/writers-room/BibleSection.jsx
@@ -61,13 +61,25 @@ export default function BibleSection({
// editor host context it cannot fetch for itself (the Writers Room evolution
// lens needs the active draft's segment index to offer real anchors).
customProps = null,
+ // Controlled mode only: the parent's read state for `items` ('loading' |
+ // 'ready' | 'error') and a retry for it. A supplied array alone cannot say
+ // whether it is the work's real roster or what survived a failed read.
+ loadStatus: loadStatusProp = 'ready', onRetry: onRetryProp = null,
}) {
const [internalItems, setInternalItems] = useState(itemsProp || []);
const items = itemsProp ?? internalItems;
const [editingId, setEditingId] = useState(null);
const [creating, setCreating] = useState(false);
- const [loading, setLoading] = useState(false);
+ const [ownStatus, setOwnStatus] = useState('ready');
+ const [retryKey, setRetryKey] = useState(0);
const mountedRef = useMounted();
+ const controlled = !!itemsProp;
+ const loadStatus = controlled ? loadStatusProp : ownStatus;
+ const retry = controlled ? onRetryProp : () => setRetryKey((k) => k + 1);
+
+ // A different work starts from an empty roster; a retry (same work) keeps
+ // the rows from the last successful read.
+ useEffect(() => { if (!itemsProp) setInternalItems([]); }, [workId, itemsProp]);
useEffect(() => {
if (itemsProp) return undefined;
@@ -76,13 +88,16 @@ export default function BibleSection({
// are not interchangeable. The component stays mounted across a work swap,
// so only `active` keeps the previous work's bible out of this one.
let active = true;
- setLoading(true);
+ setOwnStatus('loading');
config.api.list(workId)
- .then((list) => { if (active && mountedRef.current) setInternalItems(list); })
- .catch(() => { if (active && mountedRef.current) setInternalItems([]); })
- .finally(() => { if (active && mountedRef.current) setLoading(false); });
+ .then((list) => {
+ if (!active || !mountedRef.current) return;
+ setInternalItems(list);
+ setOwnStatus('ready');
+ })
+ .catch(() => { if (active && mountedRef.current) setOwnStatus('error'); });
return () => { active = false; };
- }, [workId, itemsProp, mountedRef]);
+ }, [workId, itemsProp, mountedRef, retryKey]);
// Internal state uses a functional updater so back-to-back saves (the add
// form and a row editor can both be open) each merge against the freshest
@@ -118,11 +133,29 @@ export default function BibleSection({
</button>
</div>
- {loading && items.length === 0 && (
+ {loadStatus === 'loading' && items.length === 0 && (
<BrailleSpinner text="Loading…" />
)}
- {!loading && items.length === 0 && !creating && (
+ {loadStatus === 'error' && (
+ <div role="alert" className="flex items-center gap-2 px-1 mb-2 text-port-error">
+ <AlertTriangle size={11} className="shrink-0" />
+ <span className="flex-1">
+ Couldn&apos;t load this list{items.length > 0 ? ' — showing the last loaded rows' : ''}.
+ </span>
+ {retry && (
+ <button
+ type="button"
+ onClick={retry}
+ className="min-h-[44px] -my-2 px-2 underline hover:text-white"
+ >
+ Retry
+ </button>
+ )}
+ </div>
+ )}
+
+ {loadStatus === 'ready' && items.length === 0 && !creating && (
<div className="text-gray-500 italic px-1 mb-2">{config.emptyText}</div>
)}
diff --git a/client/src/components/writers-room/BibleSection.test.jsx b/client/src/components/writers-room/BibleSection.test.jsx
index fc5a57e16f..0ca4599221 100644
--- a/client/src/components/writers-room/BibleSection.test.jsx
+++ b/client/src/components/writers-room/BibleSection.test.jsx
@@ -291,3 +291,51 @@ describe.each(SCENARIOS)('$label (BibleSection)', (s) => {
expect(screen.getByRole('textbox', { name: s.primaryLabel })).toBeInTheDocument();
});
});
+
+// #12390: a failed read must not be indistinguishable from an empty roster.
+describe('BibleSection load failure (#12390)', () => {
+ afterEach(() => cleanup());
+
+ it('standalone: shows an alert + Retry instead of empty-state copy, and retry recovers', async () => {
+ listWritersRoomCharacters
+ .mockRejectedValueOnce(new Error('boom'))
+ .mockResolvedValueOnce([{ id: 'char-1', name: 'Ada', aliases: [], role: '', physicalDescription: 'x' }]);
+
+ render(<CharactersBible workId="work-1" />);
+
+ expect(await screen.findByRole('alert')).toHaveTextContent(/couldn.t load/i);
+ expect(screen.queryByText(/no .* yet/i)).toBeNull();
+
+ await userEvent.click(screen.getByRole('button', { name: 'Retry' }));
+ await screen.findByText('Ada');
+ expect(screen.queryByRole('alert')).toBeNull();
+ });
+
+ it('controlled: a refresh failure keeps the prior rows visible beside the alert', async () => {
+ render(
+ <CharactersBible
+ workId="work-1"
+ characters={[{ id: 'char-1', name: 'Ada', aliases: [], role: '', physicalDescription: 'x' }]}
+ loadStatus="error"
+ onRetry={vi.fn()}
+ />,
+ );
+ expect(await screen.findByRole('alert')).toBeInTheDocument();
+ expect(screen.getByText('Ada')).toBeInTheDocument();
+ });
+
+ it('controlled: loadStatus=error renders the alert and routes Retry to onRetry; ready+empty keeps guidance', async () => {
+ const onRetry = vi.fn();
+ const { rerender } = render(
+ <CharactersBible workId="work-1" characters={[]} loadStatus="error" onRetry={onRetry} />,
+ );
+ expect(await screen.findByRole('alert')).toBeInTheDocument();
+ expect(screen.queryByText(/no .* yet/i)).toBeNull();
+ await userEvent.click(screen.getByRole('button', { name: 'Retry' }));
+ expect(onRetry).toHaveBeenCalledTimes(1);
+
+ rerender(<CharactersBible workId="work-1" characters={[]} loadStatus="ready" onRetry={onRetry} />);
+ expect(screen.queryByRole('alert')).toBeNull();
+ expect(screen.getByText(/no .* yet/i)).toBeInTheDocument();
+ });
+});
diff --git a/client/src/components/writers-room/CharactersBible.jsx b/client/src/components/writers-room/CharactersBible.jsx
index ca45ba858a..40cc9ccd8e 100644
--- a/client/src/components/writers-room/CharactersBible.jsx
+++ b/client/src/components/writers-room/CharactersBible.jsx
@@ -149,7 +149,7 @@ const CHARACTER_CONFIG = {
// mounts in sync (e.g. drawer + storyboard chip count). When omitted we fetch
// and own the list so this can stand alone.
export default function CharactersBible({
- workId, characters, onCharactersChange, readingTheme = 'dark', hotRefId = null, segments = null,
+ workId, characters, onCharactersChange, readingTheme = 'dark', hotRefId = null, segments = null, loadStatus, onRetry,
}) {
return (
<BibleSection
@@ -158,6 +158,8 @@ export default function CharactersBible({
onItemsChange={onCharactersChange}
readingTheme={readingTheme}
hotRefId={hotRefId}
+ loadStatus={loadStatus}
+ onRetry={onRetry}
config={CHARACTER_CONFIG}
// The active draft's segment index, so the evolution lens can anchor a
// stage to a real chapter/scene instead of asking for a raw `seg-NNN`.
diff --git a/client/src/components/writers-room/ObjectsBible.jsx b/client/src/components/writers-room/ObjectsBible.jsx
index 102036a17b..8dfab308b6 100644
--- a/client/src/components/writers-room/ObjectsBible.jsx
+++ b/client/src/components/writers-room/ObjectsBible.jsx
@@ -57,7 +57,7 @@ const OBJECT_CONFIG = {
// see BibleSection.jsx for the shared implementation these three configure.
// Distinct from analysis snapshots — this is the canonical roster that
// survives across `objects` analysis runs and accepts hand-edits.
-export default function ObjectsBible({ workId, objects, onObjectsChange, readingTheme = 'dark', hotRefId = null }) {
+export default function ObjectsBible({ workId, objects, onObjectsChange, readingTheme = 'dark', hotRefId = null, loadStatus, onRetry }) {
return (
<BibleSection
workId={workId}
@@ -65,6 +65,8 @@ export default function ObjectsBible({ workId, objects, onObjectsChange, reading
onItemsChange={onObjectsChange}
readingTheme={readingTheme}
hotRefId={hotRefId}
+ loadStatus={loadStatus}
+ onRetry={onRetry}
config={OBJECT_CONFIG}
/>
);
diff --git a/client/src/components/writers-room/PlacesBible.jsx b/client/src/components/writers-room/PlacesBible.jsx
index fee0e280b3..ccfbffef69 100644
--- a/client/src/components/writers-room/PlacesBible.jsx
+++ b/client/src/components/writers-room/PlacesBible.jsx
@@ -69,7 +69,7 @@ const PLACE_CONFIG = {
// Controlled vs. uncontrolled: caller may pass `places` to keep multiple
// mounts in sync (e.g. drawer + storyboard chip count). When omitted we fetch
// and own the list so this can stand alone.
-export default function PlacesBible({ workId, places, onPlacesChange, readingTheme = 'dark', hotRefId = null }) {
+export default function PlacesBible({ workId, places, onPlacesChange, readingTheme = 'dark', hotRefId = null, loadStatus, onRetry }) {
return (
<BibleSection
workId={workId}
@@ -77,6 +77,8 @@ export default function PlacesBible({ workId, places, onPlacesChange, readingThe
onItemsChange={onPlacesChange}
readingTheme={readingTheme}
hotRefId={hotRefId}
+ loadStatus={loadStatus}
+ onRetry={onRetry}
config={PLACE_CONFIG}
/>
);
diff --git a/client/src/components/writers-room/StoryboardBibleTab.jsx b/client/src/components/writers-room/StoryboardBibleTab.jsx
index e529c83169..002723a9c5 100644
--- a/client/src/components/writers-room/StoryboardBibleTab.jsx
+++ b/client/src/components/writers-room/StoryboardBibleTab.jsx
@@ -66,6 +66,8 @@ export default function StoryboardBibleTab({
hotRefId = null,
dirty = false,
segments = null,
+ loadStatus = 'ready',
+ onRetry = null,
}) {
const meta = BIBLE_KINDS[kind];
const Bible = meta.Component;
@@ -75,6 +77,8 @@ export default function StoryboardBibleTab({
[meta.changeProp]: onItemsChange,
readingTheme,
hotRefId,
+ loadStatus,
+ onRetry,
// Only the character bible anchors anything to the manuscript (the
// evolution lens, #6445); places and objects ignore it.
...(kind === 'characters' ? { segments } : {}),
@@ -88,7 +92,7 @@ export default function StoryboardBibleTab({
running={running}
anyRunning={anyRunning}
onRefresh={onRefresh}
- empty={items.length === 0}
+ empty={loadStatus === 'ready' && items.length === 0}
dirty={dirty}
/>
<Bible {...bibleProps} />
diff --git a/client/src/components/writers-room/StoryboardPanel.jsx b/client/src/components/writers-room/StoryboardPanel.jsx
index 7d43ea1262..b4b0716fb4 100644
--- a/client/src/components/writers-room/StoryboardPanel.jsx
+++ b/client/src/components/writers-room/StoryboardPanel.jsx
@@ -70,6 +70,11 @@ function StoryboardPanel({
onLiveRenderContextChange,
registerSceneImageMerge,
objects = [],
+ // Per-kind read state ('loading' | 'ready' | 'error') for the three bible
+ // arrays, plus a targeted retry. An empty array is only "no records" when
+ // its status is 'ready'.
+ bibleStatus = null,
+ onRetryBible = null,
onObjectsChange,
onRunObjects,
hotRef = null,
@@ -325,6 +330,8 @@ function StoryboardPanel({
kind="characters"
workId={work.id}
items={characters}
+ loadStatus={bibleStatus?.characters}
+ onRetry={onRetryBible && (() => onRetryBible('characters'))}
onItemsChange={onCharactersChange}
onRefresh={onRunCharacters}
running={runningKind === 'characters'}
@@ -340,6 +347,8 @@ function StoryboardPanel({
kind="world"
workId={work.id}
items={places}
+ loadStatus={bibleStatus?.places}
+ onRetry={onRetryBible && (() => onRetryBible('places'))}
onItemsChange={onPlacesChange}
onRefresh={onRunPlaces}
running={runningKind === 'places'}
@@ -354,6 +363,8 @@ function StoryboardPanel({
kind="objects"
workId={work.id}
items={objects}
+ loadStatus={bibleStatus?.objects}
+ onRetry={onRetryBible && (() => onRetryBible('objects'))}
onItemsChange={onObjectsChange}
onRefresh={onRunObjects}
running={runningKind === 'objects'}
diff --git a/client/src/components/writers-room/WorkEditor.bibleDisposal.test.jsx b/client/src/components/writers-room/WorkEditor.bibleDisposal.test.jsx
index cb75a83d46..39562d6bd6 100644
--- a/client/src/components/writers-room/WorkEditor.bibleDisposal.test.jsx
+++ b/client/src/components/writers-room/WorkEditor.bibleDisposal.test.jsx
@@ -28,7 +28,10 @@ import { createMemoryRouter, RouterProvider } from 'react-router';
const storyboardProps = [];
vi.mock('./StoryboardPanel', () => ({
default: function StoryboardPanelStub(props) {
- storyboardProps.push({ characters: props.characters, places: props.places, objects: props.objects });
+ storyboardProps.push({
+ characters: props.characters, places: props.places, objects: props.objects,
+ bibleStatus: props.bibleStatus, onRetryBible: props.onRetryBible,
+ });
return <div data-testid="storyboard-panel" />;
},
STORYBOARD_TAB: {
@@ -165,4 +168,47 @@ describe('WorkEditor bible load disposal (#7242)', () => {
expect(latest.places).toEqual(A_PLACES);
expect(latest.objects).toEqual(A_OBJECTS);
});
+
+ // #12390: a failed read is an error status, never a successful empty roster,
+ // and a targeted retry recovers one kind without touching the others.
+ it('reports a failed read as an error, preserves other kinds, and retries one kind', async () => {
+ listWritersRoomCharacters.mockRejectedValueOnce(new Error('boom')).mockResolvedValueOnce(A_CHARACTERS);
+ listWritersRoomPlaces.mockResolvedValue(A_PLACES);
+ listWritersRoomObjects.mockResolvedValue(A_OBJECTS);
+
+ render(<RouterProvider router={routerFor(WORK_A)} />);
+ await act(async () => {});
+
+ let latest = storyboardProps.at(-1);
+ expect(latest.bibleStatus).toEqual({ characters: 'error', places: 'ready', objects: 'ready' });
+ expect(latest.places).toEqual(A_PLACES);
+
+ await act(async () => { latest.onRetryBible('characters'); });
+ latest = storyboardProps.at(-1);
+ expect(latest.bibleStatus.characters).toBe('ready');
+ expect(latest.characters).toEqual(A_CHARACTERS);
+ expect(listWritersRoomPlaces).toHaveBeenCalledTimes(1);
+ });
+
+ it('drops a retry that resolves after the work switched', async () => {
+ listWritersRoomCharacters.mockRejectedValueOnce(new Error('boom'));
+ listWritersRoomPlaces.mockResolvedValue([]);
+ listWritersRoomObjects.mockResolvedValue([]);
+
+ const view = render(<RouterProvider router={routerFor(WORK_A)} />);
+ await act(async () => {});
+
+ let release;
+ listWritersRoomCharacters.mockImplementationOnce(() => new Promise((resolve) => { release = resolve; }));
+ await act(async () => { storyboardProps.at(-1).onRetryBible('characters'); });
+
+ listWritersRoomCharacters.mockResolvedValue([]);
+ view.rerender(<RouterProvider router={routerFor(WORK_B)} />);
+ await act(async () => {});
+ release(A_CHARACTERS);
+ await act(async () => {});
+
+ expect(storyboardProps.at(-1).characters).toEqual([]);
+ expect(storyboardProps.at(-1).bibleStatus.characters).toBe('ready');
+ });
});
diff --git a/client/src/components/writers-room/WorkEditor.jsx b/client/src/components/writers-room/WorkEditor.jsx
index f5f7dedef1..56460723ad 100644
--- a/client/src/components/writers-room/WorkEditor.jsx
+++ b/client/src/components/writers-room/WorkEditor.jsx
@@ -92,6 +92,15 @@ const ANALYSIS_LABELS = {
[ANALYSIS_KIND.FORMAT]: 'Format pass',
};
+// Bible rosters read per work. A failed read is a distinct status, never an
+// empty list: an empty array is "no records" only once its status is 'ready'.
+const BIBLE_READERS = {
+ characters: listWritersRoomCharacters,
+ places: listWritersRoomPlaces,
+ objects: listWritersRoomObjects,
+};
+const BIBLE_LOADING = { characters: 'loading', places: 'loading', objects: 'loading' };
+
const SIDEBAR_WIDTH_KEY = 'wr.sidebarWidth';
const SIDEBAR_DEFAULT = 480;
const SIDEBAR_MIN = 320;
@@ -126,6 +135,11 @@ export default function WorkEditor({ work, onChange, onToggleExercise, exerciseO
const [characters, setCharacters] = useState([]);
const [places, setPlaces] = useState([]);
const [objects, setObjects] = useState([]);
+ const [bibleStatus, setBibleStatus] = useState(BIBLE_LOADING);
+ // Per-kind request generation: only the newest read for a kind may land.
+ const bibleGenRef = useRef({ characters: 0, places: 0, objects: 0 });
+ const workIdRef = useRef(work.id);
+ workIdRef.current = work.id;
const [runningKind, setRunningKind] = useState(null);
const [runStartedAt, setRunStartedAt] = useState(null);
const [drawer, setDrawer] = useState(null);
@@ -290,20 +304,50 @@ export default function WorkEditor({ work, onChange, onToggleExercise, exerciseO
// them, so nothing re-reads the server until the user re-runs an extraction.
// In the meantime StoryboardPanel enriches work B's image-gen prompts with
// work A's characters and places, and those renders are persisted.
+ const setBibleRows = useCallback((kind, rows) => {
+ if (kind === 'characters') setCharacters(rows);
+ else if (kind === 'places') setPlaces(rows);
+ else setObjects(rows);
+ }, []);
+
+ // A read that fails keeps the rows of the last successful read and surfaces
+ // an error status (retryable per kind) instead of installing an empty list.
+ const readBible = useCallback((kind, workId) => {
+ const gen = ++bibleGenRef.current[kind];
+ setBibleStatus((prev) => ({ ...prev, [kind]: 'loading' }));
+ return BIBLE_READERS[kind](workId).then((rows) => {
+ if (gen !== bibleGenRef.current[kind]) return;
+ setBibleRows(kind, rows || []);
+ setBibleStatus((prev) => ({ ...prev, [kind]: 'ready' }));
+ }).catch(() => {
+ if (gen !== bibleGenRef.current[kind]) return;
+ setBibleStatus((prev) => ({ ...prev, [kind]: 'error' }));
+ });
+ }, [setBibleRows]);
+
+ // An extraction result is the full merged roster: it supersedes any read in
+ // flight and clears a prior load error.
+ const applyBibleRows = useCallback((kind, rows) => {
+ bibleGenRef.current[kind] += 1;
+ setBibleRows(kind, rows);
+ setBibleStatus((prev) => ({ ...prev, [kind]: 'ready' }));
+ }, [setBibleRows]);
+
+ const retryBible = useCallback((kind) => readBible(kind, workIdRef.current), [readBible]);
+
useEffect(() => {
let active = true;
- Promise.all([
- listWritersRoomCharacters(work.id).catch(() => []),
- listWritersRoomPlaces(work.id).catch(() => []),
- listWritersRoomObjects(work.id).catch(() => []),
- ]).then(([chars, plcs, objs]) => {
- if (!active) return;
- setCharacters(chars || []);
- setPlaces(plcs || []);
- setObjects(objs || []);
- });
- return () => { active = false; };
- }, [work.id]);
+ // The previous work's rosters never stay visible while this one loads.
+ setCharacters([]);
+ setPlaces([]);
+ setObjects([]);
+ Object.keys(BIBLE_READERS).forEach((kind) => { if (active) readBible(kind, work.id); });
+ return () => {
+ active = false;
+ // Invalidate every in-flight read, including a retry started on this work.
+ Object.keys(bibleGenRef.current).forEach((kind) => { bibleGenRef.current[kind] += 1; });
+ };
+ }, [work.id, readBible]);
useEffect(() => { onDirtyChange?.(dirty || polishBusy || !!runningKind); }, [dirty, polishBusy, runningKind, onDirtyChange]);
const wordCount = useMemo(() => countWords(body), [body]);
@@ -645,13 +689,13 @@ export default function WorkEditor({ work, onChange, onToggleExercise, exerciseO
}
toast.success(`${ANALYSIS_LABELS[kind] || kind} complete`);
if (kind === 'characters' && Array.isArray(snapshot.result?.mergedProfiles)) {
- setCharacters(snapshot.result.mergedProfiles);
+ applyBibleRows('characters', snapshot.result.mergedProfiles);
}
if (kind === 'places' && Array.isArray(snapshot.result?.mergedProfiles)) {
- setPlaces(snapshot.result.mergedProfiles);
+ applyBibleRows('places', snapshot.result.mergedProfiles);
}
if (kind === 'objects' && Array.isArray(snapshot.result?.mergedProfiles)) {
- setObjects(snapshot.result.mergedProfiles);
+ applyBibleRows('objects', snapshot.result.mergedProfiles);
}
if (kind === 'format' && snapshot.result?.formattedBody) {
// Apply only if the buffer is untouched since the pass started. Comparing
@@ -666,7 +710,7 @@ export default function WorkEditor({ work, onChange, onToggleExercise, exerciseO
}
}
return true;
- }, [runningKind, work.id, polishBusy, exercisePending]);
+ }, [runningKind, work.id, polishBusy, exercisePending, applyBibleRows]);
// Sequential pipeline for the 3-step storyboard setup. Run characters →
// places → script in order so each later step has the earlier bible to
@@ -1092,6 +1136,8 @@ export default function WorkEditor({ work, onChange, onToggleExercise, exerciseO
characters={characters}
places={places}
objects={objects}
+ bibleStatus={bibleStatus}
+ onRetryBible={retryBible}
onCharactersChange={setCharacters}
onPlacesChange={setPlaces}
onObjectsChange={setObjects}