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
fix([issue-2993]): refuse a partial unlock that would strand a clipless imported direction
[._.]/ Adam Eivy4561c3517279
diff --git a/client/src/components/sprites/WalkWorkflow.jsx b/client/src/components/sprites/WalkWorkflow.jsxindex a1a0c5bf9a..ce9d790c59 100644--- a/client/src/components/sprites/WalkWorkflow.jsx+++ b/client/src/components/sprites/WalkWorkflow.jsx@@ -416,11 +416,17 @@ function DirectionCard({// Approval is where a direction's geometry gets frozen into the// set the atlas compiles, so a drifted candidate can't be approved// — the server refuses it, and offering the button anyway would- // just hand back a 409 after the click.+ // just hand back a 409 after the click. Same for a run still+ // packaged by the source pipeline: its per-frame images were never+ // imported, so approving it 409s RUN_FRAMES_MISSING however well its+ // geometry happens to match. Reprocessing from the clip is the way+ // through, and it clears the flag.<buttononClick={() => setConfirming(true)}- disabled={Boolean(drift)}- title={drift ? `Re-derive this direction to ${cycleLabel} before approving it` : undefined}+ disabled={Boolean(drift) || Boolean(run?.importedPackaging)}+ title={run?.importedPackaging+ ? 'This run was packaged by the source pipeline, which kept its frames — reprocess it from its clip first'+ : drift ? `Re-derive this direction to ${cycleLabel} before approving it` : undefined}className="w-full px-2 py-0.5 text-xs bg-port-success/20 border border-port-success rounded text-port-success disabled:opacity-50">Approve@@ -514,13 +520,19 @@ export default function WalkWorkflow({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. The server's own gate- // is authoritative (its 409 is the backstop); this only decides what to offer.- const unlockBlocked = importedWalkSet && !runs.some(hasClip);+ // Since #2984 imports each run's clip, such a set is no longer a dead end —+ // but unlock drops EVERY approval, so the server refuses it unless EVERY+ // still-imported direction has a clip (a stranded one could be neither+ // reprocessed nor re-approved). Mirror that scope exactly, per direction, so+ // the button and the 409 are computed from the same facts; the server's gate is+ // still authoritative, this only decides what to offer.+ const clipByDirection = useMemo(() => {+ const out = {};+ for (const run of runs) if (hasClip(run)) out[run.direction] = true;+ return out;+ }, [runs]);+ const unlockBlocked = importedWalkSet+ && !(importedDirections?.length && importedDirections.every((d) => clipByDirection[d]));// 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@@ -650,7 +662,7 @@ export default function WalkWorkflow({<Lock className="w-3 h-3" /> walk set frozen · immutable</p>{unlockBlocked ? (- <span className="text-[10px] text-gray-500" title="Imported from the source pipeline with no source clips on disk — re-import the character to bring them across">+ <span className="text-[10px] text-gray-500" title="Unlocking re-opens every direction, and at least one imported direction has no source clip on disk to re-derive from — re-import the character to bring its clips across, or reopen the directions that do have clips one at a time">imported · no clips to re-derive</span>) : unlockConfirm ? (diff --git a/client/src/components/sprites/WalkWorkflow.test.jsx b/client/src/components/sprites/WalkWorkflow.test.jsxindex 10bcb58402..e7d314ebc9 100644--- a/client/src/components/sprites/WalkWorkflow.test.jsx+++ b/client/src/components/sprites/WalkWorkflow.test.jsx@@ -509,7 +509,7 @@ describe('WalkWorkflow reprocess + reopen', () => {},}],selection: { directions: { east: { status: 'approved', runId: 'run-east' } } },- walkSet: { imported: true, directions: { east: { status: 'approved' } } },+ walkSet: { imported: true, importedDirections: ['east'], directions: { east: { status: 'approved' } } },walkTarget: {frameCount: 12, fps: 10, source: 'derived', sourceLabel: 'from the first approved direction', drift: [],},@@ -527,6 +527,48 @@ describe('WalkWorkflow reprocess + reopen', () => {expect(screen.queryByText(/no clips to re-derive/)).toBeNull();});+ // Unlock re-opens every direction, so the server refuses it unless EVERY+ // still-imported direction has a clip — a stranded one could be neither+ // reprocessed nor re-approved. The header must mirror that scope rather than+ // "any run anywhere has a clip", or it offers a guaranteed 409.+ it('hides Unlock when one imported direction has no clip, while Reopen stays on the one that does', async () => {+ render(+ <MemoryRouter>+ <WalkWorkflow+ record={{ id: 'example-walker' }}+ reference={{ manifest: { mainReference: { locked: true }, anchors: [{ direction: 'east', status: 'locked' }] } }}+ walk={{+ runs: [{+ id: 'run-east',+ direction: 'east',+ status: 'approved',+ sourceVideoPath: 'grok/run-east/generated/source-video.mp4',+ stripPreview: {+ stripPath: 'grok/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: ['east', '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.queryByRole('button', { name: /^Unlock$/ })).toBeNull();+ expect(screen.getByRole('button', { name: /^Reopen$/ })).toBeTruthy();+ });+// 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.diff --git a/server/services/sprites/atlas.js b/server/services/sprites/atlas.jsindex e9e5aba0f7..d9c1d2c93f 100644--- a/server/services/sprites/atlas.js+++ b/server/services/sprites/atlas.js@@ -34,6 +34,7 @@ import {import { ServerError } from '../../lib/errorHandler.js';import {spriteDir, resolveSpriteAssetPath, RUNTIME_POINTER_REL, RUNTIME_PUBLICATIONS_REL,+ isSourcePipelinePath,} from './paths.js';import { requireCharacter, loadManifest } from './reference.js';import { SPRITE_DIRECTIONS } from './prompts.js';@@ -47,7 +48,7 @@ import {} from './walkPostprocess.js';import { ATLAS_IDLE_COLUMN } from './walkBounds.js';import {- withWalkWriteTail, walkSetRelPath, isImportedWalkSet, importedWalkDirections,+ withWalkWriteTail, walkSetRelPath, importedWalkDirections,} from './walk.js';// Player atlas contract (source pipeline runtime_publish.py): 96px cells,@@ -218,12 +219,16 @@ 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.+ // `isImportedWalkSet` expanded so the direction list is built once. The+ // selectionPath disjunct is the set-level marker on its own — a set that is+ // imported but lists no source-packaged direction.const stale = importedWalkDirections(walkSet);- if (stale.length || isImportedWalkSet(walkSet)) {+ if (stale.length || isSourcePipelinePath(walkSet.selectionPath)) {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. `+ 'Reopen each such direction and reprocess it from its imported clip to re-derive the frames here, then compile. '+ + 'A direction with no imported clip cannot be re-derived at all — re-import the character to bring its clips across. '+ 'The imported runtime atlases remain available in the asset library.',{ status: 409, code: 'LEGACY_IMPORTED_WALK_SET' },);diff --git a/server/services/sprites/walk.js b/server/services/sprites/walk.jsindex 9f5e1cfdce..0844ae24cb 100644--- a/server/services/sprites/walk.js+++ b/server/services/sprites/walk.js@@ -219,10 +219,12 @@ const runDirRelOf = (run) => runDirOfPath(run?.sourceVideoPath)*/async function resolveRunClipRel(recordId, run, runDirRel) {const dir = spriteDir(recordId);- const candidates = [+ // Deduped: a native run's declared clip IS the conventional path, and probing+ // it twice would double the stats on the healthy majority.+ const candidates = [...new Set([toRecordRelativeAssetPath(recordId, run?.sourceVideoPath),runDirRel ? `${runDirRel}/generated/${SOURCE_CLIP_NAME}` : null,- ].filter(Boolean);+ ].filter(Boolean))];const resolved = await Promise.all(candidates.map((rel) => resolveDriftTolerantRel(dir, rel)));return resolved.find(Boolean) || null;}@@ -295,7 +297,14 @@ function normalizeRunAssetPaths(recordId, run) {const rel = out[field] && toRecordRelativeAssetPath(recordId, out[field]);if (rel && rel !== out[field]) out = { ...out, [field]: rel };}- return out;+ // A run whose packaged manifest is STILL named against the source repo was+ // packaged there, which means its per-frame images were never imported (the+ // importer skips frames/). Stamped here because this is where that fact is+ // still visible — one line up it has been re-anchored away — and it costs no+ // I/O, unlike stat-ing every frame on a read the client polls. The client gates+ // Approve on it: approving such a run 409s RUN_FRAMES_MISSING, and the flag+ // clears by itself the moment a reprocess rewrites the manifest record-relative.+ return isSourcePipelinePath(run.postprocessManifest) ? { ...out, importedPackaging: true } : out;}// A candidate/approved run's stripPreview names a packed strip PNG on disk. If@@ -318,10 +327,19 @@ function normalizeRunAssetPaths(recordId, run) {// red error with the green "approved" badge. Keeping the status lets the client// route recovery correctly off `stripMissing` + the direction's approved/finalized// state (regenerate an unapproved candidate; unlock the set for a finalized one).+//+// Resolved drift-tolerantly, like the source clip below: an imported manifest can+// name the strip under one run layout for a file stored under the other, and both+// spellings denote the same PNG (paths.js#resolveDriftTolerantRel). Healing that+// here — rather than only for the clip — is what keeps a drifted import from+// badging "strip missing" over an intact strip, losing its loop preview, its trim+// link, and its contribution to the set's packaged geometry.async function normalizeMissingStrip(recordId, run) {const stripPath = run?.stripPreview?.stripPath;if (!stripPath) return run;- if (await pathExists(join(spriteDir(recordId), stripPath))) return run;+ const found = await resolveDriftTolerantRel(spriteDir(recordId), stripPath);+ if (found === stripPath) return run;+ if (found) return { ...run, stripPreview: { ...run.stripPreview, stripPath: found } };const { stripPath: _dropped, ...stripPreviewRest } = run.stripPreview;return { ...run, stripMissing: true, stripPreview: stripPreviewRest };}@@ -979,8 +997,12 @@ async function packageRun(recordId, run, overrides = {}, location = {}) {// imported run that means persisting the record-relative form in place of the// source-repo anchor its manifest was copied with.run.sourceVideoPath = location.clipRel || `${runRel}/generated/${SOURCE_CLIP_NAME}`;- const videoAbs = resolveSpriteAssetPath(recordId, run.sourceVideoPath);try {+ // Inside the try on purpose: unlike the old `join(runAbs, …)` this can throw+ // (the confinement gate), and this function's contract is that a packaging+ // failure is CAPTURED onto the run record — a throw escaping here would+ // strand an attach at 'postprocessing' with no error text.+ const videoAbs = resolveSpriteAssetPath(recordId, run.sourceVideoPath);const manifest = await loadManifest(recordId);const anchor = manifest?.anchors?.find((a) => a.direction === run.direction);if (!anchor?.path) throw new Error(`No locked ${run.direction} anchor in the reference manifest`);@@ -1084,36 +1106,68 @@ export function unlockWalkSet(recordId) {}/**- * Refuse un-finalizing an imported walk set that has no clip to re-derive from.+ * The directions among `scope` that have no clip on disk to re-derive from.+ * Bounded at eight, so fan out rather than walking them serially — the path that+ * examines every direction is the refusal path.+ */+async function directionsWithoutClip(recordId, walkSet, scope) {+ const clips = await Promise.all(scope+ .map((direction) => directionClipRel(recordId, walkSet.directions?.[direction])));+ return scope.filter((_, i) => !clips[i]);+}++const notReDerivable = (detail) => new ServerError(+ `${detail} Re-import this character to bring its walk clips across, or create a new character version to revise it.`,+ { status: 409, code: 'LEGACY_IMPORTED_WALK_SET' },+);++/**+ * Refuse un-finalizing an imported walk set that has nothing to re-derive from.** The original guard refused EVERY imported set, on the stated grounds that it* "has no regenerable clips behind it" — true when it was written, and false* since #2984 taught the importer to copy each run's `source-video.mp4`. So the* gate now keys on the evidence the justification always named: is a clip- * actually on disk for the directions being re-opened? (#2993)+ * actually on disk? (#2993)** Provenance still selects WHO gets examined, and only that: a native set is* never gated, exactly as before — a user who cleaned up their own rendered- * clips must not suddenly find Unlock refused. Among imported sets, `directions`- * is the scope — one direction for `reopen`, all of them for `unlock` — and one- * clip anywhere in scope is enough, because that is one direction the user can- * genuinely bring onto a new target. A set with none is still a dead end, and- * still says so.+ * clips must not suddenly find Unlock refused.+ *+ * The scope is what separates the two callers, and it is not cosmetic. `reopen`+ * un-approves ONE direction, so one direction's clip is the whole question.+ * `unlock` drops EVERY approval and the frozen set with them — and a+ * source-packaged direction with no clip can be neither reprocessed (nothing to+ * re-derive from) nor re-approved (its frames were never imported, so+ * RUN_FRAMES_MISSING), which would strand that direction permanently with no way+ * back short of re-importing. So unlock requires that every still-imported+ * direction be re-derivable, and names the ones that aren't — pointing at the+ * per-direction reopen, which is safe precisely because it leaves the rest frozen.*/-async function assertReDerivable(recordId, walkSet, directions, verb) {+async function assertSetReDerivable(recordId, walkSet) {if (!isImportedWalkSet(walkSet)) 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.`,- { status: 409, code: 'LEGACY_IMPORTED_WALK_SET' },+ const stale = importedWalkDirections(walkSet);+ // Marked imported at the SET level with no source-packaged direction to+ // examine (an empty or already-re-anchored `directions` map behind a copied+ // selectionPath): no evidence either way, so keep the blanket refusal.+ if (!stale.length) {+ throw notReDerivable('This walk set was imported from the source pipeline and carries no directions that can be re-derived here — unlocking is not supported.');+ }+ const stranded = await directionsWithoutClip(recordId, walkSet, stale);+ if (!stranded.length) return;+ throw notReDerivable(+ `Unlocking re-opens every direction, and ${stranded.join(', ')} would be left with no source clip to re-derive from and no packaged frames to re-approve — so ${stranded.length === 1 ? 'it' : 'they'} could not be brought back. Reopen the directions that do have clips one at a time instead.`,);}+/** Reopen's per-direction twin of the gate above. */+async function assertDirectionReDerivable(recordId, walkSet, direction) {+ if (!isImportedWalkSet(walkSet)) return;+ const stranded = await directionsWithoutClip(recordId, walkSet, [direction]);+ if (!stranded.length) return;+ throw notReDerivable(`This walk set was imported from the source pipeline and the ${direction} direction has no source clip on disk — reopening is not supported, because there would be nothing to re-derive from.`);+}+// Un-finalize: drop the canonical "finalized" signal (the walk-set file) FIRST,// then downgrade the record status — the exact inverse of finalize's order, so a// crash mid-unfinalize can only leave a cosmetic stale status, never a@@ -1130,7 +1184,7 @@ async function unlockWalkSetImpl(recordId) {if (!walkSet) {throw new ServerError('No finalized walk set to unlock', { status: 409, code: 'WALK_SET_NOT_FINAL' });}- await assertReDerivable(recordId, walkSet, Object.keys(walkSet.directions || {}), 'unlocking');+ await assertSetReDerivable(recordId, walkSet);await dropFinalizedWalkSet(recordId);// Seed a fresh (empty) selection so EVERY direction re-opens: with the walk// set gone each direction would still read `approved` from the old selection@@ -1170,7 +1224,7 @@ export function reopenWalkDirection(recordId, { direction }) {async function reopenWalkDirectionImpl(recordId, direction) {await requireCharacter(recordId);const walkSet = await loadWalkSet(recordId);- await assertReDerivable(recordId, walkSet, [direction], 'reopening');+ await assertDirectionReDerivable(recordId, walkSet, direction);const selection = (await loadSelection(recordId)) || seedSelection(recordId);if (selection.directions?.[direction]?.status !== 'approved') {throw new ServerError(`Direction ${direction} is not approved`, { status: 409, code: 'DIRECTION_NOT_APPROVED' });diff --git a/server/services/sprites/walk.test.js b/server/services/sprites/walk.test.jsindex 213c68dbb3..462717a7f1 100644--- a/server/services/sprites/walk.test.js+++ b/server/services/sprites/walk.test.js@@ -906,10 +906,27 @@ describe('imported walk sets — evidence-based re-derive', () => {await expect(unlockWalkSet(id)).rejects.toMatchObject({status: 409,code: 'LEGACY_IMPORTED_WALK_SET',- message: expect.stringContaining('no source clip on disk'),+ message: expect.stringContaining('east'),});});+ // Unlock drops EVERY approval, and a source-packaged direction with no clip can+ // be neither reprocessed nor re-approved (its frames were never imported) — so a+ // partial unlock would strand it permanently. The whole-set action refuses; the+ // per-direction one, which leaves the rest frozen, still works.+ it('refuses to unlock a mixed set, naming the direction that would be stranded', async () => {+ const id = await characterWithLockedAnchors(newId(), ['east']);+ await importedCharacter(id, { east: {}, north: { clip: false } });++ await expect(unlockWalkSet(id)).rejects.toMatchObject({+ status: 409,+ code: 'LEGACY_IMPORTED_WALK_SET',+ message: expect.stringContaining('north would be left with no source clip'),+ });+ // …and the frozen set is untouched by the refusal.+ expect((await getWalkState(id)).walkSet).not.toBeNull();+ });+it('reopens the imported direction that has a clip and refuses the one that does not', async () => {const id = await characterWithLockedAnchors(newId(), ['east']);await importedCharacter(id, { east: {}, north: { clip: false } });@@ -961,9 +978,27 @@ describe('imported walk sets — evidence-based re-derive', () => {const { runs } = await getWalkState(id);expect(runs[0].sourceVideoPath).toBe(`grok/${runIds.east}/generated/source-video.mp4`);expect(runs[0].sourceClipMissing).toBeUndefined();+ // Drift healing is one fact about imported trees, not one fact about clips:+ // the strip is declared under the other layout too, and must resolve rather+ // than badge "strip missing" over a PNG that is present and intact.+ expect(runs[0].stripPreview.stripPath).toBe(`grok/${runIds.east}/generated/east-strip.png`);+ expect(runs[0].stripMissing).toBeUndefined();await expect(reopenWalkDirection(id, { direction: 'east' })).resolves.toBeTruthy();});+ // Zero-I/O provenance: a run whose packaged manifest is still named against the+ // source repo was packaged there, so its frames were never imported. The client+ // gates Approve on this rather than offering a button that always 409s.+ it('flags a run whose packaging is still the source pipeline\'s, and clears it on re-derive', async () => {+ const id = await characterWithLockedAnchors(newId(), ['east']);+ const runIds = await importedCharacter(id, { east: {} });+ expect((await getWalkState(id)).runs[0].importedPackaging).toBe(true);++ await unlockWalkSet(id);+ await rerunWalkPostprocess(id, { runId: runIds.east });+ expect((await getWalkState(id)).runs[0].importedPackaging).toBeUndefined();+ });+// "Declares a clip" and "has a clip" must not read the same: the flag is what// lets the client offer reopen/reprocess only where they can actually work.// The linkage to the atlas: re-deriving a direction and re-approving it