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
feat: per-run readinessGate override for series autopilot (#1580)
[._.]/ Adam Eivy3451bac5faac
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex e40e9fb67e..7ec9979219 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -82,6 +82,7 @@- **[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', …)`) — leaning toward the high end: 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 review's per-comment auto-fixes bill extra and scale with the findings, which isn't knowable at plan time, so a heavy editorial pass can exceed its estimate.) The editorial-checks pass — which bills a single action but fans out to many LLM calls whose count depends on manuscript chunking — additionally carries a rough **LLM-call proxy** (*issues × enabled LLM checks*, 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`)+- **[issue-1580] Series Autopilot's editorial-health readiness gate can now be loosened or tightened for a single run, without editing global settings.** The gate that decides "manuscript clean" before drafting visuals (`noOpenHigh` by default, the stricter `noOpenHighOrMedium`, or `none` to skip it) only ever read the persisted setting — so a one-off "proceed to visuals with a looser gate" run meant changing the install-wide default, running, and remembering to change it back, exactly the friction `maxEditorialRounds` already avoids. The autopilot start payload now accepts an optional **`readinessGate`** that wins over the persisted setting for that run only (per-run override → persisted setting → default), resolved once at start and stamped onto the run so the loop, the dry-run plan, and a later Resume all agree on which gate applied. The dry-run plan's health-gate step now names the effective gate (e.g. *"gate: none"*). A new **Readiness gate** selector in the autopilot Options popover surfaces it in the UI — unlike the round inputs it is a per-run choice that does **not** persist, so a single looser/stricter run never touches your saved default (the selector shows what that saved default is). (`server/services/pipeline/seriesAutopilot.js`, `server/routes/pipeline/autopilot.js`, `client/src/components/pipeline/AutopilotPanel.jsx`)- **[issue-1578] Series Autopilot now streams per-check editorial progress, not just a single end-of-pass total.** The editorial-checks pass runs every enabled check across the manuscript and previously broadcast only one terminal frame — a total finding count with `0 blocking` — so during a long (issues × checks) pass the UI could show only "running" until the whole pass finished, with no signal about which check was executing or what it found. The autopilot now forwards the runner's **per-check `check:start` / `check:complete` frames** up its live progress stream, each carrying the check's label and a **high/medium/low severity breakdown** of that check's findings, so the panel shows real-time progress like *"Editorial check: Info dumping — 3 finding(s) (1H/2M/0L)"* as each check completes (errored and gated-skip checks are labeled distinctly). The same severity breakdown is now attached to each entry in the run's `perCheck` summary. (`server/services/pipeline/editorial/checkRunner.js`, `server/services/pipeline/seriesAutopilot.js`, `client/src/components/pipeline/AutopilotPanel.jsx`)## Providersdiff --git a/client/src/components/pipeline/AutopilotPanel.jsx b/client/src/components/pipeline/AutopilotPanel.jsxindex 51e0276951..1954770d0e 100644--- a/client/src/components/pipeline/AutopilotPanel.jsx+++ b/client/src/components/pipeline/AutopilotPanel.jsx@@ -25,6 +25,17 @@ const ROUND_MAX = 20;const DEFAULT_ARC_ROUNDS = 3;const DEFAULT_EDITORIAL_ROUNDS = 2;const DEFAULT_BEAT_CONTINUITY_ROUNDS = 2;++// Editorial-health readiness gate (#1316/#1580) — the "manuscript clean" bar the+// autopilot must clear before visuals. Mirrors READINESS_GATES on the server. The+// Options select sends a chosen gate as a PER-RUN override only (it does NOT+// persist, unlike the round inputs) so a one-off looser/stricter run never edits+// the install's saved default; '' means "use the saved default" and sends nothing.+const READINESS_GATE_LABELS = {+ noOpenHigh: 'No open High findings',+ noOpenHighOrMedium: 'No open High or Medium (strict)',+ none: 'None — skip the health gate',+};const clampRound = (n, fallback) => {// A blank/cleared field falls back to the default — NOT 0. (Number('') === 0,// and 0 means "skip the gate", so without this a cleared input would silently@@ -163,6 +174,11 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdateconst [arcRounds, setArcRounds] = useState(DEFAULT_ARC_ROUNDS);const [editorialRounds, setEditorialRounds] = useState(DEFAULT_EDITORIAL_ROUNDS);const [beatContinuityRounds, setBeatContinuityRounds] = useState(DEFAULT_BEAT_CONTINUITY_ROUNDS);+ // Per-run readiness-gate override (#1580). '' = use the saved default (send+ // nothing). `savedGate` is the persisted gate, shown in the "saved default"+ // option label so the user knows what the fallback is.+ const [readinessGate, setReadinessGate] = useState('');+ const [savedGate, setSavedGate] = useState('');// Per-field dirty flags. Until a field is edited its input shows a display// default we must NOT persist (that would clobber a higher saved setting on// the untouched gate). Tracked per-field so editing one gate never discards@@ -188,6 +204,8 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdateif (!arcEditedRef.current) setArcRounds(Number.isInteger(pec.maxArcVerifyRounds) ? pec.maxArcVerifyRounds : DEFAULT_ARC_ROUNDS);if (!editorialEditedRef.current) setEditorialRounds(Number.isInteger(pec.maxEditorialRounds) ? pec.maxEditorialRounds : DEFAULT_EDITORIAL_ROUNDS);if (!beatContinuityEditedRef.current) setBeatContinuityRounds(Number.isInteger(pec.maxBeatContinuityRounds) ? pec.maxBeatContinuityRounds : DEFAULT_BEAT_CONTINUITY_ROUNDS);+ // Persisted readiness gate — display-only, drives the "saved default" label.+ setSavedGate(READINESS_GATE_LABELS[pec.readinessGate] ? pec.readinessGate : '');}).catch(() => null); // load failed → inputs keep defaults but start() only persists EDITED fieldsreturn () => { canceled = true; };@@ -289,7 +307,11 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdateif (editorialEditedRef.current) roundOverrides.maxEditorialRounds = clampRound(editorialRounds, DEFAULT_EDITORIAL_ROUNDS);if (beatContinuityEditedRef.current) roundOverrides.maxBeatContinuityRounds = clampRound(beatContinuityRounds, DEFAULT_BEAT_CONTINUITY_ROUNDS);if (Object.keys(roundOverrides).length) await persistRounds(roundOverrides);- const res = await startPipelineAutopilot(seriesId, { includeVisual, fileGaps, ...roundOverrides }, { silent: true })+ // Per-run readiness-gate override (#1580): send it ONLY when the user picked a+ // specific gate. Unlike the round inputs we never persist it — '' leaves the+ // server to resolve the gate from the saved setting (then the default).+ const gateOverride = READINESS_GATE_LABELS[readinessGate] ? { readinessGate } : {};+ const res = await startPipelineAutopilot(seriesId, { includeVisual, fileGaps, ...roundOverrides, ...gateOverride }, { silent: true }).catch((err) => { toast.error(err.message || 'Could not start autopilot'); return null; });setStarting(false);if (!res) return;@@ -299,7 +321,7 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdate// effect can reject a stale terminal frame from the previous run.activeRunIdRef.current = res.runId || null;setActive(true);- }, [seriesId, includeVisual, fileGaps, arcRounds, editorialRounds, beatContinuityRounds, persistRounds]);+ }, [seriesId, includeVisual, fileGaps, arcRounds, editorialRounds, beatContinuityRounds, readinessGate, persistRounds]);const cancel = useCallback(async () => {await cancelPipelineAutopilot(seriesId).catch(() => null);@@ -404,6 +426,25 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdate<p className="text-[11px] text-gray-500">How many auto-resolve rounds each gate attempts before pausing for human review (0 skips the gate, max {ROUND_MAX}). Saved as the default and reused on Resume.</p>+ <div className="flex items-center gap-2 pt-1">+ <label htmlFor="autopilot-readiness-gate" className="text-xs text-gray-300">Readiness gate</label>+ <select+ id="autopilot-readiness-gate"+ value={readinessGate}+ onChange={(e) => setReadinessGate(e.target.value)}+ className="px-2 py-1 rounded text-xs bg-port-bg border border-port-border text-gray-200"+ >+ <option value="">+ Use saved default{savedGate ? ` (${READINESS_GATE_LABELS[savedGate]})` : ''}+ </option>+ {Object.entries(READINESS_GATE_LABELS).map(([value, label]) => (+ <option key={value} value={value}>{label}</option>+ ))}+ </select>+ </div>+ <p className="text-[11px] text-gray-500">+ The editorial-health bar this run must clear before drafting visuals. A per-run choice applies to this run only — it does not change the saved default.+ </p><p className="text-[11px] text-gray-500">Runs under the CoS auto-run autonomy domain. With it set to <em>dry-run</em>, this only previews the plan.</p>diff --git a/client/src/components/pipeline/AutopilotPanel.test.jsx b/client/src/components/pipeline/AutopilotPanel.test.jsxindex 5a034384d7..ef3baf0ed5 100644--- a/client/src/components/pipeline/AutopilotPanel.test.jsx+++ b/client/src/components/pipeline/AutopilotPanel.test.jsx@@ -103,6 +103,38 @@ describe('AutopilotPanel', () => {);});+ it('sends a chosen readiness gate as a per-run override without persisting it (#1580)', async () => {+ renderPanel({ id: 's1', targetFormat: 'comic' });+ await waitFor(() => expect(getPipelineAutopilotStatus).toHaveBeenCalled());+ fireEvent.click(screen.getByRole('button', { name: /options/i }));+ fireEvent.change(screen.getByLabelText('Readiness gate'), { target: { value: 'none' } });+ fireEvent.click(screen.getByRole('button', { name: /run autopilot/i }));+ await waitFor(() => expect(startPipelineAutopilot).toHaveBeenCalledWith(+ 's1', { includeVisual: true, fileGaps: false, readinessGate: 'none' }, { silent: true },+ ));+ // Per-run only — the gate is never persisted to settings.+ expect(patchSettingsSlice).not.toHaveBeenCalledWith(+ 'pipelineEditorialChecks',+ expect.objectContaining({ readinessGate: expect.anything() }),+ expect.anything(),+ );+ });++ it('omits readinessGate when left on the saved default (#1580)', async () => {+ getSettings.mockResolvedValue({ pipelineEditorialChecks: { readinessGate: 'noOpenHighOrMedium' } });+ renderPanel({ id: 's1', targetFormat: 'comic' });+ await waitFor(() => expect(getPipelineAutopilotStatus).toHaveBeenCalled());+ fireEvent.click(screen.getByRole('button', { name: /options/i }));+ // The saved default is surfaced in the "use saved default" option label.+ await waitFor(() => expect(screen.getByLabelText('Readiness gate')).toHaveValue(''));+ expect(screen.getByText(/Use saved default \(No open High or Medium/)).toBeInTheDocument();+ fireEvent.click(screen.getByRole('button', { name: /run autopilot/i }));+ // Nothing chosen → no readinessGate sent; server resolves from the setting.+ await waitFor(() => expect(startPipelineAutopilot).toHaveBeenCalledWith(+ 's1', { includeVisual: true, fileGaps: false }, { silent: true },+ ));+ });+it('clears to the default (not 0) when a round input is emptied', async () => {renderPanel({ id: 's1', targetFormat: 'comic' });await waitFor(() => expect(getPipelineAutopilotStatus).toHaveBeenCalled());diff --git a/server/routes/pipeline/autopilot.js b/server/routes/pipeline/autopilot.jsindex 13148c591b..cbec2f097a 100644--- a/server/routes/pipeline/autopilot.js+++ b/server/routes/pipeline/autopilot.js@@ -17,6 +17,7 @@ import { asyncHandler, ServerError } from '../../lib/errorHandler.js';import { validateRequest, MAX_CONVERGENCE_ROUNDS } from '../../lib/validation.js';import * as seriesSvc from '../../services/pipeline/series.js';import * as autopilot from '../../services/pipeline/seriesAutopilot.js';+import { READINESS_GATES } from '../../services/pipeline/editorialScore.js';import { mapServiceError, providerOverrideShape } from './shared.js';const router = Router();@@ -54,6 +55,12 @@ const autopilotStartSchema = z.object({// Absent/empty = run every enabled check (the default). Per-run only (no// persisted default); unknown/disabled ids are silently ignored by the runner.editorialCheckIds: z.array(z.string().min(1)).optional(),+ // Per-run editorial-health readiness gate override (#1580). When omitted, the+ // gate falls back to the persisted pipelineEditorialChecks.readinessGate, then+ // the service default — so loosening (or tightening) the "manuscript clean" bar+ // for one run no longer requires editing global settings. Enum shares the+ // canonical READINESS_GATES set so the API and the scorer can't drift.+ readinessGate: z.enum(READINESS_GATES).optional(),});router.post('/series/:id/autopilot/start', asyncHandler(async (req, res) => {diff --git a/server/services/pipeline/seriesAutopilot.js b/server/services/pipeline/seriesAutopilot.jsindex fc099de455..2b6bb06005 100644--- a/server/services/pipeline/seriesAutopilot.js+++ b/server/services/pipeline/seriesAutopilot.js@@ -94,7 +94,7 @@ import * as autoRunner from './autoRunner.js';import { seedReviewFromFindings, getReview } from './manuscriptReview.js';import { runEditorialChecks, buildEditorialCheckPlan, enabledChecksConsumeReverseOutline, summarizeCheckErrors } from './editorial/checkRunner.js';import { generateReverseOutline, getReverseOutline } from './reverseOutline.js';-import { computeHealth, openBlockers } from './editorialScore.js';+import { computeHealth, openBlockers, READINESS_GATES, resolveReadinessGate } from './editorialScore.js';import { getSettings } from '../settings.js';import { readReadinessGate } from '../../lib/editorial/index.js';import { generateManuscriptFix, acceptManuscriptFix } from './manuscriptFix.js';@@ -148,6 +148,18 @@ export function resolveAutopilotRounds(options = {}, settings = null) {};}+// Resolve the effective editorial-health readiness gate for a run (#1580): an+// explicit per-run option wins, then the persisted+// pipelineEditorialChecks.readinessGate, then null — the caller resolves null to+// DEFAULT_READINESS_GATE via resolveReadinessGate. Mirrors resolveAutopilotRounds+// so the gate is overridable per-run exactly like the round bounds; stamped onto+// the run options once at start so the loop, the dry-run plan, and a later resume+// all read the same effective gate.+export function resolveAutopilotReadinessGate(options = {}, settings = null) {+ if (READINESS_GATES.includes(options?.readinessGate)) return options.readinessGate;+ return readReadinessGate(settings);+}+// Per-gate copy for the non-convergence pause — shared by the arc-verify and// editorial loops so the two messages can't drift.const PAUSE_GATES = {@@ -1125,8 +1137,11 @@ async function runEditorialChecksPass(sId, record) {// fixes; remaining blockers need a human (or a re-run after edits).async function runEditorialHealthGate(sId, record) {if (record.cancelRequested) return { canceled: true };- const settings = await getSettings().catch(() => null);- const gate = readReadinessGate(settings) || undefined;+ // The effective gate (per-run override → persisted setting → null) was resolved+ // and stamped onto record.options at start (#1580), mirroring the round bounds —+ // so the loop and the dry-run plan can't disagree on which gate applied. null+ // falls through to DEFAULT_READINESS_GATE inside computeHealth/openBlockers.+ const gate = record.options.readinessGate || undefined;// Do NOT swallow a getReview error into an empty review — that would fail OPEN// (the gate would pass on a corrupt/unreadable store and let the run proceed to// visuals without verifying health). Let it bubble to the coordinator's@@ -1473,7 +1488,10 @@ function buildDryRunPlan(series, issues, options, costContext = {}) {estActions: llmCheckCount > 0 ? 1 : 0,estLlmCalls,});- plan.push({ kind: 'editorialHealthGate', count: 1, note: 'editorial health readiness gate (#1316)', estActions: 0 });+ // Surface the effective readiness gate (#1580) so a per-run override is+ // visible in the dry-run plan, mirroring how roundsNote exposes the bounds.+ const gate = resolveReadinessGate(options?.readinessGate);+ plan.push({ kind: 'editorialHealthGate', count: 1, note: `editorial health readiness gate (#1316) — gate: ${gate}`, estActions: 0 });}if (VISUAL_DRAFT_ENABLED && wantsVisual(options) && wantsComic(series, options)) {// canonVerify runs an LLM pass but bills no cos action (token-only) — 0 budget.@@ -1514,7 +1532,11 @@ export async function startSeriesAutopilot(sId, options = {}) {// effective values. A resume reuses this same path, so a raised persisted// setting takes effect on the next Resume without re-specifying it.const settings = await getSettings().catch(() => null);- const runOptions = { ...options, ...resolveAutopilotRounds(options, settings) };+ const runOptions = {+ ...options,+ ...resolveAutopilotRounds(options, settings),+ readinessGate: resolveAutopilotReadinessGate(options, settings),+ };if (existing) {// A finished run still in its replay window — evict it so this fresh rundiff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.jsindex 1576d32ec4..1bdedb17fa 100644--- a/server/services/pipeline/seriesAutopilot.test.js+++ b/server/services/pipeline/seriesAutopilot.test.js@@ -262,6 +262,25 @@ describe('resolveNextStep (pure)', () => {).maxArcVerifyRounds).toBe(MAX_ARC_VERIFY_ROUNDS);});+ it('resolveAutopilotReadinessGate: per-run option wins, else setting, else null (#1580)', () => {+ const { resolveAutopilotReadinessGate } = autopilot;+ // per-run override wins over a persisted setting+ expect(resolveAutopilotReadinessGate(+ { readinessGate: 'none' },+ { pipelineEditorialChecks: { readinessGate: 'noOpenHighOrMedium' } },+ )).toBe('none');+ // persisted setting fills in when no per-run override+ expect(resolveAutopilotReadinessGate({}, { pipelineEditorialChecks: { readinessGate: 'noOpenHighOrMedium' } }))+ .toBe('noOpenHighOrMedium');+ // null when neither is set — the caller resolves null to the default gate+ expect(resolveAutopilotReadinessGate({}, null)).toBeNull();+ // an invalid per-run gate falls through to the persisted setting+ expect(resolveAutopilotReadinessGate(+ { readinessGate: 'bogus' },+ { pipelineEditorialChecks: { readinessGate: 'none' } },+ )).toBe('none');+ });+it('regenerates the arc for an arc-only series with no volumes', () => {const arcOnly = { targetFormat: 'comic', arc: { logline: 'L', summary: 'S' }, seasons: [] };expect(resolveNextStep(arcOnly, []).kind).toBe('generateArc');@@ -376,6 +395,20 @@ describe('resolveNextStep (pure)', () => {expect(autopilot.__testing.summarizePlanCost(null)).toEqual({ estActions: 0, estLlmCalls: 0 });});+ it('dry-run plan surfaces the effective readiness gate on the health-gate step (#1580)', () => {+ 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 gateNote = (opts) => autopilot.__testing.buildDryRunPlan(series, issues, opts)+ .find((p) => p.kind === 'editorialHealthGate')?.note;+ // No override → the plan shows the default gate.+ expect(gateNote({})).toMatch(/gate: noOpenHigh$/);+ // A per-run override is reflected in the plan note.+ expect(gateNote({ readinessGate: 'none' })).toMatch(/gate: none$/);+ expect(gateNote({ readinessGate: 'noOpenHighOrMedium' })).toMatch(/gate: noOpenHighOrMedium$/);+ // An invalid gate falls through to the default.+ expect(gateNote({ readinessGate: 'bogus' })).toMatch(/gate: noOpenHigh$/);+ });+it('asks to generate episodes for a season with no issues', () => {const step = resolveNextStep(comic, []);expect(step).toMatchObject({ kind: 'generateEpisodes', seasonId: 'se1' });