Add Switch Case flow-control block with per-case execution branches#2452
Merged
Conversation
Contributor
Author
|
Companion frontend PR: roboflow/roboflow#12428 |
Adds roboflow_core/switch_case@v1: routes execution to one of several branches by matching a string-coerced input value against case keys (flat Dict[str, StepSelector]), with optional case-insensitive matching and a default branch (empty default terminates). Engine changes required for per-case branching: - graph_constructor: selectors held in dict properties get a unique execution branch per key (Branch[step -> cases[red]]); list properties keep the shared-branch behavior, so ContinueIf semantics are unchanged. - execution_data_manager: deduplicate branch names when registering non-SIMD flow-control masks. Fixes a pre-existing crash where any non-SIMD flow-control step with multiple next_steps raised 'Attempted to re-register maks for execution branch' (regression test added). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
always_visible promotes the cases editor onto the block card itself instead of burying it in the Additional Properties panel - the case mapping is the primary interaction for this block. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
0cf5b58 to
4964b17
Compare
dkosowski87
reviewed
Jun 12, 2026
Addresses review feedback on #2452: - Bump EXECUTION_ENGINE_V1_VERSION 1.10.1 -> 1.11.0 to account for the per-case dict execution branches (graph_constructor) and the non-SIMD mask dedup fix (execution_data_manager). - Add a changelog entry describing both changes. - Raise SwitchCase get_execution_engine_compatibility floor to >=1.11.0 since the block depends on the new engine behavior. - Update the EE version assertions in workflow endpoint tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
roboflow_core/switch_case@v1, a flow-control block that routes execution to one of several branches by matching an input value against case keys — a multi-way alternative to chaining Continue If blocks.Block semantics
value(selector or literal) is string-coerced and matched against the keys ofcases: Dict[str, StepSelector](e.g.{"red": "$steps.on_red"}); optionalcase_insensitivetoggle.default_next_stepsruns; if that is empty the branch terminates.cases+default_next_steps(each target step may be referenced at most once per flow-control step — engine constraint) and case-key collisions under case-insensitive matching, with readable errors instead of the engine's compile-time one.casesis a flat dict because selector discovery only finds step selectors one level deep (schema_parser.pyignores nested references).Execution engine changes (required for per-case branching)
graph_constructor.py: selectors held in dict properties now get a unique execution branch per key (Branch[$steps.switch -> cases[red]]). Previously all selectors in one property shared a single branch, so selecting one case would have activated every case target. List properties (next_steps) keep the shared-branch behavior — ContinueIf semantics are unchanged.execution_data_manager/manager.py: deduplicate branch names when registering non-SIMD flow-control masks. This fixes a pre-existing bug: any non-SIMD flow-control step with two or morenext_stepscrashed with "Attempted to re-register maks for execution branch" (reproducible on main with plain ContinueIf; regression test added).UI metadata:
casesis markedalways_visibleso the builder renders it as a primary field. Companion frontend PR in roboflow/roboflow adds per-case connection handles in the workflow builder.Testing
tests/workflows/unit_tests/core_steps/control_flow/test_switch_case.py): manifest validation + run() behavior incl. coercion edge cases (True→"True",None→"None",1.0→"1.0").test_workflow_with_switch_case.py): case match / default / terminate routing throughExecutionEngine, plus compile-time duplicate-target failure.next_stepsContinueIf fix (test_workflow_with_flow_control.py).tests/workflows/unit_tests/execution_engine/suite passes (542 total in the affected areas)./workflows/run) and from the workflow builder UI.🤖 Generated with Claude Code