fix(workflows): fail switch step on non-mapping cases instead of crashing#3481
Open
Noor-ul-ain001 wants to merge 1 commit into
Open
fix(workflows): fail switch step on non-mapping cases instead of crashing#3481Noor-ul-ain001 wants to merge 1 commit into
Noor-ul-ain001 wants to merge 1 commit into
Conversation
…hing `SwitchStep.validate()` already rejects a non-mapping `cases`, but the engine's `execute()` path does not auto-validate (see `WorkflowEngine.load_workflow`, whose docstring notes the definition is "not yet validated"). On an unvalidated run, `execute` called `cases.items()` on the raw value, so a list or scalar `cases` authoring mistake raised `AttributeError` and took down the whole run — the engine invokes `step_impl.execute()` with no surrounding try/except. Guard `execute` to return a FAILED StepResult naming the type error instead, mirroring the fan-out step's non-list `items` handling. The expression is still evaluated first, so its value is surfaced in the step output for downstream context. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Summary
SwitchStep.validate()already rejects a non-mappingcases, but the engine'sexecute()path does not auto-validate —WorkflowEngine.load_workflow's docstring explicitly notes the returned definition is "not yet validated; callvalidate_workflow()orengine.validate()separately."On such an unvalidated run,
SwitchStep.executeiterated the raw value withcases.items(), so a list or scalarcases(an easy authoring mistake) raisedAttributeError. The engine callsstep_impl.execute()with no surrounding try/except, so that exception took down the entire run rather than failing just the step.Fix
Guard
executeto return aFAILEDStepResultnaming the type error instead of crashing — mirroring the existing fan-out step behavior for a non-listitems(test_execute_non_list_items_fails_loudly) and the "report validation errors instead of crashing" direction of #3421. The expression is still evaluated first, so its value is surfaced in the step output for downstream context.This is the same bug class as the recent
max_iterations/timeout/ fan-inoutputguards: a validator catches the bad value, but the runtime path crashes on it when validation is skipped.Testing
TestSwitchStep::test_execute_non_dict_cases_fails_loudly(list, str, intcases).tests/test_workflows.pypasses except the 11 pre-existing Windows symlink-guard tests, which fail identically on a clean base (require elevation on Windows).ruff checkclean on the changed files.🤖 Generated with Claude Code