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
recover stuck editorial-review UI when the SSE stream dies without a terminal frame
[._.]/ Adam Eivy805afd0bc56e
diff --git a/client/src/pages/PipelineManuscriptEditor.jsx b/client/src/pages/PipelineManuscriptEditor.jsxindex 5652bd7bac..69d789492a 100644--- a/client/src/pages/PipelineManuscriptEditor.jsx+++ b/client/src/pages/PipelineManuscriptEditor.jsx@@ -205,8 +205,10 @@ export default function PipelineManuscriptEditor() {// Streamed generate-edits review — `reviewActive` gates the SSE subscription;// the latest frame drives the per-chunk button label. The terminal frame- // re-fetches the review (comments now carry pre-built fixes).- const { latest: reviewLatest } = usePipelineManuscriptCompletenessProgress(seriesId, { enabled: reviewActive });+ // re-fetches the review (comments now carry pre-built fixes). `closed` flips+ // true when the stream ends for ANY reason, including a non-terminal death+ // (attach 404, dropped connection) where no terminal frame ever arrives.+ const { latest: reviewLatest, closed: reviewClosed } = usePipelineManuscriptCompletenessProgress(seriesId, { enabled: reviewActive });// On mount, re-attach to an in-flight streamed run (e.g. after a reload mid-run).useEffect(() => {@@ -217,6 +219,22 @@ export default function PipelineManuscriptEditor() {return () => { canceled = true; };}, [seriesId]);+ // Re-fetch the persisted review after a streamed run lands (the runner seeds+ // it server-side; comments now carry pre-built fixes). `meta` populates the+ // chunk badge from the terminal frame when there was one.+ const reloadReviewAfterRun = (meta = null) =>+ getPipelineManuscriptReview(seriesId)+ .then((review) => {+ const next = Array.isArray(review?.comments) ? review.comments : [];+ setComments(next);+ if (meta) setReviewMeta({ chunked: !!meta.chunked, chunkCount: meta.chunkCount || 1 });+ const openCount = next.filter((c) => c.status === 'open').length;+ toast.success(meta?.chunked+ ? `Editorial review complete — ${openCount} open notes with drafted edits (reviewed in ${meta.chunkCount} chunks)`+ : `Editorial review complete — ${openCount} open notes with drafted edits`);+ })+ .catch((err) => toast.error(err.message || 'Failed to load review'));+// Terminal-frame handler for the streamed run: refresh comments + toast, then// tear the subscription down. Per-chunk frames only drive the button label.useEffect(() => {@@ -224,25 +242,25 @@ export default function PipelineManuscriptEditor() {const type = reviewLatest.type;if (type !== 'complete' && type !== 'canceled' && type !== 'error') return;setReviewActive(false);- if (type === 'complete') {- getPipelineManuscriptReview(seriesId)- .then((review) => {- const next = Array.isArray(review?.comments) ? review.comments : [];- setComments(next);- setReviewMeta({ chunked: !!reviewLatest.chunked, chunkCount: reviewLatest.chunkCount || 1 });- const openCount = next.filter((c) => c.status === 'open').length;- toast.success(reviewLatest.chunked- ? `Editorial review complete — ${openCount} open notes with drafted edits (reviewed in ${reviewLatest.chunkCount} chunks)`- : `Editorial review complete — ${openCount} open notes with drafted edits`);- })- .catch((err) => toast.error(err.message || 'Failed to load review'));- } else if (type === 'canceled') {- toast.success('Editorial review canceled');- } else {- toast.error(reviewLatest.error || 'Editorial review failed');- }+ if (type === 'complete') reloadReviewAfterRun(reviewLatest);+ else if (type === 'canceled') toast.success('Editorial review canceled');+ else toast.error(reviewLatest.error || 'Editorial review failed');+ // eslint-disable-next-line react-hooks/exhaustive-deps}, [reviewActive, reviewLatest, seriesId]);+ // Recovery: the stream died WITHOUT a terminal frame (attach 404, dropped+ // connection, server restart). Don't strand the UI with the Run button stuck+ // disabled — drop the active flag and re-fetch the review, since the runner+ // may have completed + seeded server-side even though we lost the stream.+ useEffect(() => {+ if (!reviewActive || !reviewClosed) return;+ const t = reviewLatest?.type;+ if (t === 'complete' || t === 'canceled' || t === 'error') return; // handled above+ setReviewActive(false);+ reloadReviewAfterRun();+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [reviewActive, reviewClosed, reviewLatest, seriesId]);+const startGenerateEditsReview = async (mode) => {setReviewStarting(true);const result = await startPipelineManuscriptCompleteness(seriesId, {diff --git a/client/src/pages/PipelineManuscriptEditor.test.jsx b/client/src/pages/PipelineManuscriptEditor.test.jsxindex 68ab806f5d..029384ee6b 100644--- a/client/src/pages/PipelineManuscriptEditor.test.jsx+++ b/client/src/pages/PipelineManuscriptEditor.test.jsx@@ -367,6 +367,10 @@ class MockEventSource {}close() { this.readyState = MockEventSource.CLOSED; }emit(payload) { this.onmessage?.({ data: JSON.stringify(payload) }); }+ // Simulate a non-terminal stream death (attach 404, dropped connection): the+ // hook flips `closed` true via onerror when readyState is CLOSED, with no+ // terminal frame ever delivered.+ fail() { this.readyState = MockEventSource.CLOSED; this.onerror?.(); }}MockEventSource.CONNECTING = 0;MockEventSource.OPEN = 1;@@ -430,4 +434,24 @@ describe('PipelineManuscriptEditor — generate-edits streamed review', () => {expect(screen.getByText('Accept')).toBeInTheDocument();expect(screen.queryByText('Generate fix')).not.toBeInTheDocument();});++ it('recovers when the SSE stream dies without a terminal frame (button re-enables, review re-fetched)', async () => {+ api.startPipelineManuscriptCompleteness.mockResolvedValue({ runId: 'cr-1', sseUrl: '/sse' });+ api.getPipelineManuscriptReview.mockResolvedValue({ schemaVersion: 1, comments: [comment] });+ renderEditor();+ await screen.findByText('My Series');++ fireEvent.click(screen.getByLabelText(/Generate edits for every finding/i));+ fireEvent.click(screen.getByText('Run editorial review'));+ await waitFor(() => expect(MockEventSource.instances.length).toBeGreaterThan(0));+ // Mid-run the button is disabled (busy) showing progress text.+ await screen.findByText(/Starting editorial review|Drafting edits/);++ // Connection drops with no complete/canceled/error frame.+ lastEs().fail();++ // Recovery: button re-enables (no longer stuck) and the review is re-fetched.+ expect(await screen.findByText('Run editorial review')).toBeInTheDocument();+ await waitFor(() => expect(api.getPipelineManuscriptReview).toHaveBeenCalledTimes(2));+ });});