Skip to content

Import Cycles reports "None detected" for every two-file import cycle in the default (undirected) build #4839

Closed

Description

@VedantJoshi23

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

  • graphifyy 0.9.89 (PyPI), and v8 @ 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:
        continue

Keeping 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:

  1. Stamp the surviving edge. When the dropped reverse edge is imports_from/re_exports, and is neither type_only nor deferred, mark the surviving edge (for example reverse_import: true), and have find_import_cycles add 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 of graph.json see no format change.
  2. Detect cycles on the extraction edges (before the build) instead of on the built graph.
  3. 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

Investigated and reproduced with the help of Claude Code; I've reviewed the findings above.

Activity

  1. github-actions commented on Oct 28, 2026

    @github-actions

    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.

  2. safishamsi commented on Oct 30, 2026

    @safishamsi
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions