Comfy-Org / Comfy-Org/ComfyUI_frontend
refactor: Rearchitect workflow/graph data sync to prevent desynced state during loading
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 699
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 490
Description
## Summary
Explore rearchitecting the relationship between workflow data and the active workflow object so that the desynced state during graph loading cannot occur in the first place, rather than relying on guard flags to patch around it.
## Background
PR #9531 fixed a bug where workflow data and the active workflow object could become out of sync during loading, allowing `checkState` calls to write data into the wrong workflow. The fix introduces `ChangeTracker.isLoadingGraph` as a guard flag in `src/scripts/changeTracker.ts` and `src/stores/appModeStore.ts`.
While this guard is effective, it is a defensive patch around a deeper architectural issue: the workflow loading sequence allows a window of time where the active workflow reference and the graph being configured are decoupled.
## Goal
Investigate and implement an architectural solution so that:
- The workflow data and the graph/active workflow object are always in sync — there is no window during loading where they can diverge.
- Guard flags like `isLoadingGraph` are no longer needed to prevent state corruption.
- `checkState`, app-mode data sync, and other state-writing paths are naturally safe to call at any point, because the data they read always belongs to the correct workflow.
## Possible approaches to explore
- Ensure the active workflow reference is updated atomically with the graph configuration step, so there is never a moment where the two are mismatched.
- Make `checkState` and related paths read workflow identity directly from the graph being serialized, rather than from a separately-tracked active workflow reference.
- Introduce a transactional loading primitive that gates all state-writing side effects until the load is fully committed.
## References
- Fix PR: #9531
- Regression test issue: #9532
- Requested by: @pythongosssss in https://github.com/Comfy-Org/ComfyUI_frontend/pull/9531
┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-9533-refactor-Rearchitect-workflow-graph-data-sync-to-prevent-desynced-state-during-loadin-31c6d73d365081cc8bdbe411567ae17a) by [Unito](https://www.unito.io)
Contributor guide
Assessment
This issue has not been assessed yet.