Browse Source

fix: make saveAsFile atomic with rollback on failure

Save the previous workflowId and workflowName before mutating state.
If saveToFile() fails, restore the previous values so the workflow
identity is unchanged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 5 months ago
parent
commit
e4c3cbc9d9
  1. 9
      src/store/workflowStore.ts

9
src/store/workflowStore.ts

@ -1843,7 +1843,7 @@ export const useWorkflowStore = create<WorkflowStore>((set, get) => ({
return false;
}
const { saveDirectoryPath } = get();
const { saveDirectoryPath, workflowId: prevId, workflowName: prevName } = get();
if (!saveDirectoryPath) {
return false;
}
@ -1856,7 +1856,12 @@ export const useWorkflowStore = create<WorkflowStore>((set, get) => ({
hasUnsavedChanges: true,
});
return await get().saveToFile();
const success = await get().saveToFile();
if (!success) {
// Rollback to previous identity on failure
set({ workflowId: prevId, workflowName: prevName });
}
return success;
},
initializeAutoSave: () => {

Loading…
Cancel
Save