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

address review (codex): recover catalog thumb + Generate from transient/terminal failures

[._.]/ Adam Eivyf25d624a12cf
diff --git a/client/src/pages/Catalog.jsx b/client/src/pages/Catalog.jsx
index 98ffea4a91..61e13d07cb 100644
--- a/client/src/pages/Catalog.jsx
+++ b/client/src/pages/Catalog.jsx
@@ -19,6 +19,7 @@ import {
getCatalogStats,
rerunCatalogMigration,
} from '../services/apiCatalog';
+import MediaImage from '../components/MediaImage';
import { payloadSnippet } from '../lib/catalogTypes';
import { useCatalogTypes } from '../hooks/useCatalogTypes.jsx';
@@ -38,21 +39,20 @@ function TypeBadge({ type, getType }) {
}
// Card thumbnail: the ingredient's portrait (or most recent reference image),
-// resolved from the media library at /data/images/<key>. Falls back to a dimmed
-// Sparkles placeholder when there's no image or the file fails to load, so every
-// card keeps the same footprint and the grid stays aligned.
+// resolved from the media library at /data/images/<key>. With no image we show a
+// dimmed Sparkles placeholder; with one we render through <MediaImage>, which
+// tolerates a not-yet-arrived peer asset (shows "Syncing" and auto-swaps to the
+// live image on the asset-arrived event) instead of permanently breaking on a
+// transient 404. Either way the slot keeps a fixed footprint so the grid aligns.
function CardThumb({ mediaKey, alt }) {
- const [failed, setFailed] = useState(false);
- const showImage = !!mediaKey && !failed;
return (
<div className="w-14 h-14 shrink-0 rounded-md overflow-hidden border border-port-border bg-port-bg flex items-center justify-center">
- {showImage ? (
- <img
+ {mediaKey ? (
+ <MediaImage
src={`/data/images/${mediaKey}`}
alt={alt}
className="w-full h-full object-cover"
loading="lazy"
- onError={() => setFailed(true)}
/>
) : (
<Sparkles size={18} className="text-gray-600" aria-hidden="true" />
diff --git a/client/src/pages/Catalog.test.jsx b/client/src/pages/Catalog.test.jsx
index 2ce9eaaab9..34252bcafe 100644
--- a/client/src/pages/Catalog.test.jsx
+++ b/client/src/pages/Catalog.test.jsx
@@ -20,6 +20,12 @@ vi.mock('../services/apiCatalogTypes', () => ({
listCatalogTypes: vi.fn(),
}));
+// MediaImage pulls in the socket service; stub it to a plain <img> so the card
+// thumbnail's src/alt are assertable without the socket wiring.
+vi.mock('../components/MediaImage', () => ({
+ default: ({ src, alt, ...rest }) => <img src={src} alt={alt} {...rest} />,
+}));
+
import Catalog from './Catalog';
import {
listCatalogIngredients,
diff --git a/client/src/pages/CatalogIngredient.jsx b/client/src/pages/CatalogIngredient.jsx
index e555a22641..2afebb9758 100644
--- a/client/src/pages/CatalogIngredient.jsx
+++ b/client/src/pages/CatalogIngredient.jsx
@@ -884,10 +884,21 @@ function GenerateImageControl({ name, description, onComplete }) {
onComplete?.(filename);
}, [onComplete]);
+ // A failed/canceled render never fires onFilename, so without this the button
+ // would stay disabled+"Generating…" with no retry path. Clear the job on a
+ // terminal non-success status to re-enable Generate.
+ const handleStatus = useCallback((status) => {
+ if (status === 'failed' || status === 'canceled') {
+ setJobId(null);
+ if (status === 'failed') toast.error('Image generation failed');
+ }
+ }, []);
+
return (
<span className="inline-flex items-center gap-2">
{jobId && (
- <MediaJobThumb jobId={jobId} label="Generated image" size="xs" onFilename={handleFilename} />
+ <MediaJobThumb jobId={jobId} label="Generated image" size="xs"
+ onFilename={handleFilename} onStatus={handleStatus} />
)}
<button
type="button"
diff --git a/client/src/pages/CatalogIngredient.test.jsx b/client/src/pages/CatalogIngredient.test.jsx
index 1f2dbee02f..f56e0f8c27 100644
--- a/client/src/pages/CatalogIngredient.test.jsx
+++ b/client/src/pages/CatalogIngredient.test.jsx
@@ -77,8 +77,14 @@ vi.mock('../services/apiSystem', () => ({ generateImage: vi.fn() }));
// handed in, simulating a completed render without the socket/job machinery.
vi.mock('../components/pipeline/MediaJobThumb', async () => {
const { useEffect } = await import('react');
- function MockMediaJobThumb({ jobId, onFilename }) {
- useEffect(() => { if (jobId && onFilename) onFilename(`${jobId}.png`); }, [jobId, onFilename]);
+ // A jobId of 'fail-job' simulates a failed render (drives onStatus); any other
+ // id simulates a completed render (drives onFilename).
+ function MockMediaJobThumb({ jobId, onFilename, onStatus }) {
+ useEffect(() => {
+ if (!jobId) return;
+ if (jobId === 'fail-job') onStatus?.('failed');
+ else onFilename?.(`${jobId}.png`);
+ }, [jobId, onFilename, onStatus]);
return null;
}
return { default: MockMediaJobThumb };
@@ -199,6 +205,21 @@ describe('CatalogIngredient — character sheet', () => {
));
});
+ it('re-enables Generate after a failed render (does not get stuck)', async () => {
+ const { generateImage } = await import('../services/apiSystem');
+ generateImage.mockResolvedValue({ jobId: 'fail-job' });
+ renderPage();
+ await waitFor(() => expect(screen.getByDisplayValue('Sharp eyes, ink-stained cuffs.')).toBeTruthy());
+
+ fireEvent.click(screen.getByRole('button', { name: /^Generate$/i }));
+ // The MediaJobThumb stub drives onStatus('failed') for 'fail-job'; the
+ // control must clear the job and re-enable rather than hang on "Generating…".
+ await waitFor(() => {
+ const btn = screen.getByRole('button', { name: /^Generate$/i });
+ expect(btn).toHaveProperty('disabled', false);
+ });
+ });
+
it('disables Generate when the ingredient has no description text', async () => {
getCatalogIngredientDetails.mockImplementation(async () => detailsOf({
...CHAR_FIXTURE,