Commit 7d69b8a
fix(supply_chain): replace exponential Levenshtein with iterative DP (#329)
## Summary
The previous \`levenshtein_rows\` implementation was a naïve recursive
edit-distance that branched three ways at every position, giving
O(3^min(n,m)) worst-case time. Fine on the 4-6 char fixtures the unit
tests exercise; catastrophic on real GitHub-Action slugs like
\`actions/checkout@v4\` (16 chars) — a single typosquat comparison took
several seconds, and an estate-wide scan hung indefinitely (each
workflow file kicks off ~30 comparisons against the known-good
allowlist).
## What changed
\`lib/rules/supply_chain.ex\` — \`levenshtein/2\` now uses:
* **Iterative DP** — O(n*m) time, O(m) space (single rolling row).
* **\`abs(n-m) > 2\` short-circuit** — typosquat detection only cares
about edit-distance ≤ 2; we return 3 immediately when the length
difference already exceeds that, skipping the DP work entirely.
## Smoke test
Scanned \`gitbot-fleet\` (the repo that originally hung):
| | Before | After |
|---|---|---|
| Elapsed | ≥60s (timeout, no result) | **20 ms** |
| Findings | — | 3 |
## Why this matters
Full estate self-scan (279 repos) previously hung at repo ~20 (timeouts
cascaded). With this fix, the scan completes in ~30s and surfaced 8,025
findings across 21 rules — that's the corpus the rules-coverage handoff
(see CLAUDE.md → "Outstanding work") works from.
## Test plan
- [x] Smoke: gitbot-fleet scan returns in <30s
- [ ] CI green
- [ ] Existing unit tests for SC004 (\`test/supply_chain_test.exs\`)
still pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 35f9f3c commit 7d69b8a
1 file changed
Lines changed: 37 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
686 | 686 | | |
687 | 687 | | |
688 | 688 | | |
689 | | - | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
690 | 692 | | |
691 | 693 | | |
692 | 694 | | |
693 | | - | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
694 | 704 | | |
695 | 705 | | |
696 | | - | |
697 | | - | |
| 706 | + | |
| 707 | + | |
698 | 708 | | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
703 | 712 | | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
712 | 733 | | |
713 | 734 | | |
714 | 735 | | |
| |||
0 commit comments