Description
Summary
codegraph roles --role dead (and the underlying classifyRoles/classify_node in both engines) treats "has at least one inbound calls edge" as sufficient evidence of liveness — it never checks whether that caller is itself reachable from anything live. This means a genuinely-unreachable function that is called only by another genuinely-unreachable function is never flagged dead, because the direct fan-in count is > 0 regardless of the caller's own reachability.
Concrete repro
function computeHelper(x: number): number {
return x + 1;
}
function makeThing(): { doThing: () => number } {
return {
doThing: () => computeHelper(1),
};
}
export function useThing(): number {
const t = makeThing();
return 42; // t.doThing() is never called anywhere
}computeHelper has exactly one caller — the closure assigned to doThing — so its fan-in is 1 and it is classified core/non-dead, even though doThing (and therefore computeHelper) is never actually invoked by anything reachable from useThing's real control flow.
This is the residual mechanism behind the historical #1770/#1895 investigation: even after #1895 fixes the object-literal-property value-ref liveness check (bare-identifier/shorthand property values now require independent invocation evidence), a function whose only caller is itself dead still isn't flagged, because roles --role dead never verifies that a caller is reachable — it only checks that a caller exists at all.
Suggested fix direction
Replace (or augment) the direct fan-in check with proper reachability analysis: compute the set of nodes reachable via calls edges from confirmed-live roots (entry-classified nodes, exported public API, framework dispatch points), and classify anything outside that reachable set as dead — regardless of whether it happens to have some inbound edge from another also-unreachable node. This is a substantial change to the dead-code classifier's core algorithm (in both src/graph/classifiers/roles.ts and crates/codegraph-core/src/graph/classifiers/roles.rs), needs its own design pass (worklist/BFS from roots vs. the current single-pass per-node classification), and should be scoped as its own issue rather than folded into a narrower fix.
Related
- roles --role dead: object-literal property-value references count as liveness without checking if the property is ever invoked (false negative) #1895 — object-literal property-value references counted as liveness without checking if the property is invoked (narrower, now fixed for the bare-identifier/shorthand value-ref mechanism)
- leiden/partition.ts: Partition.deltaCPM/deltaModularityDirected/deltaModularityUndirected/getCandidateCommunityCount are unreachable dead code codegraph's dead-detector misses #1770 — the concrete
Partitiondead-code removal that originally surfaced this gap
Activity
fix(classifiers): scope reexport-derived public-surface roots to the …
fix(classifiers): detect transitively-unreachable dead code, not just…
fix(extractors): qualify object literals returned from factory functi…
fix(roles): incremental classification now applies the #2032 reachabi…
fix(build): treat an empty file_hashes table as a from-scratch build (#…
fix(extractors): logical-or/ternary function fallbacks get a real cal…
fix(resolver): this-bound EventEmitter callback registrations get a r…