Skip to content

Commit a160e29

Browse files
committed
State Machine: Use FIFO list for state traversal
Change to_visit from a set to a list and use pop(0) to perform a FIFO traversal of states. Replace set.add calls with list.append when enqueuing Next/Choices/Catch targets. This makes state traversal deterministic (BFS-like) instead of relying on unordered set.pop behavior while preserving reachable-state checks.
1 parent 7a404c4 commit a160e29

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/cfnlint/rules/resources/stepfunctions/StateMachineDefinition.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ def _validate_states(
182182
# 2. Traverse reachable states from StartAt and collect errors for
183183
# missing transition targets along the way.
184184
reachable: set[str] = set()
185-
to_visit: set[str] = {start_at}
185+
to_visit: list[str] = [start_at]
186186
transition_errors: list[ValidationError] = []
187187

188188
while to_visit:
189-
current = to_visit.pop()
189+
current = to_visit.pop(0)
190190
if current in reachable or current not in states:
191191
continue
192192

@@ -210,7 +210,7 @@ def _validate_states(
210210
[field],
211211
)
212212
if isinstance(target, str) and target in states:
213-
to_visit.add(target)
213+
to_visit.append(target)
214214

215215
# Choices[].Next
216216
for idx, choice in enumerate(state.get("Choices") or []):
@@ -227,7 +227,7 @@ def _validate_states(
227227
["Choices", idx, "Next"],
228228
)
229229
if isinstance(target, str) and target in states:
230-
to_visit.add(target)
230+
to_visit.append(target)
231231

232232
# Catch[].Next
233233
for idx, catch in enumerate(state.get("Catch") or []):
@@ -244,9 +244,7 @@ def _validate_states(
244244
["Catch", idx, "Next"],
245245
)
246246
if isinstance(target, str) and target in states:
247-
to_visit.add(target)
248-
249-
# Recurse into nested state machines (Parallel branches, Map processors)
247+
to_visit.append(target)
250248
state_type = state.get("Type")
251249

252250
if state_type == "Parallel":

0 commit comments

Comments
 (0)