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: measure the packaging window from when packaging started, not from the render

[._.]/ Adam Eivy0d974eb1e97f
diff --git a/server/services/sprites/animationTrackWorkflow.js b/server/services/sprites/animationTrackWorkflow.js
index c2359ce27c..262615cc3a 100644
--- a/server/services/sprites/animationTrackWorkflow.js
+++ b/server/services/sprites/animationTrackWorkflow.js
@@ -422,6 +422,11 @@ export async function attachTrackTuiResult(trackId, recordId, runId, videoAbs) {
return;
}
run.status = 'postprocessing';
+ // Anchors the packaging staleness window (normalizeStaleAnimationRun). It MUST
+ // be measured from here rather than from `createdAt`: a local render can have
+ // been queued hours before packaging starts, so a createdAt-anchored window
+ // reports every healthy local run as interrupted the moment it begins to pack.
+ run.postprocessingStartedAt = new Date().toISOString();
run.sourceVideoPath = `${runRelPath(run.id)}/generated/${SOURCE_CLIP_NAME}`;
await saveRun(recordId, run);
await packageTrackRun(row, recordId, run);
diff --git a/server/services/sprites/localAnimationRender.js b/server/services/sprites/localAnimationRender.js
index 80490771dc..dab3c0b96a 100644
--- a/server/services/sprites/localAnimationRender.js
+++ b/server/services/sprites/localAnimationRender.js
@@ -432,9 +432,8 @@ const GROK_RENDER_STALE_MS = GROK_TUI_TIMEOUT_MS + 60_000;
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.
+// already generous and the lane makes no difference to it — but it is measured
+// from `postprocessingStartedAt`, NOT `createdAt`; see the branch below.
const PACKAGING_STALE_MS = GROK_RENDER_STALE_MS;
/**
@@ -474,7 +473,16 @@ export const normalizeStaleAnimationRun = (run, errorMessage) => {
// 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
+ // Measured from when PACKAGING started, not from when the render was queued.
+ // A local render can precede its packaging by hours, so a createdAt-anchored
+ // window would report every healthy local run as interrupted the instant it
+ // began to pack — and, because the in-flight guards read this normalized
+ // status, would release them and invite a second multi-hour render for a
+ // facing that already has a good candidate. Records written before this
+ // field existed fall back to `createdAt`, which is what they were measured
+ // against anyway.
+ const startedAt = run.postprocessingStartedAt ?? run.createdAt;
+ return Date.now() - runCreatedAtMs(startedAt) <= PACKAGING_STALE_MS
? run
: { ...run, status: 'error', postprocessError: errorMessage };
}
diff --git a/server/services/sprites/localAnimationRender.test.js b/server/services/sprites/localAnimationRender.test.js
index 8c21fe7090..f2953ca268 100644
--- a/server/services/sprites/localAnimationRender.test.js
+++ b/server/services/sprites/localAnimationRender.test.js
@@ -454,34 +454,55 @@ 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();
+ const packing = (overrides = {}) => ({
+ status: 'postprocessing',
+ createdAt: ago(60_000),
+ postprocessingStartedAt: ago(60_000),
+ ...overrides,
+ });
it('leaves a run that is genuinely still packaging alone', () => {
- const run = grokRun({ createdAt: ago(2 * 60_000) });
+ const run = packing({ postprocessingStartedAt: ago(2 * 60_000) });
+ expect(normalizeStaleAnimationRun(run, 'boom')).toBe(run);
+ });
+
+ it('leaves a LOCAL run alone that packed just now after rendering for HOURS', () => {
+ // The regression this window is easiest to get wrong: anchoring it on
+ // `createdAt` reports every healthy local run as interrupted the instant it
+ // starts packing — and, because the in-flight guards read the normalized
+ // status, releases them and invites a second multi-hour render for a facing
+ // that already has a good candidate.
+ const run = packing({
+ provider: LOCAL_VIDEO_PROVIDER_ID,
+ jobId: 'j',
+ createdAt: ago(3 * 60 * 60_000),
+ postprocessingStartedAt: ago(30_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
+ it('errors a run still packaging long after packaging began, on EITHER lane', () => {
+ // Packaging is bounded local CPU work (decode, align, despill, pack). 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');
+ const normalized = normalizeStaleAnimationRun(
+ packing({ provider, postprocessingStartedAt: 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('falls back to createdAt for a record written before the field existed', () => {
+ // Which is what such a record was already measured against, so this changes
+ // nothing for it either way.
+ const legacy = { status: 'postprocessing', createdAt: ago(40 * 60_000) };
+ expect(normalizeStaleAnimationRun(legacy, 'boom').status).toBe('error');
+ const fresh = { status: 'postprocessing', createdAt: ago(60_000) };
+ expect(normalizeStaleAnimationRun(fresh, 'boom')).toBe(fresh);
});
it('never touches a run that already reached a terminal state', () => {
diff --git a/server/services/sprites/walk.js b/server/services/sprites/walk.js
index 8d615f1d74..96363e713c 100644
--- a/server/services/sprites/walk.js
+++ b/server/services/sprites/walk.js
@@ -1166,6 +1166,11 @@ export async function attachTuiWalkResult(recordId, runId, videoAbs) {
}
run.sourceVideoSha256 = await sha256File(videoAbs);
run.status = 'postprocessing';
+ // Anchors the packaging staleness window (normalizeStaleAnimationRun). It MUST
+ // be measured from here rather than from `createdAt`: a local render can have
+ // been queued hours before packaging starts, so a createdAt-anchored window
+ // reports every healthy local run as interrupted the moment it begins to pack.
+ run.postprocessingStartedAt = new Date().toISOString();
await saveRunRecord(recordId, run);
await packageRun(recordId, run);
await saveRunRecord(recordId, run);
diff --git a/server/services/sprites/walk.test.js b/server/services/sprites/walk.test.js
index b230633cab..20939f0d4b 100644
--- a/server/services/sprites/walk.test.js
+++ b/server/services/sprites/walk.test.js
@@ -688,6 +688,45 @@ describe('startWalkGeneration — local render lane (#4876)', () => {
expect(run.status).toBe('rendering');
});
+ it('keeps a local run that renders for HOURS then packs looking healthy, and still blocked', async () => {
+ // The user-visible shape of the packaging-window bug: `getWalkState` is what
+ // the card polls every few seconds while a run packages, and the in-flight
+ // guard reads the same normalized state. Anchoring the window on `createdAt`
+ // made a successful 3-hour render report "interrupted" the instant it began
+ // to pack AND released the guard — so a Regenerate click would start a second
+ // multi-hour render for a facing that already had a good candidate.
+ const id = await characterWithLockedAnchors(newId());
+ const { runId } = await startWalkGeneration(id, { direction: 'east', provider: 'local' });
+ const runJson = join(TEST_ROOT, 'sprites', id, 'runs', runId, 'animation-run.json');
+ const stored = JSON.parse(await readFile(runJson, 'utf8'));
+ stored.createdAt = new Date(Date.now() - 3 * 60 * 60_000).toISOString();
+ stored.status = 'postprocessing';
+ stored.postprocessingStartedAt = new Date().toISOString();
+ await writeFile(runJson, JSON.stringify(stored));
+
+ const run = (await getWalkState(id)).runs.find((r) => r.id === runId);
+ expect(run.status).toBe('postprocessing');
+ expect(run.postprocessError).toBeUndefined();
+ await expect(startWalkGeneration(id, { direction: 'east', provider: 'local' }))
+ .rejects.toMatchObject({ code: 'WALK_RENDER_IN_PROGRESS' });
+ });
+
+ it('errors a run whose PACKAGING itself was interrupted, freeing the direction', async () => {
+ const id = await characterWithLockedAnchors(newId());
+ const { runId } = await startWalkGeneration(id, { direction: 'east', provider: 'local' });
+ const runJson = join(TEST_ROOT, 'sprites', id, 'runs', runId, 'animation-run.json');
+ const stored = JSON.parse(await readFile(runJson, 'utf8'));
+ stored.status = 'postprocessing';
+ stored.postprocessingStartedAt = new Date(Date.now() - 40 * 60_000).toISOString();
+ await writeFile(runJson, JSON.stringify(stored));
+
+ const run = (await getWalkState(id)).runs.find((r) => r.id === runId);
+ expect(run.status).toBe('error');
+ // Both in-flight guards count `postprocessing` as busy, so without the
+ // normalization this direction would be unrenderable forever.
+ await expect(startWalkGeneration(id, { direction: 'east', provider: 'local' })).resolves.toBeTruthy();
+ });
+
it('reports a local attach that found no clip in local terms, not grok terms', async () => {
const id = await characterWithLockedAnchors(newId());
const { runId } = await startWalkGeneration(id, { direction: 'east', provider: 'local' });