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

fix: drain queued manuscript saves before a format switch, not just dirty ones (#3399)

[._.]/ Adam Eivy0acb4ce300be
diff --git a/client/src/pages/PipelineManuscriptEditor.jsx b/client/src/pages/PipelineManuscriptEditor.jsx
index 517036951c..662b63f4c6 100644
--- a/client/src/pages/PipelineManuscriptEditor.jsx
+++ b/client/src/pages/PipelineManuscriptEditor.jsx
@@ -480,6 +480,14 @@ export default function PipelineManuscriptEditor() {
// rather than discarding the user's text — `undefined` means the save was a
// no-op (an in-flight save already persisted it), which is not a failure.
const flushPendingSectionSaves = async () => {
+ // Drain what's already queued first: a section can be mid-save while its
+ // live text happens to match the baseline (typed, blurred, then typed back),
+ // which reads as "clean" — switching formats under that in-flight save would
+ // swap `sections` out from under it and land its result on the new format's
+ // badge. Re-derive dirty afterwards, so a queued save that FAILED shows up
+ // here and gets retried rather than silently passing the gate.
+ const queued = [...pendingSaves.current.values()];
+ if (queued.length) await Promise.all(queued);
const dirty = liveSectionsRef.current.filter((s) => isSectionDirty(baselineRef.current, s));
if (dirty.length === 0) return true;
const results = await Promise.all(dirty.map((s) => saveSectionContent(s, s.content)));
diff --git a/client/src/pages/PipelineManuscriptEditor.test.jsx b/client/src/pages/PipelineManuscriptEditor.test.jsx
index 016030b01a..3b056becae 100644
--- a/client/src/pages/PipelineManuscriptEditor.test.jsx
+++ b/client/src/pages/PipelineManuscriptEditor.test.jsx
@@ -340,6 +340,31 @@ describe('PipelineManuscriptEditor', () => {
);
});
+ it('waits out an in-flight save whose text was typed back to the baseline (#3399)', async () => {
+ mockBothFormats();
+ const original = 'The hero walked in. She left.';
+ let resolveFirst;
+ api.savePipelineManuscriptSection.mockImplementationOnce(() => new Promise((res) => { resolveFirst = res; }));
+ renderEditor();
+ const ta = await screen.findByDisplayValue(original);
+ fireEvent.change(ta, { target: { value: 'edited' } });
+ fireEvent.blur(ta);
+ await waitFor(() => expect(api.savePipelineManuscriptSection).toHaveBeenCalledTimes(1));
+
+ // Typed back to the saved text: the section now reads CLEAN, but its save is
+ // still in flight — switching formats here would swap `sections` out from
+ // under it and land its result on the incoming format.
+ fireEvent.change(ta, { target: { value: original } });
+ fireEvent.click(screen.getByText('Teleplay'));
+ await act(async () => {});
+ expect(api.getPipelineManuscript).not.toHaveBeenCalledWith('ser-1', 'teleplay', { silent: true });
+
+ await act(async () => {
+ resolveFirst({ section: { issueId: 'iss-1', number: 1, title: 'One', stageId: 'prose', content: 'edited', versions: [] } });
+ });
+ expect(await screen.findByDisplayValue('INT. ROOM - DAY')).toBeInTheDocument();
+ });
+
it('aborts a format switch when the pending edit fails to save (#3399)', async () => {
api.savePipelineManuscriptSection.mockResolvedValue(null);
renderEditor();