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 (ollama): validate a facing against the track's own list, not the grid's

[._.]/ Adam Eivyf9b265ecf102
diff --git a/client/src/services/apiSprites.js b/client/src/services/apiSprites.js
index 9f5d8922d7..e762a1f929 100644
--- a/client/src/services/apiSprites.js
+++ b/client/src/services/apiSprites.js
@@ -145,7 +145,7 @@ export const approveSpriteWalk = (id, body, options = {}) => request(`/sprites/$
// Approve one packaged candidate for a non-walk track. Returns that track's
// updated `{ track, bounds, selection, set, runs }` state.
-export const approveSpriteTrack = (id, trackId, body, options = {}) => request(
+export const approveSpriteTrack = (id, trackId, body = {}, options = {}) => request(
`/sprites/${encodeURIComponent(id)}/tracks/${encodeURIComponent(trackId)}/approve`,
{ method: 'POST', body: JSON.stringify(body), ...options },
);
diff --git a/server/lib/validation.js b/server/lib/validation.js
index 28939a03fe..e49a820398 100644
--- a/server/lib/validation.js
+++ b/server/lib/validation.js
@@ -1078,6 +1078,20 @@ export const spriteRuntimeContractSchema = z.object({
cellSize: z.number().int().min(16).max(1024).nullable().optional(),
columnCount: z.number().int().min(1).max(256).nullable().optional(),
}).superRefine((value, ctx) => {
+ // An empty set means no registered track is a publishable baseline. The boot
+ // guard in `assertAnimationTrackRows` makes that unreachable today (it
+ // requires exactly one per record kind), but this schema must not silently
+ // become "any contract passes" if that ever changes — with `[0]` undefined,
+ // `path: [undefined]` and an empty message would report a rejection nothing
+ // could act on. Refuse the whole contract with a message naming the cause.
+ if (!SPRITE_STANDALONE_CONTRACT_FIELDS.length) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: [],
+ message: 'No animation track declares itself a publishable baseline (standaloneContract) — a runtime contract cannot be validated',
+ });
+ return;
+ }
if (SPRITE_STANDALONE_CONTRACT_FIELDS.every((field) => value[field] === undefined)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
diff --git a/server/services/sprites/animationTrackWorkflow.js b/server/services/sprites/animationTrackWorkflow.js
index 37b108424c..1e8422f1c7 100644
--- a/server/services/sprites/animationTrackWorkflow.js
+++ b/server/services/sprites/animationTrackWorkflow.js
@@ -6,12 +6,15 @@
* source reference → prepare a chroma matte → start ONE user-requested Grok
* image-to-video render → package it deterministically → review → approve →
* freeze the set. Nothing about that sequence is scanner-shaped or ambient
- * shaped; they differed only in three registry facts (#3136 promoted each to a
- * field on the track row):
+ * shaped; they differed only in facts the track registry now carries:
*
- * - `sourceReference` which locked image seeds the render (`anchor` per
- * facing, or the one `main`)
- * - `directional` how many facings must be approved before the set freezes
+ * - `directional` how many facings the track is authored across (and so
+ * how many must be approved before the set freezes) AND —
+ * derived from it via `sourceReferenceFor` — which locked
+ * image seeds the render: this facing's own anchor, or the
+ * one main reference. Derived rather than declared because
+ * only one pairing can work; a row that claimed the other
+ * would render one facing's clip for every row.
* - `selectionKind` / `setKind` / `finalErrorCode`
* the on-disk discriminators and the 409 code
*
@@ -22,10 +25,6 @@
* and set-level targets that no other track has, and folding those in would make
* this module the union of every track's features rather than their intersection.
*
- * Note `sourceReference` is DERIVED (`sourceReferenceFor`) rather than a row
- * field: only one pairing with `directional` can work, so declaring it would let
- * a row claim a combination that renders the same clip for every facing.
- *
* **On-disk compatibility is exact, not approximate.** Every path, `kind`
* string, run field, error code and message this writes is byte-identical to
* what the two clones wrote, because installs already hold approved scanner sets
@@ -75,13 +74,6 @@ const RUN_RECORD_NAME = 'animation-run.json';
*/
export const trackAuthoringDirections = (trackId) => trackDirections(trackId);
-/**
- * The one facing a non-directional track is authored at — its own single row,
- * read off the same slice rather than restated as `'south'`, so the authoring
- * side and the compiled grid can never disagree about which row that is.
- */
-const soleDirectionOf = (trackId) => trackAuthoringDirections(trackId)[0];
-
// The on-disk layout, per track. `<track>/` subdirectory and `-<track>-` infix,
// which is exactly what scanner.js and ambient.js each spelled for themselves.
const selectionRelPath = (trackId, id) => `${trackId}/${id}-${trackId}-selection-v1.json`;
@@ -181,6 +173,31 @@ function trackSourceFor(row, manifest, direction) {
};
}
+/**
+ * The facing a request is for, resolved against the track's OWN facing list.
+ *
+ * A non-directional track occupies exactly its single row, so its facing is
+ * derived from the registry rather than accepted from the request — no
+ * user-supplied direction can drift from what the compiler will later expect.
+ *
+ * A directional track's facing must be one the TRACK has, not merely one the
+ * sprite grid has: the route's Zod enum accepts all eight facings, but
+ * `trackAuthoringDirections` is a per-track slice, so a future track with fewer
+ * facings would otherwise accept a render for a row it doesn't occupy — which
+ * would author a set the compiler refuses, after the render was already paid for.
+ */
+function resolveTrackDirection(row, requested) {
+ const authored = trackAuthoringDirections(row.id);
+ if (!row.directional) return authored[0];
+ if (!authored.includes(requested)) {
+ throw new ServerError(
+ `The ${row.id} track has no '${String(requested)}' facing — it is authored across: ${authored.join(', ')}`,
+ { status: 400, code: 'TRACK_DIRECTION_INVALID' },
+ );
+ }
+ return requested;
+}
+
/** The 409 for a render/approval whose source reference isn't frozen yet. */
const notLockedError = (source, row, verb) => new ServerError(
`Lock the ${source.label} before ${verb} its ${row.label.toLowerCase()}`,
@@ -197,10 +214,7 @@ async function startTrackGenerationImpl(trackId, recordId, body) {
requireTrack(recordId, row.id), loadManifest(recordId), loadSet(row.id, recordId), trackRuns(row.id, recordId),
]);
if (existingSet) throw setFinalError(row);
- // A non-directional track occupies exactly row 0, so its facing is derived
- // from the registry rather than accepted from the request — no user-supplied
- // direction can drift from what `trackDirections()` will later compile.
- const direction = row.directional ? body.direction : soleDirectionOf(row.id);
+ const direction = resolveTrackDirection(row, body.direction);
const source = trackSourceFor(row, reference, direction);
if (!source.locked) throw notLockedError(source, row, 'generating');
const chromaKey = resolveChromaKey({ manifest: reference, record });
@@ -371,7 +385,7 @@ async function approveTrackRunImpl(trackId, recordId, { direction: requested, ru
const row = getAnimationTrack(trackId);
await requireTrack(recordId, row.id);
if (await loadSet(row.id, recordId)) throw setFinalError(row);
- const direction = row.directional ? requested : soleDirectionOf(row.id);
+ const direction = resolveTrackDirection(row, requested);
const label = row.label.toLowerCase();
const run = await loadRun(recordId, runId);
if (!run || run.track !== row.id) throw new ServerError(`Unknown ${label} run: ${runId}`, { status: 404, code: 'RUN_NOT_FOUND' });
diff --git a/server/services/sprites/animationTrackWorkflow.test.js b/server/services/sprites/animationTrackWorkflow.test.js
index 7ddf6c9027..a94b5e1be0 100644
--- a/server/services/sprites/animationTrackWorkflow.test.js
+++ b/server/services/sprites/animationTrackWorkflow.test.js
@@ -259,6 +259,28 @@ describe.each(TRACKS)('the generic workflow drives the $id track', (track) => {
await expect(approveTrackRun(track.id, id, { ...track.body, runId: 'no-such-run' }))
.rejects.toMatchObject({ status: 404, code: 'RUN_NOT_FOUND' });
});
+
+ it('resolves the facing against the TRACK\'s own list, not the grid\'s', async () => {
+ const id = await track.seed(newId());
+ if (row().directional) {
+ // The route's Zod enum accepts all eight grid facings, but a track is
+ // authored across its OWN slice — so a facing outside it must be refused
+ // here rather than authoring a set the compiler will later refuse, after
+ // the render was already paid for.
+ await expect(startTrackGeneration(track.id, id, { ...track.body, direction: 'nowhere' }))
+ .rejects.toMatchObject({ status: 400, code: 'TRACK_DIRECTION_INVALID' });
+ await expect(startTrackGeneration(track.id, id, { ...track.body, direction: undefined }))
+ .rejects.toMatchObject({ status: 400, code: 'TRACK_DIRECTION_INVALID' });
+ expect(executeTuiRun).not.toHaveBeenCalled();
+ } else {
+ // A single-row track derives its facing, so a bogus request value is
+ // ignored rather than trusted — it can't drift from what the compiler
+ // will expect.
+ const { runId } = await startTrackGeneration(track.id, id, { ...track.body, direction: 'nowhere' });
+ const { runs } = await getTrackState(track.id, id);
+ expect(runs.find((r) => r.id === runId).direction).toBe(track.expectedDirection);
+ }
+ });
});
describe('registry-derived authoring shape (#3136)', () => {