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): legacy pivot, anchor probe, redraw lock, cycle floor

[._.]/ Adam Eivy7e67c4e4d243
diff --git a/server/services/sprites/atlas.js b/server/services/sprites/atlas.js
index 9792add8bb..dd59ed1139 100644
--- a/server/services/sprites/atlas.js
+++ b/server/services/sprites/atlas.js
@@ -47,7 +47,7 @@ import {
WALK_PHASES, WALK_FPS,
pyRound, pyRoundTo, median, decodeRgbaFrame, premultipliedResize,
sampleBorderKey, validateMeasuredKey, recoverAlphaFrame, despillKeyFrame,
- alphaBbox, robustBottomRow, rootX, ROBUST_BASELINE_MIN_PIXELS, compositeOnto, sha256Buffer,
+ alphaBbox, robustBottomRow, rootX, rootBandForManifest, ROBUST_BASELINE_MIN_PIXELS, compositeOnto, sha256Buffer,
} from './walkPostprocess.js';
import { ATLAS_IDLE_COLUMN } from './walkBounds.js';
import { WALK_TRACK, ANIMATION_TRACK_IDS } from './animationTracks.js';
@@ -458,7 +458,13 @@ async function compileDirectionRow(recordId, direction, validated, geometry) {
// rule and walk on the other the character visibly pops sideways the instant
// the game starts or stops the gait (#3021). Measured at the silhouette
// threshold, matching how this cell's scale was derived.
- const idleTorsoX = rootX(idleScaled.scaled, alphaBbox(idleScaled.scaled, SILHOUETTE_ALPHA_THRESHOLD) || idleScaled.bounds);
+ // …with the band THIS manifest's frames were packed on. #3049 moved the
+ // packer from the hip band to the torso band, but a set compiled WITHOUT
+ // reprocessing its runs still has hip-packed frames; measuring their idle as
+ // torso would anchor the two columns on different landmarks and reintroduce
+ // exactly the idle-to-walk pop this rule exists to prevent.
+ const idleBand = rootBandForManifest(manifest);
+ const idleTorsoX = rootX(idleScaled.scaled, alphaBbox(idleScaled.scaled, SILHOUETTE_ALPHA_THRESHOLD) || idleScaled.bounds, idleBand);
const idle = placeCell(
idleScaled.scaled, idleScaled.bounds, idleScaled.baseline,
sharedRowPasteX(pyRound(geometry.pivot[0] - idleTorsoX), [idleScaled.bounds], geometry),
diff --git a/server/services/sprites/walk.js b/server/services/sprites/walk.js
index 9d0b35ecda..be87d3514e 100644
--- a/server/services/sprites/walk.js
+++ b/server/services/sprites/walk.js
@@ -1472,7 +1472,14 @@ export async function getWalkSourceFrames(recordId, runId, { extract = false } =
if (!known) throw new ServerError(`Unknown walk run: ${runId}`, { status: 404, code: 'RUN_NOT_FOUND' });
return sourceFrameResponse(runId, known, walkTarget, walkSet, {
reason: 'run-not-packaged',
- lockReason: 'no-source-video',
+ // A frozen set outranks the missing clip, matching `reDeriveLockReason`'s
+ // own ordering. Hardcoding 'no-source-video' here made the Loop Trimmer
+ // treat a FINALIZED set as merely clipless for a redraw-only direction
+ // (an imagegen cycle has no run directory) — so it left `CycleTarget`
+ // enabled, which 409s on change, and suppressed the lock panel that
+ // carries the unlock. That is the pair of defects #3043 set out to fix,
+ // still reachable through the one direction that has no run behind it.
+ lockReason: walkSet ? 'finalized' : 'no-source-video',
});
}
const { runDirRel } = found;
@@ -1686,9 +1693,21 @@ async function resolveUnlockBlock(recordId, walkSet, clipByDirection = null) {
const notBlocked = { blocked: false, stranded: [], acknowledgeable: false };
if (!isImportedWalkSet(walkSet)) return notBlocked;
const stale = importedWalkDirections(walkSet);
+ // `resolveWalkRenderability` is deliberately I/O-free, so it checks the
+ // manifest's CLAIM that an anchor is locked but not that the file is still
+ // there — and the render path's own `ANCHOR_MISSING` probe does. A manifest
+ // that still marks a since-deleted anchor locked would therefore pass the
+ // gate, drop all eight approvals on the acknowledged unlock, and then fail
+ // every Generate — precisely the stranding the acknowledgement promises can't
+ // happen. So the promise is only made after probing the files too. Bounded at
+ // eight stats, and only on the blocked path.
const regenerable = async (scope) => {
const [manifest, record] = await Promise.all([loadManifest(recordId), getRecord(recordId)]);
- return scope.every((direction) => !resolveWalkRenderability(manifest, record, direction).error);
+ const resolved = scope.map((direction) => resolveWalkRenderability(manifest, record, direction));
+ if (resolved.some((r) => r.error)) return false;
+ const present = await Promise.all(resolved
+ .map((r) => pathExists(resolveSpriteAssetPath(recordId, r.anchor.path))));
+ return present.every(Boolean);
};
// No per-direction evidence to examine, and unlock re-opens the whole set — so
// the whole set has to be regenerable before the escape is honest.
diff --git a/server/services/sprites/walk.test.js b/server/services/sprites/walk.test.js
index bbce70d0e1..aca49ab263 100644
--- a/server/services/sprites/walk.test.js
+++ b/server/services/sprites/walk.test.js
@@ -1641,6 +1641,34 @@ describe('getWalkSourceFrames', () => {
expect(out.reason).toBe('run-not-packaged');
expect(out.editable).toBe(false);
expect(out.current).toEqual({ frameCount: 12, fps: 12 });
+ // Not finalized here (no walk-set file), so the clipless reason stands.
+ expect(out.lockReason).toBe('no-source-video');
+
+ /**
+ * …but a FROZEN set outranks it. This branch hardcoded 'no-source-video',
+ * so for a redraw-only direction — the one shape with no run directory —
+ * the Loop Trimmer treated a finalized set as merely clipless: it left
+ * `CycleTarget` enabled (which 409s on change) and suppressed the lock
+ * panel carrying the unlock. Both are the defects #3043 exists to fix,
+ * reachable through the single direction that has no run behind it.
+ */
+ await writeFile(join(TEST_ROOT, 'sprites', id, 'walk', `${id}-walk-set-v1.json`), JSON.stringify({
+ schemaVersion: 1,
+ kind: 'finalized-eight-direction-walk-set',
+ characterId: id,
+ status: 'final',
+ directionOrder: SPRITE_DIRECTIONS,
+ directions: {
+ east: {
+ status: 'approved',
+ runId: `${id}-v19-east`,
+ runPath: 'imagegen/v19',
+ runManifest: 'imagegen/v19/walk-east-v19-manifest.json',
+ },
+ },
+ }));
+ const frozen = await getWalkSourceFrames(id, `${id}-v19-east`);
+ expect(frozen.lockReason).toBe('finalized');
});
it('404s an unknown run', async () => {
diff --git a/server/services/sprites/walkPostprocess.js b/server/services/sprites/walkPostprocess.js
index f04f813852..f0e5b244f1 100644
--- a/server/services/sprites/walkPostprocess.js
+++ b/server/services/sprites/walkPostprocess.js
@@ -389,9 +389,16 @@ export function selectCycleIndices(signatures, frameCount = WALK_FRAME_COUNT) {
if (n < frameCount + 1) {
throw new Error(`Need at least ${frameCount + 1} extracted frames, got ${n}`);
}
- // A window of at least `frameCount` gives one distinct source frame per phase.
- let chosen = findCycleWindow(signatures, frameCount, frameCount);
- // …but that floor also HIDES any gait whose real period is shorter, and forces
+ // ONE search, floored at the shortest period worth accepting — not a
+ // `frameCount`-floored search with a shorter probe after it. The two-call shape
+ // had a hole: the first call THROWS `No detectable moving walk cycle` when no
+ // window at/above `frameCount` clears `MIN_CYCLE_MOTION`, so the shorter probe
+ // never ran and the short-cycle path rejected exactly the clips it was added to
+ // support. Searching `[shortFloor, maxLen]` once is also strictly equivalent
+ // for the long case: that range contains `[frameCount, maxLen]`, so when the
+ // global best is a long window it IS the long search's best.
+ //
+ // The floor HIDES any gait whose real period is shorter, and forces
// a longer window that is not a whole number of cycles (#3052). A real clip's
// gait ran 11 frames while 12 phases were requested, so the search could only
// offer a 15-frame window — 1.36 cycles. Its endpoints still matched (a
@@ -401,12 +408,8 @@ export function selectCycleIndices(signatures, frameCount = WALK_FRAME_COUNT) {
// to reach the requested count is a far smaller artifact than replaying a third
// of a stride. The ratio guard keeps this to MILD upsampling — a much shorter
// period would be mostly held frames, and a longer window wins there.
- const shortFloor = Math.max(GAIT_MIN_PERIOD, Math.ceil(frameCount * MIN_PERIOD_RATIO));
- if (shortFloor < frameCount) {
- const probe = findCycleWindow(signatures, frameCount, shortFloor);
- if (probe.cycleLength < frameCount) chosen = probe;
- }
- const { start, cycleLength, seam, motion } = chosen;
+ const shortFloor = Math.min(frameCount, Math.max(GAIT_MIN_PERIOD, Math.ceil(frameCount * MIN_PERIOD_RATIO)));
+ const { start, cycleLength, seam, motion } = findCycleWindow(signatures, frameCount, shortFloor);
// Even phase distribution, in integer arithmetic (#3050).
//
// This is the ONE place that deliberately does not use `pyRound`. Banker's
@@ -497,6 +500,31 @@ export function alphaBbox(frame, threshold = BBOX_ALPHA_THRESHOLD) {
return { left, top, right: right + 1, bottom: bottom + 1 };
}
+/**
+ * The measuring band `rootX` uses, as `[topFraction, bottomFraction]` of bbox
+ * height. TORSO is current (#3049); HIP is what every manifest packed before it
+ * used, and must stay reachable — the atlas measures the idle anchor live with
+ * `rootX` while the walk cells carry the pivot their packer baked in, so a set
+ * compiled without reprocessing needs the band its frames were packed with or
+ * the idle and walk columns anchor on different landmarks and the character pops
+ * sideways entering the gait. `alignment.operation` in the run manifest is what
+ * distinguishes them; see `ALIGN_OP_TORSO_X`.
+ */
+export const ROOT_BAND_TORSO = [0.30, 0.58];
+export const ROOT_BAND_HIP = [0.42, 0.76];
+
+/** The `alignment.operation` stamp written by the torso-pivot packer (#3049). */
+export const ALIGN_OP_TORSO_X = 'one-fixed-scale-per-frame-torso-x-and-baseline-y';
+
+/**
+ * The band a packed manifest's frames were aligned with. A manifest that
+ * predates #3049 — or carries no `alignment.operation` at all — was packed on
+ * the hip band, and re-measuring it as torso would misregister it.
+ */
+export const rootBandForManifest = (manifest) => (
+ manifest?.alignment?.operation === ALIGN_OP_TORSO_X ? ROOT_BAND_TORSO : ROOT_BAND_HIP
+);
+
/**
* x-center of the character at the TORSO band (30%–58% of bbox height) — the
* per-frame pivot the alignment pins to x=192.
@@ -510,11 +538,11 @@ export function alphaBbox(frame, threshold = BBOX_ALPHA_THRESHOLD) {
* genuinely stationary in a walk-in-place, so pinning it is both the stablest
* measurement and the right physical model; arms and legs then swing around it.
*/
-export function rootX(frame, bbox) {
+export function rootX(frame, bbox, band = ROOT_BAND_TORSO) {
const { data, width } = frame;
const H = bbox.bottom - bbox.top;
- const bandTop = bbox.top + pyRound(H * 0.30);
- const bandBottom = bbox.top + pyRound(H * 0.58);
+ const bandTop = bbox.top + pyRound(H * band[0]);
+ const bandBottom = bbox.top + pyRound(H * band[1]);
const xs = [];
for (let y = bandTop; y < bandBottom; y++) {
for (let x = bbox.left; x < bbox.right; x++) {
@@ -631,7 +659,7 @@ export async function alignFrames(frames) {
// Both axes vary per frame again (#3049): x pins this frame's torso to the
// pivot, y its robust baseline. The distinguishing fact vs the pre-#3021
// shape is WHICH landmark x uses — the torso band, not the hip/leg band.
- operation: 'one-fixed-scale-per-frame-torso-x-and-baseline-y',
+ operation: ALIGN_OP_TORSO_X,
// The per-frame torso measurements the anchor is taken from. Kept for
// diagnostics: their spread is the drift this alignment cancels, so a
// regression shows up as `translations[i][0]` going constant while these
diff --git a/server/services/sprites/walkPostprocess.test.js b/server/services/sprites/walkPostprocess.test.js
index 4b347149b6..ace63ec002 100644
--- a/server/services/sprites/walkPostprocess.test.js
+++ b/server/services/sprites/walkPostprocess.test.js
@@ -15,6 +15,7 @@ import {
isUsableMeasuredKey, longestUsableSpan,
recoverAlphaFrame, despillKeyFrame, imageDistance, selectCycleIndices,
alphaBbox, rootX, robustBottomRow, alignFrames, packStrip, validateFrames, buildContrastSheet,
+ rootBandForManifest, ROOT_BAND_TORSO, ROOT_BAND_HIP, ALIGN_OP_TORSO_X,
prepareWalkAnchorChromaInput, WALK_PHASES, WALK_CELL_SIZE, WALK_FRAME_COUNT,
} from './walkPostprocess.js';
import { keyChannelSplit } from './chromaKey.js';
@@ -267,6 +268,34 @@ describe('alphaBbox / rootX', () => {
expect(rootX(frame, bbox)).toBe(19.5); // symmetric rect → center column median
expect(alphaBbox(makeFrame(8, 8))).toBeNull();
});
+
+ /**
+ * #3049 moved the packer's landmark from the hip band to the torso band, but
+ * the atlas measures the IDLE anchor live with `rootX` while the walk cells
+ * carry whichever pivot their packer baked in. A set compiled without
+ * reprocessing its runs therefore has hip-packed frames, and measuring their
+ * idle as torso anchors the two columns on different landmarks — the
+ * idle→walk pop this rule exists to prevent. The band must follow the
+ * manifest, and an absent `alignment.operation` means "packed before #3049".
+ */
+ it('selects the measuring band from the manifest that packed the frames', () => {
+ expect(rootBandForManifest({ alignment: { operation: ALIGN_OP_TORSO_X } })).toBe(ROOT_BAND_TORSO);
+ // Legacy / imported / absent — all predate the torso pivot.
+ expect(rootBandForManifest({ alignment: { operation: 'one-fixed-scale-shared-hip-x-plus-per-frame-baseline-y' } })).toBe(ROOT_BAND_HIP);
+ expect(rootBandForManifest({ alignment: {} })).toBe(ROOT_BAND_HIP);
+ expect(rootBandForManifest({})).toBe(ROOT_BAND_HIP);
+ expect(rootBandForManifest(null)).toBe(ROOT_BAND_HIP);
+ });
+
+ // The two bands must actually measure different things, or the branch above is
+ // decorative: a torso-heavy silhouette whose legs sit off to one side.
+ it('measures a different landmark per band', () => {
+ const frame = makeFrame(60, 100);
+ fillRect(frame, 30, 5, 50, 55, [50, 50, 50, 255]); // torso, right side
+ fillRect(frame, 5, 55, 25, 95, [50, 50, 50, 255]); // legs, left side
+ const bbox = alphaBbox(frame);
+ expect(rootX(frame, bbox, ROOT_BAND_TORSO)).not.toBe(rootX(frame, bbox, ROOT_BAND_HIP));
+ });
});
describe('alignFrames / packStrip', () => {