## Diamond Recursion Scan (pytorch) — CLEAN (deeper scan)

**Scan date:** 2026-03-29
**Pattern:** Recursive cycle/dependency check without visited set (CWE-407 diamond recursion, O(2^D))

### Files examined

- `torch/_inductor/scheduler.py:topological_sort_schedule` — uses `seen = OrderedSet()` — CLEAN
- `torch/_inductor/memory.py:topological_sort_lpmf` — uses `seen` OrderedSet — CLEAN  
- `torch/_inductor/memory.py:dfs_visit` — uses `color` dict (WHITE/GRAY/BLACK) — CLEAN
- `torch/_inductor/augmented_graph_helper.py:_get_all_ancestors` — iterative with `ancestors` set — CLEAN
- `torch/_inductor/fx_passes/overlap_scheduling.py:_collect_node_ancestors` — iterative DP — CLEAN
- `torch/_dynamo/graph_deduplication.py:_has_cycle` — delegates to topological sort — CLEAN
- `torch/package/_digraph.py` — uses networkx DiGraph — CLEAN
- `torch/utils/data/graph.py:traverse_dps` — no DAG traversal without visited — CLEAN
- `torch/autograd/` — engine is C++, Python wrappers don't do DAG traversal — CLEAN

### Verdict: CLEAN — no diamond recursion CWE-407 found beyond existing pytorch-0001..0003
