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: estimate cos-action budget + LLM-call cost in autopilot dry-run plan (#1576)

[._.]/ Adam Eivy896d990c6994
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index e6ed45eb0b..43ea07aeee 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -55,6 +55,7 @@
- **[issue-1573] Series Autopilot now flags editorial checks that errored instead of reporting a silent "clean" run.** Each editorial check runs inside a boundary guard so one bad check (a malformed prompt, a provider timeout, a missing context) can't abort the whole pass — but a check that *threw* produced no findings, and the autopilot's per-pass broadcast always reported "0 blocking" and completed as if everything had run. A check that errored every run looked clean until someone inspected the raw per-check results. The editorial-checks round frame now carries an **errored count + the failing check ids**, and a run that finished with any errored check is qualified on the terminal summary and the persisted status banner (a caution, not "production-ready") so the partial failure is visible — the dimension that errored was never actually evaluated. The standalone "run editorial checks" panel surfaces the same errored aggregate on its completion frame. (`server/services/pipeline/seriesAutopilot.js`, `server/services/pipeline/editorial/checkRunner.js`, `server/services/pipeline/series.js`, `client/src/components/pipeline/AutopilotPanel.jsx`)
- **[issue-1574] Series Autopilot now retries a failed beats/text child run before giving up, instead of marking it attempted and silently skipping it.** When the autopilot delegates to a child runner (volume beats or per-issue text/scripts), the child can finish with its target stage still empty because the underlying LLM call failed. Previously the work was marked *attempted* before the result was inspected, so the resolver skipped it on the next pass — a failed beats run wasn't caught until a downstream stage tripped over the empty `idea`, and a failed text run only paused after the fact. The autopilot now **verifies the child actually produced its output** (every issue in the volume has a beat sheet / the issue's required script stages landed) and, on a miss, **retries the child once** (skip-existing, so the retry only fills the gap) before marking the work attempted. Each attempt is budget-gated and bills one action like any other step; if the output is still missing after the retry the run emits an escalation frame and **pauses for review with the missing stages as residual findings** rather than marching on toward a "done" with no script. A per-run **`maxChildRetries`** option tunes the retry budget (0 restores the legacy single-attempt behavior). (`server/services/pipeline/seriesAutopilot.js`)
- **[issue-1575] Series Autopilot can now run a subset of editorial checks for a single run, without touching the global enabled set.** The editorial-checks pass always ran *every* enabled check, so piloting one new check — or skipping an expensive one for a single run — meant toggling checks globally and remembering to flip them back. The autopilot start payload now accepts an optional **`editorialCheckIds`** array; when present, that run's editorial-checks pass evaluates only those check ids (unknown or disabled ids are ignored), and the same subset drives the budget gate so billing and execution agree on the set. Absent or empty falls back to the full enabled set (the unchanged default). The dry-run plan also names the subset (e.g. *"per-run subset of 2 editorial check(s)"*) instead of implying the whole enabled set will run. (`server/services/pipeline/seriesAutopilot.js`, `server/routes/pipeline/autopilot.js`)
+- **[issue-1576] The Series Autopilot dry-run plan now estimates its budget cost, so a large series on a small daily cap can be spotted before it burns through text generation and never reaches editorial.** The dry-run plan enumerated the steps it *would* run but gave no sense of how much of the daily CoS action budget they'd consume. Each planned step now carries an estimated **cos-action count** — the same unit the daily cap gates on (`recordDomainUsage('cos', …)`) — computed as an upper bound: convergence loops (arc verify, beat continuity, editorial review) counted at their max rounds (verify + resolve per round), per-item steps at one action per issue, and the pure gates that bill nothing (editorial health gate, canon verify) shown as zero-cost. The editorial-checks pass — which bills a single action but fans out to one LLM call per *issue × enabled LLM check* — additionally carries that **LLM-call estimate** (e.g. *"~18 LLM call(s)"* for a 9-issue series with 2 LLM checks). The plan panel shows each step's `≈N act` and an **Est. budget** footer totalling the run's actions and editorial-check LLM calls, on both the start and the terminal dry-run frame. (`server/services/pipeline/seriesAutopilot.js`, `client/src/components/pipeline/AutopilotPanel.jsx`)
## Providers
diff --git a/client/src/components/pipeline/AutopilotPanel.jsx b/client/src/components/pipeline/AutopilotPanel.jsx
index 9362bc7842..d7bf560072 100644
--- a/client/src/components/pipeline/AutopilotPanel.jsx
+++ b/client/src/components/pipeline/AutopilotPanel.jsx
@@ -146,6 +146,7 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdate
const [starting, setStarting] = useState(false);
const [mode, setMode] = useState(null);
const [plan, setPlan] = useState(null);
+ const [planTotals, setPlanTotals] = useState(null);
const [showOpts, setShowOpts] = useState(false);
const [includeVisual, setIncludeVisual] = useState(true);
const [fileGaps, setFileGaps] = useState(false);
@@ -236,8 +237,10 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdate
if (latest?.type === 'start') {
setMode(latest.mode || null);
if (Array.isArray(latest.plan)) setPlan(latest.plan);
+ if (latest.planTotals) setPlanTotals(latest.planTotals);
} else if (latest?.type === 'complete' && latest.dryRun && Array.isArray(latest.plan)) {
setPlan(latest.plan);
+ if (latest.planTotals) setPlanTotals(latest.planTotals);
}
}, [latest]);
@@ -263,6 +266,7 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdate
const start = useCallback(async () => {
setStarting(true);
setPlan(null);
+ setPlanTotals(null);
// Collect ONLY the gates the user edited (clamped, real values — never the
// display defaults of untouched gates, which would mask a saved setting). Send
// them as per-run overrides AND persist them: the override makes the edit
@@ -422,9 +426,24 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdate
{plan.map((p, i) => (
<li key={i} className="flex items-center gap-1.5">
<ChevronRight size={10} /> {stepLabel(p.kind)} ×{p.count}{p.note ? ` — ${p.note}` : ''}
+ {Number.isFinite(p.estActions) && p.estActions > 0 ? (
+ <span className="text-gray-500 ml-auto whitespace-nowrap">≈{p.estActions} act</span>
+ ) : null}
</li>
))}
</ul>
+ {/* #1576 — estimated budget cost so a large series on a small daily cap
+ can see, before starting, whether it will exhaust the cos action
+ budget on text/verify and never reach editorial. */}
+ {planTotals && (Number.isFinite(planTotals.estActions) || Number.isFinite(planTotals.estLlmCalls)) ? (
+ <div className="mt-1.5 pt-1.5 border-t border-port-border/60 text-gray-400 flex items-center gap-1.5">
+ <span className="uppercase tracking-wider text-gray-500">Est. budget</span>
+ <span className="ml-auto whitespace-nowrap">
+ ≈{planTotals.estActions || 0} cos action(s)
+ {planTotals.estLlmCalls ? ` · ~${planTotals.estLlmCalls} editorial-check LLM call(s)` : ''}
+ </span>
+ </div>
+ ) : null}
</div>
) : null}
diff --git a/client/src/components/pipeline/AutopilotPanel.test.jsx b/client/src/components/pipeline/AutopilotPanel.test.jsx
index be76e2761a..c94206034b 100644
--- a/client/src/components/pipeline/AutopilotPanel.test.jsx
+++ b/client/src/components/pipeline/AutopilotPanel.test.jsx
@@ -210,6 +210,19 @@ describe('AutopilotPanel', () => {
expect(screen.getByText(/Verifying arc/i)).toBeInTheDocument();
});
+ it('renders the estimated budget total from planTotals (#1576)', async () => {
+ sseLatest = {
+ type: 'complete', dryRun: true, runId: 'r1',
+ plan: [{ kind: 'verifyArc', count: 1, estActions: 5 }, { kind: 'editorialChecks', count: 1, estActions: 1, estLlmCalls: 6 }],
+ planTotals: { estActions: 6, estLlmCalls: 6 },
+ };
+ renderPanel({ id: 's1', targetFormat: 'comic' });
+ await waitFor(() => expect(getPipelineAutopilotStatus).toHaveBeenCalled());
+ expect(await screen.findByText(/Est\. budget/i)).toBeInTheDocument();
+ expect(screen.getByText(/≈6 cos action/i)).toBeInTheDocument();
+ expect(screen.getByText(/~6 editorial-check LLM call/i)).toBeInTheDocument();
+ });
+
it('renders canon readiness gaps with a link to the issue Nouns page', async () => {
getPipelineSeriesCanonReadiness.mockResolvedValue({
ready: false,
diff --git a/server/services/pipeline/seriesAutopilot.js b/server/services/pipeline/seriesAutopilot.js
index b7921a0525..eecc805384 100644
--- a/server/services/pipeline/seriesAutopilot.js
+++ b/server/services/pipeline/seriesAutopilot.js
@@ -207,6 +207,35 @@ function divergencePauseReason(gate, blockingCount, rounds) {
// Dry-run plan note for a bounded gate: "skipped (0 rounds)" or "up to N rounds".
const roundsNote = (rounds) => (rounds === 0 ? 'skipped (0 rounds)' : `up to ${rounds} rounds`);
+// Dry-run cost model (#1576) — each planned step carries an estimated
+// `estActions`: the number of cos actions it bills via recordDomainUsage('cos',
+// { actions }), i.e. the unit the daily budget cap gates on. Surfacing it lets a
+// user see, before starting, whether a large series will exhaust the cap on
+// text/verify and never reach editorial. Estimates are UPPER BOUNDS — convergence
+// loops counted at their max rounds (they usually converge sooner), per-item
+// steps at one action per item (retries excluded). A few steps cost nothing
+// against the cap (editorialHealthGate, canonVerify) and carry estActions: 0.
+//
+// A bounded verify→resolve convergence loop (arc, beat-continuity, editorial)
+// bills one action per verify plus one per resolve; the final round never
+// resolves (it converges or pauses). Upper bound: rounds verifies + (rounds-1)
+// resolves.
+const convergenceLoopActions = (rounds) => (rounds <= 0 ? 0 : 2 * rounds - 1);
+
+// Sum a dry-run plan's per-step estimates into run totals. `estActions` is the
+// budget-relevant total (cos daily-cap units); `estLlmCalls` aggregates the
+// check-pass fan-out (editorialChecks bills a single cos action but issues one
+// LLM call per issue×check). Pure — safe to call at broadcast time and in tests.
+function summarizePlanCost(plan) {
+ return (Array.isArray(plan) ? plan : []).reduce(
+ (acc, step) => ({
+ estActions: acc.estActions + (Number.isFinite(step?.estActions) ? step.estActions : 0),
+ estLlmCalls: acc.estLlmCalls + (Number.isFinite(step?.estLlmCalls) ? step.estLlmCalls : 0),
+ }),
+ { estActions: 0, estLlmCalls: 0 },
+ );
+}
+
// When true, a comic-target run with `includeVisual` proceeds past the text +
// editorial terminal into draft cover/page rendering (see runVisualDraft).
export const VISUAL_DRAFT_ENABLED = true;
@@ -1363,21 +1392,27 @@ async function dispatchStep(sId, step, record) {
// plan (counts of every unmet step) rather than returning only the next one —
// so it can't reuse the single-step resolver. Kept deliberately in sync by
// hand; they share the same predicates (textReady, isComicTarget, isStageReady).
-function buildDryRunPlan(series, issues, options) {
+// `costContext.editorialLlmCheckCount` (optional) is the resolved number of
+// enabled LLM-kind editorial checks for this run's subset — supplied by the
+// caller (which has loaded settings) so this stays a pure, synchronous function.
+// When provided it drives the editorialChecks step's estLlmCalls (issues × LLM
+// checks) and whether that pass bills a cos action at all; absent, the step
+// estimates a single LLM check.
+function buildDryRunPlan(series, issues, options, costContext = {}) {
const plan = [];
const ordered = orderedIssues(issues);
const seasons = Array.isArray(series?.seasons) ? [...series.seasons].sort(byNumber) : [];
// Mirror the resolver: generateArc runs when arc text is missing OR there are
// no volumes at all (an arc-only series), so a dry-run plan must show it too.
const noArc = !series?.arc?.logline && !series?.arc?.summary;
- if (noArc || seasons.length === 0) plan.push({ kind: 'generateArc', count: 1 });
+ if (noArc || seasons.length === 0) plan.push({ kind: 'generateArc', count: 1, estActions: 1 });
const emptySeasons = seasons.filter((s) => !ordered.some((i) => i.seasonId === s.id));
- if (emptySeasons.length) plan.push({ kind: 'generateEpisodes', count: emptySeasons.length });
+ if (emptySeasons.length) plan.push({ kind: 'generateEpisodes', count: emptySeasons.length, estActions: emptySeasons.length });
const arcRounds = Number.isInteger(options?.maxArcVerifyRounds) ? options.maxArcVerifyRounds : MAX_ARC_VERIFY_ROUNDS;
- plan.push({ kind: 'verifyArc', count: 1, note: roundsNote(arcRounds) });
+ plan.push({ kind: 'verifyArc', count: 1, note: roundsNote(arcRounds), estActions: convergenceLoopActions(arcRounds) });
const beatsNeeded = seasons.filter((s) =>
ordered.some((i) => i.seasonId === s.id && !isStageReady(i.stages?.idea))).length;
- if (beatsNeeded) plan.push({ kind: 'beatSheet', count: beatsNeeded });
+ if (beatsNeeded) plan.push({ kind: 'beatSheet', count: beatsNeeded, estActions: beatsNeeded });
// beatContinuity (#1510) runs once when the run will have a beat corpus to
// check: beats already exist, OR beatSheet will generate them this run. Mirror
// the resolver's `ordered.some(issueHasBeats)` gate (post-generation), so a
@@ -1386,31 +1421,54 @@ function buildDryRunPlan(series, issues, options) {
const bcRounds = Number.isInteger(options?.maxBeatContinuityRounds)
? options.maxBeatContinuityRounds
: MAX_BEAT_CONTINUITY_ROUNDS;
- plan.push({ kind: 'beatContinuity', count: 1, note: roundsNote(bcRounds) });
+ plan.push({ kind: 'beatContinuity', count: 1, note: roundsNote(bcRounds), estActions: convergenceLoopActions(bcRounds) });
}
const textNeeded = ordered.filter((i) => !textReady(i, series, options)).length;
- if (textNeeded) plan.push({ kind: 'textStages', count: textNeeded });
- if (wantsComic(series, options)) plan.push({ kind: 'scriptVerify', count: ordered.length });
+ if (textNeeded) plan.push({ kind: 'textStages', count: textNeeded, estActions: textNeeded });
+ if (wantsComic(series, options)) plan.push({ kind: 'scriptVerify', count: ordered.length, estActions: ordered.length });
const edRounds = Number.isInteger(options?.maxEditorialRounds) ? options.maxEditorialRounds : MAX_EDITORIAL_ROUNDS;
- plan.push({ kind: 'editorialReview', count: 1, note: roundsNote(edRounds) });
+ // Editorial review is a verify→auto-fix convergence loop like the arc gate, so
+ // the per-round estimate mirrors it (analyze + one resolve batch / round). The
+ // per-comment auto-fixes within a round bill additionally and scale with the
+ // number of blocking findings, which isn't knowable at plan time.
+ plan.push({ kind: 'editorialReview', count: 1, note: roundsNote(edRounds), estActions: convergenceLoopActions(edRounds) });
// maxEditorialRounds === 0 skips the whole editorial gate in execute mode
// (runEditorial marks editorialReviewed + editorialChecksReviewed +
// 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: 'reverseOutline', count: 1, note: 'refresh scene segmentation for editorial checks (#1349)', estActions: 1 });
// #1575 — when a per-run subset is set, the plan must say so rather than imply
// the full enabled set runs.
const editorialSubset = editorialSubsetIds(options);
- plan.push({ kind: 'editorialChecks', count: 1, note: editorialSubset
+ // The checks pass bills a single cos action (only when an LLM check runs) but
+ // fans out to one LLM call per issue × enabled LLM check — surface that fan-out
+ // as estLlmCalls so a large series's check cost is visible. When the caller
+ // didn't resolve the enabled-check count, assume one LLM check runs.
+ const llmCheckCount = Number.isInteger(costContext?.editorialLlmCheckCount)
+ ? costContext.editorialLlmCheckCount
+ : 1;
+ const estLlmCalls = ordered.length * llmCheckCount;
+ const checksNote = editorialSubset
? `per-run subset of ${editorialSubset.length} editorial check(s) (#1575)`
- : 'enabled editorial checks (#1284)' });
- plan.push({ kind: 'editorialHealthGate', count: 1, note: 'editorial health readiness gate (#1316)' });
+ : 'enabled editorial checks (#1284)';
+ plan.push({
+ kind: 'editorialChecks',
+ count: 1,
+ note: llmCheckCount > 0 ? `${checksNote} — ~${estLlmCalls} LLM call(s)` : checksNote,
+ estActions: llmCheckCount > 0 ? 1 : 0,
+ estLlmCalls,
+ });
+ plan.push({ kind: 'editorialHealthGate', count: 1, note: 'editorial health readiness gate (#1316)', estActions: 0 });
}
if (VISUAL_DRAFT_ENABLED && wantsVisual(options) && wantsComic(series, options)) {
- plan.push({ kind: 'canonVerify', count: 1, note: 'descriptive integrity of drawn nouns' });
+ // canonVerify runs an LLM pass but bills no cos action (token-only) — 0 budget.
+ plan.push({ kind: 'canonVerify', count: 1, note: 'descriptive integrity of drawn nouns (no budget cost)', estActions: 0 });
const visualNeeded = ordered.filter((i) => !visualReady(i)).length;
- if (visualNeeded) plan.push({ kind: 'visualDraft', count: visualNeeded, note: 'cover + back + all pages (draft)' });
+ // Each draft render bills one cos action: cover + back per issue, plus one per
+ // interior page. The interior-page count isn't known until the script parses,
+ // so the estimate counts the two covers and notes the per-page additions.
+ if (visualNeeded) plan.push({ kind: 'visualDraft', count: visualNeeded, note: 'cover + back + all pages (draft) — +1 action per interior page', estActions: visualNeeded * 2 });
}
return plan;
}
@@ -1499,14 +1557,21 @@ export async function startSeriesAutopilot(sId, options = {}) {
if (mode === 'dry-run') {
const series = await getSeries(sId);
const issues = await listIssues({ seriesId: sId });
- const plan = buildDryRunPlan(series, issues, runOptions);
- broadcast(sId, { type: 'start', runId, mode, target: series.targetFormat, plan });
+ // Resolve the enabled LLM-check count (#1576) so the plan's editorialChecks
+ // step can estimate its issues × checks LLM fan-out. Mirrors the actual
+ // pass: same subset (editorialSubsetIds) and same settings the checks read.
+ const settings = await getSettings().catch(() => null);
+ const checkPlan = await buildEditorialCheckPlan(sId, { checkIds: editorialSubsetIds(runOptions), settings }).catch(() => null);
+ const editorialLlmCheckCount = checkPlan ? checkPlan.checks.filter((c) => c.kind === 'llm').length : undefined;
+ const plan = buildDryRunPlan(series, issues, runOptions, { editorialLlmCheckCount });
+ const planTotals = summarizePlanCost(plan);
+ broadcast(sId, { type: 'start', runId, mode, target: series.targetFormat, plan, planTotals });
// Carry the plan on the terminal frame too: a dry-run emits start +
// complete synchronously, often before the client attaches, and
// attachSseClient replays only the LAST frame — so the plan would be
// lost if it lived solely on the start frame.
- broadcast(sId, { type: 'complete', runId, dryRun: true, steps: plan.length, plan, completedAt: new Date().toISOString() });
- console.log(`🧭 autopilot dry-run — series=${sId.slice(0, 12)} steps=${plan.length}`);
+ broadcast(sId, { type: 'complete', runId, dryRun: true, steps: plan.length, plan, planTotals, completedAt: new Date().toISOString() });
+ console.log(`🧭 autopilot dry-run — series=${sId.slice(0, 12)} steps=${plan.length} est≈${planTotals.estActions} action(s) ${planTotals.estLlmCalls} LLM call(s)`);
return;
}
@@ -1651,4 +1716,4 @@ export async function recoverStuckAutopilots() {
}
// Export internals for tests.
-export const __testing = { runs, buildDryRunPlan, providerOverrideOpts, providerIdOpts };
+export const __testing = { runs, buildDryRunPlan, summarizePlanCost, providerOverrideOpts, providerIdOpts };
diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.js
index 1836311780..5066da54f0 100644
--- a/server/services/pipeline/seriesAutopilot.test.js
+++ b/server/services/pipeline/seriesAutopilot.test.js
@@ -308,6 +308,74 @@ describe('resolveNextStep (pure)', () => {
expect(noteFor({ editorialCheckIds: [] })).toMatch(/enabled editorial checks/);
});
+ it('annotates every dry-run step with an estActions estimate (#1576)', () => {
+ 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: {} },
+ { id: 'i2', seasonId: 'se1', number: 2, arcPosition: 2, stages: {} },
+ ];
+ const plan = autopilot.__testing.buildDryRunPlan(series, issues, {});
+ // Every step carries a numeric estimate.
+ expect(plan.every((p) => Number.isFinite(p.estActions))).toBe(true);
+ const byKind = Object.fromEntries(plan.map((p) => [p.kind, p]));
+ // verifyArc: convergence loop at the default 3 rounds → 2*3-1 = 5 actions.
+ expect(byKind.verifyArc.estActions).toBe(5);
+ // textStages: one child action per not-yet-text-ready issue (2 here).
+ expect(byKind.textStages.estActions).toBe(2);
+ // Pure-gate steps that bill nothing against the cap are zero-cost.
+ expect(byKind.editorialHealthGate.estActions).toBe(0);
+ });
+
+ it('scales verify/editorial estActions with the per-run round caps (#1576)', () => {
+ 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 actionsFor = (opts, kind) => autopilot.__testing.buildDryRunPlan(series, issues, opts)
+ .find((p) => p.kind === kind)?.estActions;
+ // 0 rounds → the loop is skipped → 0 actions.
+ expect(actionsFor({ maxArcVerifyRounds: 0 }, 'verifyArc')).toBe(0);
+ // 1 round → a single verify, no resolve → 1 action.
+ expect(actionsFor({ maxArcVerifyRounds: 1 }, 'verifyArc')).toBe(1);
+ // 4 rounds → 4 verifies + 3 resolves → 7 actions.
+ expect(actionsFor({ maxArcVerifyRounds: 4 }, 'verifyArc')).toBe(7);
+ // Editorial review follows the same convergence shape.
+ expect(actionsFor({ maxEditorialRounds: 2 }, 'editorialReview')).toBe(3);
+ });
+
+ it('estimates editorialChecks LLM fan-out as issues × enabled LLM checks (#1576)', () => {
+ 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: {} },
+ { id: 'i2', seasonId: 'se1', number: 2, arcPosition: 2, stages: {} },
+ { id: 'i3', seasonId: 'se1', number: 3, arcPosition: 3, stages: {} },
+ ];
+ const stepFor = (ctx) => autopilot.__testing.buildDryRunPlan(series, issues, {}, ctx)
+ .find((p) => p.kind === 'editorialChecks');
+ // 2 enabled LLM checks × 3 issues = 6 LLM calls; the pass bills 1 cos action.
+ const two = stepFor({ editorialLlmCheckCount: 2 });
+ expect(two.estLlmCalls).toBe(6);
+ expect(two.estActions).toBe(1);
+ expect(two.note).toMatch(/~6 LLM call/);
+ // No enabled LLM check → no cos action billed and no LLM calls.
+ const none = stepFor({ editorialLlmCheckCount: 0 });
+ expect(none.estActions).toBe(0);
+ expect(none.estLlmCalls).toBe(0);
+ });
+
+ it('summarizePlanCost totals estActions and estLlmCalls across the plan (#1576)', () => {
+ 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 plan = autopilot.__testing.buildDryRunPlan(series, issues, {}, { editorialLlmCheckCount: 3 });
+ const totals = autopilot.__testing.summarizePlanCost(plan);
+ const manualActions = plan.reduce((s, p) => s + (p.estActions || 0), 0);
+ const manualLlm = plan.reduce((s, p) => s + (p.estLlmCalls || 0), 0);
+ expect(totals.estActions).toBe(manualActions);
+ expect(totals.estLlmCalls).toBe(manualLlm);
+ // Single issue × 3 LLM checks → 3 editorial-check LLM calls in the total.
+ expect(totals.estLlmCalls).toBe(3);
+ // A non-array (defensive) summarizes to zeroes.
+ expect(autopilot.__testing.summarizePlanCost(null)).toEqual({ estActions: 0, estLlmCalls: 0 });
+ });
+
it('asks to generate episodes for a season with no issues', () => {
const step = resolveNextStep(comic, []);
expect(step).toMatchObject({ kind: 'generateEpisodes', seasonId: 'se1' });