Module cycle_origins
Expand description
cycle-origins analysis — pinpoint the commit where each HEAD
dependency cycle first formed.
dependency-cycles lists the import-graph cycles that exist now.
This goes further: for each cycle it bisects history — reading source
at past revisions via Repo::read_blob_at — to find the earliest
commit where that exact cycle existed, i.e. the commit that closed the
loop. Actionable archaeology: “the a ↔ b ↔ c tangle formed at
abc1234 on 2026-03-15.”
§Method
The HEAD cycles come from the shared SCC kernel applied to the import
graph reconstructed at HEAD (via
[architecture_trend::import_graph_at_rev], so the cycle definition
and the bisect predicate use the exact same machinery). For each
cycle, a binary search over the date-ordered commit list finds the
transition from “cycle absent” to “cycle present”, rebuilding the
import graph in memory at each probe and testing whether the cycle’s
files sit in a single SCC there.
Binary search assumes a cycle, once formed, stays formed — its
presence is monotonic over time. Cycles that form, break and reform
are rare; for those the search still returns one valid formation
point. Only the MAX_CYCLES largest cycles are traced (each costs
~log₂(commits) graph rebuilds), bounding cost on tangled repos.
Structs§
- Cycle
Origin Row - One traced dependency cycle and the commit where it first formed.
Constants§
- MAX_
CYCLES - Maximum number of cycles to trace (largest first), bounding the historical-scan cost on heavily-tangled repositories.
Functions§
- run_
cycle_ origins - Run the
cycle-originsanalysis. Returns one row per traced HEAD cycle, largest first. Needs repository access (it reads historical blobs).