Replace runtime spatial-index queries during BFS with a pre-compiled adjacency list for O(1) edge traversal. Also fix potential UnboundLocalError for `ref` in the pin-checking exception handler and simplify validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>