Skip to content

fix(graph): handle loop body steps in graph traversal#348

Merged
pocky merged 1 commit into
mainfrom
fix/graph-traversal-loop-awareness
May 14, 2026
Merged

fix(graph): handle loop body steps in graph traversal#348
pocky merged 1 commit into
mainfrom
fix/graph-traversal-loop-awareness

Conversation

@pocky
Copy link
Copy Markdown
Contributor

@pocky pocky commented May 14, 2026

Summary

  • Graph traversal was blind to loop steps: ExecutionOrder skipped body steps entirely and NextDefaultStep ignored Loop.OnComplete, causing incorrect step ordering and reachability analysis for for_each/while workflows.
  • ExecutionOrder now inlines loop body steps immediately after the loop step before advancing to on_complete, matching actual runtime execution order.
  • NextDefaultStep now prefers Loop.OnComplete over OnSuccess as the default continuation target for loop steps, with OnSuccess retained as fallback when on_complete is absent.
  • GetTransitions now emits body step names and on_complete as outbound edges for loop steps, so reachability analysis (FindReachableStates) correctly marks body steps and post-loop targets as reachable.

Changes

Graph Traversal

  • internal/domain/workflow/graph.go: Extend NextDefaultStep to check Loop.OnComplete before OnSuccess; extend ExecutionOrder to inline loop body steps; extend GetTransitions to include loop body references and on_complete as outbound edges.

Tests

  • internal/domain/workflow/graph_test.go: Add 7 tests covering GetTransitions for for_each and while steps, NextDefaultStep with and without on_complete, ExecutionOrder for both loop types with body steps, and FindReachableStates reachability through loop bodies and on_complete.

Test plan

  • Run make test-unit and confirm all new graph tests pass with zero failures
  • Run make test-race to verify no data races in graph traversal under concurrent access
  • Validate a for_each workflow with body steps: awf validate <workflow> should report no unreachable steps
  • Run awf run <for_each_workflow> and confirm body steps execute in the declared order before advancing to on_complete

Generated with awf commit workflow

- `internal/domain/workflow/graph.go`: Add loop body and on_complete awareness to NextDefaultStep, ExecutionOrder, and GetTransitions
- `internal/domain/workflow/graph_test.go`: Add 202 lines of tests for for_each/while loop graph traversal
@pocky pocky marked this pull request as ready for review May 14, 2026 16:29
@pocky pocky merged commit 13b4e26 into main May 14, 2026
5 checks passed
@pocky pocky deleted the fix/graph-traversal-loop-awareness branch May 14, 2026 16:29
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.

1 participant