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): arc-only series, mid-loop budget gate, paused-label null

[._.]/ Adam Eivy5f09edd5bb26
diff --git a/client/src/components/pipeline/AutopilotPanel.jsx b/client/src/components/pipeline/AutopilotPanel.jsx
index 5c02ff4e19..bedfa43020 100644
--- a/client/src/components/pipeline/AutopilotPanel.jsx
+++ b/client/src/components/pipeline/AutopilotPanel.jsx
@@ -278,7 +278,7 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdate
: ap.status === 'done' ? <CheckCircle2 size={13} className="text-port-success" />
: <AlertCircle size={13} className="text-port-error" />}
<span className={ap.status === 'paused' ? 'text-port-warning' : ap.status === 'done' ? 'text-port-success' : 'text-port-error'}>
- {ap.status === 'paused' ? `Paused at ${stepLabel(ap.currentStep)}` : ap.status === 'done' ? 'Last run completed — draft is production-ready' : 'Last run errored'}
+ {ap.status === 'paused' ? (ap.currentStep ? `Paused at ${stepLabel(ap.currentStep)}` : 'Paused') : ap.status === 'done' ? 'Last run completed — draft is production-ready' : 'Last run errored'}
</span>
</div>
{ap.lastError && ap.status !== 'done' ? <p className="text-[11px] text-gray-400 mt-1">{ap.lastError}</p> : null}
diff --git a/client/src/components/pipeline/AutopilotPanel.test.jsx b/client/src/components/pipeline/AutopilotPanel.test.jsx
index 20cf72fb0e..d103a0f24b 100644
--- a/client/src/components/pipeline/AutopilotPanel.test.jsx
+++ b/client/src/components/pipeline/AutopilotPanel.test.jsx
@@ -95,6 +95,13 @@ describe('AutopilotPanel', () => {
expect(screen.getByRole('button', { name: /stop/i })).toBeInTheDocument();
});
+ it('shows a generic Paused label when the marker has no current step', async () => {
+ renderPanel({ id: 's1', targetFormat: 'comic', autopilot: { status: 'paused', currentStep: null } });
+ await waitFor(() => expect(getPipelineAutopilotStatus).toHaveBeenCalled());
+ expect(screen.getByText('Paused')).toBeInTheDocument();
+ expect(screen.queryByText(/Paused at null/i)).not.toBeInTheDocument();
+ });
+
it('renders a dry-run plan delivered only on the terminal frame', async () => {
sseLatest = { type: 'complete', dryRun: true, runId: 'r1', plan: [{ kind: 'verifyArc', count: 1 }, { kind: 'visualDraft', count: 2, note: 'draft' }] };
renderPanel({ id: 's1', targetFormat: 'comic' });
diff --git a/server/services/pipeline/seriesAutopilot.js b/server/services/pipeline/seriesAutopilot.js
index a5887943ed..07d4860ec6 100644
--- a/server/services/pipeline/seriesAutopilot.js
+++ b/server/services/pipeline/seriesAutopilot.js
@@ -210,9 +210,15 @@ export function resolveNextStep(series, issues, runState = {}, options = {}) {
const seasons = Array.isArray(series?.seasons) ? [...series.seasons].sort(byNumber) : [];
const ordered = orderedIssues(issues);
- // STEP 1 — arc.
- if (!series?.arc?.logline && !series?.arc?.summary) {
- return { kind: 'generateArc', reason: 'series has no arc' };
+ // STEP 1 — arc. Also (re)generate when there are no seasons at all: an
+ // arc-only series (arc text present, seasons: []) has nothing for the
+ // episode/issue steps to expand, and would otherwise sail through verify/
+ // review of an empty issue list and be marked done with no volumes. The
+ // attempted-guard stops a re-loop if arc generation yields no seasons (the
+ // dispatch pauses in that case).
+ const noArc = !series?.arc?.logline && !series?.arc?.summary;
+ if (!runState.arcAttempted && (noArc || seasons.length === 0)) {
+ 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).
@@ -357,6 +363,18 @@ const providerIdOpts = (record) => ({
model: record.options.modelOverride,
});
+// Pause result when the cos action budget is exhausted, else null. Used to gate
+// EACH billable call inside the multi-call verify/editorial convergence loops —
+// the conductor's per-step budget check only fires once before the step, so
+// without this a single step could bill several actions past the daily cap.
+// gapFiled:true so a budget pause doesn't also file a generic stalled gap
+// (mirrors the conductor's own loop-level budget pause, which files none).
+async function budgetPause() {
+ const budget = await getDomainBudgetStatus('cos');
+ if (budget.withinBudget) return null;
+ return { pause: true, gapFiled: true, reason: `daily cos ${budget.exceeded || 'actions'} budget reached` };
+}
+
// ---------------------------------------------------------------------------
// Step dispatch.
// ---------------------------------------------------------------------------
@@ -379,6 +397,8 @@ async function runArcVerify(seriesId, record) {
}
for (let round = 1; round <= maxRounds; round += 1) {
if (record.cancelRequested) return { canceled: true };
+ const beforeVerify = await budgetPause();
+ if (beforeVerify) return beforeVerify;
const { issues } = await verifyArc(seriesId, providerOverrideOpts(record));
await recordDomainUsage('cos', { actions: 1 });
const blocking = issues.filter((i) => ARC_BLOCKING.has(i.severity));
@@ -393,6 +413,10 @@ async function runArcVerify(seriesId, record) {
return { pause: true, reason: `arc verification did not converge after ${maxRounds} rounds`, residual: blocking };
}
if (record.cancelRequested) return { canceled: true };
+ // resolveVerifyIssues bills another action — recheck the budget so a single
+ // step can't overspend the daily cap mid-loop.
+ const beforeResolve = await budgetPause();
+ if (beforeResolve) return beforeResolve;
await resolveVerifyIssues(seriesId, { findings: blocking, ...providerOverrideOpts(record) });
await recordDomainUsage('cos', { actions: 1 });
}
@@ -508,6 +532,8 @@ async function runEditorial(sId, record) {
}
for (let round = 1; round <= maxRounds; round += 1) {
if (record.cancelRequested) return { canceled: true };
+ const beforeAnalyze = await budgetPause();
+ if (beforeAnalyze) return beforeAnalyze;
const { issues, runId } = await analyzeManuscriptCompleteness(sId, {
withEdits: true,
...providerOverrideOpts(record),
@@ -532,6 +558,8 @@ async function runEditorial(sId, record) {
// Bounded auto-fix: apply a fix for each open high-severity comment, then
// the loop re-analyzes. Each fix is wrapped so one bad anchor doesn't abort
// the pass (boundary use of try/catch — these call into LLM/file paths).
+ const beforeFix = await budgetPause();
+ if (beforeFix) return beforeFix;
const review = await getReview(sId).catch(() => ({ comments: [] }));
const open = (review.comments || []).filter((c) => c.status === 'open' && EDITORIAL_BLOCKING.has(c.severity));
for (const comment of open) {
@@ -721,10 +749,21 @@ async function runCanonVerify(sId, record) {
async function dispatchStep(sId, step, record) {
switch (step.kind) {
case 'generateArc': {
+ // Mark attempted up front so the resolver won't re-route here if arc
+ // generation yields no seasons (avoids an infinite generateArc loop).
+ record.runState.arcAttempted = true;
const r = await generateArcOverview(sId, providerOverrideOpts(record));
- const cur = await getSeries(sId);
- await commitSeasonsWithRemap(cur, { arc: r.arc, seasons: r.seasons });
+ const committed = await commitSeasonsWithRemap(await getSeries(sId), { arc: r.arc, seasons: r.seasons });
await recordDomainUsage('cos', { actions: 1 });
+ const seasonCount = committed?.series?.seasons?.length ?? (await getSeries(sId)).seasons?.length ?? 0;
+ if (seasonCount === 0) {
+ // No specific gap filed here — let the conductor file generateArc-stalled.
+ return {
+ pause: true,
+ reason: 'arc generation produced no volumes — cannot create issues; review the series bible and regenerate the arc',
+ residual: [{ severity: 'high', location: 'arc', problem: 'arc overview returned zero seasons/volumes' }],
+ };
+ }
return {};
}
case 'generateEpisodes': {
@@ -824,6 +863,7 @@ export async function startSeriesAutopilot(sId, options = {}) {
mode,
options,
runState: {
+ arcAttempted: false,
arcVerified: false,
editorialReviewed: false,
canonVerified: false,
diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.js
index 60ad776f10..e32b31c217 100644
--- a/server/services/pipeline/seriesAutopilot.test.js
+++ b/server/services/pipeline/seriesAutopilot.test.js
@@ -97,6 +97,9 @@ const checkSeriesCanonReadiness = vi.fn(async (seriesId) => ({
}));
vi.mock('./canonReadiness.js', () => ({ checkSeriesCanonReadiness }));
+// Mocked domainUsage binding, so a test can drive the budget per call.
+const { getDomainBudgetStatus } = await import('../domainUsage.js');
+
// Real services + the unit under test (imported AFTER the mocks above).
const seriesSvc = await import('./series.js');
const seasonsSvc = await import('./seasons.js');
@@ -133,6 +136,9 @@ beforeEach(() => {
nextTaskId = 0;
autopilot.__testing.runs.clear();
vi.clearAllMocks();
+ // 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);
});
// ---------------------------------------------------------------------------
@@ -147,10 +153,20 @@ describe('resolveNextStep (pure)', () => {
});
it('treats a present arc summary (no logline) as having an arc', () => {
- const step = resolveNextStep({ targetFormat: 'comic', arc: { summary: 'S' }, seasons: [] }, []);
+ const step = resolveNextStep(
+ { targetFormat: 'comic', arc: { summary: 'S' }, seasons: [{ id: 'se1', number: 1 }] },
+ [{ id: 'i1', seasonId: 'se1', number: 1, arcPosition: 1, stages: {} }],
+ );
expect(step.kind).not.toBe('generateArc');
});
+ 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');
+ // once arc generation has been attempted, it does not re-loop into generateArc
+ expect(resolveNextStep(arcOnly, [], { arcAttempted: true }).kind).not.toBe('generateArc');
+ });
+
it('asks to generate episodes for a season with no issues', () => {
const step = resolveNextStep(comic, []);
expect(step).toMatchObject({ kind: 'generateEpisodes', seasonId: 'se1' });
@@ -370,6 +386,38 @@ describe('autopilot conductor', () => {
expect(series.autopilot?.residualFindings?.[0]?.problem).toBe('plot hole');
});
+ 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
+ // generateArcOverview mock returns seasons:[] → commit yields no volumes.
+ 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('generateArc');
+ expect(last?.reason).toMatch(/no volumes/);
+ expect(arcSpies.generateArcOverview).toHaveBeenCalledTimes(1); // not looping
+ });
+
+ it('rechecks budget mid arc-verify loop and pauses before resolveVerifyIssues', async () => {
+ verifyFindings = [{ severity: 'high', problem: 'x' }];
+ // Budget is fine until verifyArc has run once, then exhausted — so the
+ // pre-resolve recheck must pause instead of billing resolveVerifyIssues.
+ getDomainBudgetStatus.mockImplementation(async () => (
+ arcSpies.verifyArc.mock.calls.length >= 1
+ ? { withinBudget: false, exceeded: 'actions' }
+ : { withinBudget: true, exceeded: null }
+ ));
+ const { seriesId } = await seedComplete();
+ await autopilot.startSeriesAutopilot(seriesId, { maxArcVerifyRounds: 3 });
+ await waitFor(runFinished(seriesId));
+ const last = autopilot.__testing.runs.get(seriesId)?.lastPayload;
+ expect(last?.type).toBe('paused');
+ expect(last?.reason).toMatch(/budget/);
+ expect(arcSpies.verifyArc).toHaveBeenCalledTimes(1);
+ expect(arcSpies.resolveVerifyIssues).not.toHaveBeenCalled();
+ });
+
it('pauses when the cos daily budget is exhausted', async () => {
budgetStatus = { withinBudget: false, exceeded: 'actions' };
const { seriesId } = await seedComplete();