Skip to content

argo: implement fanout switch case support - #3331

Open
npow wants to merge 3 commits into
npow/switch-fanout-casesfrom
npow/argo-switch-fanout
Open

argo: implement fanout switch case support#3331
npow wants to merge 3 commits into
npow/switch-fanout-casesfrom
npow/argo-switch-fanout

Conversation

@npow

@npow npow commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #3328 (Support fanout switch cases).

Implements Argo Workflows support for list-valued switch cases. The approach:

  • Output: changes the switch-step Argo parameter from a scalar step name to a comma-separated list of chosen targets ("step1,step2" for fanout, "step" for single-target — no format change for existing flows).
  • Conditions: updates all three when-condition sites in argo_workflows.py from ==step equality to a CEL membership test: split(',').exists(x, x == 'step'). This is backwards-compatible — a single-element list behaves identically to the old scalar comparison.
  • Tests: adds switch_fanout core integration graph + hit/miss test cases; updates the test FlowFormatter to emit list-valued switch case values.

Test plan

  • pytest test/unit/test_switch_fanout_cases.py — existing unit tests still pass
  • pytest test/unit/test_graph_structure.py — graph structure tests still pass
  • Argo core integration tests with the new switch_fanout graph (hit and miss cases)
  • Existing switch core tests (switch_basic, switch_nested, etc.) still pass — the CEL split(',').exists(...) condition is equivalent to == for single-target cases

🤖 Generated with Claude Code

Nissan Pow and others added 3 commits August 4, 2026 21:52
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Switch `switch-step` output from a scalar step name to a comma-separated
list of chosen targets so a single Argo output parameter can represent
both single-target cases ("step") and list-valued fanout cases
("step1,step2").

Update all three `when`-condition patterns in argo_workflows.py from
the old equality format (`==step`) to a CEL membership test
(`split(',').exists(x, x == 'step')`), which handles both cases uniformly
without changing behavior for existing single-target flows.

Add switch_fanout core integration test (hit and miss cases) and update
the test formatter to emit list-valued case values.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Implements list-valued switch cases for Argo Workflows by serializing selected targets into one output parameter and using membership-based branch conditions.

  • Removes compile-time and runtime rejection of switch fanout cases.
  • Writes all selected targets as a comma-separated switch-step value.
  • Updates DAG, recursive-step, and foreach conditions to test target membership.
  • Adds formatter support and core integration coverage for single-target and fanout selections.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code failure identified.

The new serialized switch output is consumed consistently at each routing site, and the reconverging fanout path retains both selected inputs while allowing the unselected path to be skipped without blocking completion.

Important Files Changed

Filename Overview
metaflow/plugins/argo/argo_workflows.py Removes fanout rejection and consistently changes all three switch-routing sites from scalar equality to membership checks.
metaflow/plugins/argo/argo_workflows_decorator.py Serializes every selected switch target into the scalar Argo output parameter using a comma-delimited representation.
test/core/metaflow_test/formatter.py Extends generated test flows to emit list-valued switch cases while retaining scalar-case formatting.
test/core/graphs/switch_fanout.json Adds a graph covering a scalar case and a two-target fanout that reconverges at a join.
test/core/tests/switch_fanout_case.py Verifies both the single-target path and the fanout path, including merged artifacts from both selected branches.

Reviews (1): Last reviewed commit: "argo: implement fanout switch case suppo..." | Re-trigger Greptile

@talsperre
talsperre force-pushed the npow/switch-fanout-cases branch from 753cc95 to c1dde7e Compare August 13, 2026 16:41
.template(sanitized_name)
.when(
"{{steps.%s-internal.outputs.parameters.switch-step}}==%s"
"{{=steps['%s-internal'].outputs.parameters['switch-step'].split(',').exists(x, x == '%s')}}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is leading to

Invalid 'when' expression '({{=(tasks['start'].status == 'Succeeded' ? tasks['start'].outputs.parameters['switch-step'].split(',').exists(x, x == 'branch_a') : false)}})': Invalid token: '{{=' (hint: try wrapping the affected expression in quotes ("))

in many test flows of mine.

in_func = node.in_funcs[0]
foreach_task.when(
"{{tasks.%s.outputs.parameters.switch-step}}==%s"
"{{=tasks['%s'].outputs.parameters['switch-step'].split(',').exists(x, x == '%s')}}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

possibly similar issue with this expression.

@talsperre
talsperre force-pushed the npow/switch-fanout-cases branch from 64889dd to 91f39e6 Compare August 21, 2026 21:35
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.

2 participants