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

refactor([issue-2993]): move run-layout drift resolution into paths.js and stamp imported directions

[._.]/ Adam Eivy552b1f6d2e25
diff --git a/client/src/components/sprites/PublishWorkflow.jsx b/client/src/components/sprites/PublishWorkflow.jsx
index b268af71d5..551360d83c 100644
--- a/client/src/components/sprites/PublishWorkflow.jsx
+++ b/client/src/components/sprites/PublishWorkflow.jsx
@@ -114,10 +114,12 @@ export default function PublishWorkflow({ record, walk, atlas, onChanged }) {
<Package size={16} className="text-port-accent" /> Runtime Atlas
</h3>
<p className="text-xs text-gray-500">
- Some directions are still packaged by the source pipeline, which kept their per-frame
- images — PortOS cannot compile from those. Reopen each one above and reprocess it from
- its imported clip to re-derive the frames here, then compile. The imported runtime
- atlases remain in the asset library below.
+ {walk.walkSet.importedDirections?.length
+ ? `${walk.walkSet.importedDirections.join(', ')} ${walk.walkSet.importedDirections.length === 1 ? 'is' : 'are'} still packaged`
+ : 'Some directions are still packaged'} by the source pipeline, which kept their
+ per-frame images — PortOS cannot compile from those. Reopen each one above and reprocess
+ it from its imported clip to re-derive the frames here, then compile. The imported
+ runtime atlases remain in the asset library below.
</p>
</div>
);
diff --git a/client/src/components/sprites/WalkWorkflow.jsx b/client/src/components/sprites/WalkWorkflow.jsx
index 0c7808aa4e..a1a0c5bf9a 100644
--- a/client/src/components/sprites/WalkWorkflow.jsx
+++ b/client/src/components/sprites/WalkWorkflow.jsx
@@ -144,6 +144,17 @@ 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.
+// Whether a run can be re-derived without a new render. The server resolves
+// `sourceVideoPath` against disk and flags `sourceClipMissing` when the clip the
+// record names isn't there, so "declares a clip" and "has one" never read the
+// same. Named once because every affordance below gates on it — and the header's
+// Unlock and a card's Reopen disagreeing about the same run would be a bug.
+const hasClip = (run) => Boolean(run?.sourceVideoPath) && !run?.sourceClipMissing;
+
+// The one remedy for an imported direction with nothing behind it. The clip is
+// the importer's to bring across, so authoring a new version by hand isn't it.
+const REIMPORT_REMEDY = 're-import this character to bring its source clip across';
+
const driftRemedy = ({ approved, hasSourceClip, imported }) => {
// Evidence, not provenance: the server gates re-derivation on whether the
// direction's clip is actually on disk, so an imported direction whose clip
@@ -151,9 +162,7 @@ const driftRemedy = ({ approved, hasSourceClip, imported }) => {
// clip behind it is a dead end — and for an import the fix is re-importing the
// character, not authoring a new version by hand.
if (!hasSourceClip) {
- return imported
- ? 're-import this character to bring its source clip across'
- : 'import this direction\'s source clip to re-derive it';
+ return imported ? REIMPORT_REMEDY : 'import this direction\'s source clip to re-derive it';
}
if (approved) return 'reopen this direction to re-derive it from its clip';
return 'reprocess it from its clip';
@@ -260,11 +269,11 @@ function DirectionCard({
// link stands for approved and finalized runs too, since a trim is a
// non-destructive derived artifact under `walk/trims/`.
const trimmable = Boolean(run?.stripPreview?.stripPath);
- // Whether this direction can be re-derived without a new render: the server
- // resolves `sourceVideoPath` against disk and flags `sourceClipMissing` when
- // the clip the record names isn't there, so declaring a clip and having one
- // never read the same. Every reopen/reprocess affordance below gates on this.
- const hasSourceClip = Boolean(run?.sourceVideoPath) && !run?.sourceClipMissing;
+ const hasSourceClip = hasClip(run);
+ // The dead end: still packaged by the source pipeline AND no clip to re-derive
+ // from. Everything the server refuses for this direction refuses on exactly
+ // this, so every affordance below reads it rather than the import label alone.
+ const importedNoClip = imported && !hasSourceClip;
const statusLabel = approved ? 'approved'
: (pending || rendering) ? 'rendering…'
: run?.status === 'postprocessing' ? 'packaging…'
@@ -313,8 +322,7 @@ function DirectionCard({
naming them there would advise a guaranteed-409 the drift badge and
the hidden Reopen/Unlock buttons already avoid. With a clip it
recovers exactly like a native direction. */}
- Walk strip missing on disk — {imported && !hasSourceClip
- ? 're-import this character to bring its source clip across'
+ Walk strip missing on disk — {importedNoClip ? REIMPORT_REMEDY
: finalized ? 'unlock the set to regenerate this direction' : 'regenerate to repack it'}.
</p>
)}
@@ -432,7 +440,7 @@ function DirectionCard({
unlock, so offering the button would guarantee a 409 on click. An
imported direction whose clip came across reopens like any other.
Mirrors how the header gates Unlock. */}
- {approved && (!imported || hasSourceClip) && (
+ {approved && !importedNoClip && (
reopening ? (
<ConfirmButtonPair
prompt={finalized ? 'Reopen (un-freezes set)?' : 'Reopen this direction?'}
@@ -496,16 +504,23 @@ export default function WalkWorkflow({
const selection = walk?.selection || null;
const finalized = Boolean(walk?.walkSet);
// A source-pipeline import (#2895) still carries directions PortOS cannot
- // compile from. The server stamps this flag on the walk state so the client
- // doesn't re-derive the path convention itself.
+ // compile from. The server stamps both the set-level flag and the precise
+ // per-direction list, so the client never re-derives the path convention — and
+ // a card reads the fact about ITS OWN direction rather than a set-wide
+ // approximation, since directions leave the list one at a time as they are
+ // re-derived. An older peer's walk state may carry only the boolean; fall back
+ // to it so every direction still reads as imported there.
const importedWalkSet = Boolean(walk?.walkSet?.imported);
- // …but since #2984 imports each run's clip, such a set is only a dead end when
+ const importedDirections = walk?.walkSet?.importedDirections || null;
+ const isImportedDirection = (direction) => (importedDirections
+ ? importedDirections.includes(direction) : importedWalkSet);
+ // Since #2984 imports each run's clip, such a set is only a dead end when
// NOTHING behind it can be re-derived — which is exactly when the server
// refuses to unlock it. Gate the affordance on that, not on the import label,
// so an import with its clips intact gets the real Unlock button instead of a
- // "new version to revise" note that is no longer true.
- const unlockBlocked = importedWalkSet
- && !(walk?.runs || []).some((run) => run.sourceVideoPath && !run.sourceClipMissing);
+ // "new version to revise" note that is no longer true. The server's own gate
+ // is authoritative (its 409 is the backstop); this only decides what to offer.
+ const unlockBlocked = importedWalkSet && !runs.some(hasClip);
// direction → jobId for in-flight video renders. The hook instance is owned
// by the Sprites page and shared with the asset collection (#2931) so both
@@ -707,7 +722,7 @@ export default function WalkWorkflow({
pending={Boolean(pendingJobs[anchor.direction])}
targetSaving={targetSaving}
drift={driftByDirection[anchor.direction] || null}
- imported={importedWalkSet}
+ imported={isImportedDirection(anchor.direction)}
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 9d1afcfb63..10bcb58402 100644
--- a/client/src/components/sprites/WalkWorkflow.test.jsx
+++ b/client/src/components/sprites/WalkWorkflow.test.jsx
@@ -526,4 +526,38 @@ describe('WalkWorkflow reprocess + reopen', () => {
expect(screen.getByRole('button', { name: /^Unlock$/ })).toBeTruthy();
expect(screen.queryByText(/no clips to re-derive/)).toBeNull();
});
+
+ // The set-level flag stays true while ANY direction is still source-packaged,
+ // so a card must read the per-direction list the server stamps — otherwise a
+ // direction already re-derived here keeps being treated as un-reopenable.
+ it('reads the per-direction imported list, not the set-level flag', async () => {
+ render(
+ <MemoryRouter>
+ <WalkWorkflow
+ record={{ id: 'example-walker' }}
+ reference={{ manifest: { mainReference: { locked: true }, anchors: [{ direction: 'east', status: 'locked' }] } }}
+ walk={{
+ // East carries no clip, but it is NOT in importedDirections — it was
+ // already re-derived here, so the server no longer refuses it.
+ runs: [{ id: 'run-east', direction: 'east', status: 'approved', stripPreview: { stripPath: 'runs/run-east/generated/strip.png', frameCount: 12, fps: 10, cellWidth: 384, cellHeight: 384 } }],
+ selection: { directions: { east: { status: 'approved', runId: 'run-east' } } },
+ walkSet: {
+ imported: true,
+ importedDirections: ['north'],
+ directions: { east: { status: 'approved' }, north: { status: 'approved' } },
+ },
+ walkTarget: {
+ frameCount: 12, fps: 10, source: 'derived', sourceLabel: 'from the first approved direction', drift: [],
+ },
+ }}
+ renders={noRenders()}
+ duration={6}
+ onDurationChange={vi.fn()}
+ onGenerate={vi.fn()}
+ onChanged={vi.fn()}
+ />
+ </MemoryRouter>,
+ );
+ expect(screen.getByRole('button', { name: /^Reopen$/ })).toBeTruthy();
+ });
});
diff --git a/server/services/sprites/atlas.js b/server/services/sprites/atlas.js
index b7f4c82892..e9e5aba0f7 100644
--- a/server/services/sprites/atlas.js
+++ b/server/services/sprites/atlas.js
@@ -218,8 +218,8 @@ export async function validateForCompile(recordId) {
// the directions still carrying source-pipeline provenance block the compile,
// and the message names them so the remedy is per-direction too. Their
// already-published runtime atlases were imported and remain browsable.
- if (isImportedWalkSet(walkSet)) {
- const stale = importedWalkDirections(walkSet);
+ const stale = importedWalkDirections(walkSet);
+ if (stale.length || isImportedWalkSet(walkSet)) {
const which = stale.length ? `${stale.join(', ')} ${stale.length === 1 ? 'is' : 'are'}` : 'This walk set is';
throw new ServerError(
`${which} still packaged by the source pipeline, whose per-frame images were not imported — PortOS cannot compile from them. `
diff --git a/server/services/sprites/importer.js b/server/services/sprites/importer.js
index 27cc16299c..d028198796 100644
--- a/server/services/sprites/importer.js
+++ b/server/services/sprites/importer.js
@@ -27,7 +27,9 @@ import { readdir, copyFile, rm } from 'fs/promises';
import { PATHS, ensureDir, sha256File, atomicWrite, pathExists, readJSONFile, expandHome } from '../../lib/fileUtils.js';
import { ServerError } from '../../lib/errorHandler.js';
import { upsertImportedRecord } from './records.js';
-import { spriteDir, RUN_DIR_MATCH, altRunLayoutPath } from './paths.js';
+import {
+ spriteDir, RUN_DIR_MATCH, altRunLayoutPath, resolveDriftTolerantRel, SOURCE_CLIP_NAME,
+} from './paths.js';
import { isValidSpriteId } from './recordsLogic.js';
// The source pipeline keys everything on magenta; imported characters carry it
@@ -159,8 +161,8 @@ const ASSET_REF = /\.(png|gif|json)$/i;
// Matched by exact shape rather than a blanket `.mp4` rule so unrelated videos
// in the source tree still stay behind. `raw/` frames deliberately remain
// excluded below — ~5× the bytes of the clip they were extracted from, and
-// re-derivation re-extracts them on demand.
-const SOURCE_CLIP_NAME = 'source-video.mp4';
+// re-derivation re-extracts them on demand. (The name itself lives in paths.js —
+// the importer, the postprocess, and the walk service all key on it.)
const SOURCE_CLIP_REF = new RegExp(`${RUN_DIR_MATCH.source}/generated/source-video\\.mp4$`);
const EXCLUDED_RUN_SEGMENTS = /(^|\/)(raw|frames|review)\//;
// Free-text log fields in run records can contain path-looking strings that
@@ -205,15 +207,6 @@ function collectManifestRefs(node, characterId, refs, expectations) {
}
}
-// Resolve a declared path against the SOURCE tree, tolerating run-layout drift
-// (`altRunLayoutPath`): returns whichever path actually exists — the declared
-// one or its twin — or null when neither does.
-async function resolveSourceRel(srcCharDir, rel) {
- if (await pathExists(join(srcCharDir, rel))) return rel;
- const alt = altRunLayoutPath(rel);
- return alt && (await pathExists(join(srcCharDir, alt))) ? alt : null;
-}
-
// Read a character-dir JSON with the same drift tolerance, so a manifest
// naming `runs/<run-id>/…` still expands when the source stores that run under
// `grok/<run-id>/`. Read-then-fall-back rather than probe-then-read: readJson
@@ -232,7 +225,7 @@ async function readCharJson(srcCharDir, rel) {
// else would import a file nothing can find. Only the source lookup tolerates
// drift.
async function copyCharFile(srcCharDir, destDir, rel) {
- const srcRel = await resolveSourceRel(srcCharDir, rel);
+ const srcRel = await resolveDriftTolerantRel(srcCharDir, rel);
if (!srcRel) return false;
const dest = join(destDir, rel);
await ensureDir(dirname(dest));
@@ -269,7 +262,7 @@ async function importApprovedDirection({ srcCharDir, destDir, characterId, direc
// expand their manifests.
collectManifestRefs(await readJson(join(destDir, manifestRel)), characterId, refs, hashExpectations);
const runRel = relToCharacterDir(dir.runPath, characterId);
- if (runRel && (await resolveSourceRel(srcCharDir, `${runRel}/generated/review-preview.json`))) {
+ if (runRel && (await resolveDriftTolerantRel(srcCharDir, `${runRel}/generated/review-preview.json`))) {
refs.add(`${runRel}/generated/review-preview.json`);
}
// One extra expansion level: packaged manifests / previews the run record
@@ -288,7 +281,7 @@ async function importApprovedDirection({ srcCharDir, destDir, characterId, direc
// layout — that path is already in `refs` and denotes the same file.
const clipRel = runRel && `${runRel}/generated/${SOURCE_CLIP_NAME}`;
if (clipRel && RUN_DIR_MATCH.test(runRel) && !refs.has(clipRel) && !refs.has(altRunLayoutPath(clipRel))
- && (await resolveSourceRel(srcCharDir, clipRel))) {
+ && (await resolveDriftTolerantRel(srcCharDir, clipRel))) {
refs.add(clipRel);
}
refs.delete(manifestRel);
diff --git a/server/services/sprites/paths.js b/server/services/sprites/paths.js
index 52cf876625..6af1788d89 100644
--- a/server/services/sprites/paths.js
+++ b/server/services/sprites/paths.js
@@ -14,7 +14,7 @@
import { join, resolve } from 'path';
import { readdir, stat } from 'fs/promises';
import sharp from 'sharp';
-import { PATHS, isPathInsideDir } from '../../lib/fileUtils.js';
+import { PATHS, isPathInsideDir, pathExists } from '../../lib/fileUtils.js';
import { createBoundedStateMap } from '../../lib/boundedStateMap.js';
import { ServerError } from '../../lib/errorHandler.js';
import { isValidSpriteId } from './recordsLogic.js';
@@ -48,9 +48,25 @@ export const RUNTIME_PUBLICATIONS_REL = 'runtime/publications.json';
* repo-anchor segment is assumed already record-relative and passed through
* unchanged — this is what makes the helper a no-op for PortOS's own runs.
*/
+/**
+ * The path prefix the source art pipeline anchors every embedded reference at.
+ * A copied manifest names `art-source/sprites/<recordId>/…` for a file that, on
+ * this side, sits at the record root — so this marker is what distinguishes
+ * "still carries source-pipeline provenance" from "PortOS-owned and relative".
+ * It can sit at any index (absolute / repo-prefixed variants), matching the
+ * importer's own recognition — hence `includes`, not a prefix test.
+ */
+export const SOURCE_PIPELINE_ANCHOR = 'art-source/sprites/';
+export const isSourcePipelinePath = (p) => typeof p === 'string' && p.includes(SOURCE_PIPELINE_ANCHOR);
+
+// The i2v clip every animation run is derived from, inside its `generated/` dir.
+// Named here rather than in each consumer: the importer copies it, the
+// postprocess reads it, and the walk service re-derives from it.
+export const SOURCE_CLIP_NAME = 'source-video.mp4';
+
export function toRecordRelativeAssetPath(recordId, rawPath) {
if (typeof rawPath !== 'string' || !rawPath) return null;
- const marker = `art-source/sprites/${recordId}/`;
+ const marker = `${SOURCE_PIPELINE_ANCHOR}${recordId}/`;
const idx = rawPath.indexOf(marker);
// Match importer.js's relToCharacterDir: an already-relative path may still
// carry a leading slash (an absolute-style source value) — strip it before
@@ -102,6 +118,29 @@ export function altRunLayoutPath(rel) {
return match ? `${RUN_DIR_PREFIXES.find((p) => p !== match[1])}${match[2]}` : null;
}
+/** The run directory at the head of a record-relative path, under either layout. */
+export const runDirOfPath = (rel) => (typeof rel === 'string' ? RUN_DIR_MATCH.exec(rel)?.[0] || null : null);
+
+/**
+ * The spelling of `rel` that actually exists under `baseDir` — the declared one
+ * or its run-layout twin — or null when neither does.
+ *
+ * The drift this absorbs is one fact about the source trees, not one fact about
+ * clips: a manifest can name `runs/<id>/…` for a file stored under `grok/<id>/…`
+ * and both spellings denote the same artifact. Every reader that resolves a
+ * declared path against disk wants this, which is why it lives beside
+ * `altRunLayoutPath` rather than inside any one consumer (the importer resolves
+ * its source reads through it; the walk service resolves run clips through it).
+ * A path outside a run directory has no twin, so this degrades to a plain
+ * existence check.
+ */
+export async function resolveDriftTolerantRel(baseDir, rel) {
+ if (typeof rel !== 'string' || !rel) return null;
+ if (await pathExists(join(baseDir, rel))) return rel;
+ const alt = altRunLayoutPath(rel);
+ return alt && (await pathExists(join(baseDir, alt))) ? alt : null;
+}
+
// Raw ffmpeg-extracted frame intermediates inside an animation run (30–96
// near-identical PNGs per run, `grok|runs/<run>/generated/raw/`). Kept on
// disk for the postprocessor but omitted from the asset listing — they'd
diff --git a/server/services/sprites/walk.js b/server/services/sprites/walk.js
index 5b164bd0ba..9f5e1cfdce 100644
--- a/server/services/sprites/walk.js
+++ b/server/services/sprites/walk.js
@@ -31,6 +31,7 @@ import { getSettings } from '../settings.js';
import { getRecord, updateRecord } from './records.js';
import {
spriteDir, resolveSpriteAssetPath, toRecordRelativeAssetPath, RUN_DIR_MATCH, altRunLayoutPath,
+ runDirOfPath, resolveDriftTolerantRel, isSourcePipelinePath, SOURCE_CLIP_NAME,
} from './paths.js';
import { requireCharacter, loadManifest } from './reference.js';
import { SPRITE_DIRECTIONS, anchorIdForDirection, buildWalkVideoPrompt } from './prompts.js';
@@ -93,13 +94,9 @@ async function loadWalkSet(recordId) {
}
// A phase-1 imported walk set (#2895) is copied verbatim from the source
-// pipeline: every embedded path is repo-root-anchored (`art-source/sprites/…`)
-// and its packaged per-frame PNGs were never imported. The marker can sit at
-// any index (absolute/repo-prefixed variants), matching the importer's own
-// relToCharacterDir recognition — hence `includes`, not a prefix test.
-const SOURCE_PIPELINE_MARKER = 'art-source/sprites/';
-const isSourcePipelinePath = (p) => typeof p === 'string' && p.includes(SOURCE_PIPELINE_MARKER);
-
+// pipeline: every embedded path stays anchored at the SOURCE repo root
+// (paths.js#isSourcePipelinePath) and its packaged per-frame PNGs were never
+// imported.
/**
* The directions of a walk set that are STILL packaged by the source pipeline —
* their approved entry names the source tree, so their per-frame PNGs are not on
@@ -193,17 +190,12 @@ async function saveRunRecordAt(recordId, run, runDirRel) {
const saveRunRecord = (recordId, run) => saveRunRecordAt(recordId, run, runRelPath(run.id));
-// The run directory a record-relative run path names, under either layout.
-const runDirOfPath = (rel) => (typeof rel === 'string' ? RUN_DIR_MATCH.exec(rel)?.[0] || null : null);
-
-// The run directory a selection / walk-set entry names — `runPath` first, then
-// the manifest it declares. Null for an imagegen redraw entry, which names a
-// version directory rather than a run (and so has no i2v clip behind it).
-function runDirRelForEntry(recordId, entry) {
- const layoutPath = toRecordRelativeAssetPath(recordId, entry?.runPath)
- || toRecordRelativeAssetPath(recordId, entry?.runManifest);
- return runDirOfPath(layoutPath);
-}
+// The record-relative path a selection / walk-set entry names its run by —
+// `runPath` first, then the manifest it declares. An imagegen redraw entry
+// resolves to a version directory rather than a run directory, which is what
+// `runDirOfPath` returning null downstream distinguishes.
+const entryLayoutPath = (recordId, entry) => toRecordRelativeAssetPath(recordId, entry?.runPath)
+ || toRecordRelativeAssetPath(recordId, entry?.runManifest);
// The run directory a loaded run record implies, for a caller that has the
// record but not the directory it came from. Every candidate field is
@@ -213,34 +205,26 @@ const runDirRelOf = (run) => runDirOfPath(run?.sourceVideoPath)
|| runDirOfPath(run?.postprocessManifest)
|| runDirOfPath(run?.stripPreview?.stripPath);
-const SOURCE_CLIP_NAME = 'source-video.mp4';
-
/**
* The record-relative i2v clip a run can be re-derived from, or null when none
* is on disk.
*
- * Four candidates, in evidence order: the clip the record declares (re-anchored,
- * since an imported record declares it against the SOURCE repo root), that path
- * under the other run layout, then the conventional `<run-dir>/generated/` name
- * and ITS twin. The layout twins matter because source trees drift — a manifest
- * can name `runs/<id>/…` for a file stored under `grok/<id>/…` and both spellings
- * denote the same clip (paths.js#altRunLayoutPath); the importer resolves source
- * reads the same way, so a drifted tree that imported successfully must also be
- * re-derivable here.
+ * Two candidate names, each resolved drift-tolerantly (paths.js — the declared
+ * spelling or its run-layout twin): the clip the record declares, re-anchored
+ * since an imported record declares it against the SOURCE repo root, then the
+ * conventional `<run-dir>/generated/` name for a record that names none at all.
+ * Probed together rather than in sequence — a run whose clip is genuinely gone
+ * is re-checked on every poll, so the miss case must not cost a round trip per
+ * candidate.
*/
async function resolveRunClipRel(recordId, run, runDirRel) {
- const declared = toRecordRelativeAssetPath(recordId, run?.sourceVideoPath);
- const conventional = runDirRel ? `${runDirRel}/generated/${SOURCE_CLIP_NAME}` : null;
- const candidates = [];
- for (const rel of [declared, conventional]) {
- if (!rel) continue;
- candidates.push(rel, altRunLayoutPath(rel));
- }
- for (const rel of [...new Set(candidates.filter(Boolean))]) {
- // eslint-disable-next-line no-await-in-loop -- ordered preference: stop at the first clip that exists
- if (await pathExists(join(spriteDir(recordId), rel))) return rel;
- }
- return null;
+ const dir = spriteDir(recordId);
+ const candidates = [
+ toRecordRelativeAssetPath(recordId, run?.sourceVideoPath),
+ runDirRel ? `${runDirRel}/generated/${SOURCE_CLIP_NAME}` : null,
+ ].filter(Boolean);
+ const resolved = await Promise.all(candidates.map((rel) => resolveDriftTolerantRel(dir, rel)));
+ return resolved.find(Boolean) || null;
}
async function requireUnfinalized(recordId) {
@@ -343,7 +327,7 @@ async function normalizeMissingStrip(recordId, run) {
}
/**
- * Resolve the run's i2v source clip against DISK, so "can this direction be
+ * Fold a resolved i2v source clip onto a run, so "can this direction be
* re-derived?" is answered by evidence rather than by whether the record happens
* to name a clip (#2993).
*
@@ -359,9 +343,7 @@ async function normalizeMissingStrip(recordId, run) {
* record's own provenance, and consumers gate on the flag. In memory only; the
* hash-pinned record on disk is never rewritten here.
*/
-async function normalizeSourceClip(recordId, run) {
- const runDirRel = runDirRelOf(run);
- const clipRel = await resolveRunClipRel(recordId, run, runDirRel);
+function applySourceClip(run, clipRel, runDirRel) {
if (clipRel) return clipRel === run.sourceVideoPath ? run : { ...run, sourceVideoPath: clipRel };
if (!runDirRel && !run?.sourceVideoPath) return run;
return { ...run, sourceClipMissing: true };
@@ -470,13 +452,13 @@ async function loadRunForEntry(recordId, direction, entry) {
// for an entry that carries only a manifest. An entry that declares one layout
// for a run stored under the other still resolves (`resolveRunAt`), and the
// directory it really came from is what the record is normalized against.
- const runDirRel = runDirRelForEntry(recordId, entry);
+ const layoutPath = entryLayoutPath(recordId, entry);
+ if (!layoutPath) return null;
+ const runDirRel = runDirOfPath(layoutPath);
if (runDirRel) {
const found = await resolveRunAt(recordId, runDirRel);
return found ? normalizeRunRecord(recordId, found.run, found.runDirRel) : null;
}
- if (!toRecordRelativeAssetPath(recordId, entry.runPath)
- && !toRecordRelativeAssetPath(recordId, entry.runManifest)) return null;
return loadRedrawRun(recordId, direction, entry);
}
@@ -485,7 +467,7 @@ async function loadRunForEntry(recordId, direction, entry) {
* nothing to re-derive from — the evidence the un-finalize gate below keys on.
*/
async function directionClipRel(recordId, entry) {
- const runDirRel = runDirRelForEntry(recordId, entry);
+ const runDirRel = runDirOfPath(entryLayoutPath(recordId, entry));
if (!runDirRel) return null;
const found = await resolveRunAt(recordId, runDirRel);
return resolveRunClipRel(recordId, found?.run, found?.runDirRel || runDirRel);
@@ -626,11 +608,32 @@ export async function getWalkState(recordId) {
const allRuns = (await Promise.all(
[...entryRuns, ...scannedRuns]
.map(normalizeStaleRendering)
- .map(async (run) => normalizeSourceClip(recordId, await normalizeMissingStrip(recordId, run))),
+ // The strip and the clip are different files, so probe them CONCURRENTLY
+ // and merge — chaining would add a serialized stat per run to a read the
+ // client polls every few seconds while a run packages.
+ .map(async (run) => {
+ // Resolved from the ORIGINAL run: normalizeMissingStrip may drop a
+ // dangling stripPath, which is one of the fields the run directory is
+ // inferred from.
+ const runDirRel = runDirRelOf(run);
+ const [stripped, clip] = await Promise.all([
+ normalizeMissingStrip(recordId, run),
+ resolveRunClipRel(recordId, run, runDirRel),
+ ]);
+ return applySourceClip(stripped, clip, runDirRel);
+ }),
)).sort((a, b) => runCreatedAtMs(b.createdAt) - runCreatedAtMs(a.createdAt));
- // Stamp the imported flag so the client reads intent (`walkSet.imported`)
- // instead of re-deriving the source-pipeline path convention itself.
- const stampedWalkSet = walkSet ? { ...walkSet, imported: isImportedWalkSet(walkSet) } : null;
+ // Stamp the imported provenance so the client reads intent instead of
+ // re-deriving the source-pipeline path convention itself — and stamp the
+ // per-direction LIST alongside the boolean, because that is the precise fact:
+ // a direction leaves the list the moment it is re-derived here, so the client
+ // can gate each card (and name the blocking directions) on the same evidence
+ // the compiler will apply, not on a set-wide approximation.
+ const stampedWalkSet = walkSet ? {
+ ...walkSet,
+ imported: isImportedWalkSet(walkSet),
+ importedDirections: importedWalkDirections(walkSet),
+ } : null;
const walkTarget = resolveWalkTargetFor({
record: await recordPromise,
selection,
@@ -1099,10 +1102,11 @@ export function unlockWalkSet(recordId) {
*/
async function assertReDerivable(recordId, walkSet, directions, verb) {
if (!isImportedWalkSet(walkSet)) return;
- for (const direction of directions) {
- // eslint-disable-next-line no-await-in-loop -- stop at the first re-derivable direction
- if (await directionClipRel(recordId, walkSet.directions?.[direction])) return;
- }
+ // Bounded at eight directions, and the path that examines ALL of them is the
+ // refusal — so fan out rather than walking them serially to find nothing.
+ const clips = await Promise.all(directions
+ .map((direction) => directionClipRel(recordId, walkSet.directions?.[direction])));
+ if (clips.some(Boolean)) return;
const scope = directions.length === 1 ? `the ${directions[0]} direction has` : 'its directions have';
throw new ServerError(
`This walk set was imported from the source pipeline and ${scope} no source clip on disk — ${verb} is not supported, because there would be nothing to re-derive from. Re-import this character to bring its walk clips across, or create a new character version to revise it.`,
@@ -1243,7 +1247,7 @@ async function approveWalkDirectionImpl(recordId, { direction, runId }) {
// still legible, and name the remedy. A minimal manifest that declares no
// frames[] is unchanged — the strip sha stays the primary tamper check. (#2993)
const framePaths = (Array.isArray(packaged.frames) ? packaged.frames : [])
- .map((frame) => toRecordRelativeAssetPath(recordId, typeof frame === 'string' ? frame : frame?.path))
+ .map((frame) => toRecordRelativeAssetPath(recordId, frame?.path))
.filter(Boolean);
const framesOnDisk = await Promise.all(framePaths
.map((rel) => pathExists(join(spriteDir(recordId), rel))));