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: preserve durable shot runs for synchronous API callers (#13204)
[._.]/ Adam Eivyabe06ced78dd
diff --git a/docs/features/fableloom.md b/docs/features/fableloom.mdindex 28ca8128b1..23fdafba4a 100644--- a/docs/features/fableloom.md+++ b/docs/features/fableloom.md@@ -424,7 +424,7 @@ a starting image are mutually exclusive.The shot planner starts a background run with `POST /api/fableloom/:id/episodes/:episodeId/shots/start`.`GET .../shots/status` reattaches to its latest state; `POST .../shots/cancel` stops after the active provider call.-The UI receives `fableloom:shots:run` snapshots and reloads status on reconnect. The legacy `POST .../shots/plan` remains synchronous for existing callers.+The UI receives `fableloom:shots:run` snapshots and reloads status on reconnect. The legacy `POST .../shots/plan` waits for the same durable worker and returns the completed plan for existing callers; its HTTP connection does not own that worker. Both start paths accept explicit resume.Draft and review run on one source scene at a time with the episode's compact graph digest. A final text consistency review receives the complete shot plan and graph, without the complete teleplay. Existing stage and provider timeout settings stay in effect; large inputs show a reminder to check the effective timeout. Stage failures name the stage, round, scene and provider.diff --git a/server/routes/fableLoom.js b/server/routes/fableLoom.jsindex 74228b8dd6..beead41f60 100644--- a/server/routes/fableLoom.js+++ b/server/routes/fableLoom.js@@ -9,11 +9,10 @@*/import { Router } from 'express';-import { startEpisodeShotRun, getEpisodeShotRun, cancelEpisodeShotRun } from '../services/fableLoom/shotRuns.js';+import { startEpisodeShotRun, getEpisodeShotRun, cancelEpisodeShotRun, planEpisodeShotRun } from '../services/fableLoom/shotRuns.js';import { asyncHandler, ServerError } from '../lib/errorHandler.js';import { validateRequest } from '../lib/validation.js';import {- shotAutopilotSchema,shotRunStartSchema,shotApplySchema,branchSchema,@@ -55,7 +54,6 @@ import {} from '../lib/fableLoomPlayback.js';import { getUniverse } from '../services/universeBuilder.js';import {- runEpisodeShotAutopilot,applyEpisodeShots,addEpisode,addNode,@@ -338,7 +336,7 @@ router.post('/:id/episodes/:episodeId/shots/cancel', asyncHandler(async (req, reres.json(await cancelEpisodeShotRun(req.params.id, req.params.episodeId));}));router.post('/:id/episodes/:episodeId/shots/plan', asyncHandler(async (req, res) => {- res.json(await runEpisodeShotAutopilot(req.params.id, req.params.episodeId, validateRequest(shotAutopilotSchema, req.body)));+ res.json(await planEpisodeShotRun(req.params.id, req.params.episodeId, validateRequest(shotRunStartSchema, req.body ?? {})));}));router.post('/:id/episodes/:episodeId/shots/apply', asyncHandler(async (req, res) => {res.json(await applyEpisodeShots(req.params.id, req.params.episodeId, validateRequest(shotApplySchema, req.body)));diff --git a/server/routes/fableLoom.test.js b/server/routes/fableLoom.test.jsindex 817a579a09..bc8dabdb40 100644--- a/server/routes/fableLoom.test.js+++ b/server/routes/fableLoom.test.js@@ -54,7 +54,7 @@ vi.mock('../services/fableLoom/index.js', () => ({reviewEpisodeContinuity: vi.fn(),}));-vi.mock('../services/fableLoom/shotRuns.js', () => ({ startEpisodeShotRun: vi.fn(), getEpisodeShotRun: vi.fn(), cancelEpisodeShotRun: vi.fn() }));+vi.mock('../services/fableLoom/shotRuns.js', () => ({ startEpisodeShotRun: vi.fn(), planEpisodeShotRun: vi.fn(), getEpisodeShotRun: vi.fn(), cancelEpisodeShotRun: vi.fn() }));import * as shotRuns from '../services/fableLoom/shotRuns.js';import * as fableLoom from '../services/fableLoom/index.js';import routes from './fableLoom.js';diff --git a/server/services/fableLoom/shotRuns.js b/server/services/fableLoom/shotRuns.jsindex 5f4c23d1ef..d27d1deb6f 100644--- a/server/services/fableLoom/shotRuns.js+++ b/server/services/fableLoom/shotRuns.js@@ -93,7 +93,13 @@ export async function startEpisodeShotRun(loomId, episodeId, { resume = false, .run.message = resume ? 'Resuming shot planning…' : 'Starting shot planning…';await publish(run);active.set(key, run);- void execute(run).catch(error => console.error(`❌ Shot run persistence failed: ${error.message}`));+ void execute(run).catch(error => {+ console.error(`❌ Shot run persistence failed: ${error.message}`);+ run.status = 'failed';+ run.message = 'Could not persist the shot run. Previously saved steps remain available for recovery.';+ run.revision += 1;+ fableLoomRunEvents.emit('shots', snapshot(run));+ });return snapshot(run);});}@@ -111,3 +117,25 @@ export async function cancelEpisodeShotRun(loomId, episodeId) {return snapshot(run);});}++/** Compatibility callers still await a plan, but do not own the worker's lifetime. */+export async function planEpisodeShotRun(loomId, episodeId, options = {}) {+ let runId;+ let resolveResult, rejectResult;+ const earlyTerminals = new Map();+ const result = new Promise((resolve, reject) => { resolveResult = resolve; rejectResult = reject; });+ const accept = run => {+ if (run.loomId !== loomId || run.episodeId !== episodeId || !['completed', 'failed', 'canceled'].includes(run.status)) return;+ if (!runId) { earlyTerminals.set(run.id, run); return; }+ if (run.id !== runId) return;+ if (run.status === 'completed') resolveResult(run.result);+ else rejectResult(new ServerError(run.message, { status: 422, code: 'SHOT_RUN_FAILED' }));+ };+ // Subscribe before start, including an instant completion or an already-active run.+ fableLoomRunEvents.on('shots', accept);+ return startEpisodeShotRun(loomId, episodeId, options).then(run => {+ runId = run.id;+ accept(earlyTerminals.get(runId) || run);+ return result;+ }).finally(() => fableLoomRunEvents.off('shots', accept));+}diff --git a/server/services/fableLoom/shots.test.js b/server/services/fableLoom/shots.test.jsindex b184fc0d38..5a30222d02 100644--- a/server/services/fableLoom/shots.test.js+++ b/server/services/fableLoom/shots.test.js@@ -227,3 +227,12 @@ it('repairs cross-scene consistency findings within the remaining rounds and keeexpect(checkpoint.consistency[0].review.risks).toEqual(['Preserve the lamp placement between scenes.']);expect(checkpoint.scenes[groups[0].sceneId].rounds[0].feedback).toContain('lamp');});++it('keeps the synchronous compatibility response backed by a durable background journal', async () => {+ const { planEpisodeShotRun, getEpisodeShotRun } = await import('./shotRuns.js');+ const { loom, ep, groups } = await setup();+ mockPlan(groups);+ const result = await planEpisodeShotRun(loom.id, ep);+ expect(result.validation.stats.ready).toBe(true);+ expect((await getEpisodeShotRun(loom.id, ep))).toMatchObject({ status: 'completed', result: { sourceFingerprint: result.sourceFingerprint } });+});