spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

fix(workflows): fail fan-in step on non-list wait_for instead of crashing

Open Noor-ul-ain001 opened this issue 4 months ago • 0 comments

Summary

FanInStep.validate() and the engine's fan-in wiring checks both reject a non-list wait_for, but the engine's execute() path does not auto-validate — WorkflowEngine.load_workflow's docstring notes the returned definition is "not yet validated; call validate_workflow() or engine.validate() separately."

On such an unvalidated run, FanInStep.execute iterated the raw value (for step_id in wait_for), with two bad outcomes depending on the type:

  • Scalar (wait_for: 5, wait_for: null) → TypeError, which took down the whole run, since the engine calls step_impl.execute() with no surrounding try/except.
  • String (wait_for: stepA) → silently iterated the string's characters, returning a join of empty results with a COMPLETED status:
>>> FanInStep().execute({"id": "f", "wait_for": "stepA"}, ctx).output["results"]
[{}, {}, {}, {}, {}]   # one bogus empty result per character, COMPLETED

That silent-wrong case is exactly the "silent empty result + COMPLETED" wiring bug the engine's own fan-in validation comment (engine.py) warns against.

Fix

Guard execute to return a FAILED StepResult naming the type error — mirroring the fan-out step's non-list items handling (test_execute_non_list_items_fails_loudly) and the switch/max_iterations/timeout/fan-in-output guards. A missing wait_for key still defaults to an empty list (COMPLETED), unchanged; the guard fires only on an explicit non-list value.

Same bug class as #3481 and prior fixes: a validator catches the bad value, but the runtime path crashes (or silently misbehaves) on it when validation is skipped.

Testing

  • Added TestFanInStep::test_execute_non_list_wait_for_fails_loudly (parametrized over str, int, None, dict).
  • Full tests/test_workflows.py passes except the 11 pre-existing Windows symlink-guard tests (fail identically on a clean base; require elevation).
  • ruff check clean on the changed files.

🤖 Generated with Claude Code

Noor-ul-ain001 avatar Jul 12 '26 15:07 Noor-ul-ain001