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
refactor: enforce the routed-job downgrade contract inside enqueueJob (#4683)
[._.]/ Adam Eivy50677677bee1
diff --git a/client/src/components/media/MediaJobsQueue.jsx b/client/src/components/media/MediaJobsQueue.jsxindex 00298cd69a..3e72ed18eb 100644--- a/client/src/components/media/MediaJobsQueue.jsx+++ b/client/src/components/media/MediaJobsQueue.jsx@@ -56,9 +56,9 @@ const codexEffortOf = (raw) => (typeof raw === 'string' ? raw.trim() : '');// Compact "engine / model" badge so a failed row tells the user *what* failed,// not just that it failed. Codex jobs carry `params.model`; local image/video// jobs carry `params.modelId`; training jobs carry a runtime + character. A-// federated job is badged `remote` off the server-projected `renderer` field.+// federated job is badged `remote` off the server-projected `job.renderer`.// Trims long HF repo paths to the tail segment.-function modelLabel(params) {+function modelLabel(params, renderer) {if (!params) return null;if (params.runtime || params.runId) {// Training job — surface the engine + who's being trained, not a prompt.@@ -89,9 +89,9 @@ function modelLabel(params) {}const id = (params.modelId || '').trim();// A federated render ran on a peer, so it must not wear the local badge. The- // server projects `renderer` (and rebuilds `modelId` off the wire request)+ // server projects `job.renderer` (and rebuilds `modelId` off the wire request)// for exactly this — the raw job nulls both to fail closed on a downgrade.- const where = params.renderer === 'remote' ? 'remote' : 'local';+ const where = renderer === 'remote' ? 'remote' : 'local';if (!id) return where;const tail = id.includes('/') ? id.slice(id.lastIndexOf('/') + 1) : id;return `${where} / ${tail}`;@@ -382,7 +382,11 @@ function JobRow({ job, onCancel, onRetry, onRunNow, onDelete }) {: 0;// Inline edit form for retry-with-overrides.const [editing, setEditing] = useState(false);- const canEdit = canRetry;+ // A federated job renders from the wire request inside its `remoteMedia`+ // marker, so a prompt/model edit here would never reach the peer — and the+ // server re-normalizes the retry anyway. Offer the plain Retry, not the+ // editor, rather than showing a form whose edits are silently discarded.+ const canEdit = canRetry && job.renderer !== 'remote';const { isConfirming, requestDelete, cancelDelete, confirmDelete } = useConfirmDelete();return (<div className="bg-port-bg border border-port-border rounded p-2.5">@@ -393,9 +397,9 @@ function JobRow({ job, onCancel, onRetry, onRunNow, onDelete }) {<div className="text-sm font-medium truncate"><span className="font-mono">{job.id.slice(0, 8)}</span><span className="text-port-text-muted"> · {job.kind}</span>- {modelLabel(job.params) && (+ {modelLabel(job.params, job.renderer) && (<span className="text-port-text-muted" title={job.params.model || job.params.modelId || ''}>- {' · '}{modelLabel(job.params)}+ {' · '}{modelLabel(job.params, job.renderer)}</span>)}{job.position && job.status === 'queued' && (diff --git a/client/src/components/media/MediaJobsQueue.test.jsx b/client/src/components/media/MediaJobsQueue.test.jsxindex a6b2ca0ccd..8f85f40e57 100644--- a/client/src/components/media/MediaJobsQueue.test.jsx+++ b/client/src/components/media/MediaJobsQueue.test.jsx@@ -122,7 +122,8 @@ describe('MediaJobsQueue — federated render badge', () => {kind: 'image',status: 'running',queuedAt: '2026-06-19T10:00:00Z',- params: { prompt: 'a lighthouse at dusk', modelId: 'dev', renderer: 'remote' },+ renderer: 'remote',+ params: { prompt: 'a lighthouse at dusk', modelId: 'dev' },}]);render(<MediaJobsQueue kind="image" />);@@ -138,6 +139,20 @@ describe('MediaJobsQueue — federated render badge', () => {expect(await screen.findByText(/local \/ z-image-turbo/)).toBeInTheDocument();});++ it('offers plain Retry but not the editor on a failed federated job', async () => {+ // A prompt/model edit would never reach the peer — the remote executor+ // renders from the wire request inside the marker — so showing the form+ // would silently discard what the user typed.+ const user = userEvent.setup();+ listMediaJobs.mockResolvedValue([{ ...failedLocalJob, id: 'remotefail0000beef', renderer: 'remote' }]);++ render(<MediaJobsQueue kind="image" />);+ await expandReel(user);++ expect(await screen.findByRole('button', { name: /^Retry$/ })).toBeInTheDocument();+ expect(screen.queryByLabelText('Edit and retry')).not.toBeInTheDocument();+ });});describe('MediaJobsQueue — Codex reasoning-effort retry control', () => {diff --git a/server/routes/imageGen.js b/server/routes/imageGen.jsindex 3d9b0580fc..65f93563ab 100644--- a/server/routes/imageGen.js+++ b/server/routes/imageGen.js@@ -44,7 +44,6 @@ import { buildUniverseRunTag } from '../services/universeRunTag.js';import { getSettings } from '../services/settings.js';import { federatedMediaImageJobSubmissionSchema } from '../lib/validation.js';import { prepareRemoteMediaJob } from '../services/federatedMedia/remoteSubmission.js';-import { routedJobParams } from '../services/federatedMedia/routedJobParams.js';const router = Router();@@ -479,14 +478,13 @@ router.post('/generate', imageGenUploads, asyncHandler(async (req, res) => {mediaProviderPeerId: _peerId, mediaProviderEngine: _engine,mode: _mode, cloudModel: _cloudModel, ...jobParams} = params;- // The conditioning prompt and the model id ride ONLY inside the versioned- // marker. `routedJobParams` nulls every top-level field a LOCAL dispatcher- // would render from, so an older build that cannot route `remoteMedia`- // fails closed on its own model guard rather than quietly re-rendering this- // job for real on local hardware. See that module for the full contract.+ // The prompt and model ride only inside the versioned marker: enqueueJob+ // normalizes any job carrying one into the downgrade-safe shape, so this+ // render cannot be re-run for real by a build rolled back past+ // `remoteMedia`. Contract: services/federatedMedia/routedJobParams.js.const queued = enqueueJob({kind: 'image',- params: routedJobParams({ params: jobParams, remoteMedia }),+ params: { ...jobParams, remoteMedia },});return res.json(queuedImageResponse({...queued,diff --git a/server/routes/imageGen.test.js b/server/routes/imageGen.test.jsindex a17592993e..62f90c5daa 100644--- a/server/routes/imageGen.test.js+++ b/server/routes/imageGen.test.js@@ -1465,14 +1465,10 @@ describe('Image Gen Routes', () => {});const [{ params }] = mediaJobQueue.enqueueJob.mock.calls[0];- // Blank top-level prompt, nulled model + interpreter, no routing fields:- // an older build that cannot read `remoteMedia` falls through to a local- // render it has to refuse, rather than quietly re-running this job on- // local hardware. The shape contract itself lives in- // services/federatedMedia/routedJobParams.test.js.- expect(params.prompt).toBe('');- expect(params.modelId).toBeNull();- expect(params.pythonPath).toBeNull();+ // The conditioning prompt rides only inside the versioned marker, and the+ // routing fields never reach the queue. enqueueJob owns blanking the+ // local render fields on top of this (#4683) — its own suites cover that,+ // and enqueueJob is mocked here.expect(params.remoteMedia.request.prompt).toBe('a lighthouse at dusk');expect(params.remoteMedia.request.modelId).toBe('dev');expect(params).not.toHaveProperty('mediaProviderPeerId');diff --git a/server/routes/mediaJobs.js b/server/routes/mediaJobs.jsindex c7c6251623..4fa8162bd3 100644--- a/server/routes/mediaJobs.js+++ b/server/routes/mediaJobs.js@@ -15,7 +15,6 @@ import { promptFromMedia } from '../services/mediaPromptFromMedia.js';import { CODEX_EFFORT_LEVELS } from '../lib/providerModels.js';import { sanitizeJob } from '../services/mediaJobQueue/sanitizeJob.js';import { validateVideoRetryParams } from '../services/videoGen/prepareParams.js';-import { routedJobParams } from '../services/federatedMedia/routedJobParams.js';const router = Router();@@ -294,15 +293,11 @@ router.post('/:id/retry', asyncHandler(async (req, res) => {// fallback (CODEX_IMAGEGEN_DEFAULT_EFFORT) take over, which a merged sentinel// string could not do (it would fail the CODEX_EFFORT_LEVELS validation).if (clearEffort) delete params.effort;- // A retried federated job must keep the downgrade-safe shape (#4683). The- // remote executor renders from `remoteMedia.request`, so a merged `prompt` /- // `modelId` override never reached the peer anyway — but leaving one on- // top-level params would hand a rolled-back build a locally-renderable job.- // Re-normalize instead of trusting the merge.- const retryParams = params.remoteMedia !== undefined- ? routedJobParams({ params, remoteMedia: params.remoteMedia })- : params;- const result = enqueueJob({ kind: job.kind, params: retryParams, owner: job.owner });+ // A federated retry needs no special handling here: enqueueJob re-normalizes+ // any job carrying a `remoteMedia` marker, so a merged prompt/model override+ // (which never reached the peer anyway — the remote executor renders from+ // `remoteMedia.request`) cannot restore a locally-renderable shape.+ const result = enqueueJob({ kind: job.kind, params, owner: job.owner });// Drop the original failed/canceled row from archive — the new job inherits// its work, and leaving both visible just lets users keep clicking Retry on// the dead row and stacking duplicate jobs. If the prune returns false thediff --git a/server/routes/mediaJobs.test.js b/server/routes/mediaJobs.test.jsindex 09da274589..da6281cbd4 100644--- a/server/routes/mediaJobs.test.js+++ b/server/routes/mediaJobs.test.js@@ -166,11 +166,12 @@ describe('mediaJobs routes', () => {expect(call.params.steps).toBe(40);});- it('POST /:id/retry re-normalizes a federated job so an override cannot restore a locally-renderable shape', async () => {- // The remote executor renders from `remoteMedia.request`, so these- // overrides never reached the peer anyway — but leaving them on top-level- // params would hand a build rolled back before `remoteMedia` a job it could- // render locally for real (#4683).+ it('POST /:id/retry hands a federated job back to enqueueJob with its marker intact', async () => {+ // The retry route deliberately does NOT special-case a federated job:+ // enqueueJob re-normalizes anything carrying a marker into the+ // downgrade-safe shape (#4683), so the override the user typed — which+ // never reached the peer anyway, the remote executor renders from+ // `remoteMedia.request` — cannot restore a locally-renderable job.const remoteMedia = {wireVersion: 1,peerId: '00000000-0000-4000-8000-0000000004f1',@@ -185,10 +186,6 @@ describe('mediaJobs routes', () => {.send({ params: { prompt: 'something else', modelId: 'sdxl-base' } });expect(r.status).toBe(200);const { params } = stubs.enqueueJob.mock.calls[0][0];- expect(params.prompt).toBe('');- expect(params.modelId).toBeNull();- expect(params.pythonPath).toBeNull();- // The marker (and the surviving job params) still ride through untouched.expect(params.remoteMedia).toEqual(remoteMedia);expect(params.width).toBe(512);});diff --git a/server/routes/videoGen.js b/server/routes/videoGen.jsindex 9b01b57a60..64bd15fd85 100644--- a/server/routes/videoGen.js+++ b/server/routes/videoGen.js@@ -69,7 +69,6 @@ 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 { routedJobParams } from '../services/federatedMedia/routedJobParams.js';const router = Router();@@ -1069,14 +1068,13 @@ router.post('/', frameImageUpload, asyncHandler(async (req, res) => {kind: 'video',request,});- // Prompt, dials, and model id ride ONLY inside the versioned marker.- // `routedJobParams` is shared with the routed image path so the two shapes- // cannot drift: an older build that can't route `remoteMedia` hits- // generateVideo's "Prompt is required" guard, and its `Unknown video model`- // guard behind that, instead of re-rendering this job locally.+ // Prompt and dials ride only inside the versioned marker: enqueueJob+ // normalizes any job carrying one into the downgrade-safe shape, so a build+ // rolled back past `remoteMedia` cannot re-render this locally. Contract:+ // services/federatedMedia/routedJobParams.js.const { jobId, position, status } = enqueueJob({kind: 'video',- params: routedJobParams({ remoteMedia }),+ params: { remoteMedia },});return res.json({jobId,diff --git a/server/routes/videoGen.test.js b/server/routes/videoGen.test.jsindex d25448d57a..d1bfac720e 100644--- a/server/routes/videoGen.test.js+++ b/server/routes/videoGen.test.js@@ -2293,14 +2293,10 @@ describe('videoGen routes', () => {});const [{ params }] = mediaJobQueue.enqueueJob.mock.calls[0];- // Blank top-level prompt, nulled model + interpreter: an older build that- // cannot read `remoteMedia` hits generateVideo's "Prompt is required"- // guard (and its model guard behind that) instead of re-rendering this- // job on local hardware. Shape contract:- // services/federatedMedia/routedJobParams.test.js.- expect(params.prompt).toBe('');- expect(params.modelId).toBeNull();- expect(params.pythonPath).toBeNull();+ // Prompt and dials ride only inside the versioned marker; no local render+ // input is carried over at all. enqueueJob owns blanking the rest (#4683)+ // — its own suites cover that, and enqueueJob is mocked here.+ expect(params).toEqual({ remoteMedia: expect.objectContaining({ peerId: federatedPeerId }) });expect(params.remoteMedia.request.prompt).toBe('a slow pan across a harbour');expect(params.remoteMedia.request.modelId).toBe('ltx2');});diff --git a/server/services/federatedMedia/routedJobParams.js b/server/services/federatedMedia/routedJobParams.jsindex 93a1447eea..20f6418d63 100644--- a/server/services/federatedMedia/routedJobParams.js+++ b/server/services/federatedMedia/routedJobParams.js@@ -1,10 +1,13 @@/*** The persisted params shape for a media job that renders on a federated peer.*- * Both routed generate paths (`routes/imageGen.js`, `routes/videoGen.js`) build- * their queue params through this one helper so the two cannot drift: the- * downgrade contract below only holds if every routed job carries the same- * shape.+ * `enqueueJob` applies this to EVERY job carrying a `remoteMedia` marker — no+ * route calls it directly. The contract below only holds if it is unbypassable:+ * a helper each routed enqueue site had to remember would be one forgotten call+ * away from shipping a job a rolled-back build renders locally for real, with+ * no guard test to catch it. It normalizes the fields every kind shares; a kind+ * with its own conditioning input still blanks that itself (audio's `lyrics`,+ * `routes/music.js`).** ## Downgrade contract (#4683)*@@ -40,10 +43,12 @@* @param {object} [args.params] - Job params that survive routing (destination* tags, dimensions, seed). Local-only routing/backend selectors are stripped* by the caller before they get here.- * @param {object} args.remoteMedia - The versioned marker from prepareRemoteMediaJob.+ * @param {object} [args.remoteMedia] - The versioned marker from+ * prepareRemoteMediaJob. Defaults to the one already on `params` — which is+ * how enqueueJob calls it, having selected the job on that same marker.* @returns {object} Params to persist on the queued proxy job.*/-export const routedJobParams = ({ params = {}, remoteMedia }) => ({+export const routedJobParams = ({ params = {}, remoteMedia = params.remoteMedia }) => ({...params,prompt: '',modelId: null,diff --git a/server/services/federatedMedia/routedJobParams.test.js b/server/services/federatedMedia/routedJobParams.test.jsindex 3255ab54ea..4252af48ae 100644--- a/server/services/federatedMedia/routedJobParams.test.js+++ b/server/services/federatedMedia/routedJobParams.test.js@@ -31,11 +31,10 @@ describe('routedJobParams', () => {expect(params.prompt).toBe('');// `null`, NOT absent — generateImage/generateVideo declare `modelId` as a- // default parameter, which fires on `undefined` only.+ // default parameter, which fires on `undefined` only. `toBeNull` is the+ // assertion that distinguishes the two.expect(params.modelId).toBeNull();- expect(params).toHaveProperty('modelId');expect(params.pythonPath).toBeNull();- expect(params).toHaveProperty('pythonPath');});it('keeps the versioned marker and the destination tags a completion hook needs', () => {@@ -56,6 +55,14 @@ describe('routedJobParams', () => {expect(params).toEqual({ prompt: '', modelId: null, pythonPath: null, remoteMedia });});++ it('defaults the marker off params, which is how enqueueJob calls it', () => {+ const params = routedJobParams({ params: { modelId: 'dev', prompt: 'edited', remoteMedia } });++ expect(params.remoteMedia).toEqual(remoteMedia);+ expect(params.prompt).toBe('');+ expect(params.modelId).toBeNull();+ });});// The point of the shape above: a machine rolled back to a build that predatesdiff --git a/server/services/mediaJobQueue/index.js b/server/services/mediaJobQueue/index.jsindex a29218bf39..2b30702193 100644--- a/server/services/mediaJobQueue/index.js+++ b/server/services/mediaJobQueue/index.js@@ -45,6 +45,8 @@ import { trainingEvents } from '../loraTraining/events.js';import { audioGenEvents } from '../audioGen/events.js';import { getSettings } from '../settings.js';import { IMAGE_GEN_MODE, CLOUD_IMAGE_GEN_MODES } from '../imageGen/modes.js';+import { REMOTE_MEDIA_MODULES, isRemoteMediaJob } from './remoteMediaJob.js';+import { routedJobParams } from '../federatedMedia/routedJobParams.js';// Cloud-CLI jobs (Codex/Grok/Agy images, Grok videos) share one parallel lane —// each render@@ -57,23 +59,11 @@ const isCloudImageJob = (j) =>(j.kind === 'image' && CLOUD_IMAGE_GEN_MODES.includes(j.params?.mode))|| (j.kind === 'video' && j.params?.mode === IMAGE_GEN_MODE.GROK);-// The federatable kinds and the adapter each one dispatches to, in one map so-// the two cannot drift apart. Kinds are listed explicitly rather than inferred-// from the marker alone: a 'training' job has no federated contract, so a marker-// on one is corrupt state that must keep taking the local path, not a routing-// instruction.-const REMOTE_MEDIA_MODULES = {- audio: () => import('../audioGen/remote.js'),- image: () => import('../imageGen/remote.js'),- video: () => import('../videoGen/remote.js'),-};--// Presence, not truthiness of individual nested fields, selects the remote-// adapter. Persisted queue state is user-editable; a malformed marker must fail-// closed in the kind's remote module rather than accidentally falling through to-// a local engine with a remote-only model id.-export const isRemoteMediaJob = (job) =>- Object.hasOwn(REMOTE_MEDIA_MODULES, job?.kind ?? '') && job.params?.remoteMedia !== undefined;+// The federated-kind map and its predicate live in ./remoteMediaJob.js so light+// consumers (sanitizeJob, route handlers) can ask "is this routed?" without+// pulling the queue in. Re-exported here because that is where callers have+// always found it.+export { isRemoteMediaJob };const jobLane = (job) => {if (isRemoteMediaJob(job)) return 'remote';@@ -1062,17 +1052,24 @@ export function enqueueJob({ kind, params, owner = null }) {throw new Error(`enqueueJob: invalid kind '${kind}'`);}const id = randomUUID();+ // Every routed job is normalized HERE rather than at each caller (#4683): the+ // downgrade contract only holds if it is unbypassable, and a future enqueue+ // site that forgets the helper would ship a job a rolled-back build renders+ // locally for real. See services/federatedMedia/routedJobParams.js.+ const safeParams = isRemoteMediaJob({ kind, params })+ ? routedJobParams({ params })+ : params;const job = {id,kind,owner,status: 'queued',queuedAt: new Date().toISOString(),- params,+ params: safeParams,// position counts "where you sit in your lane" — a running job in the// same lane occupies slot 1, then same-lane queued jobs follow.position: (() => {- const candidate = { kind, params };+ const candidate = { kind, params: safeParams };const lane = jobLane(candidate);const laneQueue = queue.filter((j) => jobLane(j) === lane);const liveCount = lane === 'cloud'diff --git a/server/services/mediaJobQueue/index.test.js b/server/services/mediaJobQueue/index.test.jsindex 39a5f33aa1..820fcdfcda 100644--- a/server/services/mediaJobQueue/index.test.js+++ b/server/services/mediaJobQueue/index.test.js@@ -880,6 +880,48 @@ describe('Audio kind (#1928)', () => {await waitFor(() => mediaJobQueue.getJob(remote.jobId)?.status === 'completed');});+ // #4683 — the downgrade contract is enforced HERE, not at each routed enqueue+ // site, so a future caller that forgets to blank the local render fields can't+ // ship a job a build rolled back past `remoteMedia` would render for real.+ it('normalizes any enqueued job carrying a marker into the downgrade-safe shape', async () => {+ stubs.generateImageRemote.mockImplementation(() => new Promise(() => {}));+ // Deliberately hostile input: a caller that passed the local render fields+ // straight through, exactly as a forgotten normalization would.+ const remote = mediaJobQueue.enqueueJob({+ kind: 'image',+ params: {+ prompt: 'a harbour',+ modelId: 'dev',+ pythonPath: '/usr/bin/python3',+ width: 512,+ remoteMedia: remoteImageMediaParams(),+ },+ });++ const { params } = mediaJobQueue.getJob(remote.jobId);+ expect(params.prompt).toBe('');+ expect(params.modelId).toBeNull();+ expect(params.pythonPath).toBeNull();+ // Surviving job params and the marker itself ride through untouched, and+ // the job still routes to the remote adapter on this build.+ expect(params.width).toBe(512);+ expect(params.remoteMedia.request.prompt).toBe('a harbour');+ await waitFor(() => stubs.generateImageRemote.mock.calls.length === 1);+ expect(stubs.generateImage).not.toHaveBeenCalled();+ });++ 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 would+ // destroy a real local run.+ const job = mediaJobQueue.enqueueJob({+ kind: 'training',+ params: { runId: 'run-1', runtime: 'mflux', modelId: 'dev', remoteMedia: remoteImageMediaParams() },+ });++ expect(mediaJobQueue.getJob(job.jobId).params.modelId).toBe('dev');+ });+it('persists cancellation intent before signaling a running remote adapter', async () => {stubs.generateAudioRemote.mockImplementation(() => new Promise(() => {}));const remote = mediaJobQueue.enqueueJob({diff --git a/server/services/mediaJobQueue/remoteMediaJob.js b/server/services/mediaJobQueue/remoteMediaJob.jsnew file mode 100644index 0000000000..14ccc8a9d1--- /dev/null+++ b/server/services/mediaJobQueue/remoteMediaJob.js@@ -0,0 +1,28 @@+/**+ * The one definition of "is this queued job rendering on a federated peer?".+ *+ * It lives in its own module rather than in `index.js` so the light consumers —+ * the public projection (`sanitizeJob.js`), route handlers — can ask the+ * question without dragging the whole queue (its timers, persistence, and+ * event emitters) into their module graph. Every caller must use this predicate+ * instead of testing `params.remoteMedia` inline: an inline test silently drops+ * the kind gate below.+ */++// The federatable kinds and the adapter each one dispatches to, in one map so+// the two cannot drift apart. Kinds are listed explicitly rather than inferred+// from the marker alone: a 'training' job has no federated contract, so a marker+// on one is corrupt state that must keep taking the local path, not a routing+// instruction.+export const REMOTE_MEDIA_MODULES = {+ audio: () => import('../audioGen/remote.js'),+ image: () => import('../imageGen/remote.js'),+ video: () => import('../videoGen/remote.js'),+};++// Presence, not truthiness of individual nested fields, selects the remote+// adapter. Persisted queue state is user-editable; a malformed marker must fail+// closed in the kind's remote module rather than accidentally falling through to+// a local engine with a remote-only model id.+export const isRemoteMediaJob = (job) =>+ Object.hasOwn(REMOTE_MEDIA_MODULES, job?.kind ?? '') && job.params?.remoteMedia !== undefined;diff --git a/server/services/mediaJobQueue/sanitizeJob.js b/server/services/mediaJobQueue/sanitizeJob.jsindex 8e681b7a2b..99a2285c29 100644--- a/server/services/mediaJobQueue/sanitizeJob.js+++ b/server/services/mediaJobQueue/sanitizeJob.js@@ -1,4 +1,5 @@import { renderFederatedMediaAudioPrompt } from '../../lib/federatedMediaWire.js';+import { isRemoteMediaJob } from './remoteMediaJob.js';// Public projection of a media job. Keep worker-only paths and subprocess// details out of both the queue API and the processing dashboard.@@ -38,27 +39,24 @@ export function sanitizeJob(job) {const remotePrompt = renderFederatedMediaAudioPrompt(job.params?.remoteMedia?.profile)?? (typeof job.params?.remoteMedia?.request?.prompt === 'string'? job.params.remoteMedia.request.prompt : null);- if (safeParams && remotePrompt) {- safeParams.prompt = remotePrompt;- }- // Same reasoning for the model id: it is nulled in top-level params so a- // downgraded build cannot render the job locally (#4683), so rebuild it from- // the marker here — the Render Queue card's model badge reads+ // 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.+ const routed = isRemoteMediaJob(job);const remoteModelId = job.params?.remoteMedia?.request?.modelId;- if (safeParams && typeof remoteModelId === 'string' && remoteModelId) {- safeParams.modelId = remoteModelId;- }- // Display-only discriminator, never persisted in job params: a routed job- // renders on a peer, so labelling it with the local-render badge ("local /- // flux") would misreport where the pixels came from.- if (safeParams && job.params?.remoteMedia !== undefined) {- safeParams.renderer = 'remote';+ if (safeParams && routed) {+ if (remotePrompt) safeParams.prompt = remotePrompt;+ if (typeof remoteModelId === 'string' && remoteModelId) safeParams.modelId = remoteModelId;}return {id: job.id,kind: job.kind,+ // Where this job renders. Job metadata, not a render input, so it rides on+ // the envelope rather than inside `params` — the PARAM_ALLOWLIST above stays+ // an exact description of what a projected `params` can contain. The UI+ // needs it because a peer render must not wear the local model badge.+ renderer: routed ? 'remote' : 'local',owner: job.owner,status: job.status,queuedAt: job.queuedAt,diff --git a/server/services/mediaJobQueue/sanitizeJob.test.js b/server/services/mediaJobQueue/sanitizeJob.test.jsindex 0cc4348ce5..57bf8a8e86 100644--- a/server/services/mediaJobQueue/sanitizeJob.test.js+++ b/server/services/mediaJobQueue/sanitizeJob.test.js@@ -78,8 +78,8 @@ describe('sanitizeJob', () => {expect(sanitized.params).toEqual({prompt: 'Instrumental orchestral music with a triumphant mood, moderate tempo, high energy, featuring brass and strings. No vocals or spoken words.',modelId: 'example/model',- renderer: 'remote',});+ expect(sanitized.renderer).toBe('remote');expect(sanitized.params).not.toHaveProperty('remoteMedia');});@@ -116,14 +116,15 @@ describe('sanitizeJob', () => {modelId: 'dev',width: 512,height: 512,- // Display-only: the Render Queue badges this 'remote / dev' rather than- // claiming a local render produced it.- renderer: 'remote',});expect(sanitized.params).not.toHaveProperty('remoteMedia');+ // Job metadata, not a render input — the Render Queue badges this+ // 'remote / dev' rather than claiming a local render produced it.+ expect(sanitized.renderer).toBe('remote');+ expect(sanitized.params).not.toHaveProperty('renderer');});- it('leaves a local job unbadged so it keeps the local render label', () => {+ it('reports a local job as locally rendered', () => {const sanitized = sanitizeJob({id: 'job-local',kind: 'image',@@ -132,6 +133,24 @@ describe('sanitizeJob', () => {});expect(sanitized.params).toEqual({ prompt: 'a lighthouse at dusk', modelId: 'dev' });- expect(sanitized.params).not.toHaveProperty('renderer');+ expect(sanitized.renderer).toBe('local');+ });++ it('reports a training job carrying a stray marker as local — training has no federated contract', () => {+ const sanitized = sanitizeJob({+ id: 'job-training',+ kind: 'training',+ status: 'running',+ params: {+ runId: 'run-1',+ runtime: 'mflux',+ modelId: 'dev',+ remoteMedia: { wireVersion: 1, request: { modelId: 'peer-model' } },+ },+ });++ expect(sanitized.renderer).toBe('local');+ // The marker must not rewrite a local training job's model either.+ expect(sanitized.params.modelId).toBe('dev');});});