Skip to content

feat: Add stopNodeId tracking for improved validation and edge control#9867

Merged
Cristhianzl merged 2 commits intomainfrom
cz/fix-edge-run-animation
Sep 16, 2025
Merged

feat: Add stopNodeId tracking for improved validation and edge control#9867
Cristhianzl merged 2 commits intomainfrom
cz/fix-edge-run-animation

Conversation

@Cristhianzl
Copy link
Member

@Cristhianzl Cristhianzl commented Sep 15, 2025

This pull request introduces improvements to the flow state management in the frontend, primarily by adding support for tracking and updating the stopNodeId in the flow store. This change enables more precise control over flow validation and edge animation, particularly when a stop node is specified. Additionally, some code cleanup was performed.

Flow store enhancements:

  • Added stopNodeId and setStopNodeId to the FlowStoreType interface and store implementation, allowing the flow to track which node is designated as the stopping point and update it as needed. [1] [2]
  • Updated validation logic to set or clear stopNodeId during flow validation, ensuring the store accurately reflects the current stopping node. [1] [2]

Edge animation logic:

  • Modified edge animation updates to exclude edges connected to the stopNodeId, preventing running animations on edges beyond the stop node.

Code cleanup:

  • Removed a console log from the sidebar component for cleaner output.
  • Minor formatting and whitespace improvements in the flow store. [1] [2] [3]

https://www.loom.com/share/1c3779ff306447998860b5f2a32f359f

Summary by CodeRabbit

  • New Features
    • Added ability to run a flow by selecting a stop node, scoping execution and validation to nodes upstream of that point.
    • Updated visualization so edges leading into the chosen stop node are not shown as running.
  • Chores
    • Removed a debug log from the flow sidebar to reduce console noise.

…atement

♻️ (flowStore.ts): Refactor useFlowStore to include a stopNodeId property and setter function for better state management and flow control.
@Cristhianzl Cristhianzl self-assigned this Sep 15, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 15, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Introduces stopNodeId state and setter in the flow store and its type definition, integrates stopNodeId into buildFlow and edge-running updates, and removes a debug log from the FlowSidebarComponent. No exported signatures removed; new fields added to FlowStoreType.

Changes

