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): block finalizing a ragged set and stop echoing the target

[._.]/ Adam Eivye31dac47b9a8
diff --git a/client/src/components/sprites/WalkWorkflow.jsx b/client/src/components/sprites/WalkWorkflow.jsx
index 91b861336e..b55c7cb550 100644
--- a/client/src/components/sprites/WalkWorkflow.jsx
+++ b/client/src/components/sprites/WalkWorkflow.jsx
@@ -144,7 +144,12 @@ function StripLoop({ recordId, stripPreview }) {
// How a drifted direction gets back onto the target, given what it still has
// behind it. Named rather than inlined as a nested ternary so the three cases
// read as the decision they are.
-const driftRemedy = ({ approved, hasSourceClip }) => {
+const driftRemedy = ({ approved, hasSourceClip, imported }) => {
+ // A source-pipeline import has no regenerable clips, so the server refuses
+ // BOTH reopen and unlock on it — pointing there would advise an action that
+ // always 409s, and imported sets are the population most likely to drift
+ // (they never passed the queue-time gate).
+ if (imported) return 'create a new character version to revise it';
if (approved) return 'reopen this direction to re-derive it';
return hasSourceClip
? 'reprocess it from its clip'
@@ -230,7 +235,7 @@ function CycleTarget({
function DirectionCard({
recordId, direction, anchorLocked, run, approved, finalized, pending,
onOpenTrimmer, onGenerate, onApprove, onRetry, onReprocess, onReopen,
- reprocessing, cycleLabel, drift, targetSaving,
+ reprocessing, cycleLabel, drift, targetSaving, imported,
}) {
const [confirming, setConfirming] = useState(false);
const [reopening, setReopening] = useState(false);
@@ -282,7 +287,7 @@ function DirectionCard({
{[drift.frameCountDrifts && `${drift.frameCount}f`, drift.fpsDrifts && `${drift.fps}fps`]
.filter(Boolean).join(' · ')} · re-derive to {cycleLabel}
<span className="block text-gray-400">
- {driftRemedy({ approved, hasSourceClip: Boolean(run?.sourceVideoPath) })}
+ {driftRemedy({ approved, hasSourceClip: Boolean(run?.sourceVideoPath), imported })}
</span>
</p>
)}
@@ -336,7 +341,10 @@ function DirectionCard({
{run.status === 'error' && (
<p className="text-[10px] text-port-error break-words">{run.postprocessError || 'postprocess failed'}</p>
)}
- <button onClick={() => onRetry(run)} className="px-2 py-0.5 text-[10px] bg-port-card border border-port-border rounded text-gray-300 hover:border-port-accent">
+ {/* Gated on the same in-flight target write as the other render
+ actions — it repacks against the set target, so firing it before
+ a target PATCH lands would use the value the server still holds. */}
+ <button onClick={() => onRetry(run)} disabled={busy} className="px-2 py-0.5 text-[10px] bg-port-card border border-port-border rounded text-gray-300 hover:border-port-accent disabled:opacity-50">
{run.status === 'postprocessing' ? 'Re-run postprocess' : 'Retry postprocess'}
</button>
</div>
@@ -527,7 +535,10 @@ export default function WalkWorkflow({
// Re-run the deterministic packer on a run's ON-DISK clip at the CURRENT
// frame-count/speed — the one call shared by the errored-run "Retry" and the
// candidate "Reprocess" buttons (no grok, no regeneration).
- const postprocessRun = (run) => postprocessSpriteWalk(recordId, { runId: run.id, frameCount, fps }, { silent: true });
+ // Geometry is deliberately NOT sent: the server adopts the set's pinned target
+ // for an omitted count/fps, so the request can't 409 against a target this
+ // page's state is one refetch behind on (#2985).
+ const postprocessRun = (run) => postprocessSpriteWalk(recordId, { runId: run.id }, { silent: true });
// Retry a wedged/errored run so a recovery also picks up the chosen cycle look.
const [retryPostprocess] = useAsyncAction(async (run) => {
@@ -665,6 +676,7 @@ export default function WalkWorkflow({
pending={Boolean(pendingJobs[anchor.direction])}
targetSaving={targetSaving}
drift={driftByDirection[anchor.direction] || null}
+ imported={importedWalkSet}
onOpenTrimmer={onOpenTrimmer}
onGenerate={onGenerate}
onApprove={approve}
diff --git a/client/src/components/sprites/WalkWorkflow.test.jsx b/client/src/components/sprites/WalkWorkflow.test.jsx
index d6e4596898..29fa651b77 100644
--- a/client/src/components/sprites/WalkWorkflow.test.jsx
+++ b/client/src/components/sprites/WalkWorkflow.test.jsx
@@ -406,15 +406,18 @@ describe('WalkWorkflow cycle-target drift', () => {
});
describe('WalkWorkflow reprocess + reopen', () => {
- it('reprocesses a candidate from its on-disk clip at the current count/fps', async () => {
+ it('reprocesses a candidate from its on-disk clip, letting the server apply the set target', async () => {
renderRun({
id: 'walk-east-abc12345', direction: 'east', status: 'candidate',
stripPreview: { stripPath: 'runs/walk-east-abc12345/generated/strip.png', frameCount: 12, fps: 10, cellWidth: 384, cellHeight: 384 },
});
await act(async () => { screen.getByRole('button', { name: /Reprocess/ }).click(); });
+ // Geometry is deliberately omitted — the server adopts the set's pinned
+ // target, so the request can't 409 against a target this page is one
+ // refetch behind on (#2985).
expect(postprocessSpriteWalk).toHaveBeenCalledWith(
'example-walker',
- { runId: 'walk-east-abc12345', frameCount: 12, fps: 10 },
+ { runId: 'walk-east-abc12345' },
{ silent: true },
);
});
diff --git a/client/src/pages/Sprites.jsx b/client/src/pages/Sprites.jsx
index 90d4344f84..c62eefabce 100644
--- a/client/src/pages/Sprites.jsx
+++ b/client/src/pages/Sprites.jsx
@@ -12,9 +12,7 @@ import { getSettings } from '../services/apiSystem.js';
import { deriveAvailableBackends } from '../lib/imageGenBackends.js';
import AppContextPicker from '../components/AppContextPicker.jsx';
import ReferenceWorkflow from '../components/sprites/ReferenceWorkflow.jsx';
-import WalkWorkflow, {
- WALK_DEFAULT_DURATION, WALK_DEFAULT_FRAME_COUNT, WALK_DEFAULT_FPS,
-} from '../components/sprites/WalkWorkflow.jsx';
+import WalkWorkflow, { WALK_DEFAULT_DURATION } from '../components/sprites/WalkWorkflow.jsx';
import LoopTrimmer from '../components/sprites/LoopTrimmer.jsx';
import PublishWorkflow from '../components/sprites/PublishWorkflow.jsx';
import AssetCollection from '../components/sprites/AssetCollection.jsx';
@@ -468,14 +466,13 @@ export default function Sprites() {
// Clip length is a per-render choice (how much source footage grok gives the
// packer) and stays page state so a Regenerate fired from an asset card honors
- // what the user picked in the walk panel. Frame count + preview fps are NOT:
- // they are pinned per walk SET on the server (#2985), because every direction
- // in one atlas must share them, so both read from the resolved walk target.
+ // what the user picked in the walk panel. Frame count + preview fps are NOT
+ // sent at all: they are pinned per walk SET on the server (#2985), and an
+ // omitted geometry adopts that target. Echoing the client's copy back would
+ // only add a staleness window — `detail` trails the server by one refetch, so
+ // a render fired right after a target change would 409 against a value the UI
+ // is no longer showing.
const [duration, setDuration] = useState(WALK_DEFAULT_DURATION);
- // Scalars, not the target object — `detail` gets a fresh identity on every
- // refetch, which would rebuild the memoized generate action each poll.
- const walkFrameCount = detail?.walk?.walkTarget?.frameCount ?? WALK_DEFAULT_FRAME_COUNT;
- const walkFps = detail?.walk?.walkTarget?.fps ?? WALK_DEFAULT_FPS;
// Image-backend availability + the selected backend `mode` are page-owned
// (#2938): both ReferenceWorkflow's picker and the asset collection's anchor
@@ -546,16 +543,14 @@ export default function Sprites() {
const generateWalk = useCallback((direction) => submitRender(
walkBegin, walkResolve, walkCancel, direction,
- () => generateSpriteWalk(id, {
- direction, duration, frameCount: walkFrameCount, fps: walkFps,
- }, { silent: true }),
+ () => generateSpriteWalk(id, { direction, duration }, { silent: true }),
`Failed to queue ${direction} walk`,
// Refetch immediately so the server's 'rendering' run lands before the
// media-job poll evicts the optimistic key (~4s) — otherwise the Generate
// button briefly re-enables and a second click would 409 the in-flight
// render. The server guard is the real backstop; this closes the UI gap.
onWorkflowChanged,
- ), [id, duration, walkFrameCount, walkFps, walkBegin, walkResolve, walkCancel, submitRender, onWorkflowChanged]);
+ ), [id, duration, walkBegin, walkResolve, walkCancel, submitRender, onWorkflowChanged]);
// `mode` is the workflow-selected backend, threaded from the asset card via
// buildCollectionActions (#2938) so a re-roll uses the same backend the
diff --git a/server/lib/validation.js b/server/lib/validation.js
index d2f2ac4985..b4c6f3fbd3 100644
--- a/server/lib/validation.js
+++ b/server/lib/validation.js
@@ -1141,8 +1141,11 @@ export const spriteWalkReopenSchema = z.object({
export const spriteWalkPostprocessSchema = z.object({
runId: spriteWalkRunIdSchema,
- // Reprocess the on-disk clip at a new count/fps without regenerating. Omitted
- // fields keep the run's stored values.
+ // Reprocess the on-disk clip without regenerating. Omitted fields adopt the
+ // set's pinned cycle target (#2985) — NOT the run's stored values, since a
+ // reprocess is how a drifted direction is brought back onto the target. A
+ // supplied value that disagrees with the target is refused with 409
+ // WALK_TARGET_MISMATCH.
frameCount: spriteWalkFrameCountSchema.optional(),
fps: spriteWalkFpsSchema.optional(),
});
diff --git a/server/services/sprites/walk.js b/server/services/sprites/walk.js
index 689239a7b5..a8caa5678e 100644
--- a/server/services/sprites/walk.js
+++ b/server/services/sprites/walk.js
@@ -360,10 +360,16 @@ async function loadRunForEntry(recordId, direction, entry) {
* Native runs stamp `frameCount`/`fps` on the run record; imported and redraw
* runs only carry them inside `stripPreview`, so read through both or every
* imported set would resolve as "no packaged geometry" and drift silently.
+ *
+ * A run the server flagged `stripMissing` is excluded: its packed strip is gone
+ * from disk, so it can never compile, and letting it win the first-packaged slot
+ * would derive the whole set's target from artwork that no longer exists —
+ * badging every healthy direction as drifted against a dead one. It keeps its
+ * `stripPreview` (only `stripPath` is dropped), so the filter has to name it.
*/
function packagedCyclesFrom(runs, approvedDirections) {
return SPRITE_DIRECTIONS.flatMap((direction) => {
- const forDirection = runs.filter((r) => r.direction === direction && r.stripPreview);
+ const forDirection = runs.filter((r) => r.direction === direction && r.stripPreview && !r.stripMissing);
const approvedRunId = approvedDirections?.[direction]?.runId;
const run = forDirection.find((r) => r.id === approvedRunId)
|| forDirection.find((r) => r.status === 'approved')
@@ -1071,6 +1077,26 @@ async function approveWalkDirectionImpl(recordId, { direction, runId }) {
approvedAt: new Date().toISOString(),
};
const allApproved = SPRITE_DIRECTIONS.every((d) => selection.directions[d]?.status === 'approved');
+ // Freezing is the LAST moment the set can still be fixed, so the per-direction
+ // gate above is not sufficient on its own: retargeting mid-set is sanctioned,
+ // so a direction approved under the OLD target stays drifted while every later
+ // approval matches the new one. Without this check the 8th approval would
+ // happily freeze that ragged set and hand the failure to atlas.js — the exact
+ // outcome this issue moves earlier. Reuse the drift the state read already
+ // computed, minus the direction being approved: its geometry was verified
+ // against the target above, and `packagedCyclesFrom` may have resolved a
+ // different (newer candidate) run for it, which would otherwise false-block.
+ if (allApproved) {
+ const drifted = walkTarget.drift.filter((d) => d.direction !== direction);
+ if (drifted.length) {
+ throw new ServerError(
+ `Cannot finalize: ${drifted.map((d) => d.direction).join(', ')} ${drifted.length === 1 ? 'is' : 'are'} `
+ + `packaged at a different cycle than the set's ${walkTarget.frameCount} frames @ ${walkTarget.fps}fps `
+ + `(${walkTarget.sourceLabel}) — reopen and reprocess ${drifted.length === 1 ? 'it' : 'them'} to the target first.`,
+ { status: 409, code: 'WALK_TARGET_MISMATCH' },
+ );
+ }
+ }
selection.status = allApproved ? 'complete' : 'in-progress';
const selectionAbs = join(spriteDir(recordId), selectionRelPath(recordId));
await ensureDir(join(spriteDir(recordId), 'walk'));
diff --git a/server/services/sprites/walk.test.js b/server/services/sprites/walk.test.js
index 9ee2029f9a..863840c32c 100644
--- a/server/services/sprites/walk.test.js
+++ b/server/services/sprites/walk.test.js
@@ -503,6 +503,69 @@ describe('walk cycle target', () => {
expect(selection.directions.east).toBeUndefined();
});
+ it('refuses to FINALIZE a set whose earlier approvals drifted from a retarget', async () => {
+ // Retargeting mid-set is sanctioned, so the per-direction gate alone isn't
+ // enough: a direction approved under the OLD target stays drifted while
+ // every later approval matches the new one, and the 8th approval would
+ // otherwise freeze a ragged set for atlas.js to reject.
+ const id = await characterWithLockedAnchors(newId(), SPRITE_DIRECTIONS);
+ const { runId: southId } = await makeCandidateRun(id, 'south', { frameCount: 12, fps: 10 });
+ await approveWalkDirection(id, { direction: 'south', runId: southId });
+ await setWalkTarget(id, { frameCount: 8, fps: 10 });
+ const rest = SPRITE_DIRECTIONS.filter((d) => d !== 'south');
+ for (const direction of rest.slice(0, -1)) {
+ const { runId } = await makeCandidateRun(id, direction, { frameCount: 8, fps: 10 });
+ await approveWalkDirection(id, { direction, runId });
+ }
+ const last = rest[rest.length - 1];
+ const { runId: lastId } = await makeCandidateRun(id, last, { frameCount: 8, fps: 10 });
+ await expect(approveWalkDirection(id, { direction: last, runId: lastId }))
+ .rejects.toMatchObject({
+ code: 'WALK_TARGET_MISMATCH',
+ message: expect.stringContaining('south'),
+ });
+ // Nothing was frozen, and the drifted direction is still named.
+ const { walkSet, walkTarget } = await getWalkState(id);
+ expect(walkSet).toBeNull();
+ expect(walkTarget.drift.map((d) => d.direction)).toContain('south');
+ });
+
+ it('does not derive the target from a direction whose packed strip is gone', async () => {
+ // A stripMissing run keeps its stripPreview (only stripPath is dropped), so
+ // without an explicit exclusion it could win the first-packaged slot and
+ // derive the whole set's target from artwork that no longer exists.
+ const id = await characterWithLockedAnchors(newId(), SPRITE_DIRECTIONS);
+ const { runId } = await makeCandidateRun(id, 'south', { frameCount: 16, fps: 24 });
+ await rm(join(TEST_ROOT, 'sprites', id, 'runs', runId, 'generated', `${id}-walk-south-strip.png`));
+ await makeCandidateRun(id, 'east', { frameCount: 8, fps: 12 });
+ const { runs, walkTarget } = await getWalkState(id);
+ expect(runs.find((r) => r.direction === 'south').stripMissing).toBe(true);
+ // 'east' — the live direction — sets the target, not the dead 'south'.
+ expect(walkTarget).toMatchObject({ frameCount: 8, fps: 12, source: 'derived' });
+ expect(walkTarget.drift).toEqual([]);
+ });
+
+ it('preserves the pinned target across unlock and reopen', async () => {
+ // Both paths reseed the selection; dropping animationTargets there would
+ // silently re-derive the target from whichever direction is re-approved
+ // first, so this pins the preservation the reseeds depend on.
+ const id = await characterWithLockedAnchors(newId(), SPRITE_DIRECTIONS);
+ await setWalkTarget(id, { frameCount: 8, fps: 12 });
+ for (const direction of SPRITE_DIRECTIONS) {
+ const { runId } = await makeCandidateRun(id, direction);
+ await approveWalkDirection(id, { direction, runId });
+ }
+ await unlockWalkSet(id);
+ expect((await readSelection(id)).animationTargets.walk)
+ .toEqual({ frameCount: 8, fps: 12, source: 'set' });
+ // …and re-approving one direction then reopening it keeps the pin too.
+ const { runId } = await makeCandidateRun(id, 'south');
+ await approveWalkDirection(id, { direction: 'south', runId });
+ await reopenWalkDirection(id, { direction: 'south' });
+ expect((await readSelection(id)).animationTargets.walk)
+ .toEqual({ frameCount: 8, fps: 12, source: 'set' });
+ });
+
it('409s a retarget on a finalized set', async () => {
const id = await characterWithLockedAnchors(newId(), SPRITE_DIRECTIONS);
for (const direction of SPRITE_DIRECTIONS) {