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
address review (codex): pause on empty text stages, ignore stale terminal SSE frame
[._.]/ Adam Eivy1183841dd9a8
diff --git a/client/src/components/pipeline/AutopilotPanel.jsx b/client/src/components/pipeline/AutopilotPanel.jsxindex 5aac375f03..01e274b589 100644--- a/client/src/components/pipeline/AutopilotPanel.jsx+++ b/client/src/components/pipeline/AutopilotPanel.jsx@@ -100,13 +100,22 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdateconst onIssuesUpdateRef = useRef(onIssuesUpdate);onSeriesUpdateRef.current = onSeriesUpdate;onIssuesUpdateRef.current = onIssuesUpdate;+ // The runId of the run THIS panel is currently tracking. After a run ends,+ // useSseProgress leaves the terminal frame in `latest`; without this guard a+ // fresh Run/Resume would see that stale terminal frame and immediately tear+ // the new run down. Terminal frames whose runId doesn't match are ignored.+ const activeRunIdRef = useRef(null);// Re-attach to an in-flight run on (re)mount.useEffect(() => {if (!seriesId) return undefined;let canceled = false;getPipelineAutopilotStatus(seriesId, { silent: true })- .then((s) => { if (!canceled && s?.active) setActive(true); })+ .then((s) => {+ if (canceled || !s?.active) return;+ activeRunIdRef.current = s.autopilot?.runId || null;+ setActive(true);+ }).catch(() => null);return () => { canceled = true; };}, [seriesId]);@@ -122,6 +131,8 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdate// Run-ended handling: refresh series (for the marker) + issues, toast outcome.useEffect(() => {if (!active || !latest || !RUN_ENDED.has(latest.type)) return;+ // Ignore a terminal frame left over from a previous run (stale `latest`).+ if (activeRunIdRef.current && latest.runId && latest.runId !== activeRunIdRef.current) return;setActive(false);getPipelineSeries(seriesId, { silent: true }).then((s) => { if (s) onSeriesUpdateRef.current?.(s); }).catch(() => null);listPipelineIssues(seriesId, { silent: true }).then((is) => onIssuesUpdateRef.current?.(Array.isArray(is) ? is : [])).catch(() => null);@@ -140,6 +151,9 @@ export default function AutopilotPanel({ series, onSeriesUpdate, onIssuesUpdateif (!res) return;setMode(res.mode || null);setShowOpts(false);+ // Track this run's id BEFORE enabling the stream so the terminal-frame+ // effect can reject a stale terminal frame from the previous run.+ activeRunIdRef.current = res.runId || null;setActive(true);}, [seriesId, includeVisual, fileGaps]);diff --git a/client/src/components/pipeline/AutopilotPanel.test.jsx b/client/src/components/pipeline/AutopilotPanel.test.jsxindex 24bb6ee1d2..a9bb3588d4 100644--- a/client/src/components/pipeline/AutopilotPanel.test.jsx+++ b/client/src/components/pipeline/AutopilotPanel.test.jsx@@ -12,9 +12,12 @@ vi.mock('../../services/api', () => ({listPipelineIssues: vi.fn(),}));vi.mock('../ui/Toast', () => ({ default: { success: vi.fn(), error: vi.fn(), warning: vi.fn() } }));-// Keep the SSE hook inert so tests don't touch EventSource.+// Controllable SSE hook so tests don't touch EventSource. `sseLatest` lets a+// test simulate a stale terminal frame left over from a previous run.+let sseLatest = null;+let sseFrames = [];vi.mock('../../hooks/usePipelineProgress', () => ({- usePipelineProgress: () => ({ latest: null, frames: [] }),+ usePipelineProgress: () => ({ latest: sseLatest, frames: sseFrames }),}));import {@@ -22,6 +25,7 @@ import {getPipelineAutopilotStatus,getPipelineSeriesCanonReadiness,} from '../../services/api';+import toast from '../ui/Toast';import AutopilotPanel from './AutopilotPanel';const renderPanel = (series, props = {}) =>@@ -33,6 +37,8 @@ const renderPanel = (series, props = {}) =>beforeEach(() => {vi.clearAllMocks();+ sseLatest = null;+ sseFrames = [];getPipelineAutopilotStatus.mockResolvedValue({ autopilot: null, active: false });startPipelineAutopilot.mockResolvedValue({ runId: 'r1', mode: 'execute', alreadyRunning: false });});@@ -77,6 +83,18 @@ describe('AutopilotPanel', () => {expect(screen.getByRole('button', { name: /resume autopilot/i })).toBeInTheDocument();});+ it('ignores a stale terminal frame from a previous run when starting again', async () => {+ startPipelineAutopilot.mockResolvedValue({ runId: 'B', mode: 'execute' });+ sseLatest = { type: 'complete', runId: 'A' }; // leftover terminal frame from run A+ renderPanel({ id: 's1', targetFormat: 'comic' });+ await waitFor(() => expect(getPipelineAutopilotStatus).toHaveBeenCalled());+ fireEvent.click(screen.getByRole('button', { name: /run autopilot/i }));+ await waitFor(() => expect(startPipelineAutopilot).toHaveBeenCalled());+ // The stale complete(A) must NOT end the new run B.+ expect(toast.success).not.toHaveBeenCalled();+ expect(screen.getByRole('button', { name: /stop/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.jsindex 276ed1b4c8..2aa27885de 100644--- a/server/services/pipeline/seriesAutopilot.js+++ b/server/services/pipeline/seriesAutopilot.js@@ -421,15 +421,31 @@ const runBeats = (seriesId, seasonId, record) => runChildToCompletion(record, {isActive: volumeBeatsRunner.isVolumeBeatsRunActive,});-const runText = (issueId, record) => runChildToCompletion(record, {- attemptedSet: record.runState.textAttempted,- kind: 'text',- id: issueId,+async function runText(issueId, record) {+ record.runState.textAttempted.add(issueId);// Forward the run's provider/model override so prose + scripts honor it like// every other step (autoRunner threads these into generateStage).- start: () => autoRunner.startAutoRunTextStages(issueId, { force: false, ...providerIdOpts(record) }),- isActive: autoRunner.isAutoRunActive,-});+ await autoRunner.startAutoRunTextStages(issueId, { force: false, ...providerIdOpts(record) });+ record.activeChild = { kind: 'text', id: issueId };+ await waitForChild(() => autoRunner.isAutoRunActive(issueId), record);+ record.activeChild = null;+ await recordDomainUsage('cos', { actions: 1 });+ // A delegated text run can end with required stages still empty (the child's+ // LLM call failed). The issue is already marked attempted, so the resolver+ // would skip it and the run could reach 'done' with no script — verify the+ // required stages landed and pause for review if they didn't.+ const issue = await getIssue(issueId);+ const series = await getSeries(issue.seriesId).catch(() => null);+ if (!textReady(issue, series)) {+ const missing = requiredScriptStages(series).filter((s) => !isStageReady(issue.stages?.[s]));+ return {+ pause: true,+ reason: `text generation for issue ${issue.number ?? issueId} did not produce required stage(s): ${missing.join(', ')}`,+ residual: missing.map((s) => ({ severity: 'high', location: `issue ${issue.number ?? '?'} / ${s}`, problem: 'stage is still empty after the text run (likely an LLM failure)' })),+ };+ }+ return {};+}async function runScriptVerify(sId, issueId, record) {record.runState.scriptChecked.add(issueId);diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.jsindex dd137edaf5..428e196c3a 100644--- a/server/services/pipeline/seriesAutopilot.test.js+++ b/server/services/pipeline/seriesAutopilot.test.js@@ -453,6 +453,22 @@ describe('autopilot conductor', () => {expect(last?.type).toBe('complete'); // gap filed, run still finishes});+ it('pauses when a delegated text run leaves required stages empty', async () => {+ // idea ready but comicScript missing → resolver routes textStages; the+ // autoRunner mock is a no-op so comicScript stays empty after the run.+ const series = await seriesSvc.createSeries({ name: 'S', logline: 'L', premise: 'P', targetFormat: 'comic' });+ await seriesSvc.updateSeries(series.id, { arc: { logline: 'A', summary: 'S' } });+ const season = await seasonsSvc.createSeason(series.id, { number: 1, title: 'V1' });+ const issue = await issuesSvc.createIssue({ seriesId: series.id, seasonId: season.id, title: 'I1', number: 1 });+ await issuesSvc.updateStage(issue.id, 'idea', ready('beats'));+ 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('textStages');+ expect(last?.reason).toMatch(/comicScript/);+ });+it('does not file gap tasks when fileGaps is off', async () => {const { seriesId } = await seedComplete({ script: 'just prose, no comic pages here' });await autopilot.startSeriesAutopilot(seriesId, { includeVisual: false });