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

refactor([issue-3231]): address quality review — single video-pin rung list, cheaper MV resolution, shared schema/normalizer copies

[._.]/ Adam Eivybbe95ac7c326
diff --git a/client/src/components/settings/ImageGenTab.jsx b/client/src/components/settings/ImageGenTab.jsx
index 9b85eb9ac2..1cb58267d7 100644
--- a/client/src/components/settings/ImageGenTab.jsx
+++ b/client/src/components/settings/ImageGenTab.jsx
@@ -6,7 +6,7 @@
* lives in the always-visible Codex CLI Imagegen section.
*/
-import { useState, useEffect, useCallback, useId } from 'react';
+import { useState, useEffect, useCallback, useId, useRef } from 'react';
import {
Save, Image as ImageIcon, Zap, Wrench, Cloud, Cpu, Globe, AlertTriangle,
Sparkles, Terminal, Key, Check, Trash2, SlidersHorizontal
@@ -22,7 +22,7 @@ import {
registerTool, updateTool, getToolsList,
saveHfToken, clearHfToken,
} from '../../services/api';
-import { isCloudCliMode, IMAGE_GEN_MODE, AGY_IMAGEGEN_DEFAULT_MODEL, AGY_IMAGEGEN_IMAGE_MODEL, CODEX_IMAGEGEN_DEFAULT_EFFORT, GROK_ASPECT_RATIOS, RENDER_TARGET_BACKEND_AUTO, RENDER_TARGET_OPTIONS, VIDEO_RENDER_MODES, modeLabel, supportsCloudModelOverride } from '../../lib/imageGenBackends';
+import { isCloudCliMode, IMAGE_GEN_MODE, AGY_IMAGEGEN_DEFAULT_MODEL, AGY_IMAGEGEN_IMAGE_MODEL, CODEX_IMAGEGEN_DEFAULT_EFFORT, GROK_ASPECT_RATIOS, RENDER_TARGET_BACKEND_AUTO, RENDER_TARGET_OPTIONS, VIDEO_RENDER_MODES, modeLabel, normalizeRenderPinValue, supportsCloudModelOverride } from '../../lib/imageGenBackends';
import { resolveCleanersFromConfig } from '../../lib/imageCleaners';
import { useMediaJobSse } from '../../hooks/useMediaJobSse';
import { useAgyModels } from '../../hooks/useAgyModels';
@@ -105,11 +105,11 @@ export function ImageGenTab() {
// Only pinned entries are kept; an absent target means "auto".
const [renderDefaults, setRenderDefaults] = useState({});
// Install-wide video backend pin (`settings.videoGen.mode`, #3231 Phase 4).
- // '' = no pin (local). The full loaded `videoGen` slice is kept so the save
- // can round-trip sibling keys (defaultModelId) — the settings PUT replaces
- // top-level slices wholesale.
+ // '' = no pin (local). The full loaded `videoGen` slice is kept in a ref —
+ // never rendered, only round-tripped at save time so sibling keys
+ // (defaultModelId) survive the settings PUT's wholesale slice replace.
const [videoGenMode, setVideoGenMode] = useState('');
- const [videoGenSlice, setVideoGenSlice] = useState({});
+ const videoGenSliceRef = useRef({});
const [sdapiUrl, setSdapiUrl] = useState('');
const [pythonPath, setPythonPath] = useState('');
const [exposeA1111, setExposeA1111] = useState(false);
@@ -237,9 +237,7 @@ export function ImageGenTab() {
// Video pin: keep the whole slice for round-trip; normalize the mode
// ('auto'/blank → '', i.e. no pin) for the select.
const vg = (s?.videoGen && typeof s.videoGen === 'object') ? s.videoGen : {};
- const vgMode = (typeof vg.mode === 'string' && vg.mode.trim() && vg.mode !== RENDER_TARGET_BACKEND_AUTO)
- ? vg.mode
- : '';
+ const vgMode = normalizeRenderPinValue(vg.mode) || '';
const m = ig.mode || IMAGE_GEN_MODE.EXTERNAL;
const url = normalizeUrl(ig.external?.sdapiUrl || ig.sdapiUrl);
const py = ig.local?.pythonPath || '';
@@ -274,7 +272,7 @@ export function ImageGenTab() {
setMode(m);
setRenderDefaults(rd);
setVideoGenMode(vgMode);
- setVideoGenSlice(vg);
+ videoGenSliceRef.current = vg;
setSdapiUrl(url);
setPythonPath(py);
setExposeA1111(expose);
@@ -406,7 +404,7 @@ export function ImageGenTab() {
),
// Install-wide video pin (#3231 Phase 4). Spread over the loaded slice so
// sibling keys (defaultModelId) survive the wholesale slice replace.
- videoGen: { ...videoGenSlice, mode: videoGenMode || null },
+ videoGen: { ...videoGenSliceRef.current, mode: videoGenMode || null },
};
try {
await updateSettings(patch, { silent: true });
@@ -427,7 +425,7 @@ export function ImageGenTab() {
// Reflect the pruned no-op entries back into the editor state so the
// dirty check compares like against like after a save.
setRenderDefaults(patch.renderDefaults);
- setVideoGenSlice(patch.videoGen);
+ videoGenSliceRef.current = patch.videoGen;
if (cxParallel !== codexParallelLimit) {
setCodexParallelLimit(cxParallel);
setParallelLimitDraft(String(cxParallel));
@@ -719,7 +717,7 @@ export function ImageGenTab() {
{RENDER_TARGET_OPTIONS.map(({ id, label, video }) => {
const entry = renderDefaults[id] || {};
const pinnedMode = entry.imageMode && entry.imageMode !== RENDER_TARGET_BACKEND_AUTO ? entry.imageMode : '';
- const pinnedVideoMode = entry.videoMode && entry.videoMode !== RENDER_TARGET_BACKEND_AUTO ? entry.videoMode : '';
+ const pinnedVideoMode = normalizeRenderPinValue(entry.videoMode) || '';
const modeSelectId = `render-default-mode-${id}`;
const modelInputId = `render-default-model-${id}`;
const videoSelectId = `render-default-video-${id}`;
diff --git a/client/src/lib/imageGenBackends.js b/client/src/lib/imageGenBackends.js
index a6a0c364b5..bc0929855c 100644
--- a/client/src/lib/imageGenBackends.js
+++ b/client/src/lib/imageGenBackends.js
@@ -57,6 +57,14 @@ export const RENDER_TARGET_OPTIONS = Object.freeze([
// `settings.videoGen.mode` pin.
export const VIDEO_RENDER_MODES = Object.freeze(['local', 'grok']);
+// Client mirror of the server's normalizeRenderPinValue
+// (server/lib/renderTargets.js) — THE one render-pin normalization rule: trim;
+// the 'auto' sentinel and blank strings collapse to null ("no pin").
+export const normalizeRenderPinValue = (v) => {
+ const s = typeof v === 'string' ? v.trim() : '';
+ return s && s !== RENDER_TARGET_BACKEND_AUTO ? s : null;
+};
+
// Client mirror of the server's GROK_ASPECT_RATIOS (imageGen/grok.js) — the
// aspect ratios grok's image_gen/image_edit tools accept, offered as the
// default-ratio picker in Settings → Image Gen → Grok.
diff --git a/server/lib/validation.js b/server/lib/validation.js
index c26ab7f360..059a9c283b 100644
--- a/server/lib/validation.js
+++ b/server/lib/validation.js
@@ -1007,10 +1007,13 @@ const renderTargetModelSchema = z.preprocess(
(v) => (v === '' ? null : v),
cloudModelIdString('model must be a valid model id').nullable().optional(),
);
+// Shared by the per-target entries and `videoGenSettingsSchema.mode` below —
+// one copy of the video-backend pin alphabet.
+const videoModePinSchema = z.enum([RENDER_TARGET_BACKEND_AUTO, ...VIDEO_GEN_MODES]).nullable().optional();
const renderTargetEntrySchema = z.object({
imageMode: z.enum([RENDER_TARGET_BACKEND_AUTO, ...QUEUEABLE_IMAGE_MODES]).nullable().optional(),
imageModel: renderTargetModelSchema,
- videoMode: z.enum([RENDER_TARGET_BACKEND_AUTO, ...VIDEO_GEN_MODES]).nullable().optional(),
+ videoMode: videoModePinSchema,
videoModel: renderTargetModelSchema,
});
export const renderDefaultsSettingsSchema = z.object(
@@ -1025,11 +1028,8 @@ export const renderDefaultsSettingsSchema = z.object(
// read it as the local-model default) — typed here so a Settings save can't
// write junk to it.
export const videoGenSettingsSchema = z.object({
- mode: z.enum([RENDER_TARGET_BACKEND_AUTO, ...VIDEO_GEN_MODES]).nullable().optional(),
- defaultModelId: z.preprocess(
- (v) => (v === '' ? null : v),
- z.string().trim().max(64).nullable().optional(),
- ),
+ mode: videoModePinSchema,
+ defaultModelId: z.preprocess(emptyToNull, z.string().trim().max(64).nullable().optional()),
});
// Per-RECORD render pin (#3231 Phase 3) — the flat `imageMode`/`imageModelId`
diff --git a/server/routes/videoGen.js b/server/routes/videoGen.js
index 74d817ceba..6f8969725c 100644
--- a/server/routes/videoGen.js
+++ b/server/routes/videoGen.js
@@ -759,15 +759,17 @@ router.post('/', frameImageUpload, asyncHandler(async (req, res) => {
// is honored only for a grok-DELIVERABLE request shape — the grok lane reads
// only prompt/dims/source-image/duration, so a request carrying local-only
// machinery (a semantic mode beyond text/image, keyframes, audio, IC refs,
- // extend, LoRAs, a last frame) stays local rather than silently dropping
- // those inputs. A pin degrades; only an explicit backend request errors.
+ // extend, LoRAs, a last frame, chunked renders) stays local rather than
+ // silently dropping those inputs. A pin degrades; only an explicit backend
+ // request errors.
const grokDeliverable = (!body.mode || body.mode === 'text' || body.mode === 'image')
&& !uploads.lastImage && !body.lastImageFile
&& !uploads.audioFile
&& !uploads.icReference && !body.icReferenceVideoIds?.length && !body.icReferenceImageFiles?.length
&& !body.extendFromVideoId
&& !body.keyframes?.length
- && !body.loraFilenames?.length;
+ && !body.loraFilenames?.length
+ && !(body.chunks != null && Number(body.chunks) > 1);
const backend = body.backend
|| (grokDeliverable
? resolveVideoMode(null, s, { target: body.musicVideo ? RENDER_TARGET.MUSIC_VIDEO : null })
diff --git a/server/services/creative/tools/media.js b/server/services/creative/tools/media.js
index 86996e0d06..b3f2cd3842 100644
--- a/server/services/creative/tools/media.js
+++ b/server/services/creative/tools/media.js
@@ -10,8 +10,8 @@ import { ASPECT_PRESETS, QUALITY_PRESETS, presetToRenderParams } from '../../../
import { getSettings } from '../../settings.js';
import { IMAGE_GEN_MODE, resolveQueueImageMode, resolveQueueImageEditMode } from '../../imageGen/modes.js';
import { renderTargetDefaults, resolveRenderTargetConfig } from '../../imageGen/cloudProviderConfig.js';
-import { RENDER_TARGET, normalizeRenderPinValue } from '../../../lib/renderTargets.js';
-import { VIDEO_GEN_MODE, VIDEO_GEN_MODES, resolveVideoMode } from '../../videoGen/modes.js';
+import { RENDER_TARGET } from '../../../lib/renderTargets.js';
+import { VIDEO_GEN_MODE, VIDEO_GEN_MODES, resolveVideoMode, hasVideoPin } from '../../videoGen/modes.js';
import { nearestGrokDuration } from '../../../lib/grokVideoClip.js';
import { COST_RENDER, resolveOwner } from './shared.js';
@@ -131,8 +131,7 @@ async function enforceRenderBackendPin(kind, params, project) {
// is byte-identical" contract above.
if (kind === 'image') {
if (!pin?.mode && !targetDefaults.imageMode) return params;
- } else if (!pin?.mode && !targetDefaults.videoMode
- && !normalizeRenderPinValue(settings.videoGen?.mode)) {
+ } else if (!pin?.mode && !hasVideoPin(settings, { target: RENDER_TARGET.CREATIVE_AGENT })) {
return params;
}
diff --git a/server/services/imageGen/prepareParams.js b/server/services/imageGen/prepareParams.js
index 4773c9475b..bba8017aed 100644
--- a/server/services/imageGen/prepareParams.js
+++ b/server/services/imageGen/prepareParams.js
@@ -82,22 +82,23 @@ export async function prepareGenerateParams({ data, files, referenceImageFields
const settings = await getSettings();
let mode = data.mode || settings.imageGen?.mode || IMAGE_GEN_MODE.EXTERNAL;
// #3231 Phase 4 — Music Video scene-frame renders resolve through the
- // render-target ladder: per-request mode → the owning project's record pin
+ // render-target ladder: the owning project's record pin
// (`imageMode`/`imageModelId`) → `renderDefaults['music-video']` → the
// install default above. The director board sends NO mode with its frame
// renders, so the record/target pins are live without any client seeding
- // (unlike the universe batch form). The layered model is stamped onto
+ // (unlike the universe batch form). An explicit per-request mode wins
+ // outright (and blocks the pinned model from leaking), so the project fetch
+ // is skipped entirely in that case. The layered model is stamped onto
// `data.cloudModel` so the route/dispatch resolution downstream picks it up;
// an explicit per-request cloudModel wins untouched.
- if (data.musicVideo?.projectId) {
+ if (!data.mode && data.musicVideo?.projectId) {
const project = await getMusicVideoProject(data.musicVideo.projectId).catch(() => null);
const pin = recordRenderPin(project || {});
const resolved = resolveRenderTargetConfig(settings, RENDER_TARGET.MUSIC_VIDEO, {
- mode: data.mode || null,
model: data.cloudModel || null,
recordMode: pin.mode,
recordModel: pin.modelId,
- fallbackMode: settings.imageGen?.mode || IMAGE_GEN_MODE.EXTERNAL,
+ fallbackMode: IMAGE_GEN_MODE.EXTERNAL,
});
mode = resolved.mode;
if (!data.cloudModel && resolved.cloud?.modelId) data.cloudModel = resolved.cloud.modelId;
diff --git a/server/services/imageGen/prepareParams.test.js b/server/services/imageGen/prepareParams.test.js
index e79dd637df..11ed900797 100644
--- a/server/services/imageGen/prepareParams.test.js
+++ b/server/services/imageGen/prepareParams.test.js
@@ -54,6 +54,8 @@ describe('music-video render-target resolution (#3231 Phase 4)', () => {
const { data, mode } = await run({ prompt: 'p', mode: 'local', musicVideo: { projectId: 'mv-1', sceneId: 's1' } });
expect(mode).toBe('local');
expect(data.cloudModel).toBeUndefined();
+ // Explicit mode wins outright, so the project store isn't even consulted.
+ expect(getProject).not.toHaveBeenCalled();
});
it('falls through to the install default with no pins, and a missing project is harmless', async () => {
diff --git a/server/services/videoGen/modes.js b/server/services/videoGen/modes.js
index 3a479e80cb..d127caa5e2 100644
--- a/server/services/videoGen/modes.js
+++ b/server/services/videoGen/modes.js
@@ -71,13 +71,26 @@ export function isVideoModeUsable(settings, mode) {
* enabled grok for IMAGES would be a surprise spend — grok video renders only
* when a request, record, or explicit user pin names it.
*/
+// The ONE enumeration of the video pin rungs (target pin, then install pin) —
+// both the resolver below and hasVideoPin walk this list, so adding a rung is
+// one edit and the "is anything pinned?" question can't drift from the ladder.
+const videoPinRungs = (settings, target) => [
+ target ? normalizeRenderPinValue(settings?.renderDefaults?.[target]?.videoMode) : null,
+ normalizeRenderPinValue(settings?.videoGen?.mode),
+];
+
+/**
+ * Does ANY video pin rung name a backend for this surface? Presence only — no
+ * usability gating — so callers with a byte-identical-when-auto contract (the
+ * creative agent's enforceRenderBackendPin) can gate on the same rung list the
+ * resolver walks instead of re-enumerating it.
+ */
+export function hasVideoPin(settings, { target = null } = {}) {
+ return videoPinRungs(settings, target).some(Boolean);
+}
+
export function resolveVideoMode(requested, settings, { target = null } = {}) {
- const candidates = [
- requested,
- target ? normalizeRenderPinValue(settings?.renderDefaults?.[target]?.videoMode) : null,
- normalizeRenderPinValue(settings?.videoGen?.mode),
- ];
- for (const mode of candidates) {
+ for (const mode of [requested, ...videoPinRungs(settings, target)]) {
if (mode && isVideoModeUsable(settings, mode)) return mode;
}
return VIDEO_GEN_MODE.LOCAL;