Cohort / File(s) Summary
Flow store state and control flow
src/frontend/src/stores/flowStore.ts
Added public stopNodeId state and setStopNodeId. In buildFlow, sets/clears stopNodeId when applicable and computes upstream subgraph accordingly. Removed unused local _nodeId. Updated updateEdgesRunningByNodes to exclude edges with sourceHandle.id === stopNodeId from running state. Minor formatting.
Flow store type additions
src/frontend/src/types/zustand/flow/index.ts
Extended FlowStoreType with `stopNodeId: string
UI cleanup
src/frontend/src/pages/FlowPage/components/flowSidebarComponent/index.tsx
Removed console.log("hasSearchInput", hasSearchInput);. No logic changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as UI / FlowPage
  participant Store as FlowStore
  participant Graph as Graph Utils

  UI->>Store: buildFlow({ startNodeId?, stopNodeId? })
  alt stopNodeId provided and no startNodeId
    Store->>Store: setStopNodeId(stopNodeId)
    Store->>Graph: computeUpstreamSubgraph(stopNodeId)
  else startNodeId provided
    Store->>Graph: computeDownstreamSubgraph(startNodeId)
  end

  Store->>Store: validate subgraph scope
  note over Store: Maintains existing validation logic

  Store->>Store: updateEdgesRunningByNodes()
  note over Store: Exclude edges where sourceHandle.id === stopNodeId

  opt clear stopNodeId when not applicable
    Store->>Store: setStopNodeId(undefined)
  end

  Store-->>UI: build complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

enhancement, size:L, lgtm

Suggested reviewers

  • lucaseduoli
  • deon-sanchez
  • mfortman11

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately captures the primary change — adding stopNodeId tracking — and explicitly notes its effects on validation and edge animation control; it is specific, concise, and uses a conventional commit prefix, so a teammate scanning history will understand the main intent.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Sep 15, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 15, 2025

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 9%
8.88% (2313/26028) 4.32% (849/19622) 6.21% (350/5636)

Unit Test Results

Tests Skipped Failures Errors Time
1046 0 💤 0 ❌ 0 🔥 15.197s ⏱️

@codecov
Copy link

codecov bot commented Sep 15, 2025

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 22.86%. Comparing base (9b0ef8b) to head (41380e8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/frontend/src/stores/flowStore.ts 0.00% 5 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (40.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (8.12%) is below the target coverage (10.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9867   +/-   ##
=======================================
  Coverage   22.86%   22.86%           
=======================================
  Files        1086     1086           
  Lines       39710    39711    +1     
  Branches     5418     5418           
=======================================
+ Hits         9078     9080    +2     
+ Misses      30477    30476    -1     
  Partials      155      155           
Flag Coverage Δ
frontend 8.12% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...FlowPage/components/flowSidebarComponent/index.tsx 0.00% <ø> (ø)
src/frontend/src/stores/flowStore.ts 10.33% <0.00%> (-0.08%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Sep 15, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/frontend/src/stores/flowStore.ts (1)

682-695: Fix stale stopNodeId when startNodeId is also provided (always sync at build start, and clear on completion/error/stop).

Currently, if both startNodeId and stopNodeId are passed, the store’s stopNodeId is not updated (Line 682 is skipped), and Line 692 only clears when stopNodeId is falsy. This can cause edge animations to use an outdated stopNodeId.

Apply this diff to synchronize at the start of build and clear at the end/error/stop:

@@
-    const edges = get().edges;
+    const edges = get().edges;
     let errors: string[] = [];
 
+    // Keep store in sync with the argument for this build (handles both presence/absence).
+    get().setStopNodeId(stopNodeId);
@@
-    } else if (stopNodeId) {
-      get().setStopNodeId(stopNodeId);
+    } else if (stopNodeId) {
       const upstream = getConnectedSubgraph(
         stopNodeId,
         get().nodes,
         edges,
         "upstream",
       );
       nodesToValidate = upstream.nodes;
       edgesToValidate = upstream.edges;
     }
-    if (!stopNodeId) {
-      get().setStopNodeId(undefined);
-    }

Also clear it on stop/error/complete:

@@ stopBuilding: () => {
-    get().buildController.abort();
+    get().buildController.abort();
+    get().setStopNodeId(undefined);
@@ onBuildComplete
         );
       }
+      // Clear stop marker after a build finishes
+      get().setStopNodeId(undefined);
@@ onBuildError
         });
       }
+      // Clear stop marker on error
+      get().setStopNodeId(undefined);
🧹 Nitpick comments (1)
src/frontend/src/stores/flowStore.ts (1)

911-916: Speed up lookups in updateEdgesRunningByNodes with a Set.

ids.includes(...) is O(N) per edge. Use a Set for O(1) membership when animating many edges.

   updateEdgesRunningByNodes: (ids: string[], running: boolean) => {
     const edges = get().edges;
-
-    const newEdges = edges.map((edge) => {
+    const idSet = new Set(ids);
+    const newEdges = edges.map((edge) => {
       if (
         edge.data?.sourceHandle &&
-        ids.includes(edge.data.sourceHandle.id ?? "") &&
+        idSet.has(edge.data.sourceHandle.id ?? "") &&
         edge.data.sourceHandle.id !== get().stopNodeId
       ) {
         edge.animated = running;
         edge.className = running ? "running" : "";
       } else {
         edge.animated = false;
         edge.className = "not-running";
       }
       return edge;
     });
     set({ edges: newEdges });
   },

Also confirm that “past the stop node” means edges whose source is stopNodeId. If it should include all downstream of stopNodeId, we need to filter by that subgraph, not just equality.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 974cbe0 and b4d295f.

📒 Files selected for processing (3)
  • src/frontend/src/pages/FlowPage/components/flowSidebarComponent/index.tsx (0 hunks)
  • src/frontend/src/stores/flowStore.ts (5 hunks)
  • src/frontend/src/types/zustand/flow/index.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • src/frontend/src/pages/FlowPage/components/flowSidebarComponent/index.tsx
🧰 Additional context used
📓 Path-based instructions (3)
src/frontend/src/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend_development.mdc)

src/frontend/src/**/*.{ts,tsx,js,jsx}: All frontend TypeScript and JavaScript code should be located under src/frontend/src/ and organized into components, pages, icons, stores, types, utils, hooks, services, and assets directories as per the specified directory layout.
Use React 18 with TypeScript for all UI components in the frontend.
Format all TypeScript and JavaScript code using the make format_frontend command.
Lint all TypeScript and JavaScript code using the make lint command.

Files:

  • src/frontend/src/types/zustand/flow/index.ts
  • src/frontend/src/stores/flowStore.ts
src/frontend/src/types/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend_development.mdc)

All TypeScript type definitions should be placed in the types directory.

Files:

  • src/frontend/src/types/zustand/flow/index.ts
src/frontend/src/stores/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend_development.mdc)

Use Zustand for state management in frontend stores.

Files:

  • src/frontend/src/stores/flowStore.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 10/11
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 11/11
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 4/11
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 9/11
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 5/11
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 8/11
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 6/11
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 7/11
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 3/11
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 2/11
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 1/11
  • GitHub Check: Run Frontend Unit Tests / Frontend Jest Unit Tests
  • GitHub Check: Test Starter Templates
🔇 Additional comments (1)
src/frontend/src/types/zustand/flow/index.ts (1)

292-294: stopNodeId and setter added — looks good; confirm reset semantics.

Type additions align with the store usage. Please confirm the field is cleared on flow resets and after builds complete/abort to avoid stale UI state.

Comment on lines +1084 to +1087
stopNodeId: undefined,
setStopNodeId: (nodeId: string | undefined) => {
set({ stopNodeId: nodeId });
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure stopNodeId resets with flow lifecycle.

stopNodeId isn’t cleared in resetFlow or resetFlowState, which can leave animations disabled for future flows.

Add clearing in both places:

@@ resetFlow: (flow) => {
     set({
       nodes,
       edges: newEdges,
       flowState: undefined,
       buildInfo: null,
       inputs,
       outputs,
       hasIO: inputs.length > 0 || outputs.length > 0,
       flowPool: {},
       currentFlow: flow,
       positionDictionary: {},
     });
+    // Clear any previous stop marker when loading a new/other flow
+    get().setStopNodeId(undefined);
   },
@@ resetFlowState: () => {
     set({
       nodes: [],
       edges: [],
       flowState: undefined,
       hasIO: false,
       inputs: [],
       outputs: [],
       flowPool: {},
       currentFlow: undefined,
       reactFlowInstance: null,
       lastCopiedSelection: null,
       verticesBuild: null,
       flowBuildStatus: {},
       buildInfo: null,
       isBuilding: false,
       isPending: true,
       positionDictionary: {},
       componentsToUpdate: [],
     });
+    // Clear stop marker on full reset
+    get().setStopNodeId(undefined);
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
stopNodeId: undefined,
setStopNodeId: (nodeId: string | undefined) => {
set({ stopNodeId: nodeId });
},
stopNodeId: undefined,
setStopNodeId: (nodeId: string | undefined) => {
set({ stopNodeId: nodeId });
},
resetFlow: (flow) => {
set({
nodes,
edges: newEdges,
flowState: undefined,
buildInfo: null,
inputs,
outputs,
hasIO: inputs.length > 0 || outputs.length > 0,
flowPool: {},
currentFlow: flow,
positionDictionary: {},
});
// Clear any previous stop marker when loading a new/other flow
get().setStopNodeId(undefined);
},
resetFlowState: () => {
set({
nodes: [],
edges: [],
flowState: undefined,
hasIO: false,
inputs: [],
outputs: [],
flowPool: {},
currentFlow: undefined,
reactFlowInstance: null,
lastCopiedSelection: null,
verticesBuild: null,
flowBuildStatus: {},
buildInfo: null,
isBuilding: false,
isPending: true,
positionDictionary: {},
componentsToUpdate: [],
});
// Clear stop marker on full reset
get().setStopNodeId(undefined);
},
🤖 Prompt for AI Agents
In src/frontend/src/stores/flowStore.ts around lines 1084 to 1087, stopNodeId is
defined and setter exists but the value is not cleared when a flow is reset;
update both resetFlow and resetFlowState to explicitly set stopNodeId to
undefined so animations aren't permanently disabled for subsequent flows, i.e.,
add logic in each reset function to call the existing setter or directly set
stopNodeId to undefined as part of the state reset.

Copy link
Collaborator

@lucaseduoli lucaseduoli left a comment

Choose a reason for hiding this comment

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

LGTM!

@github-actions github-actions bot added the lgtm This PR has been approved by a maintainer label Sep 15, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Sep 16, 2025
@sonarqubecloud
Copy link

@Cristhianzl Cristhianzl added this pull request to the merge queue Sep 16, 2025
Merged via the queue into main with commit 2e4cac9 Sep 16, 2025
35 of 39 checks passed
@Cristhianzl Cristhianzl deleted the cz/fix-edge-run-animation branch September 16, 2025 20:51
lucaseduoli pushed a commit that referenced this pull request Sep 17, 2025
#9867)

✨ (flowSidebarComponent/index.tsx): Remove unnecessary console.log statement
♻️ (flowStore.ts): Refactor useFlowStore to include a stopNodeId property and setter function for better state management and flow control.

Co-authored-by: Carlos Coelho <80289056+carlosrcoelho@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants