Repository navigation
Description
Summary
In the default undirected build, build_from_json drops the reverse-direction duplicate when a file pair carries the same relation in both directions (#1061). For imports_from, that pair is a two-file import cycle. The second leg never reaches the graph, so find_import_cycles can't see the cycle, and GRAPH_REPORT.md states "None detected".
The test suite already accounts for the collapse. The _cycles helper in tests/test_type_only_import_cycles.py notes that "in the default undirected graph two module edges between one file pair collapse to a single stored edge", and test_a_real_runtime_cycle_is_still_reported runs only with directed=True. The report doesn't account for it: it asserts an absence that the default graph can't support. Two-file cycles are also a common shape in practice: bidirectional ORM entity relations (for example TypeORM @ManyToMany/@OneToMany pairs) produce one routinely.
Environment
graphifyy0.9.89 (PyPI), andv8@0a8cd4e(0.9.97), installed from a clean checkout- Linux 6.17, Python 3.12.3
graphify update ., code only, no LLM backend configured
Minimal reproduction
// src/a.ts
import { B } from './b';
export class A { b?: B; }// src/b.ts
import { A } from './a';
export class B { a?: A; }graphify update .
Actual (identical on 0.9.89 and v8 HEAD):
GRAPH_REPORT.md:
## Import Cycles
- None detected.
graph.json ("directed": false). The symbol-level imports edges survive in both directions, but only one file-level imports_from edge does:
imports a.ts -> B (src/a.ts)
imports b.ts -> A (src/b.ts)
imports_from a.ts -> b.ts (src/a.ts)
# b.ts -> a.ts imports_from: dropped
Expected: - 2-file cycle: src/a.ts -> src/b.ts -> src/a.ts. At minimum, the section shouldn't report "None detected" when the graph type makes two-file cycles undetectable.
Real-world occurrence: lujakob/nestjs-realworld-example-app @ c1c2cc4. src/user/user.entity.ts and src/article/article.entity.ts import each other (TypeORM @ManyToMany / @OneToMany relations), and the report says "None detected".
Where
graphify/build.py on v8, around L1867:
if not G.is_directed() and G.has_edge(src, tgt):
...
if reverse and existing_rel == incoming_rel:
continueKeeping the first-seen direction is the right call for #1061. The problem is only that the dropped leg is the one fact cycle detection needs.
Possible fixes
I'm happy to send a PR, with a regression test, for whichever approach you prefer:
- Stamp the surviving edge. When the dropped reverse edge is
imports_from/re_exports, and is neithertype_onlynordeferred, mark the surviving edge (for examplereverse_import: true), and havefind_import_cyclesadd the reverse leg for stamped edges. One stored edge is kept, v0.8.22 regression of #760: fresh /graphify build round-trips correct AST output into reversed calls edges (build_from_json -> to_json undirected round-trip) #1061's direction guarantee is unchanged, and other consumers ofgraph.jsonsee no format change. - Detect cycles on the extraction edges (before the build) instead of on the built graph.
- Minimal: when the graph is undirected, say in the report that two-file cycles can't be detected, instead of "None detected".
I lean towards (1). It's the narrowest change that makes the default report correct.
Related
- v0.8.22 regression of #760: fresh /graphify build round-trips correct AST output into reversed calls edges (build_from_json -> to_json undirected round-trip) #1061: the reverse-duplicate drop this interacts with
- JS/TS graph build resolves internal imports to missing nodes and overwrites parallel directed edges #2849: same-direction collisions in directed builds; this is the opposite-direction case in undirected builds
graphify extractexportsgraph.jsonwithdirected: falseeven though the link data carries subject→object direction; no CLI opt-in for a directed build #3495: no CLI opt-in for a directed build, so CLI users can't currently work around this- Feature: expose connected components and cycles — networkx is already bundled #2489: proposed cycle detection via strongly connected components, which needs direction preserved to work
Investigated and reproduced with the help of Claude Code; I've reviewed the findings above.
Activity
github-actions commentedon Oct 28, 2026
Thanks for opening this issue, @VedantJoshi23. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.
fix(build): keep the reverse import of a two-file cycle in the undire…
safishamsi commentedon Oct 30, 2026
Fixed in v0.9.98 via #4841 (pip install graphifyy==0.9.98). A two-file import cycle is now reported in the default undirected build. Thanks for the report, @VedantJoshi23.