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

fix: let a Render Queue retry re-file the sprite run it was retried for

[._.]/ Adam Eivyee29c702ea3b
diff --git a/server/services/sprites/localAnimationJobHook.js b/server/services/sprites/localAnimationJobHook.js
index 70229ac57f..60287daee0 100644
--- a/server/services/sprites/localAnimationJobHook.js
+++ b/server/services/sprites/localAnimationJobHook.js
@@ -29,7 +29,7 @@
import { join } from 'path';
import { mediaJobEvents, listJobs } from '../mediaJobQueue/index.js';
-import { readJSONFile } from '../../lib/fileUtils.js';
+import { readJSONFile, atomicWrite } from '../../lib/fileUtils.js';
import { spriteDir, runRelPath, SOURCE_CLIP_NAME, RUN_RECORD_NAME } from './paths.js';
import { WALK_TRACK } from './animationTargets.js';
@@ -80,13 +80,22 @@ async function settleSpriteAnimationJob(job) {
// hypothetical, because the boot pass sweeps the archive unconditionally and
// a job outlives the run it filed by the archive's whole TTL.
//
- // Scope note: a job RETRIED from the Render Queue reuses this tag, so its
- // completion lands on a run that is already `error` and is skipped here. That
- // is deliberate — the sprite UI's own Regenerate mints a fresh run, and
- // re-filing an old one from a generic queue surface would resurrect a render
- // the user may have moved on from.
- const record = await readJSONFile(join(spriteDir(recordId), runRel, RUN_RECORD_NAME), null);
- if (record?.status !== 'rendering') return false;
+ // The ONE exception is a Render Queue retry: it re-enqueues the same params
+ // (tag included) under a NEW job id, so its completion lands on a run this
+ // hook already filed as `error`. Skipping that would waste the multi-hour
+ // render the user explicitly asked for. A different job id is exactly what
+ // separates it from the boot sweep re-seeing the job that PRODUCED the
+ // error — so the new id is stamped on the run before the attach, and a later
+ // sweep of that same job then reads as already-filed.
+ const recordPath = join(spriteDir(recordId), runRel, RUN_RECORD_NAME);
+ const record = await readJSONFile(recordPath, null);
+ const isRetryOfFiledRun = record?.status === 'error'
+ && typeof job.id === 'string' && job.id !== record.jobId;
+ if (record?.status !== 'rendering' && !isRetryOfFiledRun) return false;
+ if (isRetryOfFiledRun) {
+ console.log(`🎞️ ${label} retried as job ${job.id.slice(0, 8)} — re-filing the run`);
+ await atomicWrite(recordPath, { ...record, jobId: job.id });
+ }
// Try to stage the clip for a FAILED job too, not just a completed one. The
// queue stamps `interrupted by restart` on anything that was running when
// the process died — and the H3 child may well have written its final MP4
diff --git a/server/services/sprites/localAnimationJobHook.test.js b/server/services/sprites/localAnimationJobHook.test.js
index 357ca8733a..1300949e72 100644
--- a/server/services/sprites/localAnimationJobHook.test.js
+++ b/server/services/sprites/localAnimationJobHook.test.js
@@ -31,6 +31,7 @@ let runRecords = {};
vi.mock('../../lib/fileUtils.js', async (importOriginal) => ({
...await importOriginal(),
readJSONFile: async (path) => runRecords[path] ?? null,
+ atomicWrite: async (path, value) => { runRecords[path] = value; },
}));
const runPath = (recordId, runId) => `/sprites/${recordId}/runs/${runId}/animation-run.json`;
@@ -202,12 +203,41 @@ describe('settle guard — a run is filed exactly once', () => {
expect(attachTuiWalkResult).not.toHaveBeenCalled();
});
- it('does nothing for a run already filed as an error', async () => {
- runRecords[runPath('hero', 'walk-east-abc12345')] = { status: 'error' };
+ it('does nothing when the job that PRODUCED the error settles again', async () => {
+ // The boot sweep re-seeing its own job. Same id → already filed.
+ runRecords[runPath('hero', 'walk-east-abc12345')] = { status: 'error', jobId: 'mjob-1' };
expect(await settleSpriteAnimationJob(walkJob({ status: 'failed' }))).toBe(false);
expect(attachTuiWalkResult).not.toHaveBeenCalled();
});
+ it('DOES file a Render Queue retry, which carries the tag under a new job id', async () => {
+ // The retry route merges the original params, so the tag rides to a fresh
+ // job. Skipping it would waste the multi-hour render the user just asked for.
+ runRecords[runPath('hero', 'walk-east-abc12345')] = { status: 'error', jobId: 'mjob-1' };
+ expect(await settleSpriteAnimationJob(walkJob({ id: 'mjob-99' }))).toBe(true);
+ expect(collectLocalAnimationClip).toHaveBeenCalledWith(expect.objectContaining({ jobId: 'mjob-99' }));
+ expect(attachTuiWalkResult).toHaveBeenCalled();
+ });
+
+ it('stamps the retry job id so a later sweep of it reads as already filed', async () => {
+ runRecords[runPath('hero', 'walk-east-abc12345')] = { status: 'error', jobId: 'mjob-1' };
+ await settleSpriteAnimationJob(walkJob({ id: 'mjob-99' }));
+ expect(runRecords[runPath('hero', 'walk-east-abc12345')].jobId).toBe('mjob-99');
+ // The attach is mocked, so the run is still 'error' — only the id changed,
+ // which is exactly what must now make the sweep skip it.
+ attachTuiWalkResult.mockClear();
+ expect(await settleSpriteAnimationJob(walkJob({ id: 'mjob-99' }))).toBe(false);
+ expect(attachTuiWalkResult).not.toHaveBeenCalled();
+ });
+
+ it('does NOT re-file a CANDIDATE run just because a new job carries its tag', async () => {
+ // Only an ERRORED run is retryable; a good candidate must never be
+ // re-packaged out from under the user.
+ runRecords[runPath('hero', 'walk-east-abc12345')] = { status: 'candidate', jobId: 'mjob-1' };
+ expect(await settleSpriteAnimationJob(walkJob({ id: 'mjob-99' }))).toBe(false);
+ expect(attachTuiWalkResult).not.toHaveBeenCalled();
+ });
+
it('does nothing while an earlier settle is still postprocessing', async () => {
runRecords[runPath('hero', 'scanner-east-abc12345')] = { status: 'postprocessing' };
expect(await settleSpriteAnimationJob(trackJob())).toBe(false);