Documentation

Docs / Reference

ADR 0073 - A store read of every edge of one kind, for the code calls coverage count

Status: Accepted (delegated review, 2026-11-18)

Context

/api/v0/precision counts the facts this index holds in each labelled family (ADR 0066). The code_calls family (code calls edges, row D, T020 O-S1-5 (a)) had no count: ADR 0068 lists "no code_calls column in the coverage table" as a known gap because it "would need a store query by edge kind".

The store interface reads edges only by endpoint (Edges(ctx, repo, identities, kinds, direction)). A calls edge's source is not always a function or method: the built-in indexer also writes them from files, classes and variables (fastapi: 5 file and 1 variable sources among 418), so a fixed list of source kinds could miss some. Reading every node and asking Edges for their outgoing calls edges is exact, but on the self-index (20,646 nodes, 44,884 edges, 14,348 calls) it took /api/v0/precision from about 65 ms to about 1.1 s, for a popover.

Options considered

  1. Every node's outgoing edges through the existing interface. Exact, no interface change, about 1.1 s on the self-index. Rejected as too slow for a view the Evidence popover fetches on each open.
  2. A fixed list of source kinds (function, method, file, class, variable). Faster, but a kind the list misses undercounts silently: a wrong count in a view that states what the store holds. Rejected.
  3. A read-only store method EdgesOfKind(ctx, repo, kind) that selects by the edges table's primary key prefix (repository, kind). Exact, about 190 ms on the self-index, no schema change. Selected.
  4. A counting method (edges by kind and source file). Faster still, but a second, narrower read for one view; the edge list is enough today.

Decision

Add EdgesOfKind(ctx, repository, kind) ([]contract.Edge, error) to the store interface, implemented once in sqlstore for SQLite and Postgres: SELECT payload FROM edges WHERE repository=$1 AND kind=$2, sorted in Go by (kind, source, target) in byte order like Edges. It is tested on both backends (internal/store TestEdgesOfKind: the same edges as Dump and as Edges, byte order where a collation would differ, no edge of another kind or repository, an empty list for a kind with none).

/api/v0/precision serves code_calls as a sixth default.families entry with unit edges, counted by the language of the edge source's file (as PL-F9's edges are). Its label is decided by labelOf from the family marker alone, the same decision as /flow's and /source's code_calls_precision, so it is best_effort from row D on every run and never follows a file label (TestCodeCallsNeverPrecise checks the count against Dump on a run whose TypeScript files are stood in as Precise).

Consequences

Known gaps

Review notes (acceptance, 2026-11-18)

Accepted after delegated review (2026-11-17). Step FU (T020 follow-ups: the code_calls family in /api/v0/precision, C3 dialect note on Precise model source cards, C5 resolved as the no_run reason) and one independent review (the T020 task record (internal)): no class A finding; B1 (a cross-language code_calls count test) and C5 (where no_run appears) fixed in the unit.

Report a problem with this pageSource: docs/adr/0073-edges-of-kind-store-read.md