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

address review (codex): stop episode-gen loop, block on unparseable script

[._.]/ Adam Eivyb597a212b3ad
diff --git a/server/services/pipeline/seriesAutopilot.js b/server/services/pipeline/seriesAutopilot.js
index c9102834df..e582c3b698 100644
--- a/server/services/pipeline/seriesAutopilot.js
+++ b/server/services/pipeline/seriesAutopilot.js
@@ -226,8 +226,11 @@ export function resolveNextStep(series, issues, runState = {}, options = {}) {
return { kind: 'generateArc', reason: seasons.length === 0 && !noArc ? 'series has no volumes' : 'series has no arc' };
}
- // STEP 2 — a season with zero issues (in season order).
+ // STEP 2 — a season with zero issues (in season order). Skip volumes already
+ // attempted this run so an empty episode generation can't re-loop (the
+ // dispatch pauses when it produces no issues).
for (const season of seasons) {
+ if (setHas(runState.episodesAttempted, season.id)) continue;
const inSeason = ordered.filter((i) => i.seasonId === season.id);
if (inSeason.length === 0) {
return { kind: 'generateEpisodes', seasonId: season.id, reason: `volume ${season.number ?? '?'} has no issues` };
@@ -481,21 +484,23 @@ async function runScriptVerify(sId, issueId, record) {
const issue = await getIssue(issueId);
// Gate 1 — STRUCTURAL (pure, cheap): does the script parse into pages/panels?
- // A structural failure blocks page extraction, so surface + file a gap.
+ // This is the only structural validation before completion in text-only /
+ // visual-disabled comic runs, so a failure must BLOCK (pause), not just mark
+ // the issue checked — otherwise the run could report done with a script that
+ // can't become pages.
if (!scriptStructurallyReady(issue)) {
- broadcast(sId, {
- type: 'step:skip',
- kind: 'scriptVerify',
- issueId,
- reason: 'comic script did not parse into pages/panels — flagged for review',
- });
await fileGap(record, sId, {
gapKind: 'script-unparseable',
issueId,
summary: 'The comic script for this issue does not parse into pages/panels, so comic pages can\'t be extracted. It likely needs a manual fix or regeneration of the comicScript stage.',
context: `issueId=${issueId}`,
});
- return {};
+ return {
+ pause: true,
+ gapFiled: true,
+ reason: `comic script for issue ${issue.number ?? issueId} does not parse into pages/panels`,
+ residual: [{ severity: 'high', location: `issue ${issue.number ?? '?'} / comicScript`, problem: 'script did not parse into pages/panels — cannot extract comic pages' }],
+ };
}
// Gate 2 — CRAFT (LLM): does the script function as a comic script? This is
@@ -782,10 +787,20 @@ async function dispatchStep(sId, step, record) {
return {};
}
case 'generateEpisodes': {
+ // Mark attempted up front so an empty/invalid episode list can't re-loop
+ // the resolver back into generateEpisodes for the same still-empty volume.
+ record.runState.episodesAttempted.add(step.seasonId);
const r = await generateSeasonEpisodes(sId, step.seasonId, providerOverrideOpts(record));
const cur = await getSeries(sId);
- await commitEpisodesToIssues(sId, step.seasonId, r.episodes, { preloadedSeries: cur });
+ const created = await commitEpisodesToIssues(sId, step.seasonId, r.episodes, { preloadedSeries: cur });
await recordDomainUsage('cos', { actions: 1 });
+ if (!Array.isArray(created) || created.length === 0) {
+ return {
+ pause: true,
+ reason: `episode generation produced no issues for volume ${step.seasonId} — review the volume outline and regenerate`,
+ residual: [{ severity: 'high', location: `volume ${step.seasonId}`, problem: 'episode breakdown returned zero episodes/issues' }],
+ };
+ }
return {};
}
case 'verifyArc':
@@ -885,6 +900,7 @@ export async function startSeriesAutopilot(sId, options = {}) {
arcVerified: false,
editorialReviewed: false,
canonVerified: false,
+ episodesAttempted: new Set(),
beatsAttempted: new Set(),
textAttempted: new Set(),
scriptChecked: new Set(),
diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.js
index 86e47dde26..3579071203 100644
--- a/server/services/pipeline/seriesAutopilot.test.js
+++ b/server/services/pipeline/seriesAutopilot.test.js
@@ -393,6 +393,19 @@ describe('autopilot conductor', () => {
expect(series.autopilot?.residualFindings?.[0]?.problem).toBe('plot hole');
});
+ it('pauses (no infinite loop) when episode generation produces no issues', async () => {
+ const series = await seriesSvc.createSeries({ name: 'S', logline: 'L', premise: 'P', targetFormat: 'comic' });
+ await seriesSvc.updateSeries(series.id, { arc: { logline: 'A', summary: 'S' } });
+ await seasonsSvc.createSeason(series.id, { number: 1, title: 'V1' }); // volume with no issues
+ // commitEpisodesToIssues mock returns [] → no issues created.
+ await autopilot.startSeriesAutopilot(series.id, { includeVisual: false });
+ await waitFor(runFinished(series.id));
+ const last = autopilot.__testing.runs.get(series.id)?.lastPayload;
+ expect(last?.type).toBe('paused');
+ expect(last?.scope).toBe('generateEpisodes');
+ expect(arcSpies.generateSeasonEpisodes).toHaveBeenCalledTimes(1); // not looping
+ });
+
it('pauses (no infinite loop) when arc generation yields no volumes', async () => {
const series = await seriesSvc.createSeries({ name: 'S', logline: 'L', premise: 'P', targetFormat: 'comic' });
await seriesSvc.updateSeries(series.id, { arc: { logline: 'A', summary: 'S' } }); // arc but no seasons
@@ -502,13 +515,15 @@ describe('autopilot conductor', () => {
expect(autopilot.__testing.runs.get(seriesId)?.lastPayload?.type).toBe('complete');
});
- it('pauses visual draft (no art) when the comic script does not parse into pages', async () => {
+ it('blocks before visuals when the comic script does not parse (structural gate)', async () => {
+ // scriptVerify runs before canon/visual, so an unparseable script pauses
+ // there and no art is queued.
const { seriesId } = await seedComplete({ script: 'just prose, no comic pages here' });
await autopilot.startSeriesAutopilot(seriesId, { includeVisual: true });
await waitFor(runFinished(seriesId));
const last = autopilot.__testing.runs.get(seriesId)?.lastPayload;
expect(last?.type).toBe('paused');
- expect(last?.scope).toBe('visualDraft');
+ expect(last?.scope).toBe('scriptVerify');
expect(visualSpies.enqueueComicCover).not.toHaveBeenCalled();
});
@@ -529,17 +544,16 @@ describe('autopilot conductor', () => {
expect(visualSpies.enqueueVisualComicPage).not.toHaveBeenCalled();
});
- it('files a CoS gap task for an unparseable script when fileGaps is set', async () => {
+ it('pauses on an unparseable comic script and files a gap (fileGaps)', async () => {
const { seriesId } = await seedComplete({ script: 'just prose, no comic pages here' });
await autopilot.startSeriesAutopilot(seriesId, { fileGaps: true, includeVisual: false });
await waitFor(runFinished(seriesId));
- expect(addTask).toHaveBeenCalled();
- const [taskData, taskType] = addTask.mock.calls[0];
- expect(taskType).toBe('user');
- expect(taskData.app).toBe('pipeline');
- expect(taskData.description).toMatch(/script-unparseable/);
const last = autopilot.__testing.runs.get(seriesId)?.lastPayload;
- expect(last?.type).toBe('complete'); // gap filed, run still finishes
+ expect(last?.type).toBe('paused'); // structural gate blocks completion
+ expect(last?.scope).toBe('scriptVerify');
+ const descs = addTask.mock.calls.map((c) => c[0].description);
+ expect(descs.some((d) => /script-unparseable/.test(d))).toBe(true);
+ expect(descs.some((d) => /scriptVerify-stalled/.test(d))).toBe(false); // gapFiled → no dup
});
it('pauses when a delegated text run leaves required stages empty', async () => {