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: recover a sprite run stranded mid-packaging, and a clip a restart interrupted

[._.]/ Adam Eivy7314e3d11ea8
diff --git a/server/services/sprites/localAnimationJobHook.js b/server/services/sprites/localAnimationJobHook.js
index 5eb9c71b76..70229ac57f 100644
--- a/server/services/sprites/localAnimationJobHook.js
+++ b/server/services/sprites/localAnimationJobHook.js
@@ -55,10 +55,10 @@ const decodeSpriteAnimationJob = (job) => {
*
* The attach is the single place a run leaves `rendering`, on either outcome:
* it packages the clip into a candidate when the MP4 is there, and writes a
- * terminal error naming the Render Queue when it is not. So this deliberately
- * does NOT branch on the job's status beyond deciding whether staging is worth
- * attempting — a failed, canceled, and clip-less-but-completed job all converge
- * on the same honest error.
+ * terminal error naming the Render Queue when it is not. So the outcome is
+ * decided by WHAT IS ON DISK, not by the job's status — which is what lets a
+ * render interrupted after it wrote its MP4 still be recovered, and makes a
+ * genuinely failed or clip-less job converge on the same honest error.
*
* Both the staging and the attach run INSIDE the per-record write tail: the
* clip lands at the same path a user-triggered Reprocess reads, and a copy racing
@@ -79,12 +79,26 @@ async function settleSpriteAnimationJob(job) {
// with TODAY's anchor for a clip rendered from a previous one. That is not
// 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;
- if (job.status === 'completed') {
- await collectLocalAnimationClip({ jobId: job.id, videoAbs, label });
+ // 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
+ // before that happened, since the job only flips to `completed` once the
+ // queue persists the runner's event. Skipping collection there would file an
+ // error over a render that exists and orphan the clip under data/videos.
+ // `canceled` is excluded on purpose: a user who stopped a render must not
+ // get a candidate out of it, even if the file happened to land.
+ if (job.status === 'canceled') {
+ console.log(`🎞️ ${label} local render canceled — filing the run as errored`);
} else {
- console.log(`🎞️ ${label} local render ${job.status} — filing the run as errored`);
+ await collectLocalAnimationClip({ jobId: job.id, videoAbs, label });
}
await (track === WALK_TRACK
? attachTuiWalkResult(recordId, runId, videoAbs)
diff --git a/server/services/sprites/localAnimationJobHook.test.js b/server/services/sprites/localAnimationJobHook.test.js
index 991a6b45f0..357ca8733a 100644
--- a/server/services/sprites/localAnimationJobHook.test.js
+++ b/server/services/sprites/localAnimationJobHook.test.js
@@ -150,11 +150,28 @@ describe('settleSpriteAnimationJob', () => {
// a failed job strands the run at 'rendering' — permanently on the track
// lane, whose in-flight guard then 409s every retry.
await settleSpriteAnimationJob(walkJob({ status: 'failed' }));
+ expect(attachTuiWalkResult).toHaveBeenCalled();
+ });
+
+ it('STILL TRIES to stage a clip for a failed job, recovering a restart-interrupted render', async () => {
+ // The queue stamps 'interrupted by restart' on whatever was running when the
+ // process died, and the H3 child may already have written its final MP4 —
+ // the job only flips to 'completed' once the queue persists that event.
+ // Refusing to look would file an error over a render that exists and orphan
+ // the clip under data/videos.
+ await settleSpriteAnimationJob(walkJob({ status: 'failed' }));
+ expect(collectLocalAnimationClip).toHaveBeenCalledWith(expect.objectContaining({ jobId: 'mjob-1' }));
+ });
+
+ it('does NOT stage a clip for a CANCELED job', async () => {
+ // A user who stopped a render must not get a candidate out of it, even if
+ // the file happened to land.
+ await settleSpriteAnimationJob(walkJob({ status: 'canceled' }));
expect(collectLocalAnimationClip).not.toHaveBeenCalled();
expect(attachTuiWalkResult).toHaveBeenCalled();
});
- it('still runs the attach on a CANCELED job', async () => {
+ it('still runs the attach on a CANCELED track job', async () => {
await settleSpriteAnimationJob(trackJob({ status: 'canceled' }));
expect(attachTrackTuiResult).toHaveBeenCalled();
});
diff --git a/server/services/sprites/localAnimationRender.js b/server/services/sprites/localAnimationRender.js
index 14692bcffd..80490771dc 100644
--- a/server/services/sprites/localAnimationRender.js
+++ b/server/services/sprites/localAnimationRender.js
@@ -374,7 +374,9 @@ export async function collectLocalAnimationClip({ jobId, videoAbs, label }) {
// generateVideo names its output after the job id (`filename = ${jobId}.mp4`).
const renderedAbs = join(PATHS.videos, `${jobId}.mp4`);
if (!await pathExists(renderedAbs)) {
- console.error(`❌ ${label} local render reported complete with no MP4 at ${renderedAbs}`);
+ // Expected for a genuinely failed render, and the reason the caller files
+ // the run as errored — so this is informational, not an error line.
+ console.log(`🎞️ ${label} has no local clip at ${renderedAbs}`);
return false;
}
try {
@@ -428,6 +430,12 @@ const GROK_RENDER_STALE_MS = GROK_TUI_TIMEOUT_MS + 60_000;
// than grok's half hour: a local H3 clip is a multi-HOUR render on current
// Apple Silicon, and the completion hook wins this race in every normal case.
const LOCAL_RENDER_STALE_MS = 24 * 60 * 60_000;
+// How long a run of EITHER lane may sit at `postprocessing`. Unlike a render,
+// packaging is bounded local CPU work measured in minutes, so grok's window is
+// already generous and the lane makes no difference to it. Measured from
+// `createdAt` like the others — packaging follows the render, so this is only
+// ever reached well after a real render would have finished.
+const PACKAGING_STALE_MS = GROK_RENDER_STALE_MS;
/**
* Read-time normalization of a run stuck at `rendering`, shared by both lanes
@@ -458,6 +466,18 @@ const LOCAL_RENDER_STALE_MS = 24 * 60 * 60_000;
* server was down for longer than its TTL, or an attach that threw.
*/
export const normalizeStaleAnimationRun = (run, errorMessage) => {
+ // `postprocessing` needs the same treatment as `rendering`, and a TIGHTER
+ // window: it is bounded LOCAL work (decode the clip, align, despill, pack), so
+ // a run still in it long afterwards means the process doing that work died.
+ // Both in-flight guards count `postprocessing` as busy, so without this a run
+ // interrupted mid-package makes its facing permanently unrenderable — the same
+ // dead end `rendering` had, one state further along. Both lanes, because the
+ // packaging is identical on both.
+ if (run?.status === 'postprocessing') {
+ return Date.now() - runCreatedAtMs(run.createdAt) <= PACKAGING_STALE_MS
+ ? run
+ : { ...run, status: 'error', postprocessError: errorMessage };
+ }
if (run?.status !== 'rendering') return run;
const local = isLocalProviderRun(run);
if (local) {
diff --git a/server/services/sprites/localAnimationRender.test.js b/server/services/sprites/localAnimationRender.test.js
index 2560a2dcb2..8c21fe7090 100644
--- a/server/services/sprites/localAnimationRender.test.js
+++ b/server/services/sprites/localAnimationRender.test.js
@@ -64,7 +64,7 @@ const {
resolveLocalVideoModel, resolveLocalFrameCount, pickLocalRenderCanvas, localRenderFps,
getLocalAnimationProviderStatus, listAnimationProviders, planLocalAnimationRender,
localRenderManifest, enqueueLocalAnimationRender, collectLocalAnimationClip,
- localRunLiveness, spriteAnimationJobTag,
+ localRunLiveness, spriteAnimationJobTag, normalizeStaleAnimationRun,
} = await import('./localAnimationRender.js');
// The lane VOCABULARY (ids, the request normalizer, the run-record predicate)
// lives in animationWorkflow.js so lib/spriteValidation.js can build its enum
@@ -453,6 +453,45 @@ describe('collectLocalAnimationClip', () => {
});
});
+describe('normalizeStaleAnimationRun — a run stranded mid-PACKAGING', () => {
+ const grokRun = (overrides = {}) => ({ status: 'postprocessing', createdAt: new Date().toISOString(), ...overrides });
+ const ago = (ms) => new Date(Date.now() - ms).toISOString();
+
+ it('leaves a run that is genuinely still packaging alone', () => {
+ const run = grokRun({ createdAt: ago(2 * 60_000) });
+ expect(normalizeStaleAnimationRun(run, 'boom')).toBe(run);
+ });
+
+ it('errors a run still packaging long afterwards, on EITHER lane', () => {
+ // Packaging is bounded local CPU work (decode, align, despill, pack). A run
+ // still in it half an hour later means the process doing it died — and both
+ // in-flight guards count `postprocessing` as busy, so without this the
+ // facing is permanently unrenderable.
+ for (const provider of ['grok-tui', LOCAL_VIDEO_PROVIDER_ID]) {
+ const normalized = normalizeStaleAnimationRun(grokRun({ provider, createdAt: ago(40 * 60_000) }), 'boom');
+ expect(normalized.status).toBe('error');
+ expect(normalized.postprocessError).toBe('boom');
+ }
+ });
+
+ it('does not use the local lane\'s day-long render window for packaging', () => {
+ // A local RENDER gets 24h; its packaging must not inherit that, or a run
+ // interrupted mid-package blocks its facing for a day.
+ const normalized = normalizeStaleAnimationRun(
+ grokRun({ provider: LOCAL_VIDEO_PROVIDER_ID, jobId: 'j', createdAt: ago(2 * 60 * 60_000) }),
+ 'boom',
+ );
+ expect(normalized.status).toBe('error');
+ });
+
+ it('never touches a run that already reached a terminal state', () => {
+ for (const status of ['candidate', 'error', 'approved']) {
+ const run = { status, createdAt: ago(10 * 24 * 60 * 60_000) };
+ expect(normalizeStaleAnimationRun(run, 'boom')).toBe(run);
+ }
+ });
+});
+
describe('localRunLiveness', () => {
it('reports a queued or running job as live', () => {
queueJobs.set('j', { id: 'j', status: 'running' });