refactor(agentflow): Simplify ReactFlow and Context state sync#5827
refactor(agentflow): Simplify ReactFlow and Context state sync#5827
Conversation
j-sanaa
commented
Feb 24, 2026
- Replaced brittle bidirectional sync with synchronous state updates - context operations now directly update both context state and ReactFlow local state via registered callbacks
- Removed setTimeout-based sync logic that were prone to race conditions
…k-clean-bidirectional-sync
Summary of ChangesHello @j-sanaa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the state management within the Agentflow component, moving from an error-prone, time-delayed synchronization method to a direct and synchronous update strategy. The change aims to enhance the reliability and predictability of the application's state, particularly when user interactions or context-driven operations modify the ReactFlow canvas. By centralizing the control of local ReactFlow state updates within the Agentflow context, the system becomes more robust and easier to maintain, preventing inconsistencies that could arise from asynchronous updates. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively refactors the state synchronization between ReactFlow and the Agentflow context. By replacing the previous bidirectional, setTimeout-based sync with a synchronous, callback-based approach, you've eliminated a source of brittleness and potential race conditions. The new logic is much clearer and more robust, with context operations now directly updating both the context state and ReactFlow's local state. This is a great improvement for the stability and maintainability of the component.
packages/agentflow/src/infrastructure/store/AgentflowContext.tsx
Outdated
Show resolved
Hide resolved
|
/gemini review |
There was a problem hiding this comment.
Code Review
The pull request successfully refactors the state synchronization between ReactFlow and the AgentflowContext. By replacing the previous brittle bidirectional sync (which relied on setTimeout and refs to prevent loops) with a more direct, synchronous approach using registered callbacks, the code is now much simpler and less prone to race conditions. The use of refs within the context provider to store local state setters is a clever way to maintain the dual-state architecture while ensuring consistency. I have suggested one minor improvement to ensure node normalization is applied consistently across both state sources during context-initiated updates.