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
fix: close the routed-job downgrade hole on boot restore, and stop losing the routed prompt (#4683)
[._.]/ Adam Eivyfddff3a4046c
diff --git a/server/lib/federatedMediaWire.js b/server/lib/federatedMediaWire.jsindex 98b9ceb2a9..6a1650f4e7 100644--- a/server/lib/federatedMediaWire.js+++ b/server/lib/federatedMediaWire.js@@ -54,6 +54,32 @@ export function renderFederatedMediaAudioPrompt(profile) {return `Instrumental ${words(style)} music with a ${mood} mood, ${tempo} tempo, ${energy} energy${instrumentation}. No vocals or spoken words.`;}+/**+ * The prompt a finished media job actually rendered from.+ *+ * A routed job's top-level `params.prompt` is deliberately blank — that is what+ * makes it unrenderable by a build rolled back past `remoteMedia` (#4683) — so+ * anything recording what was rendered (completion hooks, the public queue+ * projection) must read the marker instead. Audio renders it from the+ * fixed-vocabulary profile, since free-form personal text never reaches an audio+ * provider at all; image and video carry the submitted prompt itself.+ *+ * Returns `null` only when there is no prompt to report, so callers can tell+ * "nothing was recorded" apart from "rendered with an empty prompt".+ *+ * @param {object} job - A media job (or anything with `.params`).+ * @returns {string|null}+ */+export function effectiveJobPrompt(job) {+ const marker = job?.params?.remoteMedia;+ if (marker) {+ const audioPrompt = renderFederatedMediaAudioPrompt(marker.profile);+ if (audioPrompt) return audioPrompt;+ if (typeof marker.request?.prompt === 'string') return marker.request.prompt;+ }+ return typeof job?.params?.prompt === 'string' ? job.params.prompt : null;+}+/*** Validate that a prompt string conforms to the canonical federated audio grammar.* Provider-side validation receives only the rendered text (not the local profile)diff --git a/server/lib/federatedMediaWire.test.js b/server/lib/federatedMediaWire.test.jsindex dbb0b83463..af06ca192c 100644--- a/server/lib/federatedMediaWire.test.js+++ b/server/lib/federatedMediaWire.test.js@@ -3,6 +3,7 @@ import {federatedMediaAudioProfileSchema,federatedMediaProviderStatusSchema,federatedMediaProviderJobSchema,+ effectiveJobPrompt,isFederatedMediaAudioPrompt,normalizeRequestedMediaKinds,renderFederatedMediaAudioPrompt,@@ -146,3 +147,44 @@ describe('federated media privacy-safe audio profiles', () => {expect(renderFederatedMediaAudioPrompt({ ...profile, mood: 'a named person' })).toBeNull();});});++describe('effectiveJobPrompt', () => {+ it('reads a routed job through to the wire request, not the blanked params', () => {+ // A routed job's top-level prompt is blank on purpose (#4683). Anything+ // recording what was rendered must read the marker, or it files a finished+ // render with no prompt at all.+ expect(effectiveJobPrompt({+ kind: 'image',+ params: {+ prompt: '',+ remoteMedia: { wireVersion: 1, request: { kind: 'image', modelId: 'dev', prompt: 'a lighthouse at dusk' } },+ },+ })).toBe('a lighthouse at dusk');+ });++ it('renders an audio job from its fixed-vocabulary profile', () => {+ expect(effectiveJobPrompt({+ kind: 'audio',+ params: {+ prompt: '',+ remoteMedia: {+ wireVersion: 1,+ profile: { style: 'ambient', mood: 'calm', tempo: 'slow', energy: 'low', instruments: [] },+ request: { engine: 'remote-audio', modelId: 'example/model' },+ },+ },+ })).toBe('Instrumental ambient music with a calm mood, slow tempo, low energy. No vocals or spoken words.');+ });++ it('returns a local job\'s own prompt untouched', () => {+ expect(effectiveJobPrompt({ kind: 'image', params: { prompt: 'a fox' } })).toBe('a fox');+ });++ it('distinguishes no prompt at all from a legitimately empty one', () => {+ expect(effectiveJobPrompt({ kind: 'image', params: {} })).toBeNull();+ expect(effectiveJobPrompt(undefined)).toBeNull();+ // An img2img render genuinely has no text — that is an empty string, not+ // "nothing was recorded".+ expect(effectiveJobPrompt({ kind: 'image', params: { prompt: '' } })).toBe('');+ });+});diff --git a/server/routes/videoGen.js b/server/routes/videoGen.jsindex 64bd15fd85..d524f7221a 100644--- a/server/routes/videoGen.js+++ b/server/routes/videoGen.js@@ -69,6 +69,7 @@ import { saveUploadedGalleryVideo } from '../services/videoUpload.js';import { JSON_BODY_LIMIT_BYTES } from '../lib/uploadLimits.js';import { createInstallLogger } from '../lib/installLogger.js';import { prepareRemoteMediaJob } from '../services/federatedMedia/remoteSubmission.js';+import { effectiveJobPrompt } from '../lib/federatedMediaWire.js';const router = Router();@@ -1266,6 +1267,17 @@ const pickJobParams = (params) => {out.icReferenceImageFiles = names;}}+ // A federated render's prompt and model live only inside the versioned marker+ // — the top-level copies are blanked so a downgraded build fails closed+ // (#4683). Read through to the wire request, as the queue's own projection+ // does, or a page reload mid-render resumes the form with an empty prompt and+ // the LOCAL default model instead of the peer's.+ if (params.remoteMedia) {+ const prompt = effectiveJobPrompt({ params });+ if (typeof prompt === 'string') out.prompt = prompt;+ const { modelId } = params.remoteMedia.request ?? {};+ if (typeof modelId === 'string' && modelId) out.modelId = modelId;+ }return out;};diff --git a/server/routes/videoGen.test.js b/server/routes/videoGen.test.jsindex d1bfac720e..e8d430a1b4 100644--- a/server/routes/videoGen.test.js+++ b/server/routes/videoGen.test.js@@ -1958,6 +1958,37 @@ describe('videoGen routes', () => {expect(r.body.activeJob.params.prompt).toBe('P running');});+ it('resumes a federated render from its marker, not the blanked local fields', async () => {+ // The routed job's top-level prompt/model are blanked so a downgraded+ // build fails closed (#4683). Without reading through to the wire+ // request, a reload mid-render would repopulate the form with an empty+ // prompt and the LOCAL default model instead of the peer's.+ mediaJobQueue.listJobs.mockImplementation(listJobsByFilter([{+ id: 'remote-running',+ kind: 'video',+ status: 'running',+ position: 1,+ params: {+ prompt: '',+ modelId: null,+ pythonPath: null,+ remoteMedia: {+ wireVersion: 1,+ peerId: federatedPeerId,+ request: {+ kind: 'video', engine: 'local', modelId: 'ltx2', prompt: 'a slow pan across a harbour',+ },+ },+ },+ }]));+ const r = await request(app).get('/api/video-gen/active');+ expect(r.status).toBe(200);+ expect(r.body.activeJob.params.prompt).toBe('a slow pan across a harbour');+ expect(r.body.activeJob.params.modelId).toBe('ltx2');+ // The marker itself stays off this surface — it carries peer routing state.+ expect(r.body.activeJob.params).not.toHaveProperty('remoteMedia');+ });+// Selection of the newest queued (not oldest) matches /cancel's fallback// selection — see the surrounding comment in routes/videoGen.js. Diverging// would mean Cancel from a resumed-queued page targets a different job.diff --git a/server/services/mediaJobQueue/index.js b/server/services/mediaJobQueue/index.jsindex 2b30702193..e6ca3fba76 100644--- a/server/services/mediaJobQueue/index.js+++ b/server/services/mediaJobQueue/index.js@@ -71,6 +71,16 @@ const jobLane = (job) => {return 'gpu';};+// Boot restoration is the second way a job enters the queue, so it needs the+// same routed-job normalization enqueueJob applies (#4683). A job written by a+// build older than that fix still carries the top-level model id a legacy+// dispatcher would render from; re-normalizing on restore (and letting the boot+// persist write the safe shape back) means upgrading and then rolling back+// cannot resurrect a locally-renderable routed job.+const restoredParams = (job) => (isRemoteMediaJob(job)+ ? routedJobParams({ params: job.params })+ : job.params);+const JOBS_FILE = join(PATHS.data, 'media-jobs.json');const COMPLETED_TTL_MS = 24 * 60 * 60 * 1000;const MAX_PERSISTED_ARCHIVE = 500;@@ -403,13 +413,16 @@ export async function initMediaJobQueue() {...j,status: 'queued',cancelRequested: marker?.cancelRequested === true,- params: {- ...j.params,- remoteMedia: {- ...(marker && typeof marker === 'object' && !Array.isArray(marker) ? marker : {}),- reconcile: true,+ params: restoredParams({+ ...j,+ params: {+ ...j.params,+ remoteMedia: {+ ...(marker && typeof marker === 'object' && !Array.isArray(marker) ? marker : {}),+ reconcile: true,+ },},- },+ }),});console.log(`🔁 media-job [${j.id.slice(0, 8)}] remote ${j.kind} interrupted — re-enqueued for reconciliation`);continue;@@ -448,7 +461,7 @@ export async function initMediaJobQueue() {safeUnlinkUpload(p);}} else if (j.status === 'queued') {- queue.push({ ...j });+ queue.push({ ...j, params: restoredParams(j) });} else {archive.push(j);}diff --git a/server/services/mediaJobQueue/index.test.js b/server/services/mediaJobQueue/index.test.jsindex 820fcdfcda..d7c80d0bb6 100644--- a/server/services/mediaJobQueue/index.test.js+++ b/server/services/mediaJobQueue/index.test.js@@ -910,6 +910,50 @@ describe('Audio kind (#1928)', () => {expect(stubs.generateImage).not.toHaveBeenCalled();});+ it('re-normalizes a routed job restored from a snapshot an older build wrote', async () => {+ // Boot restoration is the second way a job enters the queue. A record+ // persisted before #4683 still carries the top-level model id a legacy+ // dispatcher would render from, so upgrading and then rolling back would+ // otherwise resurrect a locally-renderable job.+ writeFileSync(join(tempDataDir, 'media-jobs.json'), JSON.stringify({+ jobs: [+ {+ id: 'aaaaaaaa-0000-4000-8000-000000000001',+ kind: 'image',+ status: 'queued',+ queuedAt: '2026-08-01T00:00:00.000Z',+ params: {+ prompt: 'a harbour', modelId: 'dev', pythonPath: '/usr/bin/python3',+ remoteMedia: remoteImageMediaParams(),+ },+ },+ {+ id: 'aaaaaaaa-0000-4000-8000-000000000002',+ kind: 'image',+ status: 'running',+ queuedAt: '2026-08-01T00:00:00.000Z',+ params: {+ prompt: 'a harbour', modelId: 'dev', pythonPath: '/usr/bin/python3',+ remoteMedia: remoteImageMediaParams(),+ },+ },+ ],+ }));+ stubs.generateImageRemote.mockImplementation(() => new Promise(() => {}));+ await importFresh();+ await mediaJobQueue.initMediaJobQueue();++ for (const id of ['aaaaaaaa-0000-4000-8000-000000000001', 'aaaaaaaa-0000-4000-8000-000000000002']) {+ const { params } = mediaJobQueue.getJob(id);+ expect(params.prompt).toBe('');+ expect(params.modelId).toBeNull();+ expect(params.pythonPath).toBeNull();+ expect(params.remoteMedia.request.prompt).toBe('a harbour');+ }+ // The interrupted running job still gets its reconcile flag.+ expect(mediaJobQueue.getJob('aaaaaaaa-0000-4000-8000-000000000002').params.remoteMedia.reconcile).toBe(true);+ });+it('leaves a training job carrying a stray marker on the local path', () => {// Bypass probe for the normalization above: `training` has no federated// contract, so a marker on one is corrupt state — blanking its params woulddiff --git a/server/services/mediaJobQueue/sanitizeJob.js b/server/services/mediaJobQueue/sanitizeJob.jsindex 99a2285c29..f5924836f8 100644--- a/server/services/mediaJobQueue/sanitizeJob.js+++ b/server/services/mediaJobQueue/sanitizeJob.js@@ -1,4 +1,4 @@-import { renderFederatedMediaAudioPrompt } from '../../lib/federatedMediaWire.js';+import { effectiveJobPrompt } from '../../lib/federatedMediaWire.js';import { isRemoteMediaJob } from './remoteMediaJob.js';// Public projection of a media job. Keep worker-only paths and subprocess@@ -33,16 +33,13 @@ export function sanitizeJob(job) {// in top-level params — that is what makes an older build (which cannot route// the marker) fail closed instead of quietly re-rendering the job locally.// Rebuild the prompt for the public projection without exposing private peer- // routing state. Audio renders it from the fixed-vocabulary profile (free-form- // personal text never reaches an audio provider at all); image and video carry- // the submitted prompt itself.- const remotePrompt = renderFederatedMediaAudioPrompt(job.params?.remoteMedia?.profile)- ?? (typeof job.params?.remoteMedia?.request?.prompt === 'string'- ? job.params.remoteMedia.request.prompt : null);+ // routing state.+ const remotePrompt = effectiveJobPrompt(job);// The model id is nulled in top-level params for the same reason (#4683), so// rebuild it from the marker too — the Render Queue's model badge reads- // `params.modelId`. Audio carries no wire model id and keeps whatever the- // local engine recorded.+ // `params.modelId`, and every routed kind (audio included: routes/music.js+ // requires an explicit `modelId` for a peer render) carries it on the wire+ // request. This branch is now the ONLY source of a routed job's model id.const routed = isRemoteMediaJob(job);const remoteModelId = job.params?.remoteMedia?.request?.modelId;if (safeParams && routed) {diff --git a/server/services/mediaJobQueue/sanitizeJob.test.js b/server/services/mediaJobQueue/sanitizeJob.test.jsindex 57bf8a8e86..1e34339e7c 100644--- a/server/services/mediaJobQueue/sanitizeJob.test.js+++ b/server/services/mediaJobQueue/sanitizeJob.test.js@@ -55,8 +55,11 @@ describe('sanitizeJob', () => {kind: 'audio',status: 'queued',params: {+ // Blank/nulled by routedJobParams, exactly as the queue persists it —+ // if the fixture carried the model id here too, the marker rebuild+ // below could stop working and this test would still pass.prompt: '',- modelId: 'example/model',+ modelId: null,remoteMedia: {wireVersion: 1,peerId: '00000000-0000-4000-8000-000000000001',diff --git a/server/services/sprites/reference.js b/server/services/sprites/reference.jsindex 484e754648..3d51232279 100644--- a/server/services/sprites/reference.js+++ b/server/services/sprites/reference.js@@ -58,6 +58,7 @@ import {import {analyzeForeground, paletteFromAnalysis, normalizeFromAnalysis, recompositeOnKey,} from './normalize.js';+import { effectiveJobPrompt } from '../../lib/federatedMediaWire.js';// Default i2i strengths: a render that redraws a NEW figure from the frozen// sheet (every anchor, and the main in the turnaround-first flow) mostly@@ -812,12 +813,19 @@ export async function attachReferenceCandidate(ctx) {// Prefer the completed job's live params — Render Queue's Edit & Retry// rewrites top-level params but carries the original tag through, so the// tag's model can be stale provenance.- model: ctx.job?.params?.model || ctx.job?.params?.modelId || ctx.model || null,+ // A federated render nulls the top-level model and blanks the prompt to+ // fail closed on a downgrade (#4683), so read through to the wire request+ // before falling back — otherwise the sidecar records no provenance at all.+ model: ctx.job?.params?.model+ || ctx.job?.params?.modelId+ || ctx.job?.params?.remoteMedia?.request?.modelId+ || ctx.model+ || null,// The literal prompt sent to the provider — the completed job's live params// are canonical (Render Queue's Edit & Retry can rewrite it). Persisting it// lets the preview modals show exactly what was rendered; older sidecars// without it fall back to a deterministic rebuild (services/sprites/assetPrompt.js).- prompt: ctx.job?.params?.prompt || null,+ prompt: effectiveJobPrompt(ctx.job) || null,jobId: ctx.jobId || null,...(ctx.designPrompt ? { designPrompt: ctx.designPrompt } : {}),...(ctx.correctionPrompt ? { correctionPrompt: ctx.correctionPrompt } : {}),diff --git a/server/services/writersRoomSceneImageHook.js b/server/services/writersRoomSceneImageHook.jsindex af9b58fd11..330b5754e3 100644--- a/server/services/writersRoomSceneImageHook.js+++ b/server/services/writersRoomSceneImageHook.js@@ -28,14 +28,17 @@import { createMediaJobImageHook } from './mediaJobImageHook.js';import { persistSceneImage } from './writersRoom/evaluator.js';import { writersRoomEvents } from './writersRoomEvents.js';+import { effectiveJobPrompt } from '../lib/federatedMediaWire.js';// The render filename is `${jobId}.png`; prefer the job id, fall back to// stripping the extension so the attach records a stable jobId either way.const deriveJobId = (job, filename) =>(typeof job.id === 'string' && job.id ? job.id : filename.replace(/\.png$/, ''));// The gen prompt IS the scene prompt (buildScenePrompt output), so record it on-// the attach without the tag having to carry a duplicate copy.-const derivePrompt = (job) => (typeof job.params?.prompt === 'string' ? job.params.prompt : null);+// the attach without the tag having to carry a duplicate copy. A federated+// render blanks top-level `prompt` to fail closed on a downgrade (#4683), so+// read through to the marker rather than saving the scene an empty prompt.+const derivePrompt = (job) => effectiveJobPrompt(job);const hook = createMediaJobImageHook({label: 'writers-room scene-image',