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

Use MediaImage for media card previews

[._.]/ Adam Eivy50f6ca570fe8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index dfe0bcbe1a..f72e13d179 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -23,6 +23,7 @@
## Fixed
+- **[mediacard-use-mediaimage-for-syncing-assets] Media grid thumbnails now recover cleanly for peer-synced assets.** `MediaCard` now renders previews through `MediaImage`, so a peer-pushed image or video thumbnail that arrives after the record shows the "Syncing" placeholder instead of a broken image and swaps to the real asset when `peerSync:asset-arrived` fires.
- **[catalog-ref-deletion-tombstones] Catalog ingredient unlinks now propagate to federation peers.** Unlinking an ingredient from a universe / series / issue used to hard-DELETE the `catalog_ingredient_refs` row with no `sync_sequence` bump and no tombstone — peers that already pulled the link kept it forever, leaving the "Appears in" panel stale across the federation. The ref table now soft-deletes (new `deleted` / `deleted_at` columns + an UPDATE trigger that bumps `sync_sequence` on delete/revive), `linkIngredientToRef` revives a tombstoned row on re-link, and `upsertRefFromPeer` mirrors remote deletes via `ON CONFLICT DO UPDATE`. `PORTOS_SCHEMA_VERSIONS.catalog` bumps from 1 to 2 so older peers can't push a v1-shaped payload that would silently miss tombstones.
- **[civitai-hidream-qwen-baseModels] Civitai LoRA suggestions now include HiDream and Qwen.** Both runner families existed in `RUNNER_FAMILIES` but were missing from the Civitai `baseModels` search map and the LoRA Manager UI — so every page load logged `Unknown runner family for Civitai search: hidream` / `qwen`, neither family got a "Top for …" section, and any HiDream/Qwen LoRA installed via URL ended up with `runnerFamily=null` (broken compat filter). The two families now map to Civitai's `HiDream` / `Qwen` baseModel strings and render alongside Flux 1, Flux 2, Z-Image, and ERNIE in the suggestions panel.
- **Creative Director long sessions stay fast.** Per-scene render orchestration no longer slows down as a project accumulates more scenes — previously a project could degrade from ~3.5 minutes per scene to 10–30 minutes after a long run, because every render reread and rewrote the full per-project run history as that history grew unbounded. The Runs tab now shows up to 200 of the most recent run entries per project; older completed/failed runs are dropped automatically while every in-flight task is always preserved.
diff --git a/PLAN.md b/PLAN.md
index 79ae11f1b3..0ed0f44d8d 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -36,7 +36,7 @@ The v1 catalog hardcodes six types (`character|place|object|idea|scene|concept`)
_Batch-cleared 2026-05-25: 23 Next Up items shipped together via parallel sub-agents (env-file helper, formatBytes migration, lazy voice UI text, voice long-term-memory routing, voice tool expansion + `ui_describe_visually`, three phosphene generate_ltx2.py hardenings, the peer-sync snapshot-coverage P1 refactor + ephemeralize-then-delete, per-record tombstone-ack clamp, MediaLightbox→MediaImage, global vitest peer mock, videoHistory sync category, reverse-sub UI broadcast, palette Health disambiguation, insertXxxWithId resurrection side-effects, importer tombstone detection, TUI finish-rejection note, mortalLoom errno widen, VideoGen stale-model toast, Universes sidebar grandchildren). See `git log` + `.changelog/NEXT.md`._
-- [ ] [mediacard-use-mediaimage-for-syncing-assets] **`MediaCard.jsx` grid thumbnails still use a raw `<img src={previewUrl}>`.** Same peer-sync placeholder/live-swap gap that `[peer-sync-medialightbox-use-mediaimage-for-syncing-assets]` fixed for the lightbox — `client/src/components/media/MediaCard.jsx` (~line 42) doesn't get the "Syncing" placeholder or the `peerSync:asset-arrived` atomic swap. Swap the raw `<img>` for `MediaImage`. Surfaced by that item's cross-check during the batch-clear (2026-05-25); was outside its stated scope.
+- [x] [mediacard-use-mediaimage-for-syncing-assets] **`MediaCard.jsx` grid thumbnails now use `MediaImage`.** Grid thumbnails show the peer-sync "Syncing" placeholder on missing assets and live-swap when `peerSync:asset-arrived` lands. Shipped 2026-05-30 with a MediaCard regression test.
- [ ] [chrome-canary-followups] **Hardening for the custom-Chrome-binary feature (xhigh code-review 2026-05-25).** _DONE in the v2.10.0 release review: (b) both `spawn()` calls now have `.on('error', …)` listeners; (d) `browser/server.js#loadConfig` now try/catches the `JSON.parse`; (e) `setup-browser.js#loadConfig` now warns + returns `null` and `applyCanaryToConfig` skips the save when the existing config is unreadable; (f) top-level `runCanarySetup()` is now `.catch()`-wrapped. (c) is tracked separately in `[setup-browser-canary-headless]`. Remaining: (a), (g)–(o)._ **High-severity:** (a) On macOS headed mode (the default), `browser/server.js:208` uses `macAppBundle` only and silently ignores `chromePath` — a UI user who fills in `chromePath` for Canary/Chromium/Brave but leaves `macAppBundle` empty gets stock Chrome and the log misreports the binary; couple the two fields in the UI (or auto-derive `macAppBundle` from `chromePath` when the latter is inside a `.app`). (b) Neither `spawn(chromePath, …)` (line 216) nor `spawn('/usr/bin/open', …)` (line 208) has an `.on('error', …)` listener — a typo in `chromePath` emits 'error' with no listener → `uncaughtException` → portos-browser PM2 child crashes and restart-loops. (c) `scripts/setup-browser.js#applyCanaryToConfig` writes `chromePath` + `macAppBundle` but doesn't flip `headless: false`; combined with the seed default of `headless: true` (`data.reference/browser-config.json`), a fresh install accepting Canary runs Canary invisibly. (d) `browser/server.js#loadConfig` does bare `JSON.parse(raw)` with no try/catch — combined with setup-browser's non-atomic `writeFileSync` and the `cachedConfig` race, a partial-file write crashes the supervisor on next start (PM2 restart-loop forever). **Medium-severity:** (e) `setup-browser.js#loadConfig` silently catches all JSON parse errors and returns `{}`, then `applyCanaryToConfig` saves `{chromePath, macAppBundle}` only — wiping every other user-customized key. (f) Top-level `await runCanarySetup()` has no try/catch — any EACCES on data/browser-config.json aborts `npm run setup` / `update.sh` at what was previously a no-op step. (g) Idempotency guard only checks `chromePath`: users who decline get re-prompted on every update, and users who set only `macAppBundle` keep getting re-prompted. (h) `PORTOS_USE_CANARY` only matches literal `'0'`/`'false'` (opt-out) or `'1'`/`'true'` (opt-in) — `'no'`/`'off'`/`'yes'`/`'on'`/`'True'` fall through both branches. (i) `spawnSync(install.cmd, …, { stdio: 'inherit' })` for brew/winget can hang on a sudo password prompt under non-TTY + `PORTOS_USE_CANARY=1` (update.sh stalls). (j) `cachedConfig` in `browserService.js` is stale relative to setup-browser's direct write — GET /api/browser/config returns pre-update values until process restart. (k) `saveConfig` uses bare `writeFileSync` — switch to the canonical `atomicWrite` pattern (`server/lib/fileUtils.js`). **Low-severity:** (l) `spawnSync` failure-status check `result.status !== 0` treats `status: null` (spawn-failure / signal kill) identically to a non-zero exit and never logs `result.error` — masks ENOENT/EPERM/SIGKILL. (m) `optionalPath` Zod schema accepts any string up to 1024 chars; no `.app`/`.exe` sanity check — user pastes the bundle into `chromePath` → spawn() EISDIR. (n) `launchBrowser`'s reuse-existing-Chrome early-return (line 167) fires BEFORE `headlessMode = config.headless === true` (line 170), leaving the module-level default `false` after a PM2 restart that reuses Chrome — /health reports wrong mode (pre-existing, but in a function touched by this change). (o) `detectCanary` on macOS only checks `/Applications/...`; misses per-user `~/Applications/Google Chrome Canary.app` installs (corporate Macs, `HOMEBREW_CASK_OPTS=--appdir=$HOME/Applications`).
- [ ] [strip-malloc-env-ffmpeg-children] **Extend `stripDebugMallocEnv` coverage to ffmpeg child spawns if Pinokio users still see the warning.** The Malloc-strip PR (`[ref-watch-phosphene-strip-malloc-subprocess-env]`) routed every direct Node→Python spawn through `stripDebugMallocEnv`, but ffmpeg children (`server/lib/ffmpeg.js:81`, the ffmpeg/ffprobe calls in `server/services/mediaService.js`, `server/services/videoTimeline/local.js`, and the post-render thumbnail/optimize/upscale paths in `server/services/videoGen/local.js`) still inherit `process.env`. ffmpeg on macOS links libSystem (which includes libmalloc) so it can in principle emit the same `MallocStackLogging: can't turn off…` line — unverified whether it actually does. Trigger: if Pinokio-launched installs still report stderr noise after the Python-spawn fix lands, wrap each ffmpeg spawn `env` the same way. Surfaced by reuse-review subagent during the original PR (2026-05-29).
- [ ] [mediajobqueue-shared-provider-kind-predicate] **Share a `getJobProviderKind(job)` predicate between `getGenModuleForJob` and `resolveLiveParams` in `server/services/mediaJobQueue/index.js`.** Both now encode the same `video | image+codex | image+local` partition by hand (`getGenModuleForJob` at ~line 109, `resolveLiveParams.usesLocalPython` at ~line 122). A shared `getJobProviderKind(job) → 'video-local' | 'image-local' | 'image-codex' | null` would let both branches derive from one predicate and extend cleanly to future providers. Surfaced by reuse-review during the resolveLiveParams extract (2026-05-29); deferred because today's duplication is two lines and the seam is still small.
diff --git a/client/src/components/media/MediaCard.jsx b/client/src/components/media/MediaCard.jsx
index 1fc0544252..10598fe440 100644
--- a/client/src/components/media/MediaCard.jsx
+++ b/client/src/components/media/MediaCard.jsx
@@ -1,4 +1,5 @@
import { Trash2, Download, Film, Image as ImageIcon, Sparkles, Eye, EyeOff, Maximize2, Wand2, Star, MessageSquare } from 'lucide-react';
+import MediaImage from '../MediaImage';
import AddToCollectionMenu from './AddToCollectionMenu';
import { loraDisplayName } from './normalize';
@@ -39,7 +40,7 @@ export default function MediaCard({
className="block w-full aspect-square bg-port-bg relative rounded-t-xl overflow-hidden disabled:cursor-not-allowed disabled:opacity-40"
>
{previewUrl ? (
- <img src={previewUrl} alt={prompt} className="w-full h-full object-cover" loading="lazy" />
+ <MediaImage src={previewUrl} alt={prompt} className="w-full h-full object-cover" loading="lazy" />
) : (
<div className="w-full h-full flex items-center justify-center text-gray-600">
{isVideo ? <Film className="w-10 h-10" /> : <ImageIcon className="w-10 h-10" />}
diff --git a/client/src/components/media/MediaCard.test.jsx b/client/src/components/media/MediaCard.test.jsx
new file mode 100644
index 0000000000..75c1627be6
--- /dev/null
+++ b/client/src/components/media/MediaCard.test.jsx
@@ -0,0 +1,51 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { render, screen, fireEvent, act } from '@testing-library/react';
+import MediaCard from './MediaCard';
+
+const socketHandlers = new Map();
+vi.mock('../../services/socket', () => ({
+ default: {
+ on: vi.fn((event, fn) => {
+ if (!socketHandlers.has(event)) socketHandlers.set(event, new Set());
+ socketHandlers.get(event).add(fn);
+ }),
+ off: vi.fn((event, fn) => {
+ socketHandlers.get(event)?.delete(fn);
+ }),
+ },
+}));
+
+function emitAssetArrived(payload) {
+ for (const fn of socketHandlers.get('peerSync:asset-arrived') ?? []) fn(payload);
+}
+
+const imageItem = {
+ kind: 'image',
+ key: 'image:late.png',
+ filename: 'late.png',
+ previewUrl: '/data/images/late.png',
+ downloadUrl: '/data/images/late.png',
+ prompt: 'late synced image',
+};
+
+beforeEach(() => {
+ socketHandlers.clear();
+});
+
+describe('MediaCard', () => {
+ it('uses MediaImage for grid thumbnails so peer-synced assets show and recover from the syncing placeholder', () => {
+ render(<MediaCard item={imageItem} showCollectionMenu={false} />);
+
+ fireEvent.error(screen.getByAltText('late synced image'));
+ expect(screen.getByText(/Syncing/i)).toBeInTheDocument();
+
+ act(() => {
+ emitAssetArrived({ filename: 'late.png', kind: 'image', peerId: 'peer-a' });
+ });
+
+ expect(screen.queryByText(/Syncing/i)).not.toBeInTheDocument();
+ expect(screen.getByAltText('late synced image').getAttribute('src')).toMatch(
+ /^\/data\/images\/late\.png\?_t=/
+ );
+ });
+});