Repository navigation
fix(kotlin): silent import edge drop due to grammar node type mismatch - #2531
mustaqeem66 wants to merge 1 commit into
Conversation
_KOTLIN_CONFIG declared import_types=frozenset({'import_header'}) but the
bundled tree_sitter_kotlin grammar emits 'import' nodes with
qualified_identifier children. This caused _import_kotlin to never be
invoked, silently dropping 100% of Kotlin import edges.
Fix: accept both 'import_header' and 'import' node types, and handle
qualified_identifier in the fallback by extracting the last path segment.
Impact: Cross-file dependency recall improves from ~45% to ~95% on real
Kotlin/Spring codebases (1,322 imports edges vs 0 before).
Closes Graphify-Labs#2526
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.
Graphify review — findings
This PR modifies the Kotlin import handling in graphify/extract.py. The changes update the fallback branch of _import_kotlin to also match qualified_identifier child nodes (in addition to identifier) and to take the last dot-separated segment, and they add "import" to the set of recognized import node types in _KOTLIN_CONFIG. A blank line between two config definitions was also removed. Note: the diff only touches _import_kotlin and _KOTLIN_CONFIG, which differs from the long list of changed symbols provided—reviewers may want to confirm the stated surface area matches the actual diff.
Worth a look
- Kotlin import fallback strips full package path to last segment, breaking import target id —
graphify/extract.py:628· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 1282 functions depend on the 189 functions this change touches.
Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):
extract()— 370 callers, 39 callees (high)_rebuild_code()— 93 callers, 52 callees (high)extract_xaml()— 19 callers, 17 callees (high)dispatch_command()— 2 callers, 118 callees (high)_get_extractor()— 24 callers, 6 callees (high)run_pipeline()— 8 callers, 13 callees (high)collect_files()— 17 callers, 6 callees (high)extract_vue()— 10 callers, 6 callees (high)- …and 2 more
Verification — 1282 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: 1152 function(s) in the blast radius were not formally verified this run
· 1 grounded finding(s) anchored inline below.
| raw = _read_text(child, source).split(".")[-1].strip() | ||
| tgt_nid = _make_id(raw) | ||
| edges.append({ |
There was a problem hiding this comment.
Kotlin import fallback strips full package path to last segment, breaking import target id — agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Graphify suggests a fix:
| raw = _read_text(child, source).split(".")[-1].strip() | |
| tgt_nid = _make_id(raw) | |
| edges.append({ | |
| raw = _read_text(child, source).strip() | |
| if not raw: | |
| break | |
| tgt_nid = _make_id(raw) | |
| edges.append({ |
, #2526, #2550, #2551) TypeScript (#2553, #2552, thanks @Earthfreedom): - _resolve_typescript_member_calls matched a receiver type by name alone and emitted EXTRACTED, so a third-party import could bind to an unrelated local class of the same name. It now requires the matched type to be same-file or imported by the caller's file, and tiers table-inferred receivers to INFERRED. - calls inside a callback passed to another call (const h = wrapper(arrow)) were never walked; the callback body is now walked and attributed to the declaration, through the same import-gated resolution so it cannot fabricate edges. The #2553 gate lands with #2552 by design. Kotlin (#2526, #2550, #2551; adapts PR #2531, thanks @mustaqeem66; reports from @spaceBrownie and @thomasrengot-hub): - match the bundled tree-sitter-kotlin 1.1.0 import node and resolve each import to the real target node (imports were silently dropped), so genuine calls promote to EXTRACTED via import evidence; - a fully-qualified call com.example.Foo.bar() now produces a calls edge; - a file the grammar cannot fully parse (e.g. one-line class C { val x }) now warns instead of silently extracting nothing, and declarations recovered inside an error span keep their enclosing class. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Shipped in v0.9.37 ( |
…Labs#2553, Graphify-Labs#2552, Graphify-Labs#2526, Graphify-Labs#2550, Graphify-Labs#2551) TypeScript (Graphify-Labs#2553, Graphify-Labs#2552, thanks @Earthfreedom): - _resolve_typescript_member_calls matched a receiver type by name alone and emitted EXTRACTED, so a third-party import could bind to an unrelated local class of the same name. It now requires the matched type to be same-file or imported by the caller's file, and tiers table-inferred receivers to INFERRED. - calls inside a callback passed to another call (const h = wrapper(arrow)) were never walked; the callback body is now walked and attributed to the declaration, through the same import-gated resolution so it cannot fabricate edges. The Graphify-Labs#2553 gate lands with Graphify-Labs#2552 by design. Kotlin (Graphify-Labs#2526, Graphify-Labs#2550, Graphify-Labs#2551; adapts PR Graphify-Labs#2531, thanks @mustaqeem66; reports from @spaceBrownie and @thomasrengot-hub): - match the bundled tree-sitter-kotlin 1.1.0 import node and resolve each import to the real target node (imports were silently dropped), so genuine calls promote to EXTRACTED via import evidence; - a fully-qualified call com.example.Foo.bar() now produces a calls edge; - a file the grammar cannot fully parse (e.g. one-line class C { val x }) now warns instead of silently extracting nothing, and declarations recovered inside an error span keep their enclosing class. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
This PR fixes a silent data loss bug where 100% of Kotlin import edges were dropped during extraction, reducing cross-file dependency recall from ~45% to 0% for Kotlin code.
Root Cause Analysis
The bundled
tree_sitter_kotlingrammar (PyPItree_sitter_kotlinv1.1.0) emitsimportnode types withqualified_identifierchildren. However:_KOTLIN_CONFIGonly declaredimport_types=frozenset({"import_header"})— theimportnode type was never matched, so_import_kotlinwas never invoked._import_kotlinfallback only checked foridentifierchildren, but the grammar producesqualified_identifier(e.g.,kotlinx.coroutines.delay→qualified_identifierwith childrenidentifier,.,identifier,.,identifier).This meant zero import edges were produced for any Kotlin file using the current grammar.
Changes Made
1. Updated
_KOTLIN_CONFIG(graphify/extract.py:891)Accepts both grammar generations (older forks emit
import_header, current PyPI grammar emitsimport).2. Enhanced
_import_kotlinfallback (graphify/extract.py:628-629)identifierandqualified_identifierchild typeskotlinx.coroutines.delay→delay)Reproducer
Before fix:
After fix:
Measured Impact
Tested on a 416-file Kotlin/Spring modular monolith:
importsedgesThe 45.3% baseline came entirely from
calls/referencesheuristics. The dependencies missed were the most critical ones — shared value types (Money,SkuId,Currency) and constructor-injected repositories that define Spring application architecture.Testing
importsedge creationRelated Issues
This is the Kotlin analogue of:
But with total loss rather than partial — not a single Kotlin import edge survived.
Follow-up
Wildcard imports (
import com.example.*) currently resolve to"*"and produce no edge. This is a separate issue tracked independently.Closes #2526