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: retain shot run error status and code for compatibility callers (#13204)
[._.]/ Adam Eivy7b30d2707d4a
diff --git a/server/services/fableLoom/shotRuns.js b/server/services/fableLoom/shotRuns.jsindex ab2dd27567..3c69f3008f 100644--- a/server/services/fableLoom/shotRuns.js+++ b/server/services/fableLoom/shotRuns.js@@ -4,7 +4,7 @@ import { readFile } from 'node:fs/promises';import { join } from 'node:path';import { PATHS, atomicWrite, ensureDir } from '../../lib/fileUtils.js';import { createFileWriteQueue } from '../../lib/fileWriteQueue.js';-import { ServerError } from '../../lib/errorHandler.js';+import { ServerError, normalizeError } from '../../lib/errorHandler.js';import { getLoom, findEpisode } from './records.js';import { runEpisodeShotAutopilot } from './shots.js';import { fableLoomRunEvents } from './runEvents.js';@@ -72,7 +72,10 @@ async function execute(run) {await publish(run);})).catch(error => queue(async () => {run.status = run.cancelRequested ? 'canceled' : 'failed';- run.message = error.message;+ const failure = normalizeError(error);+ run.message = failure.message;+ run.errorStatus = failure.status;+ run.errorCode = failure.code;await publish(run);})).finally(() => active.delete(key));}@@ -90,6 +93,8 @@ export async function startEpisodeShotRun(loomId, episodeId, { resume = false, .run.attempt += 1;run.status = 'running';run.cancelRequested = false;+ delete run.errorStatus;+ delete run.errorCode;run.message = resume ? 'Resuming shot planning…' : 'Starting shot planning…';await publish(run);active.set(key, run);@@ -129,7 +134,7 @@ export async function planEpisodeShotRun(loomId, episodeId, options = {}, { signif (!runId) { earlyTerminals.set(run.id, run); return; }if (run.id !== runId) return;if (run.status === 'completed') resolve(run.result);- else reject(new ServerError(run.message, { status: 422, code: 'SHOT_RUN_FAILED' }));+ else reject(new ServerError(run.message, { status: run.errorStatus || 422, code: run.errorCode || 'SHOT_RUN_FAILED' }));};onAbort = () => reject(new ServerError('The HTTP waiter closed; shot planning continues in the background.', { status: 499, code: 'SHOT_WAITER_CLOSED' }));// Subscribe before start, including instant completion or an already-active run.diff --git a/server/services/fableLoom/shots.test.js b/server/services/fableLoom/shots.test.jsindex dd6921c574..a8a97b382c 100644--- a/server/services/fableLoom/shots.test.js+++ b/server/services/fableLoom/shots.test.js@@ -192,7 +192,7 @@ describe('shot checkpoints and bounded inputs', () => {});it('deduplicates starts and preserves the last draft when canceled during a provider call', async () => {- const { startEpisodeShotRun, cancelEpisodeShotRun, getEpisodeShotRun } = await import('./shotRuns.js');+ const { startEpisodeShotRun, cancelEpisodeShotRun, getEpisodeShotRun, planEpisodeShotRun } = await import('./shotRuns.js');const { fableLoomRunEvents } = await import('./runEvents.js');const { loom, ep, groups } = await setup();let finishCall, callStarted;@@ -205,9 +205,12 @@ it('deduplicates starts and preserves the last draft when canceled during a provconst handler = run => { if (run.id === started.id && run.status === 'canceled') { fableLoomRunEvents.off('shots', handler); resolve(run); } };fableLoomRunEvents.on('shots', handler);});+ const waiting = expect(planEpisodeShotRun(loom.id, ep)).rejects.toMatchObject({ status: 409, code: 'SHOT_PLAN_CANCELED' });expect((await cancelEpisodeShotRun(loom.id, ep)).status).toBe('canceling');finishCall({ content: { groups: [groups[0]] } });await terminal;+ await waiting;+ expect(await getEpisodeShotRun(loom.id, ep)).toMatchObject({ errorStatus: 409, errorCode: 'SHOT_PLAN_CANCELED' });expect(runStagedLLM).toHaveBeenCalledTimes(1);expect((await getLoom(loom.id)).episodes).toEqual(loom.episodes);expect((await getEpisodeShotRun(loom.id, ep)).progress.rounds).toEqual([{ sceneId: groups[0].sceneId, rounds: 1, completed: false }]);@@ -284,3 +287,26 @@ it('finalizes operation status once for failures before provider execution and rexpect(aiStatus.error).toHaveBeenCalledTimes(1);expect(aiStatus.complete).not.toHaveBeenCalled();});+++it('preserves provider failure status in the compatibility response and journal, then clears it on resume', async () => {+ const { planEpisodeShotRun, getEpisodeShotRun } = await import('./shotRuns.js');+ const { loom, ep, groups } = await setup();+ runStagedLLM.mockRejectedValueOnce(new Error('CLI run timed out after 300000ms'));+ await expect(planEpisodeShotRun(loom.id, ep)).rejects.toMatchObject({ status: 502, code: 'SHOT_STAGE_FAILED' });+ expect(await getEpisodeShotRun(loom.id, ep)).toMatchObject({ status: 'failed', errorStatus: 502, errorCode: 'SHOT_STAGE_FAILED' });+ mockPlan(groups);+ await expect(planEpisodeShotRun(loom.id, ep, { resume: true })).resolves.toMatchObject({ validation: { stats: { ready: true } } });+ const completed = await getEpisodeShotRun(loom.id, ep);+ expect(completed).not.toHaveProperty('errorStatus');+ expect(completed).not.toHaveProperty('errorCode');+});++it('preserves invalid-plan errors through the compatibility waiter', async () => {+ const { planEpisodeShotRun, getEpisodeShotRun } = await import('./shotRuns.js');+ const { loom, ep, groups } = await setup();+ groups[0].shots[0].dialogue = [{ speaker: 'Courier', text: 'too many words '.repeat(30) }];+ mockPlan(groups);+ await expect(planEpisodeShotRun(loom.id, ep, { maxRounds: 1 })).rejects.toMatchObject({ status: 422, code: 'SHOT_PLAN_INVALID' });+ expect(await getEpisodeShotRun(loom.id, ep)).toMatchObject({ status: 'failed', errorStatus: 422, errorCode: 'SHOT_PLAN_INVALID' });+});