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

report a board's failed render on its own prop, not onComplete's second argument

[._.]/ Adam Eivy2c88a2e2acfd
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 4e9f4f3dd8..ce85c05177 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -74,4 +74,4 @@
- **The "Pick from Gallery" picker could only be narrowed by typing, so finding one object in one universe meant recalling a word from its prompt.** It now carries two dropdowns beside the search box: a scope select that groups every universe and media collection under `<optgroup>`s, and a type select built from the `entryCategory`/`entryKind` tags the Universe Builder stamps onto sidecars, labelled through the same `humanizeCategory` the Builder uses. Those two are separate vocabularies — a user-authored bucket can legitimately be keyed `canon` — so the type options are prefixed by which field they filter and grouped under Categories/Entry kinds rather than flattened into one list where the bucket and the stage would silently match each other. All three filters AND-combine, and both dropdowns list only universes/collections/types that actually match an image currently in the picker — a scope that can only ever produce an empty grid isn't offered, and a selection that stops matching resets itself to "All" rather than silently blanking the grid. Collection membership is matched on the stored `{ kind, ref }` pair (the same `<kind>:<ref>` string `normalizeImage` puts on `item.key`), not on a bare filename, so a collection holding video refs alongside images filters correctly. Both option fetches are best-effort: if the collections or universes call fails the picker keeps working, falling back to the universe name stamped on each sidecar, and the fetched lists are dropped on close so a reopen can't filter fresh images against stale membership. Sidecars are unvalidated JSON that also arrive from peers, so a tag that isn't a usable string is skipped rather than crashing the render — which surfaced a latent bug in the shared `humanizeCategory`: its label lookup wasn't `hasOwn`-guarded, so a user-authored category keyed `constructor` or `toString` resolved to an inherited function and handed every caller a label that throws on the next string method (#3479).
-- **Composite boards were the only Universe Builder surface with no thumbnail, so a rendered board looked unrendered.** Characters, places, objects and category variations all show their latest render as an `EntryThumbSlot` avatar with a click-to-preview lightbox; the Composites tab showed label + prompt only. Nothing was missing server-side — `compile.js` already stamps an `entryRef` of kind `sheet` on each queued board render and the completion hook already appends the resulting filename to that board's `imageRefs[]`, so the data was sitting in the record with nothing reading it. Composite rows now render through the same `EntryCard` shell + three-state `EntryThumbSlot` the variation and canon rows use (in-flight spinner → rendered thumbnail → empty placeholder with a one-click render button), so their spacing and locked accent can no longer drift from the other surfaces, and clicking a board opens the same page-level lightbox with the real render prompt hydrated from the gallery sidecar. `useRenderJobQueue` had been dropping `sheet`-kind jobs on the grounds that no row consumed them; with every kind the server stamps now settled by a row, the filter is deleted rather than widened — an allowlist that already covers everything can only ever fail closed on the next kind added, silently, with no spinner and no error. Two things this collapsed rather than copied: the row settles through `EntryThumbSlot`'s existing `onComplete` bridge instead of opening a second `useMediaJobProgress` subscription against a jobId the slot is already watching (which is what the variation and canon rows do, at the cost of a row re-render per diffusion tick), and the two page-level job handlers that had each inlined the same append-dedupe-cap now share `appendImageRefById` in `lib/bibleLimits.js`, the client mirror of the server's `mapAppendImageRef` (three other surfaces still inline their own copy). The settle callback is memoized rather than rebuilt per render: `MediaJobThumb` fires its completion effect on `[filename, onFilename]`, so a fresh arrow would re-settle the same job on every keystroke in the builder draft, each one a full gallery refetch — there is a test that fails against the unstable form. Codex review then surfaced the gap that made the whole thing conditional: the draft never adopted the ids the server sanitizer mints, so a board added and rendered in the same session had no `id` to match the one the server stamped onto `entryJobs` — no spinner, no thumbnail until reload, and (now that sheet jobs are tracked) a pending entry with no consumer to clear it. `handleSave` had the server record in hand the whole time and only ever used it for the universe list, so it now adopts the minted ids into both the draft and its dirty baseline — backfilling only the draft would leave the page permanently dirty. That fixes variations, which had the identical latent bug, in the same place rather than special-casing boards. A second review round found the same mismatch in its other shape: on records written before entry ids were persisted at all, `ensureEntryId` mints a fresh uuid on every read, and `POST /render` migrates the record — persisting yet another set — before queueing jobs against it, so the draft is holding ids that exist nowhere. The render flow now reconciles from the persisted record before it enqueues, and the adopt rule is stated as "keep every id the server also has, replace the ones it does not": an id the server has never heard of cannot be the key anything is stored under, while a confirmed id is never re-pointed and so can never be pulled out from under an in-flight job. And a failed board render now says so — `EntryThumbSlot`'s settle bridge carries the terminal status alongside the filename, so the boards can toast the way the variation and canon rows already did instead of just having the spinner vanish, while a user-initiated cancel stays silent.
+- **Composite boards were the only Universe Builder surface with no thumbnail, so a rendered board looked unrendered.** Characters, places, objects and category variations all show their latest render as an `EntryThumbSlot` avatar with a click-to-preview lightbox; the Composites tab showed label + prompt only. Nothing was missing server-side — `compile.js` already stamps an `entryRef` of kind `sheet` on each queued board render and the completion hook already appends the resulting filename to that board's `imageRefs[]`, so the data was sitting in the record with nothing reading it. Composite rows now render through the same `EntryCard` shell + three-state `EntryThumbSlot` the variation and canon rows use (in-flight spinner → rendered thumbnail → empty placeholder with a one-click render button), so their spacing and locked accent can no longer drift from the other surfaces, and clicking a board opens the same page-level lightbox with the real render prompt hydrated from the gallery sidecar. `useRenderJobQueue` had been dropping `sheet`-kind jobs on the grounds that no row consumed them; with every kind the server stamps now settled by a row, the filter is deleted rather than widened — an allowlist that already covers everything can only ever fail closed on the next kind added, silently, with no spinner and no error. Two things this collapsed rather than copied: the row settles through `EntryThumbSlot`'s existing `onComplete` bridge instead of opening a second `useMediaJobProgress` subscription against a jobId the slot is already watching (which is what the variation and canon rows do, at the cost of a row re-render per diffusion tick), and the two page-level job handlers that had each inlined the same append-dedupe-cap now share `appendImageRefById` in `lib/bibleLimits.js`, the client mirror of the server's `mapAppendImageRef` (three other surfaces still inline their own copy). The settle callback is memoized rather than rebuilt per render: `MediaJobThumb` fires its completion effect on `[filename, onFilename]`, so a fresh arrow would re-settle the same job on every keystroke in the builder draft, each one a full gallery refetch — there is a test that fails against the unstable form. Codex review then surfaced the gap that made the whole thing conditional: the draft never adopted the ids the server sanitizer mints, so a board added and rendered in the same session had no `id` to match the one the server stamped onto `entryJobs` — no spinner, no thumbnail until reload, and (now that sheet jobs are tracked) a pending entry with no consumer to clear it. `handleSave` had the server record in hand the whole time and only ever used it for the universe list, so it now adopts the minted ids into both the draft and its dirty baseline — backfilling only the draft would leave the page permanently dirty. That fixes variations, which had the identical latent bug, in the same place rather than special-casing boards. A second review round found the same mismatch in its other shape: on records written before entry ids were persisted at all, `ensureEntryId` mints a fresh uuid on every read, and `POST /render` migrates the record — persisting yet another set — before queueing jobs against it, so the draft is holding ids that exist nowhere. The render flow now reconciles from the persisted record before it enqueues, and the adopt rule is stated as "keep every id the server also has, replace the ones it does not": an id the server has never heard of cannot be the key anything is stored under, while a confirmed id is never re-pointed and so can never be pulled out from under an in-flight job. And a failed board render now says so, the way the variation and canon rows already did, instead of the spinner just vanishing — `EntryThumbSlot` reports the terminal status on a dedicated `onTerminalStatus` prop so a cancel can stay silent. That status deliberately does NOT ride on `onComplete`'s second argument, which was the first thing tried: `useSingleImageRender`'s `handleComplete(filename, key)` is wired straight into that prop by the base-style probe, so a status arriving where it expects a key looked up a job that did not exist, never cleared the real one, and left the probe spinning forever after a perfectly successful render. The full client suite did not catch it — the collision only shows up through a component boundary neither module's tests cross — so `EntryThumbSlot` now asserts `onComplete` is called with exactly one argument, which fails the moment anyone overloads it again.
diff --git a/client/src/components/universe/EntryThumbSlot.jsx b/client/src/components/universe/EntryThumbSlot.jsx
index 70e526a012..f83f260d81 100644
--- a/client/src/components/universe/EntryThumbSlot.jsx
+++ b/client/src/components/universe/EntryThumbSlot.jsx
@@ -29,13 +29,21 @@ export default function EntryThumbSlot({
primaryImageRef = null,
onRender = null,
onPreview = null,
- // Fired as `(filename, status)` when an in-flight job reaches a terminal
- // state, so callers can persist the new ref + clear the in-flight job without
- // their own job subscription. `('<file>', 'completed')` on success;
- // `(null, 'failed' | 'canceled')` on a terminal failure, which carries no
- // filename — the status is what lets a caller tell a failed render (worth
- // surfacing) from a user-initiated cancel (not worth a toast).
+ // Fired with the rendered filename when an in-flight job completes (forwarded
+ // to MediaJobThumb's onFilename) so callers can persist the new ref + clear
+ // the in-flight job without their own job subscription. Called with `null` on
+ // a terminal failure, which yields no filename.
+ //
+ // ONE argument, always. Do not overload the second positional slot with a
+ // status: `useSingleImageRender`'s `handleComplete(filename, key)` is wired
+ // straight into this prop (StyleProbeImage), and a status arriving where it
+ // expects a key re-keys its job map so the in-flight job is never cleared and
+ // the slot spins forever. Terminal status goes to `onTerminalStatus` instead.
onComplete = null,
+ // `('failed' | 'canceled')` when the job terminates without a filename, for
+ // callers that report a failed render. Separate from `onComplete` per the
+ // arity note above; fires after it, so the clear happens first either way.
+ onTerminalStatus = null,
canRender = true,
alt = 'Render',
// `'lg'` renders the empty-state box at 64x96 with a bigger Sparkles
@@ -46,16 +54,17 @@ export default function EntryThumbSlot({
// 1024x1536 universe renders so the slot doesn't crop the subject.
size = 'sm',
}) {
- // Stable identities: MediaJobThumb fires these from effects keyed on
- // `[value, callback]`, so a fresh arrow per render would re-fire the terminal
- // callback on every parent render instead of once when the job settles.
- const onFilename = useCallback(
- (filename) => onComplete?.(filename, 'completed'),
- [onComplete],
- );
+ // MediaJobThumb fires this from an effect keyed on `[effectiveStatus, onStatus]`,
+ // so it must not be a fresh arrow per render or it re-fires on every parent
+ // render instead of once when the job settles. (`onComplete` goes to
+ // `onFilename` unwrapped, so its identity — and arity — stay the caller's.)
const onStatus = useCallback(
- (s) => { if (s === 'failed' || s === 'canceled') onComplete?.(null, s); },
- [onComplete],
+ (s) => {
+ if (s !== 'failed' && s !== 'canceled') return;
+ onComplete?.(null);
+ onTerminalStatus?.(s);
+ },
+ [onComplete, onTerminalStatus],
);
if (inFlightJobId) {
// `xs` (48x80) matches the empty + completed states below so all three
@@ -71,7 +80,7 @@ export default function EntryThumbSlot({
label={alt}
size={pendingSize}
onPreview={onPreview}
- onFilename={onFilename}
+ onFilename={onComplete}
// A terminal failure/cancel never yields a filename, so `onComplete`
// (which clears the in-flight job) would otherwise never fire and the
// job stays pinned. Callers that scope render state per entity keep that
diff --git a/client/src/components/universe/EntryThumbSlot.test.jsx b/client/src/components/universe/EntryThumbSlot.test.jsx
index 96cbc21702..72066eaa67 100644
--- a/client/src/components/universe/EntryThumbSlot.test.jsx
+++ b/client/src/components/universe/EntryThumbSlot.test.jsx
@@ -64,16 +64,43 @@ describe('EntryThumbSlot — three-state thumbnail', () => {
render(<EntryThumbSlot inFlightJobId="job-x" onComplete={onComplete} canRender={false} />);
// Terminal failure yields no filename, so without this the scoped job would
// stay pinned forever (no remount to reset it) and regenerate stays disabled.
- // The status rides along so a caller can tell a failure worth reporting from
- // a user-initiated cancel.
- expect(onComplete).toHaveBeenCalledWith(null, 'failed');
+ expect(onComplete).toHaveBeenCalledWith(null);
});
- it('clears the in-flight job when the render is canceled, tagged as a cancel', () => {
+ it('clears the in-flight job when the render is canceled', () => {
jobStatus = 'canceled';
const onComplete = vi.fn();
render(<EntryThumbSlot inFlightJobId="job-y" onComplete={onComplete} canRender={false} />);
- expect(onComplete).toHaveBeenCalledWith(null, 'canceled');
+ expect(onComplete).toHaveBeenCalledWith(null);
+ });
+
+ // `useSingleImageRender`'s `handleComplete(filename, key)` is wired straight
+ // into `onComplete` (StyleProbeImage), so a second positional argument here is
+ // read as a job key: it would look up `renderingJobs['failed']`, find nothing,
+ // never clear the real job, and leave the slot spinning after every render.
+ // Terminal status therefore goes to its own prop, and `onComplete` stays
+ // strictly one-argument.
+ it('calls onComplete with exactly one argument, reporting status separately', () => {
+ jobStatus = 'failed';
+ const onComplete = vi.fn();
+ const onTerminalStatus = vi.fn();
+ render(
+ <EntryThumbSlot
+ inFlightJobId="job-w"
+ onComplete={onComplete}
+ onTerminalStatus={onTerminalStatus}
+ canRender={false}
+ />,
+ );
+ expect(onComplete.mock.calls[0]).toHaveLength(1);
+ expect(onTerminalStatus).toHaveBeenCalledWith('failed');
+ });
+
+ it('reports a cancel distinctly so callers can stay silent on one', () => {
+ jobStatus = 'canceled';
+ const onTerminalStatus = vi.fn();
+ render(<EntryThumbSlot inFlightJobId="job-v" onTerminalStatus={onTerminalStatus} canRender={false} />);
+ expect(onTerminalStatus).toHaveBeenCalledWith('canceled');
});
it('does NOT clear the in-flight job for non-terminal statuses', () => {
diff --git a/client/src/components/universeBuilder/CompositeSheetsEditor.jsx b/client/src/components/universeBuilder/CompositeSheetsEditor.jsx
index 5912e68ad9..6ff6692d95 100644
--- a/client/src/components/universeBuilder/CompositeSheetsEditor.jsx
+++ b/client/src/components/universeBuilder/CompositeSheetsEditor.jsx
@@ -14,15 +14,16 @@ export default function CompositeSheetsEditor({
// Clicking a board's thumbnail opens the page-level MediaPreview lightbox,
// same as variation / canon rows. Receives the visible filename.
onPreview = null,
- // Per-row render-pending plumbing, mirroring the variation grid:
- // `pendingByEntryId[sheet.id]` is the in-flight jobId (or undefined), and
- // `onJobSettled(sheetId, filename | null, jobId, status)` fires when that job
- // reaches a terminal state so the parent can append the new filename to the
- // board's imageRefs[] and clear the pending entry. A terminal failure/cancel
- // yields no filename, so it settles with `null` on the same callback rather
- // than a second one — the parent's clear path is identical either way, and
- // `status` is what lets it tell a failure worth reporting from a cancel.
- pendingByEntryId = {}, onJobSettled = null,
+ // Per-row render-pending plumbing, mirroring the variation grid.
+ // `pendingByEntryId[sheet.id]` is the in-flight jobId (or undefined).
+ // `onJobSettled(sheetId, filename | null, jobId)` fires when that job reaches
+ // a terminal state, so the parent can append the new filename to the board's
+ // imageRefs[] and clear the pending entry — a failure/cancel yields no
+ // filename and settles with `null`, which is the same clear either way.
+ // `onJobFailed(sheetId, 'failed' | 'canceled')` fires after it, only on a
+ // terminal failure, so the parent can report a failed render without having
+ // to tell one apart from a user-initiated cancel.
+ pendingByEntryId = {}, onJobSettled = null, onJobFailed = null,
}) {
const [adding, setAdding] = useState(false);
const [newKind, setNewKind] = useState('reference_sheet');
@@ -218,6 +219,7 @@ export default function CompositeSheetsEditor({
onPreview={onPreview}
inFlightJobId={pendingByEntryId?.[sheet.id] || null}
onJobSettled={onJobSettled}
+ onJobFailed={onJobFailed}
onToggleLock={() => toggleLockAt(idx)}
onStartEdit={() => startEdit(idx, sheet)}
onRemove={() => removeAt(idx)}
@@ -236,7 +238,7 @@ export default function CompositeSheetsEditor({
// universe surface instead of drifting per editor.
function SheetRow({
sheet, canRender, onRender, onPreview,
- inFlightJobId, onJobSettled,
+ inFlightJobId, onJobSettled, onJobFailed,
onToggleLock, onStartEdit, onRemove,
}) {
const renders = Array.isArray(sheet.imageRefs) ? sheet.imageRefs : [];
@@ -252,9 +254,13 @@ function SheetRow({
// draft) — each one a full listImageGallery() refetch — instead of once when
// the job lands.
const handleSettled = useCallback(
- (filename, status) => onJobSettled?.(sheet.id, filename, inFlightJobId, status),
+ (filename) => onJobSettled?.(sheet.id, filename, inFlightJobId),
[onJobSettled, sheet.id, inFlightJobId],
);
+ const handleFailed = useCallback(
+ (status) => onJobFailed?.(sheet.id, status),
+ [onJobFailed, sheet.id],
+ );
// Three-state thumbnail (pending spinner / rendered image / empty placeholder
// with a one-click render button), matching the variation + canon rows so a
// rendered board reads the same way its characters / places / objects do.
@@ -267,6 +273,7 @@ function SheetRow({
onRender={onRender}
onPreview={onPreview}
onComplete={handleSettled}
+ onTerminalStatus={handleFailed}
/>
);
const title = (
diff --git a/client/src/components/universeBuilder/CompositeSheetsEditor.test.jsx b/client/src/components/universeBuilder/CompositeSheetsEditor.test.jsx
index 5ae6e6443b..51c1abb3a3 100644
--- a/client/src/components/universeBuilder/CompositeSheetsEditor.test.jsx
+++ b/client/src/components/universeBuilder/CompositeSheetsEditor.test.jsx
@@ -92,7 +92,7 @@ describe('CompositeSheetsEditor', () => {
onJobSettled={onJobSettled}
/>,
);
- await waitFor(() => expect(onJobSettled).toHaveBeenCalledWith('sheet-1', 'fresh.png', 'job-9', 'completed'));
+ await waitFor(() => expect(onJobSettled).toHaveBeenCalledWith('sheet-1', 'fresh.png', 'job-9'));
});
// MediaJobThumb fires its onFilename effect on [effectiveFilename, onFilename],
@@ -118,14 +118,35 @@ describe('CompositeSheetsEditor', () => {
it('settles with a null filename on a terminal failure so the parent still clears the pending entry', async () => {
job = { status: 'failed', filename: null, error: 'boom' };
const onJobSettled = vi.fn();
+ const onJobFailed = vi.fn();
render(
<CompositeSheetsEditor
sheets={[sheet({ id: 'sheet-1' })]}
onChange={() => {}}
pendingByEntryId={{ 'sheet-1': 'job-9' }}
onJobSettled={onJobSettled}
+ onJobFailed={onJobFailed}
/>,
);
- await waitFor(() => expect(onJobSettled).toHaveBeenCalledWith('sheet-1', null, 'job-9', 'failed'));
+ await waitFor(() => expect(onJobSettled).toHaveBeenCalledWith('sheet-1', null, 'job-9'));
+ // Reported separately so the parent can toast a failure without having to
+ // tell one apart from a user-initiated cancel.
+ expect(onJobFailed).toHaveBeenCalledWith('sheet-1', 'failed');
+ });
+
+ it('does not report a failure when the job merely completes', async () => {
+ job = { status: 'completed', filename: 'fresh.png', error: null };
+ const onJobFailed = vi.fn();
+ render(
+ <CompositeSheetsEditor
+ sheets={[sheet({ id: 'sheet-1' })]}
+ onChange={() => {}}
+ pendingByEntryId={{ 'sheet-1': 'job-9' }}
+ onJobSettled={vi.fn()}
+ onJobFailed={onJobFailed}
+ />,
+ );
+ await waitFor(() => expect(screen.getByText('Costume sheet')).toBeInTheDocument());
+ expect(onJobFailed).not.toHaveBeenCalled();
});
});
diff --git a/client/src/components/universeBuilder/UniverseBuilderPage.jsx b/client/src/components/universeBuilder/UniverseBuilderPage.jsx
index b91ab532c2..887a3d2e30 100644
--- a/client/src/components/universeBuilder/UniverseBuilderPage.jsx
+++ b/client/src/components/universeBuilder/UniverseBuilderPage.jsx
@@ -293,12 +293,8 @@ export default function UniverseBuilder() {
);
}, [settleEntryJob]);
- // Composite boards on the Composites tab. A failed render is reported the same
- // way the variation and canon rows report theirs — otherwise the spinner just
- // vanishes and the user is left guessing. A user-initiated cancel is not a
- // failure, so it settles silently.
- const handleSheetJobSettled = useCallback((sheetId, filename, settledJobId = null, status = null) => {
- if (!filename && status === 'failed') toast.error('Render failed');
+ // Composite boards on the Composites tab.
+ const handleSheetJobSettled = useCallback((sheetId, filename, settledJobId = null) => {
settleEntryJob(
sheetId,
filename,
@@ -308,6 +304,13 @@ export default function UniverseBuilder() {
);
}, [settleEntryJob]);
+ // A failed board render is reported the same way the variation and canon rows
+ // report theirs — otherwise the spinner just vanishes and the user is left
+ // guessing. A user-initiated cancel is not a failure, so it stays silent.
+ const handleSheetJobFailed = useCallback((_sheetId, status) => {
+ if (status === 'failed') toast.error('Render failed');
+ }, []);
+
return (
<div className="flex flex-col h-full">
<section className="flex-1 flex flex-col gap-3 p-4 min-h-0 overflow-y-auto">
@@ -492,6 +495,7 @@ export default function UniverseBuilder() {
onPreview={openPreviewByFilename}
pendingByEntryId={pendingHeadByEntryId}
onJobSettled={handleSheetJobSettled}
+ onJobFailed={handleSheetJobFailed}
/>
{/* Add-bucket row stays available here for power users who want to
introduce a brand-new custom bucket without going through