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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
spread walk-cycle phases evenly when the period doesn't divide the frame count
[._.]/ Adam Eivyacd3b9062f8a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 301bd62a56..a55101bdba 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -188,3 +188,4 @@- **[issue-2953] Finish the image-to-3D workspace: file-upload picker, a per-record detail route, and a records library** — the `/media/3d` page now doubles as a library, listing every `image_to_3d_models` record (newest-first) as a deep-link card into a new `/media/3d/:id` detail view. The detail page mounts the reusable `GlbViewer` (with **Download .glb**) once a render lands `ready`, polls while `generating`, surfaces the runner's actionable error on `failed`, and offers re-render + delete (inline-confirm) — the URL is the source of truth for what's open, per the ID-based deep-linking convention. `GalleryImagePicker` gains an optional `allowUpload` prop: an "Upload" control saves a file off disk into the gallery via the existing peer-syncable `POST /api/image-gen/upload`, then selects it exactly like a gallery image, so an uploaded photo feeds `createImageTo3dModel` the same way a render-history pick does. No new backend surface — everything runs against the endpoints that landed in #2973.- **[issue-3043] Let a frozen imported walk set be unlocked for regeneration** — a character imported from the source pipeline whose walk set was finalized without its per-run source clips (the phase-1 import shape) had *no reachable action at all*: unlock and reopen both 409'd `LEGACY_IMPORTED_WALK_SET` (nothing to re-derive from), the cycle-target PUT 409'd `WALK_SET_FINAL` (set is frozen), and the workflow header rendered a dead `imported · no clips to re-derive` label with no button behind it — while the drift banner told the user to re-derive. The guard's premise was too narrow: it reasoned only about *re-derivation*, but a walk render is conditioned on the direction's **locked anchor**, so such a set can always be rebuilt from scratch — it just costs a new render per direction instead of a free local repack. `POST /walk/unlock` now accepts `{ acknowledgeNoClips }`, honored only where the server has proven every stranded direction has a locked anchor to regenerate from (an acknowledgement can never be the thing that strands a set — a stranded direction with an unlocked anchor still refuses, with the original error code). `getWalkState` stamps `walkSet.unlock = { blocked, stranded, acknowledgeable }` from the same resolver the gate itself uses, so the button a client offers and the 409 it might hit are computed from one reading of the set; the refusal that *can* be acknowledged past gets its own code (`LEGACY_IMPORTED_WALK_SET_REGENERABLE`) and names that path. The Walk Cycles header replaces the dead label with an **Unlock anyway** panel stating the cost as visible text rather than a tooltip (one new grok render per direction, every approval dropped, nothing deleted on disk), and the Loop Trimmer disables its `CycleTarget` while the set is frozen — it was enabled and 409'd on change — with the same two unlock offers below it. Two adjacent bugs surfaced while proving the escape is real and are fixed with it: `startWalkGenerationImpl` read `manifest.chromaKey` alone, but the importer stamps the key it used on the RECORD and copies a manifest carrying none — so every fully-locked source-pipeline import reported `MAIN_NOT_LOCKED` ("no frozen chroma key") and refused every Generate; the lookup now falls back manifest → record, the order reference.js already resolves it in at eight sites, The postprocess path carried the SAME missing rung (`run.chromaKey || manifest.chromaKey`) and died inside sharp with `Invalid hex color: undefined` on any reprocess of an imported run — a parser complaining about its argument, naming neither the field nor the record behind it. All three sites now share one `resolveChromaKey({ manifest, record, run })` (run → manifest → record), and a genuinely keyless record is refused by name before reaching the color parser. And the render path's anchor/chroma preconditions are now one shared `resolveWalkRenderability()`, so the gate that promises "every direction can be regenerated" and the render path that has to deliver it cannot drift — a predicate checking less than the render requires is exactly how an acknowledgement walks a user into the dead end it promises cannot happen.- **[issue-3049] Pin the walk aligner to the character's torso, not its bounding box** — a re-derived walk cycle slid visibly left and right as the legs scissored instead of walking in place; measured on a real packed 12-frame strip the torso travelled **29px** in a 384px cell. `alignFrames` crops each frame to its own alpha bbox and composites the crop at `dx`, and since #3021 `dx` was a single shared value — but `sourceRootXs[i]` is measured *relative to that frame's own crop*, so a constant `dx` pins `bbox.left` (the leading arm/leg extremity) and lets the body swing by the full spread of those offsets. The emitted manifest showed it exactly: `hipOffsets` spanning 26.2px against `translations` whose x was `122` for all twelve frames, and the strip itself had `bbox.left` at exactly 122 in every cell while the hip swung 179→205. #3021's premise was right (the old 42%–76% hip/leg band did migrate as the legs scissored) but freezing `dx` swapped it for a *worse* landmark: measured in absolute source coordinates over one 6s clip, the candidates rank torso 14px · hip 17px · head 24px · **bbox.left 44px** · legs 52px. So `rootX` now measures the **torso** band (30%–58%, above the knees — the visual mass a viewer tracks and the part genuinely stationary in a walk-in-place) and `dx` is per-frame again, computed from each frame's own crop offset so the shared landmark lands on the pivot every time; that cancels the crop variation *and* the residual drift grok leaves in a "walk in place" clip (~14px). `rootX` is shared with `atlas.js` for idle-frame registration, so both moved together. The #3021 guard had asserted the mechanism (`new Set(translations.map(([dx]) => dx)).size === 1`) rather than the behaviour, and its own fixed-torso/swinging-arm fixture passed while the body slid 30px — it now measures where the torso *lands* in the output frames and requires ≤1px spread, which pinning the crop cannot satisfy. Re-deriving a real direction: torso spread **29px → 1.0px**, with the hip band still swinging 8px and `bbox.left` varying 9px (limbs moving, body still).+- **[issue-3050] Spread walk-cycle phases evenly when the gait period doesn't divide the frame count** — a re-derived walk could read as a limp rather than a smooth loop: the *timing* was uneven, not the seam (which is why `validation` never flagged it — the loop closed fine). `selectCycleIndices` resamples the detected window with `pyRound(i * cycleLength / frameCount)`, and `pyRound` is Python's round-half-to-even, so a `.5` tie breaks toward the even integer — meaning the tie's *direction* depends on the parity of the integer part and consecutive ties resolve opposite ways. A 15-frame gait over 12 phases landed its ties at 2.5→2 (down), 7.5→8 (up), 12.5→12 (down), putting double-steps at positions 2, 5 and 10 — spacings of 3 and 5, an arrhythmic hitch. The run manifest corroborated it: those three transitions carried ~28% more motion than the single-step median. Phase indices are now distributed with integer half-up (`floor((i * cycleLength + frameCount/2) / frameCount)`), which resolves every tie the same way, so the unavoidable stretch is spread evenly — 15→12 moves its double-steps to 1, 5 and 9 (gaps of 4 and 4). This is the one place that deliberately does not use `pyRound`: the pixel math keeps it for byte-compatibility with the source pipeline, while phase selection is a perceptual-quality question and only it has a tie problem. The legacy 12→8 default was affected too (strides `2,1,1,2,2,1,1` → `2,1,2,1,2,1,2`), as were 18→12 and any other ratio landing ties at regular intervals; 16→12, 13→12 and 12→12 were already even and are unchanged. The old golden-array test asserted the banker's-rounding output directly; it is replaced by a property assertion — at most two distinct stride lengths, differing by 1, with the longer ones evenly spaced — checked across five ratios so a future change to the resample has to preserve it for all of them.diff --git a/server/services/sprites/walkPostprocess.js b/server/services/sprites/walkPostprocess.jsindex d6f4736944..e434f7b5b1 100644--- a/server/services/sprites/walkPostprocess.js+++ b/server/services/sprites/walkPostprocess.js@@ -364,7 +364,28 @@ export function selectCycleIndices(signatures, frameCount = WALK_FRAME_COUNT) {}if (!best) throw new Error('No detectable moving walk cycle in the source video');const [, start, cycleLength, seam, motion] = best;- const indices = Array.from({ length: frameCount }, (_, i) => start + pyRound((i * cycleLength) / frameCount));+ // Even phase distribution, in integer arithmetic (#3050).+ //+ // This is the ONE place that deliberately does not use `pyRound`. Banker's+ // rounding breaks a .5 tie toward the even integer, so the tie's DIRECTION+ // depends on the parity of the integer part — and when `cycleLength /+ // frameCount` puts ties at regular intervals, consecutive ties resolve+ // opposite ways and the phases stop being evenly spaced. A 15-frame gait+ // resampled to 12 landed ties at 2.5→2 (down), 7.5→8 (up), 12.5→12 (down),+ // giving double-steps at positions 2, 5 and 10 — spacings of 3 and 5, an+ // arrhythmic hitch that reads as a limp. Half-up resolves every tie the same+ // way, so the double-steps land at 1, 5 and 9: still 15 source frames over 12+ // phases, but the unavoidable stretch is spread evenly.+ //+ // `(i * cycleLength + frameCount/2) / frameCount` floored IS half-up, and in+ // integers it cannot drift on a float representation. Pixel math keeps+ // `pyRound` — that half is byte-compatibility with the source pipeline, this+ // half is perceptual quality, and only the latter has a tie problem.+ const half = Math.floor(frameCount / 2);+ const indices = Array.from(+ { length: frameCount },+ (_, i) => start + Math.floor((i * cycleLength + half) / frameCount),+ );if (new Set(indices).size !== frameCount) {throw new Error(`Cycle window too short to resample ${frameCount} distinct phases`);}diff --git a/server/services/sprites/walkPostprocess.test.js b/server/services/sprites/walkPostprocess.test.jsindex 570d22d712..878e9b2a3f 100644--- a/server/services/sprites/walkPostprocess.test.js+++ b/server/services/sprites/walkPostprocess.test.js@@ -172,7 +172,7 @@ describe('selectCycleIndices', () => {const SIG_LEN = 48 * 48 * 3;const constSig = (v) => Buffer.alloc(SIG_LEN, v);- it('finds the periodic window and resamples with banker\'s rounding', () => {+ it('finds the periodic window and spreads the phases evenly', () => {// Period-12 sawtooth: seam 0 at cycleLength 12, median motion 10.const pattern = [0, 10, 20, 30, 40, 50, 60, 50, 40, 30, 20, 10];const signatures = Array.from({ length: 25 }, (_, i) => constSig(pattern[i % 12]));@@ -181,8 +181,36 @@ describe('selectCycleIndices', () => {expect(cycle.windowLength).toBe(12);expect(cycle.endpointSeamScore).toBe(0);expect(cycle.medianMotionScore).toBe(10);- // round(i*12/8) = round(i*1.5) — half-to-even: 1.5→2, 4.5→4, 7.5→8, 10.5→10.- expect(indices).toEqual([0, 2, 3, 4, 6, 8, 9, 10]);+ // 12 source frames over 8 phases: strides must alternate 2,1,2,1… Banker's+ // rounding used to give [0,2,3,4,6,8,9,10] — strides 2,1,1,2,2,1,1, i.e. two+ // adjacent double-steps then two adjacent singles, which reads as a limp.+ expect(indices).toEqual([0, 2, 3, 5, 6, 8, 9, 11]);+ });++ /**+ * #3050 — the phases must be as evenly spaced as the ratio allows, for EVERY+ * ratio. Banker's rounding resolves a .5 tie toward the even integer, so the+ * tie direction flips with the parity of the integer part and consecutive ties+ * disagree; 15 source frames over 12 phases came out with double-steps at 2, 5+ * and 10 (spacings 3 and 5). Asserted as a property rather than a golden array+ * so a future change to the resample has to keep it for all of them.+ */+ it('spreads the stretch evenly for any window/frameCount ratio', () => {+ const pattern = (p, i) => Math.round(60 * Math.abs(((i % p) / p) * 2 - 1));+ for (const [period, frameCount] of [[15, 12], [16, 12], [13, 12], [18, 12], [12, 8]]) {+ const signatures = Array.from({ length: period * 2 + 2 }, (_, i) => constSig(pattern(period, i)));+ const { indices } = selectCycleIndices(signatures, frameCount);+ const strides = indices.slice(1).map((v, i) => v - indices[i]);+ // Only two stride lengths may appear, and they must differ by 1 — no frame+ // may be skipped twice as far as another beyond the unavoidable remainder.+ const distinct = [...new Set(strides)].sort((a, b) => a - b);+ expect(distinct.length).toBeLessThanOrEqual(2);+ if (distinct.length === 2) expect(distinct[1] - distinct[0]).toBe(1);+ // …and the longer strides are evenly spaced through the cycle.+ const longAt = strides.map((s, i) => (s === distinct.at(-1) ? i : -1)).filter((i) => i >= 0);+ const gaps = longAt.slice(1).map((v, i) => v - longAt[i]);+ expect(new Set(gaps).size).toBeLessThanOrEqual(1);+ }});it('rejects a static clip and too-few frames', () => {