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 (claude): pin correctionPrompt contract via shared payload helper

[._.]/ Adam Eivyd04314b0cc09
diff --git a/client/src/components/sprites/CorrectionNote.jsx b/client/src/components/sprites/CorrectionNote.jsx
index ee80da9e59..87f6ff9791 100644
--- a/client/src/components/sprites/CorrectionNote.jsx
+++ b/client/src/components/sprites/CorrectionNote.jsx
@@ -10,6 +10,20 @@
* `onChange` receives a setState-style updater so it composes with the
* page-owned `setCorrections` while preserving sibling directions' notes.
*/
+/**
+ * Build the anchor re-roll request fragment for a direction's shared correction
+ * (#2964). Returns `{ correctionPrompt }` only when the note is non-empty after
+ * trimming, else `{}` — so an absent or whitespace-only note is omitted from the
+ * request, matching the server's optional `correctionPrompt`. BOTH re-roll
+ * surfaces spread this (the ReferenceWorkflow anchor grid and the asset card via
+ * Sprites' `generateAnchor`), so they send byte-identical payloads — the single
+ * source guarantee at the request layer, not just the input layer.
+ */
+export function correctionPromptPayload(corrections, direction) {
+ const note = corrections?.[direction]?.trim();
+ return note ? { correctionPrompt: note } : {};
+}
+
export default function CorrectionNote({ direction, value, onChange, className = '' }) {
return (
<textarea
diff --git a/client/src/components/sprites/CorrectionNote.test.jsx b/client/src/components/sprites/CorrectionNote.test.jsx
new file mode 100644
index 0000000000..d69474424f
--- /dev/null
+++ b/client/src/components/sprites/CorrectionNote.test.jsx
@@ -0,0 +1,49 @@
+import { describe, it, expect, vi } from 'vitest';
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import CorrectionNote, { correctionPromptPayload } from './CorrectionNote.jsx';
+
+// The shared anchor-correction module (#2964). `correctionPromptPayload` is the
+// single source at the REQUEST layer — both re-roll surfaces (the reference
+// workflow grid and the asset card via Sprites' generateAnchor) spread it, so a
+// regression that dropped the correction or stopped trimming would flip these.
+describe('correctionPromptPayload', () => {
+ it('sends a non-empty correction as correctionPrompt', () => {
+ expect(correctionPromptPayload({ east: 'no pocket on the right sleeve' }, 'east'))
+ .toEqual({ correctionPrompt: 'no pocket on the right sleeve' });
+ });
+
+ it('trims surrounding whitespace before sending', () => {
+ expect(correctionPromptPayload({ east: ' fix the arm ' }, 'east'))
+ .toEqual({ correctionPrompt: 'fix the arm' });
+ });
+
+ it('omits the field for a whitespace-only note (server treats it as absent)', () => {
+ expect(correctionPromptPayload({ east: ' ' }, 'east')).toEqual({});
+ });
+
+ it('omits the field when the direction has no note', () => {
+ expect(correctionPromptPayload({ west: 'x' }, 'east')).toEqual({});
+ expect(correctionPromptPayload({}, 'east')).toEqual({});
+ });
+
+ it('tolerates a null/undefined corrections map', () => {
+ expect(correctionPromptPayload(null, 'east')).toEqual({});
+ expect(correctionPromptPayload(undefined, 'east')).toEqual({});
+ });
+});
+
+describe('CorrectionNote component', () => {
+ it('renders the shared value and writes a per-direction updater on change', async () => {
+ const onChange = vi.fn();
+ render(<CorrectionNote direction="east" value="keep pose" onChange={onChange} />);
+ const textarea = screen.getByLabelText(/Correction guidance for the east pose/i);
+ expect(textarea).toHaveValue('keep pose');
+ await userEvent.type(textarea, '!');
+ const updater = onChange.mock.calls[0][0];
+ // The updater merges by direction, preserving other directions' notes.
+ const merged = updater({ west: 'other' });
+ expect(merged.west).toBe('other');
+ expect(merged).toHaveProperty('east');
+ });
+});
diff --git a/client/src/components/sprites/ReferenceWorkflow.jsx b/client/src/components/sprites/ReferenceWorkflow.jsx
index 873b158c1f..f3341f0d76 100644
--- a/client/src/components/sprites/ReferenceWorkflow.jsx
+++ b/client/src/components/sprites/ReferenceWorkflow.jsx
@@ -10,7 +10,7 @@ import SpritePreview from './SpritePreview.jsx';
import GalleryImagePicker from '../imageGen/GalleryImagePicker.jsx';
import SpriteReferencePicker from './SpriteReferencePicker.jsx';
import ForkSpriteModal from './ForkSpriteModal.jsx';
-import CorrectionNote from './CorrectionNote.jsx';
+import CorrectionNote, { correctionPromptPayload } from './CorrectionNote.jsx';
// Reference workflow (issue #2896): generate main-reference candidates from
// text + optional uploaded design image, freeze the approved main, then
@@ -148,7 +148,6 @@ export default function ReferenceWorkflow({ record, reference, renders, correcti
const generate = async (target) => {
beginSubmit(target);
- const correction = corrections[target]?.trim();
try {
const { jobId } = await generateSpriteReference(recordId, {
target,
@@ -159,9 +158,7 @@ export default function ReferenceWorkflow({ record, reference, renders, correcti
...(refSource?.type === 'gallery' ? { initImageGalleryFile: refSource.filename } : {}),
...(refSource?.type === 'sprite' ? { initImageSpriteId: refSource.id } : {}),
...(refSource ? { initImageStrength: strength } : {}),
- } : {
- ...(correction ? { correctionPrompt: correction } : {}),
- }),
+ } : correctionPromptPayload(corrections, target)),
}, { silent: true });
resolveSubmit(target, jobId);
if (target === 'main') clearSource();
diff --git a/client/src/pages/Sprites.jsx b/client/src/pages/Sprites.jsx
index af7f3b08b4..14575cb20f 100644
--- a/client/src/pages/Sprites.jsx
+++ b/client/src/pages/Sprites.jsx
@@ -18,6 +18,7 @@ import WalkWorkflow, {
import LoopTrimmer from '../components/sprites/LoopTrimmer.jsx';
import PublishWorkflow from '../components/sprites/PublishWorkflow.jsx';
import AssetCollection from '../components/sprites/AssetCollection.jsx';
+import { correctionPromptPayload } from '../components/sprites/CorrectionNote.jsx';
import SpriteCatalog from '../components/sprites/SpriteCatalog.jsx';
import SpriteDetailHeader from '../components/sprites/SpriteDetailHeader.jsx';
import TabPills from '../components/ui/TabPills.jsx';
@@ -557,20 +558,18 @@ export default function Sprites() {
// buildCollectionActions (#2938) so a re-roll uses the same backend the
// Reference workflow would, not the server default. Falls back to the
// page-level selection when a caller omits it. The direction's shared
- // correction (#2964) rides along as `correctionPrompt` so the asset-card
- // re-roll sends the SAME guidance the ReferenceWorkflow anchor re-roll does.
- const generateAnchor = useCallback((direction, mode) => {
- const correction = corrections[direction]?.trim();
- return submitRender(
- refBegin, refResolve, refCancel, direction,
- () => generateSpriteReference(id, {
- target: direction,
- ...((mode || imageMode) ? { mode: mode || imageMode } : {}),
- ...(correction ? { correctionPrompt: correction } : {}),
- }, { silent: true }),
- `Failed to queue ${direction} render`,
- );
- }, [id, imageMode, corrections, refBegin, refResolve, refCancel, submitRender]);
+ // correction (#2964) rides along as `correctionPrompt` via the same
+ // `correctionPromptPayload` fragment the ReferenceWorkflow anchor re-roll
+ // uses, so the asset-card re-roll sends byte-identical guidance.
+ const generateAnchor = useCallback((direction, mode) => submitRender(
+ refBegin, refResolve, refCancel, direction,
+ () => generateSpriteReference(id, {
+ target: direction,
+ ...((mode || imageMode) ? { mode: mode || imageMode } : {}),
+ ...correctionPromptPayload(corrections, direction),
+ }, { silent: true }),
+ `Failed to queue ${direction} render`,
+ ), [id, imageMode, corrections, refBegin, refResolve, refCancel, submitRender]);
const collectionActions = useMemo(() => {
if (detail?.record?.kind !== 'character') return null;