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

address review (codex): keep corrected i2v re-rolls from being told to hold still

[._.]/ Adam Eivyf8e68cb0ac09
diff --git a/server/services/sprites/prompts.js b/server/services/sprites/prompts.js
index 13730a609e..4f18034c84 100644
--- a/server/services/sprites/prompts.js
+++ b/server/services/sprites/prompts.js
@@ -172,18 +172,43 @@ export const TURNAROUND_ID = 'turnaround';
// fix…") and the boundary between the user's words and ours disappears.
const asSentence = (note) => (/[.!?]$/.test(note) ? note : `${note}.`);
-const leadInFor = (note, subject) => (
- 'This is a corrected re-render: a previous attempt at this exact image was rejected. '
- + `Required fix: ${note} Make that fix in the image you produce. It takes priority over any `
+/**
+ * Per-medium copy for the two halves. The medium is explicit rather than shared
+ * because the sandwich has to overrule the body's pin-to-the-attachment clauses
+ * WITHOUT also overruling its motion instruction: "keep everything else
+ * identical [to the attached still]" is exactly right for an image and exactly
+ * wrong for an image-to-video render, where every frame after the first is
+ * SUPPOSED to differ from the attachment. A video surface inheriting the image
+ * wording is told to hold still — trading the ignored-correction bug for a
+ * frozen clip. `keepRest` closes the lead-in's sentence; `keepRestClosing`
+ * closes the override's.
+ */
+const CORRECTION_MEDIA = Object.freeze({
+ image: {
+ noun: 'image',
+ keepRest: 'and keep everything else identical',
+ keepRestClosing: (subject) => `everything it does not mention stays as the attached ${subject} shows it`,
+ },
+ animation: {
+ noun: 'animation',
+ keepRest: 'and leave the rest of the animation exactly as the instructions below describe it',
+ keepRestClosing: (subject) => 'the motion described above still happens in full, and every other detail of '
+ + `identity and appearance stays as the attached ${subject} shows it`,
+ },
+});
+
+const leadInFor = (note, subject, medium) => (
+ `This is a corrected re-render: a previous attempt at this exact ${medium.noun} was rejected. `
+ + `Required fix: ${note} Make that fix in the ${medium.noun} you produce. It takes priority over any `
+ `instruction below to match or preserve the attached ${subject} — change what the fix names, `
- + 'and keep everything else identical. '
+ + `${medium.keepRest}. `
);
-const overrideFor = (note, subject) => (
+const overrideFor = (note, subject, medium) => (
` Required fix (highest priority — this overrides any conflicting instruction above): ${note}`
- + ' The previous render was rejected for exactly this, so an image that does not visibly'
- + ' reflect this fix is a failed render. Change only what the fix names; everything it does'
- + ` not mention stays as the attached ${subject} shows it.`
+ + ` The previous render was rejected for exactly this, so an ${medium.noun} that does not visibly`
+ + ' reflect this fix is a failed render. Change only what the fix names;'
+ + ` ${medium.keepRestClosing(subject)}.`
);
/**
@@ -192,15 +217,31 @@ const overrideFor = (note, subject) => (
* one of them wired and not the other; that half-wired state is precisely what
* reads to the user as "the model ignored my feedback".
*
+ * `target` names both what the render DERIVES from (`subject` — "turnaround",
+ * "reference", "source image", so each surface reads naturally) and what it
+ * PRODUCES (`output` — a key of `CORRECTION_MEDIA`). Both are required and named
+ * at every call site: an optional medium defaulting to `image` is how a video
+ * builder silently ends up with wording that forbids motion.
+ *
* An absent, blank, or non-string note returns `body` untouched. That is the hard
* contract every surface depends on: a whitespace-only note must leave the prompt
* byte-identical to a blind regenerate.
*/
-export function applyCorrection(body, correctionPrompt, subject) {
+export function applyCorrection(body, correctionPrompt, { subject, output } = {}) {
+ const medium = CORRECTION_MEDIA[output];
+ // Fail fast, and BEFORE the blank-note early return — a builder that names an
+ // unknown medium has to break on the blind path too, not lie dormant until a
+ // user actually types a note.
+ if (!medium) {
+ throw new TypeError(
+ `applyCorrection: unknown output medium "${output}" `
+ + `(expected ${Object.keys(CORRECTION_MEDIA).join(' | ')})`,
+ );
+ }
const raw = typeof correctionPrompt === 'string' ? correctionPrompt.trim() : '';
if (!raw) return body;
const note = asSentence(raw);
- return leadInFor(note, subject) + body + overrideFor(note, subject);
+ return leadInFor(note, subject, medium) + body + overrideFor(note, subject, medium);
}
/**
@@ -257,7 +298,7 @@ export function buildTurnaroundPrompt({ name, designPrompt, chromaKey, correctio
+ 'labels, captions, arrows, grid, shadows, scenery, wireframe, or extra characters. '
+ 'Return exactly one PNG.',
correctionPrompt,
- 'turnaround',
+ { subject: 'turnaround', output: 'image' },
);
}
@@ -327,7 +368,7 @@ export function buildMainReferencePrompt({ name, designPrompt, chromaKey, correc
// The main derives from the sheet when there is one, so name the sheet as
// the attachment the untouched details come from; a legacy record has only
// its own reference attached.
- fromTurnaround ? 'turnaround' : 'reference',
+ { subject: fromTurnaround ? 'turnaround' : 'reference', output: 'image' },
);
}
@@ -348,7 +389,7 @@ export function buildAmbientReferencePrompt({ name, kind, designPrompt, chromaKe
+ `Use a plain exact ${keyColorPhrase(chromaKey)} background on a square 1:1 canvas. No people, scenery, text, labels, grid, `
+ 'camera angle, shadows, wireframe, or extra objects. Return exactly one PNG.',
correctionPrompt,
- 'reference',
+ { subject: 'reference', output: 'image' },
);
}
@@ -366,7 +407,7 @@ export function buildAmbientVideoPrompt({ name, kind, chromaKey, correctionPromp
+ `uniform non-emissive ${keyColorPhrase(chromaKey)} background only as a compositing matte: no scenery, text, labels, `
+ 'camera movement, cuts, added objects, or people.',
correctionPrompt,
- 'source image',
+ { subject: 'source image', output: 'animation' },
);
}
@@ -396,7 +437,7 @@ export function buildWalkVideoPrompt({ name, direction, chromaKey, correctionPro
+ 'pivot and ground line with loop-friendly walk-in-place motion. No scenery, no text, no '
+ 'labels, no camera motion, no extra figures.',
correctionPrompt,
- 'source image',
+ { subject: 'source image', output: 'animation' },
);
}
@@ -416,7 +457,7 @@ export function buildScannerPrompt({ name, direction, chromaKey, correctionPromp
+ `Keep the character centered, full body visible, and animate only over a solid ${chromaKey} background. `
+ 'No text, UI, scenery, camera movement, cuts, or additional characters.',
correctionPrompt,
- 'source image',
+ { subject: 'source image', output: 'animation' },
);
}
@@ -443,6 +484,6 @@ export function buildAnchorPrompt({ name, direction, chromaKey, correctionPrompt
+ `single centered figure on a square 1:1 canvas; plain flat ${keyColorPhrase(chromaKey)} background; no labels, no `
+ 'grid lines, no wireframe or guide colors. Return exactly one PNG.',
correctionPrompt,
- 'reference',
+ { subject: 'reference', output: 'image' },
);
}
diff --git a/server/services/sprites/prompts.test.js b/server/services/sprites/prompts.test.js
index f1b6bee3b1..886b331a90 100644
--- a/server/services/sprites/prompts.test.js
+++ b/server/services/sprites/prompts.test.js
@@ -287,56 +287,66 @@ describe('fromTurnaround prompt variants (#2979)', () => {
describe('correction prompts on every regeneration surface (#3134)', () => {
// One table so a newly-added builder can't quietly ship without the
- // correction contract: each row is a builder plus the base params it needs and
- // the noun its clause is expected to name.
+ // correction contract: each row is a builder plus the base params it needs, the
+ // noun its clause is expected to name, and the medium it produces — the video
+ // rows exist to catch a still-image "keep everything else identical" clause
+ // being handed to an image-to-video render, which would freeze the clip.
const SURFACES = [
{
label: 'turnaround sheet',
fn: buildTurnaroundPrompt,
build: (extra) => buildTurnaroundPrompt({ name: 'Scout', designPrompt: 'a wiry ranger', chromaKey: '#FF00FF', ...extra }),
subject: 'turnaround',
+ output: 'image',
},
{
label: 'main reference (from the sheet)',
fn: buildMainReferencePrompt,
build: (extra) => buildMainReferencePrompt({ name: 'Scout', designPrompt: 'a wiry ranger', chromaKey: '#FF00FF', fromTurnaround: true, ...extra }),
subject: 'turnaround',
+ output: 'image',
},
{
label: 'main reference (legacy, no sheet)',
fn: buildMainReferencePrompt,
build: (extra) => buildMainReferencePrompt({ name: 'Scout', designPrompt: 'a wiry ranger', chromaKey: '#FF00FF', ...extra }),
subject: 'reference',
+ output: 'image',
},
{
label: 'directional anchor',
fn: buildAnchorPrompt,
build: (extra) => buildAnchorPrompt({ name: 'Scout', direction: 'east', chromaKey: '#FF00FF', ...extra }),
subject: 'reference',
+ output: 'image',
},
{
label: 'ambient/place reference',
fn: buildAmbientReferencePrompt,
build: (extra) => buildAmbientReferencePrompt({ name: 'Old Willow', kind: 'place', designPrompt: 'a willow by a pond', chromaKey: '#FF00FF', ...extra }),
subject: 'reference',
+ output: 'image',
},
{
label: 'walk video',
fn: buildWalkVideoPrompt,
build: (extra) => buildWalkVideoPrompt({ name: 'Scout', direction: 'east', chromaKey: '#FF00FF', ...extra }),
subject: 'source image',
+ output: 'animation',
},
{
label: 'scanner action video',
fn: buildScannerPrompt,
build: (extra) => buildScannerPrompt({ name: 'Scout', direction: 'east', chromaKey: '#FF00FF', ...extra }),
subject: 'source image',
+ output: 'animation',
},
{
label: 'ambient loop video',
fn: buildAmbientVideoPrompt,
build: (extra) => buildAmbientVideoPrompt({ name: 'Old Willow', kind: 'place', chromaKey: '#FF00FF', ...extra }),
subject: 'source image',
+ output: 'animation',
},
];
@@ -353,14 +363,14 @@ describe('correction prompts on every regeneration surface (#3134)', () => {
expect(exported.filter((name) => !covered.has(name))).toEqual([]);
});
- for (const { label, build, subject } of SURFACES) {
+ for (const { label, build, subject, output } of SURFACES) {
describe(label, () => {
it('wraps the body in one trimmed correction sandwich', () => {
const p = build({ correctionPrompt: ' the strap floats off the shoulder ' });
// Framed up front (before any preservation clause can forbid the change)…
expect(p.startsWith('This is a corrected re-render')).toBe(true);
expect(p).toContain(
- 'Required fix: the strap floats off the shoulder. Make that fix in the image you produce.'
+ `Required fix: the strap floats off the shoulder. Make that fix in the ${output} you produce.`
+ ' It takes priority over any instruction below to match or preserve the attached'
+ ` ${subject}`,
);
@@ -376,6 +386,21 @@ describe('correction prompts on every regeneration surface (#3134)', () => {
expect(p.match(/the strap floats off the shoulder/g)).toHaveLength(2);
});
+ // A corrected re-roll must not trade the ignored-correction bug for a
+ // frozen clip: on an i2v surface the sandwich may not carry the still's
+ // "keep everything else identical [to the attachment]" wording, and has to
+ // restate that the motion the body asks for still happens.
+ it(`keeps the correction consistent with a ${output} output`, () => {
+ const p = build({ correctionPrompt: 'the legs barely lift' });
+ if (output === 'animation') {
+ expect(p).not.toContain('keep everything else identical');
+ expect(p).toContain('the motion described above still happens in full');
+ } else {
+ expect(p).toContain('keep everything else identical');
+ expect(p).not.toContain('the motion described above');
+ }
+ });
+
// The hard acceptance criterion: a blank note must not perturb the blind
// regenerate by even one byte, on any surface.
it('is byte-identical to a blind regenerate for absent/blank input', () => {
@@ -394,7 +419,7 @@ describe('applyCorrection', () => {
// The one place the correction wording is pinned to reviewed text. Every other
// suite asserts that its surface ROUTES through this helper, not what it says.
it('states precedence and targets the OUTPUT, not the attachment', () => {
- const p = applyCorrection('BODY.', ' fix the arm ', 'turnaround');
+ const p = applyCorrection('BODY.', ' fix the arm ', { subject: 'turnaround', output: 'image' });
// "apply this over the attached turnaround" (the pre-#3216 wording) pointed the
// model at a frozen, usually-correct sheet — so it concluded there was nothing
// to do. The fix belongs in the image being produced.
@@ -412,13 +437,46 @@ describe('applyCorrection', () => {
);
});
+ // The image wording tells the model to keep everything the fix doesn't name
+ // identical to the attachment. On an image-to-video render that is an
+ // instruction to hold still — so the animation medium overrides the body's
+ // preserve-the-source clauses while explicitly re-asserting its motion.
+ it('preserves the requested motion when the output is an animation', () => {
+ const p = applyCorrection('MOVE THE LEGS.', 'the legs barely lift', { subject: 'source image', output: 'animation' });
+ expect(p).toBe(
+ 'This is a corrected re-render: a previous attempt at this exact animation was rejected. '
+ + 'Required fix: the legs barely lift. Make that fix in the animation you produce. It takes '
+ + 'priority over any instruction below to match or preserve the attached source image — '
+ + 'change what the fix names, and leave the rest of the animation exactly as the instructions '
+ + 'below describe it. '
+ + 'MOVE THE LEGS.'
+ + ' Required fix (highest priority — this overrides any conflicting instruction above): the '
+ + 'legs barely lift. The previous render was rejected for exactly this, so an animation that '
+ + 'does not visibly reflect this fix is a failed render. Change only what the fix names; the '
+ + 'motion described above still happens in full, and every other detail of identity and '
+ + 'appearance stays as the attached source image shows it.',
+ );
+ expect(p).not.toContain('keep everything else identical');
+ });
+
it('keeps a note that already ends in punctuation as written', () => {
- expect(applyCorrection('BODY.', 'Move it up!', 'reference')).toContain('Required fix: Move it up! Make');
+ expect(applyCorrection('BODY.', 'Move it up!', { subject: 'reference', output: 'image' }))
+ .toContain('Required fix: Move it up! Make');
});
it('returns the body untouched for anything blank or non-string', () => {
for (const v of [undefined, null, '', ' ', '\n\t ', 0, 7, [], {}, () => {}]) {
- expect(applyCorrection('BODY.', v, 'reference'), String(v)).toBe('BODY.');
+ expect(applyCorrection('BODY.', v, { subject: 'reference', output: 'image' }), String(v)).toBe('BODY.');
+ }
+ });
+
+ // Fail loudly, and on the blind path too — a builder that names no medium (or a
+ // typo'd one) must not silently inherit still-image wording and only reveal it
+ // once a user types a note into a video re-roll.
+ it('throws on a missing or unknown output medium, even with no note', () => {
+ for (const target of [undefined, {}, { subject: 'reference' }, { subject: 'reference', output: 'video' }]) {
+ expect(() => applyCorrection('BODY.', 'fix the arm', target), String(target)).toThrow(/unknown output medium/);
+ expect(() => applyCorrection('BODY.', '', target), String(target)).toThrow(/unknown output medium/);
}
});
});
diff --git a/server/services/sprites/spriteTestFixtures.js b/server/services/sprites/spriteTestFixtures.js
index 56f15290a8..017259944b 100644
--- a/server/services/sprites/spriteTestFixtures.js
+++ b/server/services/sprites/spriteTestFixtures.js
@@ -78,10 +78,15 @@ export async function lockAllAnchors(testRoot, recordId, { lockReference, direct
* `prompts.test.js` pins it; everyone else routes through here.
*
* Both halves are checked because half a sandwich is the #3216 bug.
+ *
+ * The assertions stay medium-neutral on purpose: callers span still-image
+ * surfaces (reference) and image-to-video ones (walk / tracks), whose wording
+ * legitimately differs — a video correction must not tell the model to keep
+ * everything identical to the source still. `prompts.test.js` pins each medium.
*/
export function expectCarriesCorrection(expect, prompt, note) {
const sentence = /[.!?]$/.test(note) ? note : `${note}.`;
- expect(prompt).toContain(`Required fix: ${sentence} Make that fix in the image you produce.`);
+ expect(prompt).toContain(`Required fix: ${sentence} Make that fix in the`);
expect(prompt).toContain(`instruction above): ${sentence}`);
}
diff --git a/server/services/sprites/trackPrompts.js b/server/services/sprites/trackPrompts.js
index d7c21df57c..9a14e57233 100644
--- a/server/services/sprites/trackPrompts.js
+++ b/server/services/sprites/trackPrompts.js
@@ -106,7 +106,10 @@ export function buildTrackVideoPrompt(trackId, args) {
return applyCorrection(
renderPromptTemplate(row.promptTemplate, args),
args?.correctionPrompt,
- 'source image',
+ // A user-defined row is always an i2v track, like every compiled one — so
+ // it takes the animation wording, which overrides the template's
+ // preserve-the-source clauses without also cancelling its motion.
+ { subject: 'source image', output: 'animation' },
);
}
const build = TRACK_VIDEO_PROMPTS[trackId];
diff --git a/server/services/sprites/trackPrompts.test.js b/server/services/sprites/trackPrompts.test.js
index cb8a340ad0..54404858f4 100644
--- a/server/services/sprites/trackPrompts.test.js
+++ b/server/services/sprites/trackPrompts.test.js
@@ -77,7 +77,7 @@ const ARG_CASES = [
},
{
// A whitespace-only note must leave the prompt byte-identical to a blind
- // regenerate — the hard contract `correctionClause` promises, which the
+ // regenerate — the hard contract `applyCorrection` promises, which the
// template path has to inherit rather than re-implement.
label: 'with a blank correction note',
args: { name: 'Example Willow', kind: 'object', direction: 'south', chromaKey: '#00FF00', correctionPrompt: ' ' },
@@ -161,6 +161,10 @@ describe('a user-defined row resolves through its own template', () => {
// The template body sits BETWEEN the two halves, not after them.
expect(prompt.indexOf('jetpack burst')).toBeGreaterThan(prompt.indexOf('Required fix:'));
expect(prompt.trimEnd().endsWith('stays as the attached source image shows it.')).toBe(true);
+ // A user-defined row is an i2v track, so it gets the animation wording — the
+ // still-image "keep everything else identical" would cancel its own motion.
+ expect(prompt).toContain('Make that fix in the animation you produce');
+ expect(prompt).not.toContain('keep everything else identical');
});
it('rebuilds a known track and answers null for an unknown one (tryBuild…)', () => {