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
fix: block the next manuscript mutation while a kept draft is unsaved (#9954)
Adam Eivy45127bb558ce
diff --git a/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx b/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsxindex fc05828ff7..a78f9469c2 100644--- a/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx+++ b/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx@@ -98,11 +98,12 @@ export default function ManuscriptImpactPreview({ open, onClose, seriesId, sectifor (const target of targets) {// Settle + snapshot the touched sections per member: a draft typed while an// earlier member was in flight is saved first, and a keystroke typed during- // this one survives its response (#9954). A save failure stops the batch.+ // this one survives its response (#9954). A failed save, or a draft kept+ // over an earlier member's change, stops the batch.const snapshot = onBeginMutation ? await onBeginMutation(sectionKeysOf(target.edits)) : undefined;if (!mountedRef.current) return;if (snapshot === null) {- errors.push('an unsaved edit could not be saved first');+ errors.push('a section has an unsaved or kept draft to resolve first');break;}const result = await acceptPipelineManuscriptFix(seriesId, target.comment.id, { edits: target.edits }, { silent: true })diff --git a/client/src/pages/PipelineManuscriptEditor.jsx b/client/src/pages/PipelineManuscriptEditor.jsxindex ac6a97dbcf..42d5bb2d93 100644--- a/client/src/pages/PipelineManuscriptEditor.jsx+++ b/client/src/pages/PipelineManuscriptEditor.jsx@@ -593,8 +593,19 @@ export default function PipelineManuscriptEditor() {// adoptSectionResult — the server's text becomes the saved baseline; it// replaces the editable buffer only if that buffer is still exactly what// the mutation started from. A newer draft is kept (dirty against the new- // baseline) and is NOT auto-saved over the server change.+ // baseline) and is NOT auto-saved over the server change — so a kept draft+ // also blocks the next mutation on its section until the writer has dealt+ // with it, because settling it first would save it over that change.+ const retainedDrafts = useRef(new Set());const beginSectionMutation = async (keys = null) => {+ for (const key of [...retainedDrafts.current]) {+ const live = liveSectionsRef.current.find((s) => baselineKey(s) === key);+ if (!live || !isSectionDirty(baselineRef.current, live)) retainedDrafts.current.delete(key);+ else if (!keys || keys.includes(key)) {+ toast('Not applied — review and save your kept draft first; this action would otherwise save it over the earlier server change');+ return null;+ }+ }if (!(await flushPendingSectionSaves(keys))) {toast('Not applied — your unsaved edit could not be saved first');return null;@@ -610,9 +621,11 @@ export default function PipelineManuscriptEditor() {|| (snapshot?.has(key) && snapshot.get(key) !== live.content));setBaseline(key, content);if (retain) {+ retainedDrafts.current.add(key);patchSection(issueId, { versions });return true;}+ retainedDrafts.current.delete(key);patchSection(issueId, { content, versions });setSaveState((prev) => ({ ...prev, [issueId]: 'saved' }));return false;diff --git a/client/src/pages/PipelineManuscriptEditor.test.jsx b/client/src/pages/PipelineManuscriptEditor.test.jsxindex 4828d9713b..5e92070b4f 100644--- a/client/src/pages/PipelineManuscriptEditor.test.jsx+++ b/client/src/pages/PipelineManuscriptEditor.test.jsx@@ -866,14 +866,39 @@ describe('PipelineManuscriptEditor — mutation responses vs newer edits (#9954)expect(dirtyBadge()).not.toBeInTheDocument();});- it('saves an unblurred draft before reverting, and aborts the revert when that save fails', async () => {- api.savePipelineManuscriptSection.mockRejectedValue(new Error('disk full'));+ it('does not auto-save a kept draft over the server change: the next revert is blocked until it is saved', async () => {+ const restore = mockRestore();+ api.savePipelineManuscriptSection.mockResolvedValue({+ section: section(`${BASE} More.`, { versions: [{ runId: 'v1', createdAt: 't' }] }),+ });+ const toast = (await import('../components/ui/Toast')).default;renderEditor();const ta = await screen.findByDisplayValue(BASE);await openVersionsAndRevert();- await act(async () => {});- // First click above ran with a clean buffer; make a draft, then retry.+ await waitFor(() => expect(api.restorePipelineStageVersion).toHaveBeenCalled());+ fireEvent.change(ta, { target: { value: `${BASE} More.` } });+ await act(async () => { restore.resolveWith(); });api.restorePipelineStageVersion.mockClear();++ fireEvent.click(screen.getByRole('button', { name: /Revert/ }));+ await act(async () => {});+ expect(api.restorePipelineStageVersion).not.toHaveBeenCalled();+ expect(api.savePipelineManuscriptSection).not.toHaveBeenCalled();+ expect(toast).toHaveBeenCalledWith(expect.stringMatching(/kept draft/));++ // Once the writer saves it themselves the block lifts.+ fireEvent.blur(ta);+ await waitFor(() => expect(dirtyBadge()).not.toBeInTheDocument());+ mockRestore();+ fireEvent.click(screen.getByRole('button', { name: /Revert/ }));+ await waitFor(() => expect(api.restorePipelineStageVersion).toHaveBeenCalled());+ });++ it('saves an unblurred draft before reverting, and aborts the revert when that save fails', async () => {+ api.savePipelineManuscriptSection.mockRejectedValue(new Error('disk full'));+ renderEditor();+ const ta = await screen.findByDisplayValue(BASE);+ fireEvent.click(await screen.findByTitle('Show prior saved versions'));fireEvent.change(ta, { target: { value: `${BASE} Draft.` } });fireEvent.click(screen.getByRole('button', { name: /Revert/ }));