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
address review (codex): stop local-only gates and preflight throws from stranding routed renders
[._.]/ Adam Eivy65ce2d64bd49
diff --git a/client/src/pages/Instances.jsx b/client/src/pages/Instances.jsxindex 69f1a0d439..8129f331ec 100644--- a/client/src/pages/Instances.jsx+++ b/client/src/pages/Instances.jsx@@ -1455,12 +1455,18 @@ export default function Instances() {<AddPeerForm onAdd={fetchData} /></div>+ {/* Outside the peer-count guard on purpose: removing the last peer must+ not hide the only control that can clear a stale saved route, or every+ unattended render keeps failing its preflight with no way back. The+ component renders nothing when there is neither an option nor a saved+ route. */}+ <UnattendedRenderRouting peers={peers} />+{peers.length > 0 && (<div><h2 className="text-sm font-medium text-gray-400 uppercase tracking-wider mb-3">Peers ({peers.length})</h2>- <UnattendedRenderRouting peers={peers} /><BrainParitySchedule /><div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">{peers.map(peer => (diff --git a/docs/FEDERATED_MEDIA_PROVIDERS.md b/docs/FEDERATED_MEDIA_PROVIDERS.mdindex 1dfedcb3df..6acd2d07be 100644--- a/docs/FEDERATED_MEDIA_PROVIDERS.md+++ b/docs/FEDERATED_MEDIA_PROVIDERS.md@@ -162,6 +162,22 @@ rather than being silently rendered without its conditioning — a shot thatquietly ignores its reference frame is worse unattended than interactively,because nobody is watching to notice.+Output semantics the wire cannot express are rejected the same way: a scene+asking for a silent (audio-disabled) render would come back **with** audio, so it+is refused rather than rendered wrong. Post-processing passes (`cleanC2PA`,+`denoise`) are the one thing dropped rather than refused, with a log — they+polish the produced file rather than change what is rendered, and `cleanC2PA`+defaults on for cloud modes nobody explicitly chose. Re-applying them after+download is a follow-up.++A local-readiness gate never suppresses a routed render. "No local Python+runtime" is exactly the state a machine that routes its renders is in, so the+Creative Director first-pass and scene paths consult `hasConfiguredMediaRoute`+before skipping work the peer was going to do. A routed enqueue can also *throw*+where a local one could not (busy/stale/unauthorized provider); the scene runner+settles the scene through its normal failure path instead of leaving it stuck in+`rendering`.+Three properties are worth stating explicitly:- **Every unattended path routes, or none does.** The Creative Director plannerdiff --git a/server/services/creativeDirector/firstPassGen.js b/server/services/creativeDirector/firstPassGen.jsindex 18ae27a0ac..14c9b9c9fa 100644--- a/server/services/creativeDirector/firstPassGen.js+++ b/server/services/creativeDirector/firstPassGen.js@@ -28,7 +28,7 @@* auto-cast request. Autonomy seeds what it can; the director takes over.*/-import { enqueueUnattendedMediaJob } from '../federatedMedia/defaultRouting.js';+import { enqueueUnattendedMediaJob, hasConfiguredMediaRoute } from '../federatedMedia/defaultRouting.js';import { getSettings } from '../settings.js';import { resolveImageCleaners } from '../imageGen/index.js';import { IMAGE_GEN_MODE } from '../imageGen/modes.js';@@ -71,6 +71,23 @@ export function buildPortraitPrompt(ingredient) {* (#1867) uses the exact same queue-backed-mode gate as the portrait path* rather than re-deriving it.*/+/**+ * `resolveQueueModeParams` answers "can this machine render locally". On an+ * install that routes its unattended renders to a peer — often precisely+ * BECAUSE it has no local image runtime — a "not ready" verdict would skip+ * first-pass work the provider was going to do (#4348).+ *+ * When the image kind is routed, the local verdict is irrelevant: the routed+ * job needs only the prompt and geometry the callers add themselves, so an+ * unready local lane still yields an empty-but-ready param set.+ */+async function resolveOrRouteQueueParams(project = null) {+ const resolved = await resolveQueueModeParams(project);+ if (resolved.ready) return resolved;+ if (!(await hasConfiguredMediaRoute('image'))) return resolved;+ return { mode: resolved.mode, ready: true, jobParams: {} };+}+async function resolveQueueModeParams(project = null) {const settings = await getSettings();// Render-target ladder (#3231): the CD project's persisted renderBackend@@ -136,7 +153,7 @@ export async function enqueueFirstPassPortraits(members = [], project = null) {const list = Array.isArray(members) ? members.filter((m) => m && m.ingredientId) : [];if (list.length === 0) return { mode: null, enqueued: [], skipped: [] };- const resolved = await resolveQueueModeParams(project);+ const resolved = await resolveOrRouteQueueParams(project);if (!resolved.ready) {return { mode: resolved.mode, enqueued: [], skipped: [], reason: resolved.reason };}@@ -223,7 +240,7 @@ export async function enqueueFirstPassSceneFrames(project) {const scenes = Array.isArray(project?.treatment?.scenes) ? project.treatment.scenes : [];if (scenes.length === 0) return { mode: null, enqueued: [], skipped: [] };- const resolved = await resolveQueueModeParams(project);+ const resolved = await resolveOrRouteQueueParams(project);if (!resolved.ready) {return { mode: resolved.mode, enqueued: [], skipped: [], reason: resolved.reason };}diff --git a/server/services/creativeDirector/sceneRunner.js b/server/services/creativeDirector/sceneRunner.jsindex b53773e1ff..e5a53a21f7 100644--- a/server/services/creativeDirector/sceneRunner.js+++ b/server/services/creativeDirector/sceneRunner.js@@ -37,7 +37,7 @@ import { extractLastFrame, sampleEvaluationFrames } from '../videoGen/local.js';import { VIDEO_GEN_MODE } from '../videoGen/modes.js';import { grokVideoJobParams, resolveVideoBackendPin } from '../videoGen/backendPin.js';import { mediaJobEvents } from '../mediaJobQueue/index.js';-import { enqueueUnattendedMediaJob } from '../federatedMedia/defaultRouting.js';+import { enqueueUnattendedMediaJob, hasConfiguredMediaRoute } from '../federatedMedia/defaultRouting.js';import { getSettings } from '../settings.js';import { updateScene, updateProject, getProject } from './local.js';import { dispatchSceneEvaluation } from './sceneEvaluator.js';@@ -93,7 +93,10 @@ export async function runSceneRender(project, scene) {// the user can configure pythonPath and Resume from the UI. Only the local// lane needs it — a Grok render shells out to the CLI and never touches// Python (the media-job queue gates its own pythonPath check the same way).- if (!useGrok && !pythonPath) {+ // A routed video render never touches local Python — on a machine that+ // routes precisely BECAUSE it cannot render locally, this gate would fail+ // every scene the provider was going to handle (#4348).+ if (!useGrok && !pythonPath && !(await hasConfiguredMediaRoute('video'))) {// A pin that named a cloud backend but resolved to local means the ladder// degraded it (the backend's `enabled` toggle is off). Say so — otherwise// the user reads "configure Python" on a project they explicitly pinned to@@ -243,7 +246,20 @@ export async function runSceneRender(project, scene) {}const owner = `cd:${project.id}:${scene.sceneId}`;- const { jobId } = await enqueueUnattendedMediaJob({ kind: 'video', params, owner });+ // The scene is ALREADY persisted as 'rendering' by this point, and the+ // failure/retry listeners below are not wired until after a jobId exists. A+ // routed enqueue can throw where a local one could not — the provider is+ // busy, stale, unauthorized, or refuses the conditioning — so an unhandled+ // throw here leaves the scene stuck in 'rendering' forever with nothing to+ // advance the project. Settle it through the normal failure path instead.+ let jobId;+ try {+ ({ jobId } = await enqueueUnattendedMediaJob({ kind: 'video', params, owner }));+ } catch (error) {+ console.error(`❌ CD scene ${scene.sceneId}: could not queue the render: ${error.message}`);+ await handleRenderFailed(project.id, scene.sceneId, error.message || 'could not queue the render');+ return null;+ }// Wire one-shot listeners scoped to this jobId so we can hand off to the// evaluator on success or schedule a retry on failure. mediaJobEventsdiff --git a/server/services/federatedMedia/defaultRouting.js b/server/services/federatedMedia/defaultRouting.jsindex 057085c929..b743b0fee1 100644--- a/server/services/federatedMedia/defaultRouting.js+++ b/server/services/federatedMedia/defaultRouting.js@@ -105,6 +105,11 @@ function assertRoutableConditioning(kind, params) {// A multi-chunk video is chained locally from its own prior output; the// provider renders one clip and knows nothing about the chain.if (kind === 'video' && Number(params?.chunks) > 1) unsupported.push('chained chunks');+ // `disableAudio` is not conditioning but it IS output semantics: the wire+ // cannot carry it, so a provider renders the clip WITH audio and the caller+ // silently gets the opposite of what it asked for. Only a truthy value is a+ // conflict — the common `false` is the provider's own default anyway.+ if (kind === 'video' && params?.disableAudio === true) unsupported.push('a silent (audio-disabled) render');if (!unsupported.length) return;throw new ServerError(`A federated media provider renders text-to-${kind} only — this ${kind} job uses ${unsupported.join(' and ')}. `@@ -113,6 +118,24 @@ function assertRoutableConditioning(kind, params) {);}+/**+ * Is a kind routed at all? Reads settings only — no peer probe, no capacity+ * preflight.+ *+ * Local readiness gates ("no Python runtime, skip the render") run BEFORE the+ * enqueue, and on a machine that routes its renders precisely because it cannot+ * render locally, those gates would skip work the peer was going to do. Call+ * this to decide whether a local-readiness verdict is even relevant.+ *+ * @param {'image'|'video'} kind+ * @returns {Promise<boolean>}+ */+export async function hasConfiguredMediaRoute(kind) {+ if (!ROUTABLE_MEDIA_KINDS.includes(kind)) return false;+ const settings = await getSettings().catch(() => null);+ return !!(settings && normalizeMediaRoutingConfig(settings)[kind]);+}+/*** Resolve the configured default provider for one unattended job, if any.*@@ -191,6 +214,16 @@ const LOCAL_ONLY_ROUTED_PARAMS = Object.freeze(['mediaProviderPeerId', 'mediaProviderEngine',]);+// Post-processing passes that run over the produced FILE, not the render. The+// wire cannot request them and the remote executor does not re-apply them after+// download, so a routed job comes back without them. They are dropped with a log+// rather than rejected (as `disableAudio` is) because the distinction is what is+// rendered vs. how the artifact is polished: dropping a denoise pass still+// returns the requested image, just less clean, and `cleanC2PA` defaults to true+// for cloud modes the user never explicitly opted into. Re-applying them+// consumer-side after download is the real fix; see the follow-up issue.+const DROPPED_POST_PROCESSING = Object.freeze(['cleanC2PA', 'denoise']);+/*** Turn a resolved route plus the planner's params into the job params to* enqueue. The prompt is blanked because it rides ONLY inside the versioned@@ -199,6 +232,11 @@ const LOCAL_ONLY_ROUTED_PARAMS = Object.freeze([export function routedJobParams(params, { request, remoteMedia }) {const jobParams = { ...(params || {}) };for (const key of LOCAL_ONLY_ROUTED_PARAMS) delete jobParams[key];+ const dropped = DROPPED_POST_PROCESSING.filter((key) => jobParams[key] === true);+ for (const key of DROPPED_POST_PROCESSING) delete jobParams[key];+ if (dropped.length) {+ console.log(`🌐 Federated render: ${dropped.join(' and ')} will not run on a routed job`);+ }return { ...jobParams, prompt: '', modelId: request.modelId, remoteMedia };}diff --git a/server/services/federatedMedia/defaultRouting.test.js b/server/services/federatedMedia/defaultRouting.test.jsindex 35bdeb083a..a9631cf823 100644--- a/server/services/federatedMedia/defaultRouting.test.js+++ b/server/services/federatedMedia/defaultRouting.test.js@@ -12,7 +12,8 @@ const enqueueJob = vi.fn(() => ({ jobId: 'mj-test' }));vi.mock('../mediaJobQueue/index.js', () => ({ enqueueJob: (...args) => enqueueJob(...args) }));const {- normalizeMediaRoutingConfig, resolveDefaultMediaRoute, routedJobParams, enqueueUnattendedMediaJob,+ normalizeMediaRoutingConfig, resolveDefaultMediaRoute, routedJobParams,+ enqueueUnattendedMediaJob, hasConfiguredMediaRoute,} = await import('./defaultRouting.js');const route = { peerId: 'peer-1', engine: 'comfy', modelId: 'sdxl-remote' };@@ -196,3 +197,55 @@ describe('enqueueUnattendedMediaJob', () => {expect(enqueueJob).not.toHaveBeenCalled();});});++describe('semantic controls the wire cannot carry', () => {+ const route = { peerId: 'peer-1', engine: 'comfy', modelId: 'wan-remote' };++ beforeEach(() => {+ getSettings.mockResolvedValue({ federation: { mediaRouting: { video: route, image: route } } });+ });++ // Not conditioning, but still the opposite of what was asked for: the wire+ // can't say "no audio", so the provider renders a clip WITH audio.+ it('refuses a routed video that asked for a silent render', async () => {+ await expect(resolveDefaultMediaRoute({ kind: 'video', params: { prompt: 'p', disableAudio: true } }))+ .rejects.toMatchObject({ code: 'MEDIA_PROVIDER_INPUT_UNSUPPORTED' });+ });++ it('allows the common disableAudio:false, which matches the provider default anyway', async () => {+ await expect(resolveDefaultMediaRoute({ kind: 'video', params: { prompt: 'p', disableAudio: false } }))+ .resolves.toMatchObject({ peer: { id: 'peer-1' } });+ });++ // Post-processing over the produced FILE, not the render: dropping it still+ // returns the requested image, so it is logged rather than refused.+ it('drops post-processing passes the remote executor will not run', () => {+ const params = routedJobParams(+ { prompt: 'p', cleanC2PA: true, denoise: true },+ { request: { modelId: 'm' }, remoteMedia: {} },+ );+ expect(params).not.toHaveProperty('cleanC2PA');+ expect(params).not.toHaveProperty('denoise');+ });+});++describe('hasConfiguredMediaRoute', () => {+ // Local readiness gates ("no Python, skip the render") run BEFORE the enqueue.+ // On a machine that routes because it CAN'T render locally, that gate would+ // skip exactly the work the peer was going to do.+ it('reports a configured kind without probing the peer', async () => {+ getSettings.mockResolvedValue({+ federation: { mediaRouting: { image: { peerId: 'p', engine: 'e', modelId: 'm' } } },+ });+ await expect(hasConfiguredMediaRoute('image')).resolves.toBe(true);+ await expect(hasConfiguredMediaRoute('video')).resolves.toBe(false);+ expect(prepareRemoteMediaJob).not.toHaveBeenCalled();+ });++ it('reports false for an unroutable kind and for an unreadable settings file', async () => {+ getSettings.mockResolvedValue({ federation: { mediaRouting: { audio: { peerId: 'p', engine: 'e', modelId: 'm' } } } });+ await expect(hasConfiguredMediaRoute('audio')).resolves.toBe(false);+ getSettings.mockRejectedValue(new Error('unreadable'));+ await expect(hasConfiguredMediaRoute('image')).resolves.toBe(false);+ });+});