Skip to content

Fix(agentflow): fix duplicate and drag bug and make behavior similar to v2#5850

Merged
j-sanaa merged 7 commits intomainfrom
fix/agentflow-sdk-fix-duplicate-and-drag
Feb 27, 2026
Merged

Fix(agentflow): fix duplicate and drag bug and make behavior similar to v2#5850
j-sanaa merged 7 commits intomainfrom
fix/agentflow-sdk-fix-duplicate-and-drag

Conversation

@j-sanaa
Copy link
Copy Markdown
Contributor

@j-sanaa j-sanaa commented Feb 26, 2026

  • Added fix for duplicate nodes being dragged together
  • Fixed position, label and id of duplicate node to be similar to v2
  • Added test cases for all modified functionalities for delete and duplicate

Before changefix:

Before.fix.mov

After fix

After.fix.mov

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 addresses critical bugs and enhances the core node management features within Agentflow, specifically focusing on duplication and deletion. The changes ensure that duplicating nodes results in properly configured, uniquely identified, and correctly positioned new nodes, while deleting nodes now includes comprehensive cleanup of connected inputs and all child nodes. These updates aim to provide a more stable and intuitive user experience, aligning the behavior with the expected functionality of v2.

Highlights

  • Enhanced Node Duplication: The node duplication functionality has been significantly improved to generate unique IDs, correctly position duplicated nodes based on width and a configurable distance, and update internal anchor IDs. It also now clears connected input values or resets them to their default parameters, and adds a numerical suffix to the label for clarity.
  • Robust Node Deletion: The node deletion logic has been extended to recursively remove all descendant nodes when a parent node is deleted. Additionally, it now intelligently cleans up connected input values in other nodes that were linked to the deleted node(s), preventing orphaned connections.
  • Comprehensive Test Coverage: Extensive new test cases have been added for both node duplication and deletion functionalities, ensuring the new behaviors for ID generation, positioning, input cleanup, and recursive deletion work as expected and align with v2 behavior.
Changelog
  • packages/agentflow/src/infrastructure/store/AgentflowContext.test.tsx
    • Added new test cases for deleteNode to verify cleanup of connected input values (single and list types) and recursive deletion of parent/descendant nodes.
    • Updated existing duplicateNode tests and added new ones to cover unique ID generation using getUniqueNodeId, positioning based on node width and distance, label suffixing, anchor ID updates, and clearing/resetting connected input values.
    • Refactored test setup to use makeFlowNode for consistency and clarity.
  • packages/agentflow/src/infrastructure/store/AgentflowContext.tsx
    • Introduced helper functions isConnectionString, updateAnchorIds, deleteConnectedInput, and collectDescendants to manage node and connection logic.
    • Modified deleteNode to recursively identify and delete all descendant nodes and to clean up input values in other nodes that were connected to the deleted node(s).
    • Updated duplicateNode to use getUniqueNodeId for new node IDs, calculate position based on original node's width and a distance parameter, deep clone the node to prevent mutation, update all internal anchor IDs, clear connected input values (string and array types) or reset them to parameter defaults, and append a numerical suffix to the duplicated node's label.
    • Removed the getUniqueCopyId helper function as getUniqueNodeId is now used.
    • Imported cloneDeep from lodash and getUniqueNodeId from @/core/utils.
Activity
  • j-sanaa fixed a bug where duplicate nodes were being dragged together.
  • j-sanaa implemented fixes for the position, label, and ID of duplicate nodes to match v2 behavior.
  • j-sanaa added functionality to clean connected inputs and remove children when deleting nodes.
  • j-sanaa added new test cases to cover all modified functionalities for both delete and duplicate operations.
  • j-sanaa provided 'Before' and 'After' video demonstrations of the fixes.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces significant improvements to node deletion and duplication functionality in Agentflow. The deleteNode function now correctly handles child nodes and cleans up connections, while duplicateNode has been enhanced to better match v2 behavior, including improved positioning, ID and label generation, and proper handling of connections on duplicated nodes. A comprehensive set of tests has been added to cover these new behaviors.

My review focuses on improving the robustness of the new logic. I've identified a couple of areas where the implementation could be more resilient to edge cases, particularly in how connection strings are parsed and how labels for duplicated nodes are generated. The proposed suggestions aim to make these functions more reliable.

id: newNodeId
...clonedNode.data,
id: newNodeId,
label: clonedNode.data.label + ` (${newNodeId.split('_').pop()})`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When duplicating a node that has already been duplicated, the label generation will append another suffix, resulting in labels like My Node (1) (2). It would be more robust to first strip any existing suffix from the original label before appending the new one.

Suggested change
label: clonedNode.data.label + ` (${newNodeId.split('_').pop()})`
label: clonedNode.data.label.replace(/\s\(\d+\)$/, '') + ` (${newNodeId.split('_').pop()})`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original v2 implementation has suffix added to the original label and the same behavior is mirrored in agentflow sdk

@j-sanaa j-sanaa marked this pull request as ready for review February 26, 2026 19:56
@HenryHengZJ
Copy link
Copy Markdown
Contributor

Not directly related to this PR fix, but when a flow is opened, the edges are situated at the top side of the node, these edges only started to be in correct positions arfter hover over:

image

After hovering:
image

@j-sanaa j-sanaa merged commit 86ac9f6 into main Feb 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants