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: keep pipeline i2i renders off edit-incapable backends (#3243)

[._.]/ Adam Eivyd7f69bb3fea0
diff --git a/server/services/imageGen/cloudProviderConfig.js b/server/services/imageGen/cloudProviderConfig.js
index 5aec7d13b9..fa170977df 100644
--- a/server/services/imageGen/cloudProviderConfig.js
+++ b/server/services/imageGen/cloudProviderConfig.js
@@ -24,6 +24,7 @@ import {
CODEX_IMAGEGEN_DEFAULT_MODEL,
IMAGE_GEN_MODE,
QUEUEABLE_IMAGE_MODES,
+ isEditCapableMode,
} from './modes.js';
/**
@@ -138,8 +139,13 @@ export function resolveCloudProviderConfig(settings, mode, overrides = {}) {
* (pipeline/visualStageHelpers.js), so the mode ladder no longer grows a
* pairwise `if` per backend.
*/
-export function isModeUsable(settings, mode) {
+export function isModeUsable(settings, mode, { edit = false } = {}) {
if (!QUEUEABLE_IMAGE_MODES.includes(mode)) return false;
+ // An edit render (i2i / "use proof as base" / refine) can only go to a backend
+ // that accepts an input image at all — #3243. Without this the ladder happily
+ // returned Agy for a redraw, and the failure surfaced asynchronously in the
+ // queue as AGY_IMAGE_EDIT_UNSUPPORTED, long after the request 200'd.
+ if (edit && !isEditCapableMode(mode)) return false;
const cloud = resolveCloudProviderConfig(settings, mode);
return cloud ? cloud.enabled : true;
}
@@ -147,10 +153,17 @@ export function isModeUsable(settings, mode) {
/**
* First usable mode from an ordered candidate list, falling back to the
* cloud providers (in `CLOUD_IMAGE_GEN_MODES` order) and finally local.
+ *
+ * Pass `{ edit: true }` when the render carries an input image: edit-incapable
+ * backends are then skipped at every rung, so a record pinned to such a backend
+ * FALLS THROUGH to the next usable one rather than failing. Falling through is
+ * deliberate — a pin is a preference, and the surrounding pins already degrade
+ * this way when a pinned backend is disabled (the enforceRenderBackendPin
+ * contract). LOCAL is edit-capable, so the tail always resolves.
*/
-export function pickUsableMode(settings, candidates = []) {
+export function pickUsableMode(settings, candidates = [], { edit = false } = {}) {
const ordered = [...candidates, ...CLOUD_IMAGE_GEN_MODES, IMAGE_GEN_MODE.LOCAL];
- return ordered.find((m) => m && isModeUsable(settings, m)) || IMAGE_GEN_MODE.LOCAL;
+ return ordered.find((m) => m && isModeUsable(settings, m, { edit })) || IMAGE_GEN_MODE.LOCAL;
}
/**
diff --git a/server/services/imageGen/cloudProviderConfig.test.js b/server/services/imageGen/cloudProviderConfig.test.js
index e905620eb5..3edc9aaf7c 100644
--- a/server/services/imageGen/cloudProviderConfig.test.js
+++ b/server/services/imageGen/cloudProviderConfig.test.js
@@ -168,6 +168,19 @@ describe('isModeUsable', () => {
expect(isModeUsable(settingsWith({}), IMAGE_GEN_MODE.EXTERNAL)).toBe(false);
expect(isModeUsable(settingsWith({}), 'nonsense')).toBe(false);
});
+
+ it('refuses an edit-incapable backend for an edit render, enabled or not (#3243)', () => {
+ // Agy's generate_image takes no input image, so an i2i render routed there
+ // throws AGY_IMAGE_EDIT_UNSUPPORTED — asynchronously, inside the queue, long
+ // after the request 200'd. Enabled-ness is irrelevant: it is a capability,
+ // not a toggle.
+ const s = settingsWith({ agy: { enabled: true }, codex: { enabled: true } });
+ expect(isModeUsable(s, IMAGE_GEN_MODE.AGY)).toBe(true);
+ expect(isModeUsable(s, IMAGE_GEN_MODE.AGY, { edit: true })).toBe(false);
+ // Edit-capable backends are unaffected by the flag.
+ expect(isModeUsable(s, IMAGE_GEN_MODE.CODEX, { edit: true })).toBe(true);
+ expect(isModeUsable(s, IMAGE_GEN_MODE.LOCAL, { edit: true })).toBe(true);
+ });
});
describe('pickUsableMode', () => {
@@ -196,6 +209,24 @@ describe('pickUsableMode', () => {
)).toBe(IMAGE_GEN_MODE.CODEX);
});
+ it('falls a record pinned to an edit-incapable backend through to the next usable one (#3243)', () => {
+ // The bug: a series pinned to Agy rendered plain text-to-image fine, but
+ // every redraw ("use proof as base", a reference page, a refine pass)
+ // enqueued and then failed async. Falling through is the right answer, not
+ // an error — a pin is a preference, and the surrounding pins already degrade
+ // this way when a pinned backend is disabled.
+ const s = settingsWith({ agy: { enabled: true }, codex: { enabled: true } });
+ expect(pickUsableMode(s, [IMAGE_GEN_MODE.AGY])).toBe(IMAGE_GEN_MODE.AGY);
+ expect(pickUsableMode(s, [IMAGE_GEN_MODE.AGY], { edit: true })).toBe(IMAGE_GEN_MODE.CODEX);
+ });
+
+ it('lands on local for an edit render when every cloud backend is edit-incapable or off (#3243)', () => {
+ // LOCAL is edit-capable, so the auto tail always resolves — an edit render
+ // can never fall off the end of the ladder.
+ const agyOnly = settingsWith({ codex: { enabled: false }, grok: { enabled: false }, agy: { enabled: true } });
+ expect(pickUsableMode(agyOnly, [IMAGE_GEN_MODE.AGY], { edit: true })).toBe(IMAGE_GEN_MODE.LOCAL);
+ });
+
it('falls back to local when nothing else is usable', () => {
expect(pickUsableMode(bothOff, [IMAGE_GEN_MODE.EXTERNAL])).toBe(IMAGE_GEN_MODE.LOCAL);
expect(pickUsableMode(bothOff)).toBe(IMAGE_GEN_MODE.LOCAL);
diff --git a/server/services/imageGen/modes.js b/server/services/imageGen/modes.js
index 933364d807..d1cba366fb 100644
--- a/server/services/imageGen/modes.js
+++ b/server/services/imageGen/modes.js
@@ -37,6 +37,21 @@ export const CLOUD_IMAGE_GEN_MODES = Object.freeze([
// future backend is one edit here instead of a sweep of enum literals.
export const QUEUEABLE_IMAGE_MODES = Object.freeze([IMAGE_GEN_MODE.LOCAL, ...CLOUD_IMAGE_GEN_MODES]);
+// Backends that cannot take an input image at all (#3243). Agy's `generate_image`
+// tool accepts prompt / image name / aspect ratio / reference paths and exposes
+// no edit mode, so `agy.js` throws AGY_IMAGE_EDIT_UNSUPPORTED the moment an
+// initImagePath or referenceImagePaths arrives.
+//
+// This is the SINGLE source for that fact. It was previously encoded implicitly,
+// by `resolveQueueImageEditMode` simply never listing AGY — which is invisible to
+// any other ladder, and is why the pipeline's `pickUsableMode` ladder could route
+// an i2i redraw to Agy and fail asynchronously in the queue. A future
+// edit-incapable backend belongs here and nowhere else.
+export const EDIT_INCAPABLE_IMAGE_MODES = Object.freeze([IMAGE_GEN_MODE.AGY]);
+
+/** Can `mode` accept an input image (i2i / edit)? */
+export const isEditCapableMode = (mode) => !EDIT_INCAPABLE_IMAGE_MODES.includes(mode);
+
// Cloud-CLI providers expose no numeric i2i denoise knob, so map the
// local-runner-style strength (0..1, lower = more faithful to the source)
// onto a phrase the model reliably honors. Mirrors
diff --git a/server/services/pipeline/comicPages.js b/server/services/pipeline/comicPages.js
index 3304d7e876..7bc87290d2 100644
--- a/server/services/pipeline/comicPages.js
+++ b/server/services/pipeline/comicPages.js
@@ -230,7 +230,6 @@ export async function enqueueVisualComicPage(issueId, options = {}) {
});
}
- const mode = resolveMode(options, settings, series);
const variant = resolveVariant(options.target);
// Consistency reference: pass an already-rendered page as the init image so a
@@ -253,6 +252,10 @@ export async function enqueueVisualComicPage(issueId, options = {}) {
: fromProof
? (Number.isFinite(options.initImageStrength) ? options.initImageStrength : PROOF_AS_BASE_DEFAULT_STRENGTH)
: undefined;
+ // Resolved AFTER the init image, so an i2i render skips edit-incapable
+ // backends rather than resolving to one that rejects the job in the queue
+ // (#3243).
+ const mode = resolveMode(options, settings, series, { edit: Boolean(initImagePath) });
// Build a free-text haystack from every panel's prose (description +
// caption + sfx). Dialogue lines feed character matching via CAPS names
@@ -469,7 +472,9 @@ export async function refineComicPageRender(issueId, options = {}) {
logTag: `Pipeline comic page refine — issue=${issueId.slice(0, 8)} page=${pageIndex + 1} variant=${variant}`,
});
- const mode = resolveMode(options, settings, series);
+ // A refine render always redraws from `initImagePath`, so it is unconditionally
+ // an edit — edit-incapable backends are skipped (#3243).
+ const mode = resolveMode(options, settings, series, { edit: true });
const initImageStrength = Number.isFinite(options.initImageStrength)
? Math.min(Math.max(options.initImageStrength, 0), 1)
: REFINE_RENDER_DEFAULT_STRENGTH;
diff --git a/server/services/pipeline/covers.js b/server/services/pipeline/covers.js
index ef90e2f6b2..b92fc06a37 100644
--- a/server/services/pipeline/covers.js
+++ b/server/services/pipeline/covers.js
@@ -147,12 +147,14 @@ async function enqueueComicCoverLike(issueId, target, options = {}) {
const script = typeof options[scriptOptionKey] === 'string'
? options[scriptOptionKey]
: (record?.script || '');
- const mode = resolveMode(options, settings, series);
const variant = resolveVariant(options.target);
const fromProof = variant === 'final' && options.useProofAsBase === true;
const initImagePath = fromProof
? resolveProofInitImage(record?.proofImage, target)
: null;
+ // Resolved AFTER the init image so a proof-as-base render skips edit-incapable
+ // backends instead of failing asynchronously in the queue (#3243).
+ const mode = resolveMode(options, settings, series, { edit: Boolean(initImagePath) });
const initImageStrength = fromProof
? (Number.isFinite(options.initImageStrength) ? options.initImageStrength : PROOF_AS_BASE_DEFAULT_STRENGTH)
: undefined;
@@ -337,12 +339,13 @@ async function enqueueVolumeCoverLike(seriesId, seasonId, target, options = {})
const script = typeof options[scriptOptionKey] === 'string'
? options[scriptOptionKey]
: (record?.script || '');
- const mode = resolveMode(options, settings, series);
const variant = resolveVariant(options.target);
const fromProof = variant === 'final' && options.useProofAsBase === true;
const initImagePath = fromProof
? resolveProofInitImage(record?.proofImage, `volume ${target}`)
: null;
+ // Resolved AFTER the init image — see the issue-cover path above (#3243).
+ const mode = resolveMode(options, settings, series, { edit: Boolean(initImagePath) });
const initImageStrength = fromProof
? (Number.isFinite(options.initImageStrength) ? options.initImageStrength : PROOF_AS_BASE_DEFAULT_STRENGTH)
: undefined;
diff --git a/server/services/pipeline/visualStageHelpers.js b/server/services/pipeline/visualStageHelpers.js
index f0b923f19b..84c66046fc 100644
--- a/server/services/pipeline/visualStageHelpers.js
+++ b/server/services/pipeline/visualStageHelpers.js
@@ -76,12 +76,19 @@ const applyWorldStyle = (prompt, world, series = null) => {
// The series' persisted per-record pin (#3231 Phase 3) sits between the
// per-request override and the install-wide target pin: "this series renders
// on codex" beats the surface default, loses to an explicit UI selection.
-const resolveMode = (options, settings, series = null) => pickUsableMode(settings, [
+// `edit` marks a render that carries an input image (i2i: "use proof as base",
+// a reference page, or a refine pass). Edit-incapable backends are skipped at
+// every rung so the ladder falls through instead of resolving to one that will
+// reject the job asynchronously (#3243). It DEFAULTS from `options.initImagePath`
+// so a call site that already carries the image on `options` — enqueueVisualImage,
+// the storyboard shot path — is covered without opting in; the sites that derive
+// the init image AFTER resolving the mode pass `{ edit: true }` explicitly.
+const resolveMode = (options, settings, series = null, { edit } = {}) => pickUsableMode(settings, [
options.mode,
recordRenderPin(series).mode,
renderTargetDefaults(settings, RENDER_TARGET.PIPELINE_VISUAL).imageMode,
settings?.imageGen?.mode,
-]);
+], { edit: edit ?? Boolean(options.initImagePath) });
/**
* Resolve trained character LoRAs for a pipeline render. Local mode only —