Feat: Runflow optimization and improved dropdown behavior
This PR implements various improvements and optimizations for the run flow component.
- Given the scope and complexity of this PR, the reviewer is encouraged to checkout its branch and test run_flow's behavior manually.
This PR implements the following improvements to the runflow component:
- Flow Selection: Filter only the flows available in the specific project.
- Sorted: Sort from most recent flow edited.
- Sync Flows: Add a refresh button to re-fetch the flows.
- Output Structure: Outputs appear dynamically after loading the flow.
- Field-naming: Improved user-friendliness of field naming for inputs and outputs, with simple defaults that gain specificity upon duplicate components and input/output field name conflicts (by adding the component name or id when needed).
- Implemented database queries for fetching flows per folder and fetching a particular flow by flow id or name. The previous code would fetch all flows and later filter the result to select the user-selected one, which is very inefficient.
- Added fields to the frontend node field config that is sent to the backend in order to optimize backend behavior; e.g., an explicit 'refresh' flag for when the refresh button is clicked (otherwise, on each click of a dropdown item, the entire list data is re-fetched from the database, which is very expensive. This problem is not exclusive to the run flow component, every component's update_build_config is run each time a dropdown item is selected).
- Utilize the cache service to store the selected flow in memory, to avoid further database querying. We note that the component falls back to using the db when the cache service it not available. Further, this caching feature is optional.
- Run outputs are cached (only for that run, and set to None in _pre_run_setup to start with a fresh slate) to avoid re-executing the selected flow for each of its outputs that needs to be resolved.
- Added a
override_skipboolean flag to the base input mixin so that derived inputs (e.g., the id of the selected flow) can be persisted to runtime but kept hidden from the user entirely (show=False) for user-friendliness. - Added unit and integration tests.
Summary by CodeRabbit
Release Notes
-
New Features
- Added flow folder-based organization and querying capabilities.
- Implemented flow caching to improve performance and reduce load times.
- Introduced dynamic input/output generation from flow structures.
- Enhanced flow selection with automatic field population from selected flows.
- Added flow metadata support in dropdown selections for richer context.
- Enabled flows to be exposed and used as reusable tools.
- Improved flow execution with output resolution from cached runs.
-
Tests
- Added comprehensive unit and integration test coverage for flow operations, caching behavior, and execution workflows.
[!IMPORTANT]
Review skipped
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
Walkthrough
This PR enhances flow management by introducing new query helpers (list_flows_by_flow_folder, list_flows_by_folder_id, get_flow_by_id_or_name), refactoring RunFlowComponent with caching and dynamic graph retrieval, updating frontend metadata handling, and adding comprehensive test coverage across backend and frontend layers.
Changes
| Cohort / File(s) | Summary |
|---|---|
Backend Flow Helpers src/backend/base/langflow/helpers/flow.py, src/lfx/src/lfx/helpers/flow.py |
Introduces three new async query functions (list_flows_by_flow_folder, list_flows_by_folder_id, get_flow_by_id_or_name) with sorting/filtering; langflow version includes SQLAlchemy query logic; lfx version provides stubs with warnings. Adds SORT_DISPATCHER constant for asc/desc translation. |
Flow Model Serialization src/backend/base/langflow/services/database/models/flow/model.py |
Extends Flow.to_data() to include folder_id in serialized Data payload. |
Frontend Dropdown Components src/frontend/src/CustomNodes/helpers/mutate-template.ts, src/frontend/src/components/core/dropdownComponent/index.tsx, src/frontend/src/components/core/parameterRenderComponent/components/dropdownComponent/index.tsx |
Adds isRefresh parameter propagation; excludes "id" from metadata filtering; passes selected metadata to onSelect callback; filters metadata on refresh. |
Frontend Template & Type Updates src/frontend/src/controllers/API/queries/nodes/use-post-template-value.ts, src/frontend/src/types/components/index.ts |
Extends IPostTemplateValue with is_refresh flag and flow context (_frontend_node_flow_id, _frontend_node_folder_id); updates DropDownComponent.onSelect signature to accept selectedMetadata parameter. |
Backend RunFlowBaseComponent Refactoring src/lfx/src/lfx/base/tools/run_flow.py |
Major refactor introducing component-level caching, graph retrieval (get_flow, get_graph), dynamic field/input/output handling (get_new_fields_from_graph, update_build_config_from_graph, update_outputs, _format_flow_outputs), tool exposure (_get_tools), output resolution (_resolve_flow_output, resolve_selected_flow_output), and cached run execution (_run_flow_with_cached_graph, _pre_run_setup). |
Backend RunFlowComponent Updates src/lfx/src/lfx/components/flow_controls/run_flow.py |
Refactors update_build_config to use get_graph and update_build_config_from_graph; removes run_flow_with_tweaks; adds flow refresh/selection logic; uses new list_flows_by_flow_folder helper. |
Backend Custom Components src/lfx/src/lfx/custom/custom_component/custom_component.py, src/lfx/src/lfx/custom/custom_component/component.py |
Adds three new async flow-querying methods (alist_flows_by_flow_folder, alist_flows_by_folder_id, aget_flow_by_id_or_name); introduces _get_runtime_or_frontend_node_attr helper; makes update_outputs robust to both sync and async implementations. |
Backend Parameter & Input Handling src/lfx/src/lfx/graph/vertex/param_handler.py, src/lfx/src/lfx/inputs/input_mixin.py |
Adds early override for override_skip field in should_skip_field; introduces override_skip: bool field to BaseInputMixin. |
Backend Helpers Initialization src/lfx/src/lfx/helpers/__init__.py |
Exports new flow helpers (get_flow_by_id_or_name, list_flows_by_flow_folder, list_flows_by_folder_id) across langflow/lfx initialization branches. |
Integration Tests src/backend/tests/integration/base/tools/run_flow/test_run_flow_integration.py |
Comprehensive end-to-end and integration test suite for RunFlowComponent covering flow refresh, graph caching, output resolution, and cache behavior validation. |
Unit Tests src/backend/tests/unit/base/tools/test_run_flow.py, src/backend/tests/unit/components/logic/test_run_flow_component.py, src/backend/tests/unit/helpers/test_flow_helpers.py, src/lfx/tests/unit/helpers/test_flow_helpers.py |
Extensive unit test coverage for RunFlowBaseComponent initialization, flow retrieval, caching, I/O handling, component metadata, update_build_config workflow, and flow helper functions. |
Sequence Diagram(s)
sequenceDiagram
participant UI as Frontend/Dropdown
participant Cache as Component Cache
participant Helper as Flow Helper
participant Graph as Graph Service
participant DB as Database
UI->>Helper: list_flows_by_flow_folder(user_id, flow_id)
Helper->>DB: Query flows in folder
DB-->>Helper: Flow list
Helper-->>UI: Populate dropdown options
UI->>UI: User selects flow
UI->>Helper: get_graph(flow_name_selected, flow_id_selected)
Helper->>Cache: Check _build_flow_cache_key
alt Cache Hit
Cache-->>Helper: Cached Graph
else Cache Miss
Helper->>DB: Fetch Flow data
DB-->>Helper: Flow Data
Helper->>Graph: Build Graph from data
Graph-->>Helper: Graph object
Helper->>Cache: Cache graph
end
Helper-->>UI: Graph
UI->>UI: update_build_config_from_graph
UI-->>UI: Populate dynamic input fields
sequenceDiagram
participant User as User/Run
participant Setup as _pre_run_setup
participant Cache as Cache Service
participant Run as _run_flow_with_cached_graph
participant Output as Output Resolution
User->>Setup: Trigger pre-run
Setup->>Cache: Clear cached run outputs
Setup->>Setup: Rebuild tweak data
Setup-->>User: Ready for run
User->>Run: Execute with tweaks/inputs
Run->>Cache: Get cached graph
Run->>Run: Build flow inputs
Run->>Run: Execute flow (arun)
Run->>Cache: Cache run outputs
Run-->>User: Execution complete
User->>Output: Resolve flow output
Output->>Cache: Fetch cached run outputs
Cache-->>Output: Outputs
Output->>Output: Extract by vertex_id + output_name
Output-->>User: Resolved output
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
- Major refactor of RunFlowBaseComponent (
src/lfx/src/lfx/base/tools/run_flow.py): Extensive new methods for caching, graph retrieval, dynamic field handling, and output resolution; high logic density with multiple interdependent features. - Coordination across frontend and backend: Frontend changes (metadata propagation, refresh flags) must align with backend API updates and template value processing; requires verification of data flow consistency.
- New public API surface: Three new flow query helpers exposed across langflow/lfx packages; requires careful validation of error handling, input validation, and stub behavior.
- Test coverage diversity: Four separate test files (integration, unit) covering different layers; heterogeneous test logic and mocking patterns increase review surface area.
- State management and caching: Cache key construction, flow retrieval workflows, and run output caching introduce state-dependent behavior that requires careful scrutiny for correctness and edge cases.
Areas requiring extra attention:
- Cache invalidation and key construction logic in
_build_flow_cache_keyand_get_cached_flowto ensure correctness across different flow identification methods (ID vs. name). - Field override behavior via
override_skipand its interaction withshould_skip_fieldin parameter handling. - Synchronization between frontend metadata/refresh flags and backend template value processing to ensure end-to-end flow consistency.
- Error handling and graceful fallbacks in new flow helpers (list_flows_by_flow_folder, list_flows_by_folder_id, get_flow_by_id_or_name) across langflow and lfx stub implementations.
- Integration of async/sync dual-support in
run_and_validate_update_outputsto verify correct awaiting behavior.
Possibly related PRs
- #10136: Adds/modifies the same flow helper API surface (list_flows_by_*, get_flow_by_id_or_name) and import/export coordination between langflow and lfx.
- #9321: Modifies the same helper flow module (src/backend/base/langflow/helpers/flow.py) with logger import/usage changes.
- #10354: Introduces identical flow helper functions (list_flows_by_flow_folder, list_flows_by_folder_id, get_flow_by_id_or_name) with the same signature and validation patterns.
Suggested labels
enhancement, size:L, backend, frontend, testing
Suggested reviewers
- mpawlow
- ogabrielluiz
- lucaseduoli
Pre-merge checks and finishing touches
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Test File Naming And Structure | ⚠️ Warning | Test files follow correct naming convention (test_*.py), appropriate directory structure (unit vs integration), and have descriptive test function names with comprehensive positive and negative scenario coverage. | Remove unused run_flow import from src/backend/tests/unit/helpers/test_flow_helpers.py and refactor repeated mock setup into pytest fixtures in conftest.py for better maintainability. |
| Excessive Mock Usage Warning | ⚠️ Warning | Integration tests mock internal components (Graph, RunFlowComponent) that should be tested with real objects, undermining integration test purpose with 70+ mock statements across 350 lines. | Refactor integration tests to use real/in-memory databases and component objects instead of mocking internals; reserve mocks for external services only. |
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Docstring Coverage | ✅ Passed | Docstring coverage is 83.77% which is sufficient. The required threshold is 80.00%. |
| Test Coverage For New Implementations | ✅ Passed | PR includes comprehensive test coverage for all new implementations with unit tests covering flow helper functions, component tests, integration tests, and proper error handling across backend and LFX modules. |
| Test Quality And Coverage | ✅ Passed | PR includes comprehensive test suite with 50+ test functions, 200+ assertions, proper async patterns, error handling validation, mocks, and integration tests validating actual behavior across backend and LFX implementations. |
| Title check | ✅ Passed | The title 'Feat: Runflow optimization and improved dropdown behavior' accurately captures the main changes: runflow component optimizations and dropdown UI improvements. It is specific and directly related to the changeset. |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
Has it been tested for backwards compatibility?
Hi Himavarsha, this PR introduces breaking changes by design (e.g., dynamic outputs). I have coordinated with Rodrigo for this. Will send more info on Slack!
Component Index merge conflict
@HzaRashid There are a lot of changes in the .json files, making them much larger than they should be. Would it be possible to clean them up and ensure only your changes are included? That way, my review can be more efficient.
merged via #10720