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: give long FableLoom stages a work-duration timeout

Adam Eivy883c6187ee22
diff --git a/data.reference/prompts/stage-config.json b/data.reference/prompts/stage-config.json
index ffc15d241d..8d29f05ff3 100644
--- a/data.reference/prompts/stage-config.json
+++ b/data.reference/prompts/stage-config.json
@@ -1033,6 +1033,7 @@
"description": "Generates a complete interactive-video episode as single-camera-cut nodes, choosing its own node and ending counts from the story. Automatic cuts use one Continue path; decision nodes loop while waiting on viewer intent. Each node includes image, video, and camera-movement direction.",
"model": "heavy",
"returnsJson": true,
+ "timeout": 1200000,
"variables": []
},
"fableloom-outline-episode": {
@@ -1138,6 +1139,7 @@
"description": "Episode-scoped short-shot production planning before media generation.",
"model": "default",
"returnsJson": true,
+ "timeout": 1200000,
"variables": [
"source",
"guidance",
diff --git a/scripts/migrations/438-fableloom-stage-timeouts.js b/scripts/migrations/438-fableloom-stage-timeouts.js
new file mode 100644
index 0000000000..b1cec88d99
--- /dev/null
+++ b/scripts/migrations/438-fableloom-stage-timeouts.js
@@ -0,0 +1,62 @@
+/**
+ * Give the two long-running FableLoom stages a work-duration timeout.
+ *
+ * `fableloom-plan-shots` drafts a whole episode's timed-shot plan and
+ * `fableloom-weave-episode` weaves a whole episode graph in one LLM call.
+ * Observed runs land at 207–300s — right at the toolkit's 5-minute provider
+ * default — so a heavier episode is SIGTERM'd mid-generation by the runner's
+ * wall clock and the autopilot burns a fallback re-run from scratch (run
+ * 284788df, 2026-10-22: exit 143, zero output, identical prompt succeeded at
+ * 236s ten minutes earlier). The stageRunner treats `stage.timeout` as the
+ * home for "how long the stage's WORK takes" (it beats the provider default
+ * and survives provider-pin stripping), so this sets 20 minutes on both
+ * stages — the same headroom the importer's whole-manuscript analyze stages
+ * use (ANALYZE_STAGE_TIMEOUT_MS).
+ *
+ * The seed (`data.reference/prompts/stage-config.json`) carries the same
+ * values for fresh installs; setup-data's starter merge only adds MISSING
+ * stage entries, so existing installs need this migration to pick up the
+ * field. A stage the user deleted stays deleted; an existing `timeout` the
+ * user set themselves is never overwritten. Idempotent, and a missing file
+ * (fresh install before setup-data) is a no-op.
+ */
+
+import { readFile } from 'fs/promises';
+import { join } from 'path';
+import { atomicWrite } from '../../server/lib/fileCore.js';
+
+const STAGE_CONFIG_PATH = join('data', 'prompts', 'stage-config.json');
+const STAGE_TIMEOUTS = Object.freeze({
+ 'fableloom-plan-shots': 1_200_000,
+ 'fableloom-weave-episode': 1_200_000,
+});
+
+export default {
+ async up({ rootDir }) {
+ const fullPath = join(rootDir, STAGE_CONFIG_PATH);
+ const raw = await readFile(fullPath, 'utf-8').catch((err) => {
+ if (err.code === 'ENOENT') return null;
+ throw err;
+ });
+ if (raw == null) return { stages: 0 };
+ let config;
+ try {
+ config = JSON.parse(raw);
+ } catch (err) {
+ throw new Error(`${STAGE_CONFIG_PATH} is not valid JSON (${err.message}) — repair it and re-run migrations`);
+ }
+ const stages = config?.stages;
+ if (!stages || typeof stages !== 'object' || Array.isArray(stages)) return { stages: 0 };
+
+ let changed = 0;
+ for (const [stageName, timeout] of Object.entries(STAGE_TIMEOUTS)) {
+ const stage = stages[stageName];
+ // Absent = the user deleted the stage; a set `timeout` = their own edit.
+ if (!stage || typeof stage !== 'object' || stage.timeout != null) continue;
+ stage.timeout = timeout;
+ changed += 1;
+ }
+ if (changed) await atomicWrite(fullPath, `${JSON.stringify(config, null, 2)}\n`);
+ return { stages: changed };
+ },
+};
diff --git a/scripts/migrations/438-fableloom-stage-timeouts.test.js b/scripts/migrations/438-fableloom-stage-timeouts.test.js
new file mode 100644
index 0000000000..a195ec00dd
--- /dev/null
+++ b/scripts/migrations/438-fableloom-stage-timeouts.test.js
@@ -0,0 +1,62 @@
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+
+import migration from './438-fableloom-stage-timeouts.js';
+
+describe('migration 438 — FableLoom stage timeouts', () => {
+ let rootDir;
+ let configPath;
+
+ beforeEach(() => {
+ rootDir = mkdtempSync(join(tmpdir(), 'migration-438-'));
+ mkdirSync(join(rootDir, 'data', 'prompts'), { recursive: true });
+ configPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
+ });
+
+ afterEach(() => rmSync(rootDir, { recursive: true, force: true }));
+
+ it('sets the work-duration timeout on both stages, leaving other stages and fields alone, idempotently', async () => {
+ writeFileSync(configPath, JSON.stringify({
+ stages: {
+ 'fableloom-plan-shots': { name: 'Plan', model: 'default', returnsJson: true, variables: ['source'] },
+ 'fableloom-weave-episode': { name: 'Weave', model: 'heavy', returnsJson: true, variables: [] },
+ 'fableloom-review-shots': { name: 'Review', model: 'default', returnsJson: true },
+ },
+ }));
+
+ expect(await migration.up({ rootDir })).toEqual({ stages: 2 });
+ const { stages } = JSON.parse(readFileSync(configPath, 'utf8'));
+ expect(stages['fableloom-plan-shots']).toEqual({
+ name: 'Plan', model: 'default', returnsJson: true, variables: ['source'], timeout: 1_200_000,
+ });
+ expect(stages['fableloom-weave-episode'].timeout).toBe(1_200_000);
+ expect(stages['fableloom-review-shots']).toEqual({ name: 'Review', model: 'default', returnsJson: true });
+
+ const afterFirst = readFileSync(configPath, 'utf8');
+ expect(await migration.up({ rootDir })).toEqual({ stages: 0 });
+ expect(readFileSync(configPath, 'utf8')).toBe(afterFirst);
+ });
+
+ it('never overwrites a user-set timeout or a deleted stage', async () => {
+ writeFileSync(configPath, JSON.stringify({
+ stages: {
+ 'fableloom-plan-shots': { name: 'Plan', timeout: 60000 },
+ },
+ }));
+
+ expect(await migration.up({ rootDir })).toEqual({ stages: 0 });
+ const { stages } = JSON.parse(readFileSync(configPath, 'utf8'));
+ expect(stages['fableloom-plan-shots'].timeout).toBe(60000);
+ });
+
+ it('is a no-op when the stage config does not exist yet', async () => {
+ expect(await migration.up({ rootDir })).toEqual({ stages: 0 });
+ });
+
+ it('refuses to guess at a corrupt stage config', async () => {
+ writeFileSync(configPath, '{ not json');
+ await expect(migration.up({ rootDir })).rejects.toThrow(/not valid JSON/);
+ });
+});