Registry Mirror
Skip to content

computedDispatchTableEvidence is in-memory only — scoped incremental builds can report live dispatch-table properties as dead #2610

Open

Description

@carlos-alm

Found while planning #2088 (receiver-type-aware invoked-property matching).

Problem

computedDispatchTableEvidence (#2260) — the "this dispatch table is read via computed access" liveness channel for object-literal-property value-refs — is aggregated in memory only, from ctx.fileSymbols:

src/domain/graph/builder/stages/build-edges.ts:1376-1381

const computedDispatchTableEvidence = new Set<string>();
for (const [relPath, symbols] of fileSymbols) {
  for (const name of symbols.computedDispatchTableEvidence ?? []) {
    computedDispatchTableEvidence.add(computedDispatchTableEvidenceKey(relPath, name));
  }
}

Its sibling channel, invokedPropertyNames, was given a durable invoked_property_names table in #2087 (migration v29) for exactly this reason — a few lines above, at build-edges.ts:1351-1357, it unions the in-memory set with SELECT DISTINCT name FROM invoked_property_names.

The native engine mirrors the same asymmetry: collect_invoked_property_names takes an extra: &[String] param fed from the persisted table, while the computed-dispatch aggregation in crates/codegraph-core/src/domain/graph/builder/stages/build_edges.rs has no such param (its own doc comment says "No persisted-table union (unlike collect_invoked_property_names's extra param)").

Impact

On a scoped incremental codegraph build (ctx.fileSymbols narrowed to changed files + reverse-deps), a dispatch table whose only computed-access consumer lives in an untouched file loses its evidence. resolveFallbackTargets then drops the value-ref calls edge, and the referenced function's fan-in goes to 0 — so codegraph roles --role dead can report it dead on an incremental build while a full --no-incremental build reports it live.

This is the non-conservative error direction (a false positive for dead-code: genuinely live code reported dead), unlike #2088, which is conservative. It is also a full-vs-incremental result divergence, which the same reasoning behind #2087 treated as worth closing.

Current status

Accepted as a documented trade-off in the code comments ("the table+consumer for this idiom are typically same-file, so this narrower scope is accepted for now; a cross-file case missed on a scoped rebuild recovers on the next full build"). Filing so it is tracked rather than only living in a comment.

Suggested fix

Mirror #2087: add a computed_dispatch_table_evidence (file, name) table + migration, a persistComputedDispatchTableEvidence pass alongside persistInvokedPropertyNames, a purge entry in preparePurgeStmts (src/db/repository/build-stmts.ts) and in detect-changes.ts's full-wipe statement, and the matching extra-style union on both the TS and Rust read paths. Also wire the incremental path (src/domain/graph/builder/incremental.ts), which today reads only symbols.computedDispatchTableEvidence for the single rebuilt file (incremental.ts:1541).

Dual-engine: both stages/build-edges.ts and crates/codegraph-core/src/domain/graph/builder/stages/build_edges.rs must change together (ADR-001).

Out of scope for #2088 — that issue is about correlating evidence to a receiver, not about persisting the existing channel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    follow-up

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions