Repository navigation
Conversation
…cted build (Graphify-Labs#4839) The undirected build drops the reverse-direction duplicate of a same-relation pair (Graphify-Labs#1061). For imports_from/re_exports that dropped edge is the second leg of a two-file import cycle, so find_import_cycles never saw it and GRAPH_REPORT.md said "None detected". Stamp the kept edge with reverse_import when the dropped leg is a runtime import, and have find_import_cycles add the reverse file leg for stamped edges. The incremental reconcile treats the stamp as the target file's import, so it is cleared or carried along with that file. Co-Authored-By: Grok Bot
|
Thanks for the pull request, @Mpasha17. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.
Not checked: tests were not run; formal verification proved 0 of 3 changed function(s) (1 sampled, not proven, 2 not verified).
Formal verification. PR-changed functions: 1/3 verified (0 proven, 1 may-equivalent, 0 distinguished) · 2 not verified (2 vacuous).
Not verified on this run: build\_from\_json (vacuous: never exercised), \_reconcile\_existing\_graph (vacuous: never exercised).
Graphify review — findings
Fixes two-file import cycles going unreported in the default (undirected) build, where the reverse-direction import was dropped as a duplicate edge. The build now stamps reverse_import on the surviving imports_from/re_exports edge, and find_import_cycles reads it back as an extra file-level edge. Type-only and deferred reverse imports are not stamped, and directed builds are unchanged. Incremental rebuilds in _reconcile_existing_graph treat the stamp as belonging to the target file. It is cleared when that file is re-extracted or evicted, and carried onto the fresh edge when only the edge's own file is re-extracted, so a removed import doesn't leave a stale cycle.
No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 2140 functions depend on the 274 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
_rebuild_code()— 207 callers, 65 callees - worse:
build_from_json()— 277 callers, 20 callees - worse:
to_json()— 87 callers, 11 callees - worse:
_reconcile_existing_graph()— 1 callers, 13 callees
Verification — 2140 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 1558 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
157 of 470 test file(s) selected (33%) via static blast radius.
tests/test_affected_cli.py— impacttests/test_affected_path_file_node.py— impacttests/test_alias_folding.py— impacttests/test_analyze.py— impacttests/test_atomic_canvas_export.py— impacttests/test_atomic_writes.py— impacttests/test_backend_opt_in.py— impacttests/test_benchmark.py— impacttests/test_benchmark_raw_graph.py— impacttests/test_benchmark_real_query.py— impacttests/test_build.py— impacttests/test_build_located_semantic_identity.py— impacttests/test_build_merge_dedup_scope.py— impacttests/test_build_merge_hyperedges_and_prune.py— impacttests/test_build_merge_shrink_guard.py— impacttests/test_c_include_resolution.py— impacttests/test_cache_stale_import_target.py— impacttests/test_carried_hyperedge_remap.py— impacttests/test_charmap_encoding.py— impacttests/test_chunking.py— impacttests/test_claude_cli_backend.py— impacttests/test_cli_export.py— impacttests/test_cluster.py— impacttests/test_community_labels_skill.py— impacttests/test_compact_graph_json.py— impacttests/test_confidence.py— impacttests/test_corrupt_graph_json.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_csharp_object_creation.py— impacttests/test_dedup.py— impacttests/test_dedup_remaps_hyperedges.py— impacttests/test_dedup_shrink_refuses_force_write.py— impacttests/test_dedup_survivor_richness.py— impacttests/test_definition_file_portability.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_elixir_import_resolution.py— impacttests/test_elixir_qualified_calls.py— impacttests/test_elixir_unqualified_call_scope.py— impacttests/test_evidence_binding.py— impacttests/test_export.py— impacttests/test_export_control_characters.py— impacttests/test_export_direction.py— impacttests/test_export_idempotent_writes.py— impacttests/test_export_path_length.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_external_stub_endpoints.py— impacttests/test_extract.py— impacttests/test_falkordb_integration.py— impact- … and 107 more
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
No difference found (not proven): No behavior difference found in find\_import\_cycles (not a proof).
The verifier ran both versions of find\_import\_cycles on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
Could not verify: Could not verify build\_from\_json.
The verifier did not have enough to check build\_from\_json, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 11 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous
Could not verify: Could not verify \_reconcile\_existing\_graph.
The verifier did not have enough to check \_reconcile\_existing\_graph, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 24 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)
· 4 more finding(s) on lines outside this diff (see the check run).
|
Landed in v0.9.98, now on PyPI (pip install graphifyy==0.9.98). A two-file import cycle is reported in the default undirected build, with the stamp cleared correctly on incremental rebuilds. Thanks for the fix, @Mpasha17. |
Fixes #4839
In the default undirected build,
build_from_jsondrops the reverse-direction duplicate of a same-relation pair (#1061). Forimports_from/re_exportsthat dropped edge is the second leg of a two-file cycle, sofind_import_cyclesnever saw it and the report said "None detected".What changed:
build.py: when the 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 branch drops a reverseimports_from/re_exportsthat isn'ttype_onlyordeferred, it setsreverse_import: trueon the edge it keeps. Same edges as before, first-seen direction still wins. Directed builds never hit this branch.analyze.py:find_import_cyclesadds the reverse file leg for a stamped edge. The forward leg still skipstype_only/deferredlike before.watch.py: the stamp is really the target file's import, so the incremental reconcile treats it that way. If the target file gets re-extracted or deleted, the stamp is cleared (the rebuild adds it back if the import is still there). If only the kept edge's own file is re-extracted, the stamp moves to the fresh edge. Without this, a hook rebuild afterb.pystops importinga.pykept reporting the cycle, and editinga.pyalone made a real cycle disappear. I also pulled the existing eviction condition into a small_edge_evictedhelper so both checks use the same rule.Tests: new
tests/test_undirected_two_file_import_cycle.pycovers a TS and a Python two-file cycle in the undirected build, a one-way import, a 3-file ring next to a 2-file cycle,import type/TYPE_CHECKINGreverse legs (no cycle), other relations / deferred / type-only reverse edges not stamping, the directed build being unchanged, a graph.json round trip, and the two incremental cases. The existing type-only cycle tests pass unchanged.Ran the full suite on 3.10, 3.12, 3.13 and 3.14 against unmodified v8. Failures are the same on both trees (yaml extraction on 3.10,
safe_fetchnetwork tests, etc.), no new ones. I also ran the real CLI (graphify update .and thengraphify cluster-only .from the saved graph.json) on small Python, TS and JS two-file cycle projects. Before: "None detected". After:- 2-file cycle: a.py -> b.py -> a.py(and the same for TS and JS). The one-way, 3-file ring and TYPE_CHECKING projects give the same output as before.One thing I left alone: an
imports_fromone way plus are_exportsback is a different-relation collision. The later edge already overwrites the pair there, on v8 too, so that shape still isn't reported. That's separate from this issue. Also, a graph.json written before this change doesn't have the stamp, socluster-onlyon it still says "None detected" until the nextgraphify update.Written with help from Grok Bot; I reviewed and tested it.