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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
simplify (claude): drop STALE sentinel, expose ctx.queuedAt, reuse onFailed/onCompleted for canceled
[._.]/ Adam Eivyf89301de743a
diff --git a/client/src/components/writers-room/LiveRenderPanel.jsx b/client/src/components/writers-room/LiveRenderPanel.jsxindex 304d98dbd3..3a3a2c5ce0 100644--- a/client/src/components/writers-room/LiveRenderPanel.jsx+++ b/client/src/components/writers-room/LiveRenderPanel.jsx@@ -117,15 +117,6 @@ export default function LiveRenderPanel({pendingJobRef.current = null;if (mountedRef.current) setGenStatus('idle');};- // A canceled render (e.g. dropped from the Media Jobs queue) emits no- // *:failed when it was still queued — clear the in-flight state on the- // bridged `image-gen:canceled` so "Rendering…" doesn't stick (#1791).- const onCanceled = (data) => {- const job = pendingJobRef.current;- if (!job || data.generationId !== job.jobId) return;- pendingJobRef.current = null;- if (mountedRef.current) setGenStatus('idle');- };// The hook fires `writers-room:scene-image` once an async render lands on the// analysis snapshot — fold that entry up so the boards update reactively.// Gate on workId (the event is broadcast to every client); the downstream@@ -138,12 +129,16 @@ export default function LiveRenderPanel({};socket.on('image-gen:completed', onCompleted);socket.on('image-gen:failed', onFailed);- socket.on('image-gen:canceled', onCanceled);+ // A canceled render (e.g. dropped from the Media Jobs queue) clears the+ // in-flight state exactly like a failure — and a queued-then-canceled job+ // emits no *:failed, so this is the only signal that clears "Rendering…"+ // for it (#1791). Reuse onFailed rather than duplicate its body.+ socket.on('image-gen:canceled', onFailed);socket.on('writers-room:scene-image', onSceneImage);return () => {socket.off('image-gen:completed', onCompleted);socket.off('image-gen:failed', onFailed);- socket.off('image-gen:canceled', onCanceled);+ socket.off('image-gen:canceled', onFailed);socket.off('writers-room:scene-image', onSceneImage);};// The job snapshot is read from pendingJobRef (set at kickoff); the attachdiff --git a/client/src/pages/MusicVideo.jsx b/client/src/pages/MusicVideo.jsxindex 3cef092d21..75424d0f30 100644--- a/client/src/pages/MusicVideo.jsx+++ b/client/src/pages/MusicVideo.jsx@@ -100,20 +100,18 @@ export default function MusicVideo() {};const onCompleted = (data) => settle(data, false);const onFailed = (data) => settle(data, true);- // A canceled render (e.g. dropped from the Media Jobs queue) clears the- // scene spinner with no failure toast — settle as a non-failure (#1791).- // A queued-then-canceled job emits no *:failed, so without this the- // "Rendering…" button sticks until the page remounts.- const onCanceled = (data) => settle(data, false);socket.on('music-video:scene-image', onSceneImage);socket.on('image-gen:completed', onCompleted);socket.on('image-gen:failed', onFailed);- socket.on('image-gen:canceled', onCanceled);+ // A canceled render clears the scene spinner with no failure toast — same as+ // a completion (settle false). A queued-then-canceled job emits no *:failed,+ // so this is the only signal that clears its "Rendering…" button (#1791).+ socket.on('image-gen:canceled', onCompleted);return () => {socket.off('music-video:scene-image', onSceneImage);socket.off('image-gen:completed', onCompleted);socket.off('image-gen:failed', onFailed);- socket.off('image-gen:canceled', onCanceled);+ socket.off('image-gen:canceled', onCompleted);};}, []);diff --git a/server/lib/createNewestWinsGuard.js b/server/lib/createNewestWinsGuard.jsindex eb55277266..c76c4f4254 100644--- a/server/lib/createNewestWinsGuard.js+++ b/server/lib/createNewestWinsGuard.js@@ -23,6 +23,14 @@** In-memory and best-effort: lost on restart, which is fine for the bookkeeping* it guards. Carries `.clear()` for test reset.+ *+ * The `latest` Map is NOT self-pruning (unlike `createKeyCachedQueue`'s tail+ * Map) — it retains one entry (`key → ~24-char ISO string`) per distinct slot+ * ever marked, for the process lifetime. The cardinality is the number of scene+ * slots rendered (per-scene / per-ingredient), which is human-scale for a+ * single-user install, so the growth is a non-issue in practice. If a future+ * caller needs bounded memory, add a `.forget(key)` and call it from the same+ * deletion path that drops the underlying record.*/export function createNewestWinsGuard() {const latest = new Map();diff --git a/server/services/catalogImageAttachHook.js b/server/services/catalogImageAttachHook.jsindex da7a2b4a4c..8cd5985f9c 100644--- a/server/services/catalogImageAttachHook.js+++ b/server/services/catalogImageAttachHook.js@@ -83,11 +83,8 @@ const hook = createMediaJobImageHook({// ingredient don't both read an empty media list, both pick 'portrait', and// have the second demote the first. Different ingredients attach concurrently.serializeKey: ({ ingredientId }) => ingredientId,- attach: ({ ingredientId, tag, filename, job }) => attachGeneratedImage({- ingredientId,- kind: tag.kind,- filename,- queuedAt: typeof job.queuedAt === 'string' ? job.queuedAt : null,+ attach: ({ ingredientId, tag, filename, queuedAt }) => attachGeneratedImage({+ ingredientId, kind: tag.kind, filename, queuedAt,}),onAttached: ({ ingredientId, filename }, status) => {if (status === 'portrait' || status === 'reference') {diff --git a/server/services/mediaJobImageHook.js b/server/services/mediaJobImageHook.jsindex 7a2f409128..33c1a5e598 100644--- a/server/services/mediaJobImageHook.js+++ b/server/services/mediaJobImageHook.js@@ -53,11 +53,6 @@ import { mediaJobEvents } from './mediaJobQueue/index.js';import { createKeyCachedQueue } from '../lib/createKeyCachedQueue.js';import { createNewestWinsGuard } from '../lib/createNewestWinsGuard.js';-// Sentinel a guard'd attach returns to mean "dropped as stale" — distinct from-// a null result (attach declined / failed) so the caller skips onAttached for both-// but the guard never records a queuedAt for a render it dropped.-const STALE = Symbol('stale-render-dropped');-export function createMediaJobImageHook(config) {const {label,@@ -86,7 +81,11 @@ export function createMediaJobImageHook(config) {if (!identity) return null;const filename = job.result?.filename;if (!filename || typeof filename !== 'string') return null;- return { ...identity, job, tag, filename };+ // Normalize queuedAt once here so the guard below AND any consumer's attach+ // (e.g. catalog's portrait guard) read the same `ctx.queuedAt` instead of+ // re-deriving it.+ const queuedAt = typeof job.queuedAt === 'string' ? job.queuedAt : null;+ return { ...identity, job, tag, filename, queuedAt };}function init() {@@ -99,25 +98,25 @@ export function createMediaJobImageHook(config) {const ctx = decode(job);if (!ctx) return;const sKey = sceneKey ? sceneKey(ctx) : null;- const queuedAt = typeof job.queuedAt === 'string' ? job.queuedAt : null;const result = await serialize(serializeKey(ctx), async () => {// Newest-render-wins: drop an out-of-order older render so it can't- // clobber a newer frame on the same scene slot. Checked + recorded- // inside the serialize section so the read/write pair never races.- if (sKey && guard.isStale(sKey, queuedAt)) return STALE;+ // clobber a newer frame on the same scene slot (returns null, the same+ // "nothing applied" signal as a declined/failed attach). Checked ++ // recorded inside the serialize section so the read/write never races.+ if (sKey && guard.isStale(sKey, ctx.queuedAt)) return null;const r = await attach(ctx);// Only record the slot's newest queuedAt once the attach actually// applied — a failed attach (null) must not advance the guard, or a// later legitimate render would be wrongly dropped as stale.- if (sKey && r != null) guard.mark(sKey, queuedAt);+ if (sKey && r != null) guard.mark(sKey, ctx.queuedAt);return r;}).catch((err) => {console.log(`⚠️ ${label} hook failed for ${ctx.filename}: ${err?.message || String(err)}`);return null;});- if (result !== STALE && result != null) onAttached(ctx, result);+ if (result != null) onAttached(ctx, result);})().catch((err) => {// Last-resort net for synchronous throws (unexpected job shape, etc).console.log(`⚠️ ${label} hook crashed: ${err?.message || err}`);