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

fix: normalize archived routed jobs on restore, and let a canceled federated render retry (#4683)

[._.]/ Adam Eivyfe7330301897
diff --git a/server/routes/mediaJobs.js b/server/routes/mediaJobs.js
index 4fa8162bd3..c5c6e1fc7b 100644
--- a/server/routes/mediaJobs.js
+++ b/server/routes/mediaJobs.js
@@ -14,6 +14,7 @@ import { refineMediaPrompt } from '../services/mediaPromptRefiner.js';
import { promptFromMedia } from '../services/mediaPromptFromMedia.js';
import { CODEX_EFFORT_LEVELS } from '../lib/providerModels.js';
import { sanitizeJob } from '../services/mediaJobQueue/sanitizeJob.js';
+import { isRemoteMediaJob } from '../services/mediaJobQueue/remoteMediaJob.js';
import { validateVideoRetryParams } from '../services/videoGen/prepareParams.js';
const router = Router();
@@ -293,10 +294,23 @@ 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 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.
+ // 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. What the retry DOES have to reset is the marker's
+ // transient run state, which describes the finished attempt, not this one:
+ // - `cancelRequested` — inherited from a canceled render, it makes the
+ // executor's preflight abort the retry immediately, and the flag rides
+ // along again on every further retry. That render could never be re-run.
+ // - `reconcile` — "recover the provider job for this Idempotency-Key". The
+ // retry gets a fresh queue id, which IS the key, so there is nothing to
+ // recover; it must submit rather than skip preflight.
+ // Cleared here, not in routedJobParams — boot restoration re-enqueues an
+ // interrupted job under its ORIGINAL id and needs `reconcile: true` kept.
+ if (isRemoteMediaJob({ kind: job.kind, params })) {
+ const { cancelRequested: _canceled, reconcile: _reconcile, ...marker } = params.remoteMedia;
+ params.remoteMedia = { ...marker, cancelRequested: false, reconcile: false };
+ }
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
diff --git a/server/routes/mediaJobs.test.js b/server/routes/mediaJobs.test.js
index da6281cbd4..783bad5301 100644
--- a/server/routes/mediaJobs.test.js
+++ b/server/routes/mediaJobs.test.js
@@ -186,10 +186,54 @@ 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.remoteMedia).toEqual(remoteMedia);
+ expect(params.remoteMedia.request).toEqual(remoteMedia.request);
+ expect(params.remoteMedia.peerId).toBe(remoteMedia.peerId);
expect(params.width).toBe(512);
});
+ it('POST /:id/retry clears the marker run state so a CANCELED federated render can actually re-run', async () => {
+ // `cancelRequested` describes the finished attempt. Inherited, it makes the
+ // remote executor's preflight abort the retry on its first line — and rides
+ // along again on every further retry, so the render could never be re-run.
+ // `reconcile` is "recover the provider job for this Idempotency-Key"; the
+ // retry gets a fresh queue id, which IS the key, so there is nothing to
+ // recover and it must submit instead of skipping preflight.
+ jobStore.set('j-canceled', {
+ id: 'j-canceled', kind: 'image', owner: null, status: 'canceled',
+ params: {
+ prompt: '', modelId: null, pythonPath: null,
+ remoteMedia: {
+ wireVersion: 1,
+ peerId: '00000000-0000-4000-8000-0000000004f1',
+ cancelRequested: true,
+ reconcile: true,
+ request: { kind: 'image', engine: 'local', modelId: 'dev', prompt: 'a lighthouse at dusk' },
+ },
+ },
+ });
+ const r = await request(makeApp()).post('/api/media-jobs/j-canceled/retry').send({});
+ expect(r.status).toBe(200);
+ const { params } = stubs.enqueueJob.mock.calls[0][0];
+ expect(params.remoteMedia.cancelRequested).toBe(false);
+ expect(params.remoteMedia.reconcile).toBe(false);
+ // Everything that identifies the render survives.
+ expect(params.remoteMedia.peerId).toBe('00000000-0000-4000-8000-0000000004f1');
+ expect(params.remoteMedia.request.prompt).toBe('a lighthouse at dusk');
+ });
+
+ it('POST /:id/retry leaves a local job\'s params alone', async () => {
+ // Bypass probe for the marker reset above: a training job carrying a stray
+ // marker has no federated contract, so it must keep the local path.
+ jobStore.set('j-training', {
+ id: 'j-training', kind: 'training', owner: null, status: 'failed',
+ params: { runId: 'run-1', runtime: 'mflux', remoteMedia: { wireVersion: 1, cancelRequested: true } },
+ });
+ const r = await request(makeApp()).post('/api/media-jobs/j-training/retry').send({});
+ expect(r.status).toBe(200);
+ const { params } = stubs.enqueueJob.mock.calls[0][0];
+ expect(params.remoteMedia.cancelRequested).toBe(true);
+ });
+
it('POST /:id/retry accepts the editable video generation controls', async () => {
jobStore.set('j-video-edit', {
id: 'j-video-edit', kind: 'video', owner: null, status: 'failed',
diff --git a/server/routes/videoGen.js b/server/routes/videoGen.js
index d524f7221a..310235371d 100644
--- a/server/routes/videoGen.js
+++ b/server/routes/videoGen.js
@@ -70,6 +70,7 @@ 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';
+import { isRemoteMediaJob } from '../services/mediaJobQueue/remoteMediaJob.js';
const router = Router();
@@ -1231,7 +1232,8 @@ const ACTIVE_JOB_PARAM_FIELDS = [
// path, which the whitelist exists to keep off this surface).
'icStrength', 'icAttentionStrength', 'icSkipStage2',
];
-const pickJobParams = (params) => {
+const pickJobParams = (job) => {
+ const params = job?.params;
if (!params || typeof params !== 'object') return {};
const out = {};
for (const k of ACTIVE_JOB_PARAM_FIELDS) {
@@ -1272,8 +1274,8 @@ const pickJobParams = (params) => {
// (#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 (isRemoteMediaJob(job)) {
+ const prompt = effectiveJobPrompt(job);
if (typeof prompt === 'string') out.prompt = prompt;
const { modelId } = params.remoteMedia.request ?? {};
if (typeof modelId === 'string' && modelId) out.modelId = modelId;
@@ -1293,7 +1295,7 @@ router.get('/active', (_req, res) => {
generationId: job.id,
status: job.status,
position: job.position,
- params: pickJobParams(job.params),
+ params: pickJobParams(job),
},
});
});
diff --git a/server/services/mediaJobQueue/index.js b/server/services/mediaJobQueue/index.js
index e6ca3fba76..ac7e88c16d 100644
--- a/server/services/mediaJobQueue/index.js
+++ b/server/services/mediaJobQueue/index.js
@@ -463,7 +463,10 @@ export async function initMediaJobQueue() {
} else if (j.status === 'queued') {
queue.push({ ...j, params: restoredParams(j) });
} else {
- archive.push(j);
+ // The archive needs it too: a rolled-back build restores these rows,
+ // shows them in the Render Queue's recent reel, and its Retry hands the
+ // stored params straight to a local render.
+ archive.push({ ...j, params: restoredParams(j) });
}
}
// Re-attach jobs resume ahead of everything else (they were mid-flight), so
diff --git a/server/services/mediaJobQueue/index.test.js b/server/services/mediaJobQueue/index.test.js
index d7c80d0bb6..f4c02ae236 100644
--- a/server/services/mediaJobQueue/index.test.js
+++ b/server/services/mediaJobQueue/index.test.js
@@ -954,6 +954,37 @@ describe('Audio kind (#1928)', () => {
expect(mediaJobQueue.getJob('aaaaaaaa-0000-4000-8000-000000000002').params.remoteMedia.reconcile).toBe(true);
});
+ it('re-normalizes an ARCHIVED routed job too — the recent reel is a retry surface', async () => {
+ // A rolled-back build restores archived rows, shows them in the Render
+ // Queue's recent reel, and its Retry hands the stored params straight to a
+ // local render. Leaving the archive un-normalized would keep #4683 open
+ // through that path.
+ writeFileSync(join(tempDataDir, 'media-jobs.json'), JSON.stringify({
+ jobs: [{
+ id: 'bbbbbbbb-0000-4000-8000-000000000001',
+ kind: 'image',
+ status: 'failed',
+ error: 'peer unreachable',
+ queuedAt: new Date(Date.now() - 60_000).toISOString(),
+ // Inside the archive's 24h retention window, or the boot prune drops it.
+ completedAt: new Date().toISOString(),
+ params: {
+ prompt: 'a harbour', modelId: 'dev', pythonPath: '/usr/bin/python3',
+ remoteMedia: remoteImageMediaParams(),
+ },
+ }],
+ }));
+ await importFresh();
+ await mediaJobQueue.initMediaJobQueue();
+
+ const { params, status } = mediaJobQueue.getJob('bbbbbbbb-0000-4000-8000-000000000001');
+ expect(status).toBe('failed');
+ expect(params.prompt).toBe('');
+ expect(params.modelId).toBeNull();
+ expect(params.pythonPath).toBeNull();
+ expect(params.remoteMedia.request.prompt).toBe('a harbour');
+ });
+
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
diff --git a/server/services/sprites/reference.test.js b/server/services/sprites/reference.test.js
index 48004f05ee..e12f2e9cb8 100644
--- a/server/services/sprites/reference.test.js
+++ b/server/services/sprites/reference.test.js
@@ -493,6 +493,36 @@ describe('attachReferenceCandidate', () => {
expect(sidecar.model).toBe('retried-model');
});
+ it('reads a federated render\'s provenance through to the wire request', async () => {
+ // A routed job blanks `params.prompt` and nulls `params.modelId` so a build
+ // rolled back past `remoteMedia` fails closed (#4683) — reading them
+ // directly would record a sidecar with no provenance at all.
+ const id = newId();
+ await createCharacter(id);
+ await mkdir(join(TEST_ROOT, 'images'), { recursive: true });
+ await writeCandidatePng(join(TEST_ROOT, 'images', 'render-remote.png'));
+ await attachReferenceCandidate({
+ recordId: id, target: 'main', direction: 'south', anchorId: 'walk-south',
+ chromaKey: '#FF00FF', jobId: 'j-remote', filename: 'render-remote.png',
+ job: {
+ params: {
+ prompt: '',
+ modelId: null,
+ remoteMedia: {
+ wireVersion: 1,
+ peerId: '00000000-0000-4000-8000-0000000004f1',
+ request: { kind: 'image', engine: 'local', modelId: 'dev', prompt: 'a sprite facing south' },
+ },
+ },
+ },
+ });
+ const sidecar = JSON.parse(await readFile(
+ join(TEST_ROOT, 'sprites', id, 'reference', 'candidates', 'walk-south-candidate-01.generation.json'), 'utf8',
+ ));
+ expect(sidecar.model).toBe('dev');
+ expect(sidecar.prompt).toBe('a sprite facing south');
+ });
+
it('records an anchor correction prompt in the sidecar as provenance', async () => {
const id = newId();
await createCharacter(id);
diff --git a/server/services/writersRoomSceneImageHook.test.js b/server/services/writersRoomSceneImageHook.test.js
index 3b81faa9ea..fef804051c 100644
--- a/server/services/writersRoomSceneImageHook.test.js
+++ b/server/services/writersRoomSceneImageHook.test.js
@@ -63,6 +63,29 @@ describe('writersRoomSceneImageHook', () => {
});
});
+ it('records the wire prompt for a federated render, whose top-level prompt is blank', async () => {
+ // A routed job blanks `params.prompt` so a build rolled back past
+ // `remoteMedia` fails closed (#4683). Reading it directly would file the
+ // scene with an empty prompt instead of the one that actually rendered.
+ mediaJobEvents.emit('completed', completedImageJob({
+ params: {
+ writersRoom: tag(),
+ prompt: '',
+ modelId: null,
+ remoteMedia: {
+ wireVersion: 1,
+ peerId: '00000000-0000-4000-8000-0000000004f1',
+ request: { kind: 'image', engine: 'local', modelId: 'dev', prompt: 'a cinematic alley' },
+ },
+ },
+ filename: 'job-remote.png', id: 'job-remote',
+ }));
+ await waitFor(() => emitted.length > 0);
+ expect(persistSceneImage).toHaveBeenCalledWith('w1', 'script', {
+ sceneId: 's1', filename: 'job-remote.png', jobId: 'job-remote', prompt: 'a cinematic alley',
+ });
+ });
+
it('derives jobId from the filename when the job carries no id', async () => {
mediaJobEvents.emit('completed', completedImageJob({ params: { writersRoom: tag() }, filename: 'noid.png', id: null }));
await waitFor(() => persistSceneImage.mock.calls.length > 0);