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
address review (codex): scope render tracking per-record, tighten trim/strip facets
[._.]/ Adam Eivycbc7e53ad2f5
diff --git a/client/src/components/sprites/WalkWorkflow.jsx b/client/src/components/sprites/WalkWorkflow.jsxindex 39764b303f..36afaaf875 100644--- a/client/src/components/sprites/WalkWorkflow.jsx+++ b/client/src/components/sprites/WalkWorkflow.jsx@@ -237,7 +237,12 @@ function DirectionCard({trim request from the asset collection must open even for anapproved direction or a finalized walk set. */}{trimRun && (+ // Keyed by run id: a new trim request (from an asset card) can target a+ // DIFFERENT run than the one currently open — remount so the panel's+ // enabled-frame selection and last saved result don't leak from the+ // previous run into the new one.<TrimPanel+ key={trimRun.id}recordId={recordId}run={trimRun}onClose={() => { setTrimming(false); onTrimClose(); }}diff --git a/client/src/hooks/useSpritePendingRenders.js b/client/src/hooks/useSpritePendingRenders.jsindex 9267150bb7..12f4626b0e 100644--- a/client/src/hooks/useSpritePendingRenders.js+++ b/client/src/hooks/useSpritePendingRenders.js@@ -70,6 +70,13 @@ export function useSpritePendingRenders({// state drop the entry and fire the workflow's refetch sweep(s).useEffect(() => {if (Object.keys(pendingJobs).length === 0) return undefined;+ // Torn down when the effect re-runs (any pendingJobs change) — including+ // the clear-on-record-switch. A poll's `getMediaJob` await can resolve+ // AFTER that teardown; without this flag it would delete a key from the+ // NEW record's freshly-rehydrated map (re-enabling Generate mid-render) or+ // toast a failure for a record no longer shown. Guard every post-await+ // mutation on it.+ let cancelled = false;const timer = setInterval(async () => {const entries = Object.entries(pendingJobs).filter(([, jobId]) => jobId !== 'submitting');const results = await Promise.all(entries.map(async ([key, jobId]) => {@@ -82,6 +89,7 @@ export function useSpritePendingRenders({return { key, job: null, gone: err?.status === 404 };}}));+ if (cancelled) return; // record switched (or map changed) during the await — don't touch the new mapconst finished = results.filter(({ job, gone }) => (job ? ['completed', 'failed', 'canceled'].includes(job.status) : gone));if (finished.length === 0) return;setPendingJobs((prev) => {@@ -100,7 +108,7 @@ export function useSpritePendingRenders({}}, 4000);// sweepDelays/failMessage are per-workflow config, not reactive inputs.- return () => clearInterval(timer);+ return () => { cancelled = true; clearInterval(timer); };}, [pendingJobs, onChanged]);// Sentinel jobId while the enqueue request is in flight — reserves the keydiff --git a/client/src/hooks/useSpritePendingRenders.test.jsx b/client/src/hooks/useSpritePendingRenders.test.jsxnew file mode 100644index 0000000000..202e538a74--- /dev/null+++ b/client/src/hooks/useSpritePendingRenders.test.jsx@@ -0,0 +1,66 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import { renderHook, act, waitFor } from '@testing-library/react';++// Regression coverage for the record-scoping the hook gained when it was+// lifted to the Sprites page (#2931). Before the lift the hook lived inside a+// per-record workflow and was destroyed on a record switch; now one instance+// serves every record, so it MUST drop the previous record's in-flight map on+// switch — otherwise character B inherits character A's "Rendering…" entries.++const listMediaJobs = vi.fn();+const getMediaJob = vi.fn();+vi.mock('../services/apiMediaJobs.js', () => ({+ listMediaJobs: (...args) => listMediaJobs(...args),+ getMediaJob: (...args) => getMediaJob(...args),+}));+vi.mock('../components/ui/Toast', () => ({ default: { error: vi.fn(), success: vi.fn() } }));++import { useSpritePendingRenders } from './useSpritePendingRenders.js';++const opts = (recordId) => ({+ recordId, kind: 'video', tagKey: 'spriteWalk', tagField: 'direction', onChanged: vi.fn(),+});++beforeEach(() => {+ listMediaJobs.mockReset().mockResolvedValue([]);+ getMediaJob.mockReset();+});++describe('useSpritePendingRenders record scoping', () => {+ it('reserves a key immediately and reports it as pending', () => {+ const { result } = renderHook(() => useSpritePendingRenders(opts('char-a')));+ act(() => result.current.beginSubmit('east'));+ expect(result.current.pendingJobs.east).toBe('submitting');+ });++ it('clears the in-flight map when the record switches', async () => {+ const { result, rerender } = renderHook(+ ({ id }) => useSpritePendingRenders(opts(id)),+ { initialProps: { id: 'char-a' } },+ );+ act(() => { result.current.beginSubmit('east'); result.current.resolveSubmit('east', 'job-1'); });+ expect(result.current.pendingJobs.east).toBe('job-1');++ // Switching to character B must not carry A's "east is rendering" entry.+ rerender({ id: 'char-b' });+ await waitFor(() => expect(result.current.pendingJobs.east).toBeUndefined());+ expect(result.current.pendingJobs).toEqual({});+ });++ it('exposes stable setter identities so consumers can memoize on them', () => {+ const { result, rerender } = renderHook(() => useSpritePendingRenders(opts('char-a')));+ const first = result.current;+ act(() => rerender());+ expect(result.current.beginSubmit).toBe(first.beginSubmit);+ expect(result.current.resolveSubmit).toBe(first.resolveSubmit);+ expect(result.current.cancelSubmit).toBe(first.cancelSubmit);+ });++ it('cancelSubmit only clears its own in-flight sentinel', () => {+ const { result } = renderHook(() => useSpritePendingRenders(opts('char-a')));+ act(() => { result.current.beginSubmit('east'); result.current.resolveSubmit('west', 'job-9'); });+ act(() => result.current.cancelSubmit('east'));+ expect(result.current.pendingJobs.east).toBeUndefined();+ expect(result.current.pendingJobs.west).toBe('job-9'); // a resolved sibling job is untouched+ });+});diff --git a/client/src/lib/spriteCollectionActions.js b/client/src/lib/spriteCollectionActions.jsindex f73d6abc23..178d3fcce5 100644--- a/client/src/lib/spriteCollectionActions.js+++ b/client/src/lib/spriteCollectionActions.js@@ -46,11 +46,15 @@ export function buildCollectionActions({anchors.filter((a) => a.status === 'locked').map((a) => a.direction),);const knownDirections = new Set(anchors.map((a) => a.direction));- // Only a run whose postprocess actually packed a strip can be trimmed — the- // trim endpoint 409s (`RUN_NOT_CANDIDATE`) on anything else, so offering the- // button would be a guaranteed error toast.+ // Only a run whose postprocess packed a strip UNDER `grok/` can be trimmed:+ // the trim endpoint reads `grok/<runId>/animation-run.json` hard-coded, so a+ // strip from an imported `runs/<id>/` layout would 404 (`RUN_NOT_FOUND`).+ // Gate on the strip path's prefix, not just its presence, so the button is+ // never offered for a run the server can't trim.const trimmableRunIds = new Set(- (walk?.runs || []).filter((r) => r?.stripPreview?.stripPath).map((r) => r.id),+ (walk?.runs || [])+ .filter((r) => r?.stripPreview?.stripPath?.startsWith('grok/'))+ .map((r) => r.id),);const regenerateFor = (asset) => {diff --git a/client/src/lib/spriteFacets.js b/client/src/lib/spriteFacets.jsindex e54fd834fb..59f3554f99 100644--- a/client/src/lib/spriteFacets.js+++ b/client/src/lib/spriteFacets.js@@ -64,6 +64,12 @@ const TRIM_DIRECTION_MATCH = new RegExp(`^walk/trims/(${DIRECTION_ALTERNATION})-const RUN_DIR_MATCH = /^(?:grok|runs)\/([^/]+)\//;const MANIFEST_EXT = /\.(json|ya?ml|txt|md|csv)$/i;const ANIMATION_EXT = /\.(gif|mp4|webm|mov|m4v)$/i;+// A packed walk strip's filename. Native runs write `<id>-walk-<dir>-strip.png`,+// but imported layouts name theirs `strip.png` or `strip-video-12-clean-alpha.png`+// — so match a `strip` token at a word boundary, not just the `-strip` infix+// (which would drop every imported strip into the generic sprite bucket and+// strip it of its Regenerate/Trim actions). `stripe.png` stays excluded.+const STRIP_FILE = /(^|[-_])strips?([-_.]|$)/i;// `runtime/vN/` — the published-atlas version lives in the directory, not the// filename, so supersede detection has to read it from there.const RUNTIME_VERSION_DIR = /^runtime\/v(\d+)\//;@@ -83,7 +89,7 @@ function roleFor(path) {if (ANIMATION_EXT.test(path)) return 'animation';if (path.includes('/review/') || fileOf(path).includes('contrast-review')) return 'evidence';if (path.includes('/generated/frames/')) return 'frame';- if (fileOf(path).includes('-strip')) return 'strip';+ if (STRIP_FILE.test(fileOf(path))) return 'strip';if (path.startsWith('runtime/') || path.startsWith('atlas/')) return 'atlas';if (path.startsWith('reference/')) return 'reference';return 'sprite';@@ -98,7 +104,11 @@ function statusFor(path) {if (path.startsWith('reference/candidates/')) return 'candidate';if (path.startsWith('reference/uploads/')) return 'source';if (path.startsWith('reference/')) return 'approved';- // A saved trim is a deliberate, named output — not a raw run intermediate.+ // A saved trim is a derived DRAFT loop, not a finalized artifact — its own+ // producer manifest carries `status: candidate` — so it must not badge as+ // approved (that would read as reviewed/locked when it isn't).+ if (path.startsWith('walk/trims/')) return 'candidate';+ // Other imported `walk/` production assets are approved outputs.if (path.startsWith('walk/')) return 'approved';if (RUN_DIR_MATCH.test(path)) return 'candidate';return 'source';diff --git a/client/src/lib/spriteFacets.test.js b/client/src/lib/spriteFacets.test.jsindex 963a459166..46610fc2e6 100644--- a/client/src/lib/spriteFacets.test.js+++ b/client/src/lib/spriteFacets.test.js@@ -39,6 +39,16 @@ describe('classifySpriteAsset — role', () => {expect(facets('walk/trims/east-loop-v001-strip.png').role).toBe('strip');expect(facets('walk/trims/east-loop-v001.gif').role).toBe('animation');});++ it('classifies imported strips whose filename is not the native `-strip` infix', () => {+ // Imported layouts name strips `strip.png` or `strip-video-…` — the native+ // `-strip` infix test dropped these into the generic sprite bucket, losing+ // their Strips group + inline actions.+ expect(facets('runs/imported-7/generated/strip.png').role).toBe('strip');+ expect(facets('imagegen/v19/strip-video-12-clean-alpha.png').role).toBe('strip');+ // A word that merely contains "strip" as a substring must not match.+ expect(facets('reference/pinstripe-swatch.png').role).not.toBe('strip');+ });});describe('classifySpriteAsset — status', () => {@@ -48,7 +58,8 @@ describe('classifySpriteAsset — status', () => {expect(facets('reference/candidates/walk-east-candidate-1.png').status).toBe('candidate');expect(facets('reference/uploads/design.png').status).toBe('source');expect(facets('grok/walk-east-abc12345/generated/example-walk-east-strip.png').status).toBe('candidate');- expect(facets('walk/trims/east-loop-v001-strip.png').status).toBe('approved');+ // A saved trim is a draft loop, not an approved artifact.+ expect(facets('walk/trims/east-loop-v001-strip.png').status).toBe('candidate');});it('honors an imported rejected/ segment', () => {@@ -106,12 +117,14 @@ describe('classifySpriteAssets — supersede', () => {expect(rows.every((r) => r.facets.status === 'approved')).toBe(true);});- it('matches a trim strip to its own stem across the -strip suffix', () => {+ it('leaves trim versions as candidates — supersede only demotes approved artifacts', () => {+ // Trims are draft loops (status candidate), so the approved-only supersede+ // pass never reclassifies them; both versions stay candidate.const rows = classifySpriteAssets([{ path: 'walk/trims/east-loop-v001-strip.png' },{ path: 'walk/trims/east-loop-v002-strip.png' },]);- expect(rows.map((r) => r.facets.status)).toEqual(['superseded', 'approved']);+ expect(rows.map((r) => r.facets.status)).toEqual(['candidate', 'candidate']);});it('leaves runtime atlases alone — the publish pointer decides which is live', () => {diff --git a/client/src/pages/Sprites.jsx b/client/src/pages/Sprites.jsxindex 8431c97bf4..7950a6fdfe 100644--- a/client/src/pages/Sprites.jsx+++ b/client/src/pages/Sprites.jsx@@ -1,4 +1,4 @@-import { useEffect, useState, useCallback, useMemo } from 'react';+import { useEffect, useState, useCallback, useMemo, useRef } from 'react';import { useParams, useNavigate } from 'react-router-dom';import { PersonStanding, Package, Download, X, RefreshCw, Plus } from 'lucide-react';import toast from '../components/ui/Toast';@@ -314,13 +314,22 @@ export default function Sprites() {// closures below from rebuilding every render.const { beginSubmit: walkBegin, resolveSubmit: walkResolve, cancelSubmit: walkCancel } = walkRenders;const { beginSubmit: refBegin, resolveSubmit: refResolve, cancelSubmit: refCancel } = referenceRenders;+ // Since the render-tracking hook is now page-owned and survives a record+ // switch (it clears its map on switch), a submit started for record A that+ // resolves AFTER navigating to B would otherwise land A's jobId in B's map+ // (a spurious "Rendering…" on a direction B isn't rendering). Capture the+ // record the submit belongs to and skip resolve/cancel if we've moved on —+ // the switch already wiped A's sentinel, so there's nothing to clean up.+ const idRef = useRef(id);+ useEffect(() => { idRef.current = id; }, [id]);const submitRender = useCallback(async (begin, resolve, cancel, key, call, failMessage) => {+ const startId = idRef.current;begin(key);try {const { jobId } = await call();- resolve(key, jobId);+ if (idRef.current === startId) resolve(key, jobId);} catch (err) {- cancel(key);+ if (idRef.current === startId) cancel(key);toast.error(err?.message || failMessage);}}, []);