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

feat([issue-1349]): refresh reverse outline before scene-based editorial checks in autopilot

[._.]/ Adam Eivy7798df01fd4b
diff --git a/client/src/components/pipeline/AutopilotPanel.jsx b/client/src/components/pipeline/AutopilotPanel.jsx
index 0f5f5d76fd..9ffb235011 100644
--- a/client/src/components/pipeline/AutopilotPanel.jsx
+++ b/client/src/components/pipeline/AutopilotPanel.jsx
@@ -81,6 +81,7 @@ const STEP_LABELS = {
textStages: 'Writing prose + scripts',
scriptVerify: 'Verifying scripts',
editorialReview: 'Editorial review',
+ reverseOutline: 'Refreshing scene segmentation',
canonVerify: 'Checking canon descriptions',
visualDraft: 'Drafting comic art',
};
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.js
index 2deb892649..01b3a8445a 100644
--- a/server/services/pipeline/editorial/checkRunner.js
+++ b/server/services/pipeline/editorial/checkRunner.js
@@ -587,7 +587,28 @@ export async function buildEditorialCheckPlan(seriesId, { checkIds = null, setti
const resolved = settings || await getSettings();
const checks = getEnabledCheckRows(resolved, checkIds)
.map((row) => ({ id: row.id, label: row.label, kind: row.kind, scope: row.scope }));
- return { seriesId, checks, enabledCount: checks.length };
+ return {
+ seriesId,
+ checks,
+ enabledCount: checks.length,
+ consumesReverseOutline: enabledChecksConsumeReverseOutline(resolved, checkIds),
+ };
+}
+
+/**
+ * True when any enabled editorial check declares a reverse-outline source — the
+ * scenes (`reverseOutline`, #1296) or the plotline list (`reverseOutline.plotlines`,
+ * #1310). This is the single signal for "regenerating the reverse outline before
+ * the checks is worth the budget" (#1349): it mirrors the `needsReverseOutline`
+ * gate inside `runEditorialChecks` exactly, so the autopilot's reverse-outline
+ * refresh step and the runner agree on what consumes the outline. Takes resolved
+ * settings (sync) so a caller that already loaded them doesn't pay a second read.
+ */
+export function enabledChecksConsumeReverseOutline(settings, checkIds = null) {
+ return getEnabledChecks(settings, checkIds).some(({ check }) => {
+ const sources = checkSources(check);
+ return sources.includes('reverseOutline') || sources.includes('reverseOutline.plotlines');
+ });
}
/**
diff --git a/server/services/pipeline/editorial/checkRunner.test.js b/server/services/pipeline/editorial/checkRunner.test.js
index 7301df2be1..9f6266464d 100644
--- a/server/services/pipeline/editorial/checkRunner.test.js
+++ b/server/services/pipeline/editorial/checkRunner.test.js
@@ -76,7 +76,7 @@ vi.mock('../reverseOutline.js', () => ({ getReverseOutline: vi.fn(async () => ou
let editorialState = { characters: [] };
vi.mock('../editorialAnalysis.js', () => ({ getSeriesEditorial: vi.fn(async () => editorialState) }));
-const { runEditorialChecks, buildEditorialCheckPlan, getReviewWithStaleness } = await import('./checkRunner.js');
+const { runEditorialChecks, buildEditorialCheckPlan, getReviewWithStaleness, enabledChecksConsumeReverseOutline } = await import('./checkRunner.js');
const { runStagedLLM, resolveStageContext } = await import('../../../lib/stageRunner.js');
const { collectManuscriptSections } = await import('../arcPlanner.js');
const { getSeriesCanon } = await import('../seriesCanon.js');
@@ -738,4 +738,24 @@ describe('buildEditorialCheckPlan', () => {
expect(plan.enabledCount).toBe(plan.checks.length);
expect(plan.checks.map((c) => c.id)).toContain('naming.dissimilar-names');
});
+
+ it('exposes whether any enabled check consumes the reverse outline (#1349)', async () => {
+ const plan = await buildEditorialCheckPlan('s1');
+ // Scene/POV checks ship enabled by default, so the default plan consumes it.
+ expect(plan.consumesReverseOutline).toBe(true);
+ });
+});
+
+describe('enabledChecksConsumeReverseOutline (#1349)', () => {
+ const consumesOutline = (c) => Array.isArray(c.sources)
+ && (c.sources.includes('reverseOutline') || c.sources.includes('reverseOutline.plotlines'));
+
+ it('is true when a scene/plotline check is enabled (default settings)', () => {
+ expect(enabledChecksConsumeReverseOutline({})).toBe(true);
+ });
+
+ it('is false when every reverse-outline-consuming check is disabled', () => {
+ const settings = disableWhere(consumesOutline);
+ expect(enabledChecksConsumeReverseOutline(settings)).toBe(false);
+ });
});
diff --git a/server/services/pipeline/seriesAutopilot.js b/server/services/pipeline/seriesAutopilot.js
index 768db6698f..0eb7c04243 100644
--- a/server/services/pipeline/seriesAutopilot.js
+++ b/server/services/pipeline/seriesAutopilot.js
@@ -92,7 +92,8 @@ import {
import * as volumeBeatsRunner from './volumeBeatsRunner.js';
import * as autoRunner from './autoRunner.js';
import { seedReviewFromFindings, getReview } from './manuscriptReview.js';
-import { runEditorialChecks, buildEditorialCheckPlan } from './editorial/checkRunner.js';
+import { runEditorialChecks, buildEditorialCheckPlan, enabledChecksConsumeReverseOutline } from './editorial/checkRunner.js';
+import { generateReverseOutline, getReverseOutline } from './reverseOutline.js';
import { computeHealth, openBlockers } from './editorialScore.js';
import { getSettings } from '../settings.js';
import { readReadinessGate } from '../../lib/editorial/index.js';
@@ -303,8 +304,8 @@ export function visualReady(issue) {
* Return the first unmet step for a series given its canonical records and the
* in-run accumulator (`runState`). Pure — caller supplies fresh state.
*
- * runState fields consulted (all optional): arcVerified, editorialReviewed
- * (booleans); beatsAttempted, textAttempted, scriptChecked (Set|array of ids).
+ * runState fields consulted (all optional): arcVerified, editorialReviewed,
+ * reverseOutlineRefreshed (booleans); beatsAttempted, textAttempted, scriptChecked (Set|array of ids).
* The *attempted* sets stop a perpetually-failing step (an issue whose LLM run
* keeps erroring) from looping forever — the conductor records an attempt even
* on failure, so the resolver moves past it within one run.
@@ -385,6 +386,15 @@ export function resolveNextStep(series, issues, runState = {}, options = {}) {
return { kind: 'editorialReview', reason: 'editorial review not yet run this run' };
}
+ // STEP 5.1 — refresh the reverse-outline scene segmentation (#1349). Runs AFTER
+ // the editorial completeness pass (STEP 5, which may edit the manuscript) and
+ // BEFORE the registry checks (5.2) so the scene-consuming checks read fresh
+ // scenes. The handler self-gates: a no-op (no budget) when no enabled check
+ // reads the outline or the stored outline is already fresh.
+ if (!runState.reverseOutlineRefreshed) {
+ return { kind: 'reverseOutline', reason: 'reverse-outline segmentation not yet refreshed this run' };
+ }
+
// STEP 5.2 — registry-driven editorial checks (#1284). Runs the enabled
// editorial checks once per run and seeds their findings into the same
// manuscript-review comment set. A no-op when no checks are enabled.
@@ -731,6 +741,10 @@ async function runEditorial(sId, record) {
// checks on demand via the route.
if (maxRounds === 0) {
record.runState.editorialReviewed = true;
+ // The reverse-outline refresh (#1349) only feeds the registry checks, so a run
+ // that skips the whole editorial gate must skip it too — mark it refreshed so
+ // the resolver advances past STEP 5.1 without spending budget.
+ record.runState.reverseOutlineRefreshed = true;
record.runState.editorialChecksReviewed = true;
// Skipping the editorial gate also skips its health convergence check (#1316)
// — the resolver must advance past editorialHealthGate too.
@@ -791,6 +805,59 @@ async function runEditorial(sId, record) {
return {};
}
+// STEP 5.1 — refresh the reverse-outline scene segmentation (#1349) before the
+// registry-driven editorial checks (5.2), so the scene-consuming checks read the
+// current draft's scenes rather than a segmentation staled by this run's editorial
+// edits. Two cheap pre-gates keep this from spending budget needlessly:
+// 1. skip entirely when no enabled editorial check declares a reverse-outline
+// source (mirrors the runner's own needsReverseOutline gate), and
+// 2. skip when the stored outline is already fresh — using getReverseOutline's
+// canonical `stale` flag, NOT a stale-check reimplemented here.
+// Only when a regenerate will actually occur do we gate the daily budget and bill a
+// cos action (mirroring runEditorialChecksPass's hasLlmCheck pattern). `force:false`
+// is a belt-and-suspenders second guard against the stored outline going fresh
+// between the pre-check and the call. Failures are advisory (logged), never block.
+async function runReverseOutlineRefresh(sId, record) {
+ if (record.cancelRequested) return { canceled: true };
+ const settings = await getSettings();
+ // Gate 1 — does any enabled check even read the outline? If not, nothing to do.
+ if (!enabledChecksConsumeReverseOutline(settings)) {
+ record.runState.reverseOutlineRefreshed = true;
+ return {};
+ }
+ // Gate 2 — is the stored outline stale (or never generated against a draftable
+ // manuscript)? `no-content` (nothing drafted) needs no outline; `none` (draftable
+ // but never segmented) and a `complete`-but-`stale` outline both need a regen.
+ const current = await getReverseOutline(sId).catch(() => null);
+ const needsRegen = !!current
+ && current.status !== 'no-content'
+ && (current.status === 'none' || current.stale === true);
+ if (!needsRegen) {
+ record.runState.reverseOutlineRefreshed = true;
+ return {};
+ }
+ // A regenerate WILL spend one LLM call — gate the budget and bill, like the
+ // other LLM passes. Bridge autopilot cancellation into the stage's AbortSignal.
+ const beforeRefresh = await budgetPause();
+ if (beforeRefresh) return beforeRefresh;
+ const signal = { get aborted() { return record.cancelRequested; } };
+ const result = await generateReverseOutline(sId, { ...providerIdOpts(record), force: false, signal })
+ .catch((err) => {
+ console.log(`⚠️ autopilot: reverse-outline refresh failed for ${sId.slice(0, 12)}: ${err.message}`);
+ return null;
+ });
+ // Canceled mid-pass — don't bill, don't mark refreshed; let the loop unwind.
+ if (result?.status === 'canceled' || record.cancelRequested) return { canceled: true };
+ // Bill ONLY when the call actually regenerated (an LLM run). A `cached` result
+ // (outline went fresh in the race window) or a `no-content` series spent nothing.
+ if (result && result.cached !== true && result.status !== 'no-content') {
+ await recordDomainUsage('cos', { actions: 1 });
+ broadcast(sId, { type: 'verify:round', scope: 'reverseOutline', round: 1, findings: Array.isArray(result.scenes) ? result.scenes.length : 0, blocking: 0 });
+ }
+ record.runState.reverseOutlineRefreshed = true;
+ return {};
+}
+
// STEP 5.2 — run the registry-driven editorial checks once per run, seeding
// their findings into the same manuscript-review comment set. Only LLM-kind
// checks cost tokens, so gate the daily budget AND bill a cos action only when
@@ -1089,6 +1156,8 @@ async function dispatchStep(sId, step, record) {
return runScriptVerify(sId, step.issueId, record);
case 'editorialReview':
return runEditorial(sId, record);
+ case 'reverseOutline':
+ return runReverseOutlineRefresh(sId, record);
case 'editorialChecks':
return runEditorialChecksPass(sId, record);
case 'editorialHealthGate':
@@ -1145,6 +1214,7 @@ function buildDryRunPlan(series, issues, options) {
// editorialHealthReady), so the plan must not advertise the registry checks or
// the health gate that won't run.
if (edRounds !== 0) {
+ plan.push({ kind: 'reverseOutline', count: 1, note: 'refresh scene segmentation for editorial checks (#1349)' });
plan.push({ kind: 'editorialChecks', count: 1, note: 'enabled editorial checks (#1284)' });
plan.push({ kind: 'editorialHealthGate', count: 1, note: 'editorial health readiness gate (#1316)' });
}
@@ -1208,6 +1278,7 @@ export async function startSeriesAutopilot(sId, options = {}) {
arcVerified: false,
beatContinuityChecked: false,
editorialReviewed: false,
+ reverseOutlineRefreshed: false,
editorialChecksReviewed: false,
editorialHealthReady: false,
canonVerified: false,
diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.js
index a75f4da58b..4cfbd86840 100644
--- a/server/services/pipeline/seriesAutopilot.test.js
+++ b/server/services/pipeline/seriesAutopilot.test.js
@@ -73,11 +73,24 @@ vi.mock('./manuscriptReview.js', () => ({
seedReviewFromFindings: vi.fn(async () => ({ comments: [] })),
getReview: vi.fn(async () => ({ comments: [] })),
}));
+// Drives whether the reverse-outline refresh step (#1349) thinks a scene-consuming
+// check is enabled. Default false so the existing conductor runs skip it cheaply.
+let reverseOutlineConsumed = false;
const checkRunnerSpies = {
runEditorialChecks: vi.fn(async () => ({ runId: 'ec', findings: [], perCheck: [], canceled: false })),
- buildEditorialCheckPlan: vi.fn(async () => ({ seriesId: 's', checks: [], enabledCount: 0 })),
+ buildEditorialCheckPlan: vi.fn(async () => ({ seriesId: 's', checks: [], enabledCount: 0, consumesReverseOutline: reverseOutlineConsumed })),
+ enabledChecksConsumeReverseOutline: vi.fn(() => reverseOutlineConsumed),
};
vi.mock('./editorial/checkRunner.js', () => checkRunnerSpies);
+
+// Reverse outline (#1349) — controllable staleness + a generate spy so a test can
+// assert the refresh step regenerates only when stale and bills only then.
+let reverseOutlineState = { status: 'complete', stale: false };
+const generateReverseOutline = vi.fn(async () => ({ status: 'complete', stale: false, scenes: [{ id: 'sc1' }] }));
+vi.mock('./reverseOutline.js', () => ({
+ getReverseOutline: vi.fn(async (seriesId) => ({ seriesId, ...reverseOutlineState })),
+ generateReverseOutline,
+}));
vi.mock('../settings.js', async (importOriginal) => ({
...(await importOriginal()),
getSettings: vi.fn(async () => ({})),
@@ -151,9 +164,12 @@ beforeEach(() => {
scriptVerifyFindings = [];
canonReady = true;
canonUndescribed = [];
+ reverseOutlineConsumed = false;
+ reverseOutlineState = { status: 'complete', stale: false };
nextTaskId = 0;
autopilot.__testing.runs.clear();
vi.clearAllMocks();
+ generateReverseOutline.mockImplementation(async () => ({ status: 'complete', stale: false, scenes: [{ id: 'sc1' }] }));
// Reset the budget mock to read the `budgetStatus` var (clearAllMocks keeps
// implementations, but a prior test may have set a call-count-keyed one).
getDomainBudgetStatus.mockImplementation(async () => budgetStatus);
@@ -222,11 +238,17 @@ describe('resolveNextStep (pure)', () => {
const series = { targetFormat: 'comic', arc: { logline: 'L', summary: 'S' }, seasons: [{ id: 'se1', number: 1 }] };
const issues = [{ id: 'i1', seasonId: 'se1', number: 1, arcPosition: 1, stages: {} }];
const kinds = (opts) => autopilot.__testing.buildDryRunPlan(series, issues, opts).map((p) => p.kind);
- // With editorial enabled (default), both registry checks + health gate appear.
- expect(kinds({})).toEqual(expect.arrayContaining(['editorialReview', 'editorialChecks', 'editorialHealthGate']));
- // With maxEditorialRounds:0, execute mode skips all three — the plan must too.
+ // With editorial enabled (default), the reverse-outline refresh (#1349), both
+ // registry checks + health gate appear.
+ expect(kinds({})).toEqual(expect.arrayContaining(['editorialReview', 'reverseOutline', 'editorialChecks', 'editorialHealthGate']));
+ // The reverse-outline refresh is enumerated BEFORE the editorial checks it feeds.
+ const defaultKinds = kinds({});
+ expect(defaultKinds.indexOf('reverseOutline')).toBeLessThan(defaultKinds.indexOf('editorialChecks'));
+ // With maxEditorialRounds:0, execute mode skips the whole editorial gate — the
+ // plan must omit the reverse-outline refresh and both checks too.
const skipped = kinds({ maxEditorialRounds: 0 });
expect(skipped).toContain('editorialReview'); // shown as "skipped (0 rounds)"
+ expect(skipped).not.toContain('reverseOutline');
expect(skipped).not.toContain('editorialChecks');
expect(skipped).not.toContain('editorialHealthGate');
});
@@ -291,13 +313,23 @@ describe('resolveNextStep (pure)', () => {
expect(step.kind).toBe('editorialReview');
});
- it('asks for editorial checks after editorial review, before done/visuals', () => {
+ it('refreshes the reverse outline after editorial review, before editorial checks (#1349)', () => {
const step = resolveNextStep(
comic,
[issue({ stages: { idea: ready(), comicScript: ready(VALID_SCRIPT) } })],
{ arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true },
{ includeVisual: false },
);
+ expect(step.kind).toBe('reverseOutline');
+ });
+
+ it('asks for editorial checks once the reverse outline is refreshed (#1349)', () => {
+ const step = resolveNextStep(
+ comic,
+ [issue({ stages: { idea: ready(), comicScript: ready(VALID_SCRIPT) } })],
+ { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, reverseOutlineRefreshed: true },
+ { includeVisual: false },
+ );
expect(step.kind).toBe('editorialChecks');
});
@@ -305,7 +337,7 @@ describe('resolveNextStep (pure)', () => {
const step = resolveNextStep(
comic,
[issue({ stages: { idea: ready(), comicScript: ready(VALID_SCRIPT) } })],
- { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, editorialChecksReviewed: true },
+ { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, reverseOutlineRefreshed: true, editorialChecksReviewed: true },
{ includeVisual: false },
);
expect(step.kind).toBe('editorialHealthGate');
@@ -315,7 +347,7 @@ describe('resolveNextStep (pure)', () => {
const step = resolveNextStep(
comic,
[issue({ stages: { idea: ready(), comicScript: ready(VALID_SCRIPT) } })],
- { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, editorialChecksReviewed: true, editorialHealthReady: true },
+ { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, reverseOutlineRefreshed: true, editorialChecksReviewed: true, editorialHealthReady: true },
{ includeVisual: false },
);
expect(step.kind).toBe('done');
@@ -325,7 +357,7 @@ describe('resolveNextStep (pure)', () => {
const step = resolveNextStep(
comic,
[issue({ stages: { idea: ready(), comicScript: ready(VALID_SCRIPT) } })],
- { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, editorialChecksReviewed: true, editorialHealthReady: true },
+ { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, reverseOutlineRefreshed: true, editorialChecksReviewed: true, editorialHealthReady: true },
{ includeVisual: true, target: 'text' },
);
expect(step.kind).toBe('done');
@@ -335,7 +367,7 @@ describe('resolveNextStep (pure)', () => {
const step = resolveNextStep(
comic,
[issue({ stages: { idea: ready(), comicScript: ready(VALID_SCRIPT) } })],
- { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, editorialChecksReviewed: true, editorialHealthReady: true },
+ { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, reverseOutlineRefreshed: true, editorialChecksReviewed: true, editorialHealthReady: true },
{ includeVisual: true },
);
expect(step.kind).toBe('canonVerify');
@@ -345,7 +377,7 @@ describe('resolveNextStep (pure)', () => {
const step = resolveNextStep(
comic,
[issue({ stages: { idea: ready(), comicScript: ready(VALID_SCRIPT) } })],
- { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, editorialChecksReviewed: true, editorialHealthReady: true, canonVerified: true },
+ { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, reverseOutlineRefreshed: true, editorialChecksReviewed: true, editorialHealthReady: true, canonVerified: true },
{ includeVisual: true },
);
expect(step).toMatchObject({ kind: 'visualDraft', issueId: 'iss1' });
@@ -364,7 +396,7 @@ describe('resolveNextStep (pure)', () => {
const step = resolveNextStep(
comic,
[issue({ stages: renderedStages })],
- { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, editorialChecksReviewed: true, editorialHealthReady: true, canonVerified: true },
+ { arcVerified: true, beatContinuityChecked: true, scriptChecked: new Set(['iss1']), editorialReviewed: true, reverseOutlineRefreshed: true, editorialChecksReviewed: true, editorialHealthReady: true, canonVerified: true },
{ includeVisual: true },
);
expect(step.kind).toBe('done');
@@ -670,6 +702,59 @@ describe('autopilot conductor', () => {
expect(checkRunnerSpies.runEditorialChecks).not.toHaveBeenCalled();
});
+ it('refreshes the reverse outline before the checks when stale and a check consumes it (#1349)', async () => {
+ reverseOutlineConsumed = true;
+ reverseOutlineState = { status: 'complete', stale: true };
+ const { seriesId } = await seedComplete();
+ await autopilot.startSeriesAutopilot(seriesId, { includeVisual: false });
+ await waitFor(runFinished(seriesId));
+ expect(autopilot.__testing.runs.get(seriesId)?.lastPayload?.type).toBe('complete');
+ expect(generateReverseOutline).toHaveBeenCalledTimes(1);
+ // force:false lets the call no-op if the outline went fresh in the meantime.
+ expect(generateReverseOutline.mock.calls[0][1]).toMatchObject({ force: false });
+ });
+
+ it('skips the reverse-outline refresh when no enabled check consumes it (#1349)', async () => {
+ reverseOutlineConsumed = false; // gate 1: nothing reads the outline
+ reverseOutlineState = { status: 'complete', stale: true }; // stale, but unused
+ const { seriesId } = await seedComplete();
+ await autopilot.startSeriesAutopilot(seriesId, { includeVisual: false });
+ await waitFor(runFinished(seriesId));
+ expect(autopilot.__testing.runs.get(seriesId)?.lastPayload?.type).toBe('complete');
+ expect(generateReverseOutline).not.toHaveBeenCalled();
+ });
+
+ it('skips the reverse-outline refresh when nothing is drafted yet (#1349)', async () => {
+ reverseOutlineConsumed = true;
+ reverseOutlineState = { status: 'no-content' }; // gate 2: no manuscript to segment
+ const { seriesId } = await seedComplete();
+ await autopilot.startSeriesAutopilot(seriesId, { includeVisual: false });
+ await waitFor(runFinished(seriesId));
+ expect(autopilot.__testing.runs.get(seriesId)?.lastPayload?.type).toBe('complete');
+ expect(generateReverseOutline).not.toHaveBeenCalled();
+ });
+
+ it('bills a cos action only when the reverse outline actually regenerates (#1349)', async () => {
+ reverseOutlineConsumed = true;
+ // Fresh outline — the refresh step is a no-op and charges nothing.
+ reverseOutlineState = { status: 'complete', stale: false };
+ const a = await seedComplete();
+ await autopilot.startSeriesAutopilot(a.seriesId, { includeVisual: false });
+ await waitFor(runFinished(a.seriesId));
+ const freshCharges = recordDomainUsage.mock.calls.length;
+ expect(generateReverseOutline).not.toHaveBeenCalled();
+
+ recordDomainUsage.mockClear();
+ generateReverseOutline.mockClear();
+ // Same path, but a stale outline — exactly ONE extra cos action vs the fresh run.
+ reverseOutlineState = { status: 'complete', stale: true };
+ const b = await seedComplete();
+ await autopilot.startSeriesAutopilot(b.seriesId, { includeVisual: false });
+ await waitFor(runFinished(b.seriesId));
+ expect(generateReverseOutline).toHaveBeenCalledTimes(1);
+ expect(recordDomainUsage.mock.calls.length).toBe(freshCharges + 1);
+ });
+
it('pauses at the editorial health gate when a blocking finding remains open (#1316)', async () => {
const manuscriptReview = await import('./manuscriptReview.js');
// Completeness + checks converge clean, but the post-pass review still holds