[bug] JS/TS: member calls (Math.max(), arr.push()) and local identifiers resolve to unrelated same-named symbols repo-wide
What happened
roam health reports CRITICAL god components in JavaScript/TypeScript code that aren't god components at all: plain interface properties such as max: number, with 90+ incoming edges from dozens of files that never use them.
The edges come from calls to builtin and library methods. Math.max(...) in any file of the repo becomes an edge to the repo's own symbol named max, wherever it lives. Local variables and parameters are bound the same way: a parameter value becomes an edge to an unrelated property value in another package. The same phantom edges also distort impact, the bottleneck ranking and the dead-code results.
The reason is in extraction and resolution. A call on a receiver keeps only the property name, so Math.max() is recorded exactly like a bare max(). When the file defines and imports nothing by that name, the resolver's global fallback binds it to any indexed symbol with that name, in any package or language.
Reproduction
mkdir repro && cd repro && git init -q && mkdir server client
cat > server/knob.ts <<'EOF'
export interface Knob {
readonly min: number
readonly max: number
}
EOF
cat > client/clamp.ts <<'EOF'
export function clamp(v: number, lo: number, hi: number): number {
return Math.max(lo, Math.min(hi, v))
}
EOF
cat > server/plate.ts <<'EOF'
export interface Plate {
readonly value: number
}
EOF
cat > client/show.ts <<'EOF'
export function show(value: number): string {
return String(value)
}
EOF
git add -A && git commit -qm init
uvx --from roam-code==14.1.0 roam index --force
# list the resolved edges
python3 - <<'EOF'
import sqlite3
c = sqlite3.connect('.roam/index.db')
q = """SELECT s1.name, f1.path, e.line, e.kind, s2.name, f2.path
FROM edges e
JOIN symbols s1 ON s1.id = e.source_id JOIN files f1 ON f1.id = s1.file_id
JOIN symbols s2 ON s2.id = e.target_id JOIN files f2 ON f2.id = s2.file_id"""
for row in c.execute(q):
print(row)
EOF
Expected vs actual
-
Expected: no edges.
client/doesn't importserver/,Math.max/Math.minare builtins, andvalueinshowis the function's own parameter. -
Actual:
clamp client/clamp.ts:2 call -> max server/knob.ts clamp client/clamp.ts:2 call -> min server/knob.ts show client/show.ts:2 reference -> value server/plate.ts
Environment
- roam-code version: 14.1.0 (also seen on 13.9.0)
- Python version: 3.14.3
- OS: Fedora Linux 44
- Indexed repo size: the repro has 4 files. The real repo where we found this has 143 files and 2,777 symbols (a TypeScript monorepo with two packages that don't import each other).
Additional context
Impact on the real repo:
- One property
max: numberon a config interface received 92 incoming edges from 35 files.minreceived 88 from 40. Both were reported as CRITICAL god components. The sources wereMath.max/Math.mincalls and zod's.max()/.min(). - Before we excluded our Python tooling, neverthrow's
ok(...)in 51 TypeScript files resolved to a module-level Python variableokin an unrelated script, giving degree 115. - Other single-owner names behaved the same way:
Name Collected from pushArray.prototype.pushsetMap.set,new SetfromArray.fromerrorconsole.error,result.errorresolvePromise.resolve,path.resolvevaluelocal variables and parameters inputlocal variables and parameters - Renaming the receiving symbol doesn't help. The edges move on to the next symbol with the same name: after we renamed
Bounds.max, all ~90 edges moved toKnob.max. - Around 600 edges crossed packages or languages, and none of them existed in the code.
- The god-component factor of
roam healthdropped to ~0.002, mostly from these phantom edges.
Where it happens:
-
roam/languages/javascript_lang.py,_extract_call:# Handle method calls: obj.method() -> extract "method" if func_node.type == "member_expression": prop = func_node.child_by_field_name("property") name = self.node_text(prop, source)The receiver (
Math,arr,z.number()) is dropped, soMath.max()and a baremax()produce identical references. -
roam/index/relations.py,_best_match: the ladder ends in_bm_pick_canonical_fallback. That step always returns one of the candidates, even if the candidate is in another package or another language, and even when the reference had a receiver. -
Identifier references (e.g. arguments, around
javascript_lang.py:655) are emitted for names that are local bindings (parameters,const) of the enclosing function, and are resolved the same way.
W1456 already gated the case-insensitive fallback, citing the same failure class (Path → an unrelated PATH constant producing ~3.4k edges). This issue is the same failure class through the case-sensitive path.
Suggested fixes (any one helps; the first is the biggest):
- No global fallback for member calls. Keep a flag on references that came from a
member_expression, and skip_bm_pick_canonical_fallbackfor them. Resolvex.m()only through the same-file, same-directory or import-matched steps, or whenxresolves to an imported binding.Math.max()would then produce no edge, which is correct for a builtin. - Don't resolve local bindings. When an identifier is a parameter or local declaration of the enclosing scope, don't emit a cross-file reference for it.
- Never cross languages in the fallback. A
.tssource shouldn't resolve to a.pytarget unless a bridge says so. - Optional package scoping for monorepos. Let the fallback be limited to the nearest
package.json/pyproject.tomlroot (or apackageslist in.roam/config.json). Then two packages in one repo don't resolve into each other by name.
Glad to test a pre-release against our repo and report the before/after roam health numbers.