Repository navigation
Description
Environment
- graphify 0.9.35 (PyPI
graphifyy, uv tool install), macOS 15, Python 3.12 - Bundled grammar:
tree_sitter_kotlinas shipped in the 0.9.35 wheel - Reproduced via
graphify update .and by parsing directly with the bundled grammar
Summary
_KOTLIN_CONFIG declares import_types=frozenset({"import_header"}), but the bundled
tree_sitter_kotlin grammar emits node type import (with a qualified_identifier
child). There is no import_header node anywhere in a parsed Kotlin file, so
_import_kotlin is never invoked and zero imports edges are produced for Kotlin,
silently. _import_kotlin's own fallback would not save it either: it looks for an
identifier child, and the grammar produces qualified_identifier.
This is the Kotlin analogue of #2280 (Python imports dropped) and #2329 (Dart imports
never resolved), but with total loss rather than partial: not a single Kotlin import edge
survives.
Effect on a real repo (Kotlin/Spring modular monolith, 416 Kotlin files): a class whose
only link to its dependency is a constructor-injected property — the dominant shape in
Spring code — ends up completely orphaned in the graph. affected is blind, path
returns "no directed path" for flows that plainly exist, and query traversal cannot
reach the right files.
Reproducer
demo/Money.kt
package demo.model
data class Money(val amount: Long)demo/Ledger.kt
package demo.service
import demo.model.Money
class Ledger(private val opening: Money)Control, same shape in TypeScript — demo/Wallet.ts
export class Wallet {}demo/App.ts
import { Wallet } from "./Wallet";
export const w = new Wallet();graphify update .Current behavior (0.9.35)
TypeScript resolves both edges; Kotlin produces none.
EDGES:
imports_from : App.ts -> Wallet.ts <-- TS file-level, correct
imports : App.ts -> Wallet <-- TS symbol-level, correct
contains : Money.kt -> Money
contains : Ledger.kt -> Ledger
Ledger.kt has exactly one edge — contains to its own class. There is no edge of any
kind between Ledger.kt and Money.kt, so Money is unreachable from Ledger at any
depth.
Confirming the node type directly with the bundled grammar:
import tree_sitter, tree_sitter_kotlin
lang = tree_sitter.Language(tree_sitter_kotlin.language())
tree = tree_sitter.Parser(lang).parse(open("demo/Ledger.kt","rb").read())
print([c.type for c in tree.root_node.children])
# ['package_header', 'import', 'class_declaration']
# ^^^^^^^^ not 'import_header'
imp = tree.root_node.children[1]
print(imp.child_by_field_name("path"), [c.type for c in imp.children])
# None ['import', 'qualified_identifier']
# ^^^^ no 'path' field either, so the primary branch of _import_kotlin
# would also miss if the type matchedimport_header occurs 0 times in any file of the corpus.
Expected behavior
Kotlin emits imports edges the same way TypeScript, Java, and Scala do.
Suggested fix
Two lines, mirroring the grammar-version tolerance the config already documents for
identifiers:
_KOTLIN_CONFIG = LanguageConfig(
ts_module="tree_sitter_kotlin",
class_types=frozenset({"class_declaration", "object_declaration"}),
function_types=frozenset({"function_declaration"}),
- import_types=frozenset({"import_header"}),
+ # Grammar generations disagree: PyPI `tree_sitter_kotlin` emits `import`,
+ # older forks emit `import_header`. Accept both.
+ import_types=frozenset({"import_header", "import"}), def _import_kotlin(...):
...
# Fallback: find identifier child
for child in node.children:
- if child.type == "identifier":
- raw = _read_text(child, source)
- tgt_nid = _make_id(raw)
+ if child.type in ("identifier", "qualified_identifier"):
+ raw = _read_text(child, source).split(".")[-1].strip()
+ tgt_nid = _make_id(raw)Measured impact of the fix
Same 416-file Kotlin/Spring repo, graphify update . before and after, measuring
cross-file dependency edge recall against 512 unambiguous in-repo import statements
(only imports whose last segment resolves to exactly one file in the corpus are counted):
Kotlin imports edges |
Cross-file dep recall | Nodes | Edges | |
|---|---|---|---|---|
| 0.9.35 stock | 0 | 45.3% (232/512) | 8,097 | 11,193 |
| 0.9.35 + patch | 1,322 | 94.7% (485/512) | 11,752 | 16,158 |
The 45.3% that stock does resolve comes entirely from calls/references heuristics.
The dependencies it misses are the ones that matter most — shared value types (Money,
SkuId, Currency, Percentage) and every constructor-injected repository.
Node growth is from external import targets (Spring, Jackson) materializing as
unresolved stub nodes. If that is unwanted, it seems orthogonal and better handled by the
existing stub-rewire/prune path than by leaving the handler unreachable.
Related, not covered by this fix
Kotlin wildcard imports (import com.autoshipper.catalog.domain.*) take
raw.split(".")[-1] → "*" and resolve to nothing. With the patch applied, a file whose
only reference to a type comes via a wildcard import stays disconnected. Happy to open
that separately if you'd prefer it tracked on its own.
Adjacent open Kotlin issues (different mechanisms, same practical symptom of a
disconnected Kotlin graph): #1698 (cross-file object member calls) and #1699 (member
calls on typed receivers).
Activity
xg-gh-25 commentedon Aug 7, 2026
The Kotlin import-edge dropout (45% → 95% recall with a 2-line fix) is a schema-grammar mismatch: the config declares node type
import_header, but the bundled tree-sitter grammar emitsimport→ every query forimport_headerreturns zero matches → all import edges are silently dropped.Why this breaks silently:
Tree-sitter queries fail gracefully—a query for a nonexistent node type returns an empty result set rather than throwing an error. The extraction pipeline sees "zero imports" and assumes the file has no dependencies, rather than "the query is broken."
Root cause chain:
_KOTLIN_CONFIG(config file) declares:(import_header) @import(import_declaration)or(import_list)import_header→ finds nothing → returns[]The 2-line fix (pseudo-diff):
Or, if the grammar uses
import_listas the container:Validation:
Why this pattern matters:
This is a vocabulary impedance mismatch between configuration schema and runtime grammar. It happens when:
Systematic fix:
Add a schema-coverage test that asserts every query pattern in
_KOTLIN_CONFIGmatches at least one node in a corpus of real Kotlin files. This catches vocabulary drift before it ships.Audit recommendation:
Check other language configs (Java, Python, Rust) for similar mismatches. The pattern is:
grep -r "@import" configs/len(matches) > 0Configs that produce zero matches on real-world code are silently broken and need alignment.
Context: graph extraction and codebase analysis tooling. SwarmAI. Discussion: T-CUL
mustaqeem66 commentedon Aug 7, 2026
Fix submitted in PR #2531.
Summary of the fix:
Impact measured on 416-file Kotlin/Spring monolith:
importsedgesAll 20 Kotlin tests + 318 language tests + 567 cross-language tests pass.
kskchaitanya1993 commentedon Aug 8, 2026
Confirming the grammar mismatch on 0.9.36 — and reporting that the two-line fix is necessary but not sufficient. It restores the edges, but ~88% of them dangle, so
affected/pathrecall does not move.1. Grammar mismatch confirmed
Parsing a
.ktfile directly with the bundled grammar (tree_sitter_kotlin, 0.9.36 wheel):So
import_types=frozenset({"import_header"})atextract.py:891never matches, exactly as described.2. After the fix, the targets are unresolved
I applied both halves of the suggested fix locally:
Minimal repro — three files, no build system:
graphify extract . --code-only --no-clusternow emits 3importsedges where 0 existed before — but every target id is absent from the node set:_import_kotlinbuilds its target with_make_id(module_name)on the last dotted segment, yieldingmoney, while the declaring node issrc_money_money. Nothing reconciles the two.Consequence —
affectedis still blind to the constructor-injection shape the issue is about:LedgerimportsMoneyand takes it as a constructor parameter, and is still absent. Onlymain()appears, and only becauseMoney(5)produced acallsedge — the import edge contributed nothing.3. At scale
On a private multi-module Kotlin/Swift KMP repo:
importsedgessource_fileaffectedresult set for a widely-used classSo the headline "45% → 95% dep recall" did not reproduce here. The edge count rises sharply and the traversal results do not change at all, because the new edges terminate on stubs.
4. Suggestion
This looks like the same unresolved-target class as #2329 rather than a separate Kotlin bug — the grammar mismatch just hides it. A fix probably wants the import target resolved against declared symbols (last segment → declaring node id, falling back to the file node for a whole-file import) before the edge is appended, applied once in the shared import path rather than per-language. Happy to test a patch against both the repro and the larger repo if that's useful.
Investigated and written with Claude Code (Claude Opus 5).
fix(extract): TS member-call gating + Kotlin grammar match (#2553, #2552
safishamsi commentedon Aug 8, 2026
Fixed in v0.9.37. The Kotlin extractor now matches the bundled grammar
importnode (imports were silently dropped) and resolves each import to the real target node, which also promotes genuine calls to EXTRACTED via import evidence. Thanks for the report (and @mustaqeem66 for #2531).Merge upstream/v8 (v0.9.37) into chore/sync-upstream-0937
fix(extract): TS member-call gating + Kotlin grammar match (Graphify-…
feat(kernel): Kotlin native walker — all ten languages now gated