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([issue-3231]): keep a pinned model with its pinned backend, wire the creative-agent pin, add parity guard
[._.]/ Adam Eivyf4f6d6827e6a
diff --git a/client/src/components/creative-commission/commissionForm.js b/client/src/components/creative-commission/commissionForm.jsindex a1e0f616e4..408f79012b 100644--- a/client/src/components/creative-commission/commissionForm.js+++ b/client/src/components/creative-commission/commissionForm.js@@ -33,7 +33,10 @@ const DURATION_FIELD = { key: 'targetDurationSeconds', label: 'Duration (sec)',// conditional model picker (see CommissionConfigForm's RenderBackendSection),// mirroring the pipeline's VisualGenSettings UX; the generic field renderer in// GenerationSection skips them.-export const RENDER_BACKEND_AUTO = 'auto';+// Re-exported from the shared lib so the commission form and the Settings+// Defaults tab (#3231) can never disagree on the "no pin" protocol value.+export { RENDER_TARGET_BACKEND_AUTO as RENDER_BACKEND_AUTO } from '../../lib/imageGenBackends';+import { RENDER_TARGET_BACKEND_AUTO as RENDER_BACKEND_AUTO } from '../../lib/imageGenBackends';export const IMAGE_BACKEND_OPTIONS = [[RENDER_BACKEND_AUTO, 'Auto (install default)'],diff --git a/server/lib/creativeCommissionValidation.js b/server/lib/creativeCommissionValidation.jsindex 3178b2508c..dcf7556369 100644--- a/server/lib/creativeCommissionValidation.js+++ b/server/lib/creativeCommissionValidation.js@@ -1,6 +1,7 @@import { z } from 'zod';import { QUEUEABLE_IMAGE_MODES } from '../services/imageGen/modes.js';import { VIDEO_GEN_MODES } from '../services/videoGen/modes.js';+import { RENDER_TARGET_BACKEND_AUTO } from './renderTargets.js';// =============================================================================// CREATIVE COMMISSION SCHEMAS (Autonomous Creation Engine — #2657, Phase 1)@@ -46,8 +47,10 @@ export const CREATIVE_COMMISSION_ASPECT_RATIOS = Object.freeze(['16:9', '9:16',// so an existing commission that never sets the field behaves exactly as before.// It is deliberately NOT a member of the backend enums — it is the absence of a// pin, mirroring the `'auto'` sentinel the pipeline visual stages already ship-// (client/src/components/pipeline/stages/VisualGenSettings.jsx).-export const COMMISSION_RENDER_BACKEND_AUTO = 'auto';+// (client/src/components/pipeline/stages/VisualGenSettings.jsx). Re-exported+// from the render-target leaf (#3231) so the two "no pin" protocol values can+// never diverge.+export const COMMISSION_RENDER_BACKEND_AUTO = RENDER_TARGET_BACKEND_AUTO;// Image backends a commission may pin: the queueable image modes (local / codex// / grok — `external` never queues) plus the auto sentinel. Derived fromdiff --git a/server/lib/renderTargets.parity.test.js b/server/lib/renderTargets.parity.test.jsnew file mode 100644index 0000000000..58f885f1f1--- /dev/null+++ b/server/lib/renderTargets.parity.test.js@@ -0,0 +1,48 @@+/**+ * Cross-package parity for the render-target alphabet (#3231).+ *+ * `server/lib/renderTargets.js` is the source of truth; the client's+ * `RENDER_TARGET_OPTIONS` (client/src/lib/imageGenBackends.js) is a+ * hand-maintained mirror feeding the Settings → Image Gen → Defaults tab. A+ * typo'd or renamed id in the client list would make the strict+ * `renderDefaultsSettingsSchema` 400 the ENTIRE settings PUT — and both+ * suites would stay green, because the client test mocks updateSettings+ * (the exact mocked-client-suite blind spot this repo has shipped before).+ * This suite imports both and fails on drift instead.+ *+ * Lives server-side because the server runner loads the pure client lib fine,+ * while the client (jsdom) runner can't load server modules.+ */++import { describe, it, expect } from 'vitest';+import { RENDER_TARGET, RENDER_TARGETS, RENDER_TARGET_BACKEND_AUTO } from './renderTargets.js';+import {+ RENDER_TARGET_OPTIONS as CLIENT_OPTIONS,+ RENDER_TARGET_BACKEND_AUTO as CLIENT_AUTO,+} from '../../client/src/lib/imageGenBackends.js';++// Targets the Settings UI deliberately does NOT list yet — a pin nobody's+// resolver reads would be a control that silently does nothing. Shrink this+// as phases land (music-video ships with the Phase 4 video lane).+const DELIBERATELY_UNLISTED = new Set([RENDER_TARGET.MUSIC_VIDEO]);++describe('render-target client mirror parity (#3231)', () => {+ it('every client option id is a real server render target', () => {+ const server = new Set(RENDER_TARGETS);+ for (const { id } of CLIENT_OPTIONS) {+ expect(server.has(id), `client RENDER_TARGET_OPTIONS id "${id}" is not in server RENDER_TARGETS`).toBe(true);+ }+ });++ it('every server target is either listed client-side or deliberately unlisted', () => {+ const client = new Set(CLIENT_OPTIONS.map((o) => o.id));+ for (const id of RENDER_TARGETS) {+ expect(client.has(id) || DELIBERATELY_UNLISTED.has(id),+ `server render target "${id}" is neither in client RENDER_TARGET_OPTIONS nor allowlisted as deliberately unlisted`).toBe(true);+ }+ });++ it('the auto sentinel matches across packages', () => {+ expect(CLIENT_AUTO).toBe(RENDER_TARGET_BACKEND_AUTO);+ });+});diff --git a/server/lib/validation.js b/server/lib/validation.jsindex 6a00f179ff..249156e656 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -977,11 +977,15 @@ export const imageGenGrokSettingsSchema = z.object({denoise: z.boolean().optional(),});+// Shared "valid model id" base — one definition of the shape a cloud-CLI+// model id may take (bounds + charset), derived per consumer below so a+// future tweak (e.g. allowing `@`) lands everywhere at once.+const cloudModelIdString = (message) => z.string().trim().max(200)+ .regex(/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/, message);+const agyImageModelSchema = z.preprocess((v) => (v === '' ? undefined : v),- z.string().trim().max(200)- .regex(/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/, 'model must be a valid Agy model id')- .optional(),+ cloudModelIdString('model must be a valid Agy model id').optional(),);// Per-surface render defaults (`settings.renderDefaults`, #3231 Phase 2) —@@ -992,10 +996,7 @@ const agyImageModelSchema = z.preprocess(// instead of silently persisting a slice no resolver reads.const renderTargetModelSchema = z.preprocess((v) => (v === '' ? null : v),- z.string().trim().max(200)- .regex(/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/, 'model must be a valid model id')- .nullable()- .optional(),+ cloudModelIdString('model must be a valid model id').nullable().optional(),);const renderTargetEntrySchema = z.object({imageMode: z.enum([RENDER_TARGET_BACKEND_AUTO, ...QUEUEABLE_IMAGE_MODES]).nullable().optional(),diff --git a/server/services/creative/tools/media.js b/server/services/creative/tools/media.jsindex 5aa861cde9..3c099a9c9b 100644--- a/server/services/creative/tools/media.js+++ b/server/services/creative/tools/media.js@@ -9,7 +9,7 @@ import { enqueueJob } from '../../mediaJobQueue/index.js';import { ASPECT_PRESETS, QUALITY_PRESETS, presetToRenderParams } from '../../../lib/creativeDirectorPresets.js';import { getSettings } from '../../settings.js';import { IMAGE_GEN_MODE, resolveQueueImageMode, resolveQueueImageEditMode } from '../../imageGen/modes.js';-import { resolveRenderTargetConfig } from '../../imageGen/cloudProviderConfig.js';+import { renderTargetDefaults, resolveRenderTargetConfig } from '../../imageGen/cloudProviderConfig.js';import { RENDER_TARGET } from '../../../lib/renderTargets.js';import { VIDEO_GEN_MODE, VIDEO_GEN_MODES, resolveVideoMode } from '../../videoGen/modes.js';import { nearestGrokDuration } from '../../../lib/grokVideoClip.js';@@ -121,9 +121,18 @@ function attachMusicBedTag(params, ctx) {*/async function enforceRenderBackendPin(kind, params, project) {const pin = project?.renderBackend?.[kind];- if (!pin?.mode) return params;+ // The image lane has TWO pin sources: the project's own renderBackend pin+ // (per-record, wins) and the install-wide creative-agent renderDefaults pin+ // (#3231). The video lane stays project-pin-only until the Phase 4 video+ // wiring lands. When NEITHER source pins, params pass through untouched —+ // the "auto is byte-identical" contract above.+ if (!pin?.mode && kind !== 'image') return params;const settings = await getSettings().catch(() => null);if (!settings) return params;+ if (!pin?.mode && kind === 'image'+ && !renderTargetDefaults(settings, RENDER_TARGET.CREATIVE_AGENT).imageMode) {+ return params;+ }if (kind === 'video') {const mode = resolveVideoMode(pin.mode, settings);@@ -174,11 +183,19 @@ async function enforceRenderBackendPin(kind, params, project) {}const wantsEdit = !!params?.initImagePath || params?.referenceImagePaths?.length > 0;+ // Project pin (explicit, per-record) → creative-agent renderDefaults pin —+ // both usability-laddered so a disabled backend degrades instead of failing+ // a nightly commission.+ const requested = pin?.mode+ || renderTargetDefaults(settings, RENDER_TARGET.CREATIVE_AGENT).imageMode;const mode = wantsEdit- ? resolveQueueImageEditMode(pin.mode, settings)- : resolveQueueImageMode(pin.mode, settings);- // Mode is pinned/laddered above; this threads the creative-agent- // renderDefaults imageModel into the cloud job params (#3231).+ ? resolveQueueImageEditMode(requested, settings)+ : resolveQueueImageMode(requested, settings);+ // Mode is laddered above; this threads the creative-agent renderDefaults+ // imageModel into the cloud job params (#3231). The project's own+ // `pin.modelId` is deliberately NOT passed as the cloud model override —+ // commissions pick it from the LOCAL diffusion catalog, so it only applies+ // on the local branch below.const { cloud } = resolveRenderTargetConfig(settings, RENDER_TARGET.CREATIVE_AGENT, { mode });if (cloud) return { ...params, ...cloud.jobParams };return {@@ -186,7 +203,7 @@ async function enforceRenderBackendPin(kind, params, project) {mode: IMAGE_GEN_MODE.LOCAL,pythonPath: settings.imageGen?.local?.pythonPath || null,// The user's pinned model wins over the planner's freehand guess.- ...(pin.modelId ? { modelId: pin.modelId } : {}),+ ...(pin?.modelId ? { modelId: pin.modelId } : {}),};}diff --git a/server/services/creative/tools/media.test.js b/server/services/creative/tools/media.test.jsindex 7e03d45d4b..b5f34bf49c 100644--- a/server/services/creative/tools/media.test.js+++ b/server/services/creative/tools/media.test.js@@ -27,18 +27,38 @@ beforeEach(() => {});describe('render-backend pin — the auto/unpinned path is a strict no-op (#3135)', () => {- it('leaves image params untouched with no owning project', async () => {+ // Note (#3231): the image lane now reads settings even without a project pin+ // — the install-wide creative-agent renderDefaults pin is a second pin+ // source — so the old "no settings read at all" assertion is gone. The+ // load-bearing contract is unchanged: with NO pin from either source, the+ // enqueued params are byte-identical to the caller's.+ it('leaves image params untouched with no owning project and no renderDefaults pin', async () => {await run('media_enqueueImageJob', { prompt: 'a lighthouse' });expect(enqueued().params).toEqual({ prompt: 'a lighthouse' });- // No project ⇒ no settings read at all.- expect(getSettings).not.toHaveBeenCalled();});it('leaves image params untouched when the project has no pin', async () => {getProject.mockResolvedValue(projectWithPin(null));await run('media_enqueueImageJob', { prompt: 'p' }, { projectId: 'cd-1' });expect(enqueued().params).toEqual({ prompt: 'p' });- expect(getSettings).not.toHaveBeenCalled();+ });++ it('applies the creative-agent renderDefaults pin when the project has none (#3231)', async () => {+ getSettings.mockResolvedValue({+ imageGen: { codex: { enabled: true, codexPath: '/bin/codex', model: 'example-model', effort: 'low' } },+ renderDefaults: { 'creative-agent': { imageMode: 'codex' } },+ });+ await run('media_enqueueImageJob', { prompt: 'p' });+ expect(enqueued().params).toEqual(expect.objectContaining({ mode: 'codex', model: 'example-model' }));+ });++ it('a disabled creative-agent renderDefaults pin still leaves params flowing (degrades, never fails)', async () => {+ getSettings.mockResolvedValue({+ renderDefaults: { 'creative-agent': { imageMode: 'codex' } },+ });+ await run('media_enqueueImageJob', { prompt: 'p' });+ // Codex pin present but disabled → the usability ladder degrades to local.+ expect(enqueued().params).toEqual(expect.objectContaining({ mode: 'local', prompt: 'p' }));});it('leaves video params untouched when the project has no pin', async () => {diff --git a/server/services/imageGen/cloudProviderConfig.js b/server/services/imageGen/cloudProviderConfig.jsindex d821bb893c..0c5736c0b9 100644--- a/server/services/imageGen/cloudProviderConfig.js+++ b/server/services/imageGen/cloudProviderConfig.js@@ -188,21 +188,20 @@ export function renderTargetDefaults(settings, target) {* (e.g. `body.mode`). Wins over the target pin.* - `model` — per-request cloud model override. Wins over the target's* `imageModel` pin.- * - `resolveMode` — optional `(candidateMode, settings) => finalMode` ladder- * (e.g. `resolveQueueImageMode`) applied to the layered- * candidate, for surfaces that gate on backend usability.* - `fallbackMode`— the surface's historical final fallback when nothing* else resolves (EXTERNAL for batch-reject surfaces, LOCAL- * for local-first ones). Ignored when `resolveMode` is- * given (the ladder owns the fallback).+ * for local-first ones). Surfaces with their own usability+ * ladder (resolveQueueImageMode / pickUsableMode) resolve+ * mode first — seeding the ladder with+ * `renderTargetDefaults(...).imageMode` — and pass the+ * result as `mode` here for model threading.*- * Returns `{ mode, model, cloud }` — `cloud` is the resolveCloudProviderConfig+ * Returns `{ mode, cloud }` — `cloud` is the resolveCloudProviderConfig* bundle (null for non-cloud modes), with the layered model threaded through.*/export function resolveRenderTargetConfig(settings, target, {mode = null,model = null,- resolveMode = null,fallbackMode = null,} = {}) {const defaults = renderTargetDefaults(settings, target);@@ -214,14 +213,17 @@ export function resolveRenderTargetConfig(settings, target, {const pinnedMode = defaults.imageMode && isModeUsable(settings, defaults.imageMode)? defaults.imageMode: null;- const candidate = mode || pinnedMode;- const finalMode = resolveMode- ? resolveMode(candidate, settings)- : (candidate || settings?.imageGen?.mode || fallbackMode);- const finalModel = (typeof model === 'string' && model.trim()) ? model.trim() : defaults.imageModel;+ const finalMode = mode || pinnedMode || settings?.imageGen?.mode || fallbackMode;+ // The model pin rides WITH its backend pin: apply defaults.imageModel only+ // when the resolved mode is still the pinned backend. When the mode fell+ // back (pin disabled) or an explicit request chose another backend, the+ // pinned model must not leak — codex would happily accept `--model` with a+ // gemini id (supportsModelOverride gates by PROVIDER, not by id namespace).+ const requestedModel = (typeof model === 'string' && model.trim()) ? model.trim() : null;+ const finalModel = requestedModel+ || (defaults.imageMode && finalMode === defaults.imageMode ? defaults.imageModel : null);return {mode: finalMode,- model: finalModel,cloud: resolveCloudProviderConfig(settings, finalMode, { model: finalModel }),};}diff --git a/server/services/imageGen/cloudProviderConfig.test.js b/server/services/imageGen/cloudProviderConfig.test.jsindex 9fa0042df6..82042dba8f 100644--- a/server/services/imageGen/cloudProviderConfig.test.js+++ b/server/services/imageGen/cloudProviderConfig.test.js@@ -265,17 +265,27 @@ describe('resolveRenderTargetConfig (#3231)', () => {expect(cloud.modelId).toBe('request-model');});- it('a resolveMode ladder receives the layered candidate and owns the fallback', () => {+ it('a disabled pinned backend falls through — and takes its model pin with it', () => {const settings = withDefaults(- { codex: { enabled: true } },- // Pin grok but leave it DISABLED — the ladder must fall through, not- // honor a pinned-but-unusable backend.- { 'sprite-reference': { imageMode: IMAGE_GEN_MODE.GROK } },+ // Agy pin is DISABLED; install default is codex.+ { mode: IMAGE_GEN_MODE.CODEX, codex: { enabled: true }, agy: { enabled: false } },+ { 'universe-bible': { imageMode: IMAGE_GEN_MODE.AGY, imageModel: 'gemini-3.6-flash-low' } },);- const { mode } = resolveRenderTargetConfig(settings, 'sprite-reference', {- resolveMode: (candidate, s) => resolveQueueImageMode(candidate, s),- });+ const { mode, cloud } = resolveRenderTargetConfig(settings, 'universe-bible');expect(mode).toBe(IMAGE_GEN_MODE.CODEX);+ // The gemini model pinned FOR AGY must not leak into codex's --model —+ // supportsModelOverride gates by provider, not by id namespace.+ expect(cloud.modelId).toBe(CODEX_IMAGEGEN_DEFAULT_MODEL);+ expect(cloud.jobParams.model).toBe(CODEX_IMAGEGEN_DEFAULT_MODEL);+ });++ it('an explicit mode on another backend does not inherit the pinned model', () => {+ const settings = withDefaults(+ { codex: { enabled: true }, agy: { enabled: true } },+ { 'sprite-reference': { imageMode: IMAGE_GEN_MODE.AGY, imageModel: 'gemini-3.6-flash-low' } },+ );+ const { cloud } = resolveRenderTargetConfig(settings, 'sprite-reference', { mode: IMAGE_GEN_MODE.CODEX });+ expect(cloud.modelId).toBe(CODEX_IMAGEGEN_DEFAULT_MODEL);});it('renderTargetDefaults normalizes auto/blank/missing to null', () => {