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(fableloom): preserve terminal exports across stale status reads (#13471)
Adam Eivy3e43d6b5b31c
diff --git a/server/services/fableLoom/exports.js b/server/services/fableLoom/exports.jsindex 2ed98d65f5..5af986d3d8 100644--- a/server/services/fableLoom/exports.js+++ b/server/services/fableLoom/exports.js@@ -70,6 +70,7 @@ function publicJob(job) {async function readJob(id, loomId = null) {if (!uuid.test(id)) throw missing();+ const wasActive = active.has(id);const job = await readJSONFile(jobFile(id), absentJob, { strict: true, logError: false }).catch(() => {throw invalidState();});@@ -92,6 +93,9 @@ async function readJob(id, loomId = null) {if (job.status === 'failed' && (typeof job.error?.code !== 'string' || typeof job.error?.message !== 'string')) throw invalidState();if (loomId !== null && job.loomId !== loomId) throw missing();if (!active.has(id) && !['completed', 'failed'].includes(job.status)) {+ // The worker publishes its terminal record before releasing ownership. A read+ // spanning that release may hold an older snapshot; reload before recovery.+ if (wasActive) return readJob(id, loomId);await rmGuarded(join(jobDirectory(id), 'work'), { recursive: true, force: true });job.status = 'failed';job.error = { code: 'EXPORT_INTERRUPTED', message: 'The server restarted during export. Start a new export.' };diff --git a/server/services/fableLoom/exports.test.js b/server/services/fableLoom/exports.test.jsindex 72865ee5f4..345f9528f1 100644--- a/server/services/fableLoom/exports.test.js+++ b/server/services/fableLoom/exports.test.js@@ -10,6 +10,7 @@ import { request } from '../../lib/testHelper.js';import { errorMiddleware } from '../../lib/errorHandler.js';import { readZipArchive } from '../../lib/zipArchive.js';import * as ffmpeg from '../../lib/ffmpeg.js';+import * as jsonIo from '../../lib/jsonIo.js';import { findFfmpeg, findFfprobe, runFfmpegProcess } from '../../lib/ffmpeg.js';import {FABLELOOM_EXPORT_LIMITS, inspectFableLoomExportCharacters,@@ -835,6 +836,50 @@ describe('portable FableLoom export boundary', () => {await rm(join(PATHS.images, 'escape.png'));});+ it('retains the terminal path refusal when a persisted status read crosses worker release', async () => {+ const sourceEntered = Promise.withResolvers();+ const releaseSource = Promise.withResolvers();+ const snapshotRead = Promise.withResolvers();+ const releaseRead = Promise.withResolvers();+ const readSource = media.readFableLoomExportSource;+ vi.spyOn(media, 'readFableLoomExportSource').mockImplementation(async (...args) => {+ sourceEntered.resolve();+ await releaseSource.promise;+ return readSource(...args);+ });+ const bad = 'https://example.com/movie.mp4';+ loadHistory.mockResolvedValue([{ id: 'entry-record', filename: bad }]);+ let pendingRead;+ try {+ const id = await begin({ episodeIds: ['episode-one'] });+ await sourceEntered.promise;+ const readJSONFile = jsonIo.readJSONFile;+ vi.spyOn(jsonIo, 'readJSONFile').mockImplementationOnce(async (...args) => {+ const snapshot = await readJSONFile(...args);+ snapshotRead.resolve(snapshot);+ await releaseRead.promise;+ return snapshot;+ });+ pendingRead = getFableLoomExport(loom.id, id);+ expect(await snapshotRead.promise).toMatchObject({ jobId: id, status: 'packing' });+ releaseSource.resolve();+ await __testing.drain();+ const terminalRecord = JSON.parse(await readFile(recordFile(id), 'utf8'));+ expect(terminalRecord).toMatchObject({ status: 'failed', error: { code: 'EXPORT_MEDIA_PATH' } });+ releaseRead.resolve();+ const result = await pendingRead;+ expect(result).toMatchObject({+ status: 'failed', revision: terminalRecord.revision, error: { code: 'EXPORT_MEDIA_PATH' },+ });+ expect(JSON.stringify(result)).not.toContain(bad);+ expect(JSON.parse(await readFile(recordFile(id), 'utf8'))).toEqual(terminalRecord);+ } finally {+ releaseSource.resolve();+ releaseRead.resolve();+ await pendingRead;+ }+ });+it('persists actionable interruption and expiry states without treating malformed state as missing', async () => {loom.episodes[0].nodes[0].image = null;const id = await begin();