Documentation

Docs / Reference

ADR 0060 - Code-to-table linking: query payloads and table access edges

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

Code-to-table linking (docs/contract/claims/table-access.md, project plan M2). Number reserved by the T018h investigation; written with the change that fixes the cached payload shapes, gates and versions for Python and Rust. The TypeScript fidelity fields are a separate section, added when that unit lands; nothing in the Python and Rust decisions depends on them. The edge, unknown-record, SQL reader and oracle decisions are fixed by the task file's claim contract; steps H-B3 to H-B6 implement them and add their implementation notes here.

Context

T018h emits reads_table and writes_table edges from the functions that build queries to the table nodes the schema sources emit (sqlx migration sets, SQLModel, Prisma and Drizzle groups), so change impact (T019, row I8) can answer "what uses this table in code". The link pass sees cached facts and raw sources, never a tree (ADR 0059's payload decision). The investigation checked the caches field by field:

Options considered

  1. Link-time re-reading of retained sources (a lexer per language over the raw bytes). Rejected: it needs its own tokenizer for Python strings and Rust raw strings, comments and macro token trees, and owners would come from span containment instead of the extractor.
  2. Widen the ungated caches (HelperCalls arguments, Rust call arguments for every file). Rejected: the cost lands on every file and every consumer of those fields.
  3. Gated, versioned payloads next to the existing model payloads, capture filtered by the cheapest syntactic test that keeps every site a contract row can claim or refuse. Chosen.

Decision

Python: model payload version 2

facts.PythonModels (ADR 0053) becomes version 2 (facts.PythonModelsVersion; version 1 entries miss once) with:

Shape and rules: docs/lang/python-models.md, "Query sites".

Rust: RustFacts.Queries

[]facts.RustQuery, gated on a use of sqlx or a site path starting with sqlx::: the sqlx query macros (query!, query_as!, query_scalar!, their _unchecked forms) and query functions (query, query_as, query_scalar, query_with, query_as_with) spelt with one segment or a first segment sqlx. A site keeps Path segments, Macro, the SQL argument (the first; the second for query_as!) decoded when it is a string literal, normal or raw, or for a macro a + concatenation of literals (Literal, SQL, SQLSpan), Span, Owner (the call capture's Source) and Scope (innermost lexical scope, for resolving use sqlx::query through RustScope.Imports). Macro arguments are split on the commas between token-tree children, so commas in strings and comments never split. RustFacts.QueriesValid() is checked on every cache read. The payload is versioned by the aggregate extractor version, like the rest of RustFacts. Shape and rules: docs/lang/rust-sqlx.md.

Versions

One aggregate extractor version bump, extractors-33, covers both payloads (and the TypeScript fields if H-B2 lands in the same release; otherwise H-B2 takes the next free number).

TypeScript fidelity fields

No new TypeScript payload: every call is already cached ungated as a facts.ClientCall (callee chain, reduced arguments, owner, scope, span). Two additive fields close its two gaps, in both reductions the cache holds (routeExpr for module-level binding values and RouteCall arguments; urlExpr for ClientCall arguments, which replace the routeExpr arguments while the callee chain stays from routeExpr):

No consumer reads either field (the full suite and the fixture goldens are unchanged); the version bump is extractors-33, shared with the Python and Rust payloads. Receivers stay unproven (parameters are bound without type annotations; a callback parameter such as tx is not linked to the call receiving the callback), so TypeScript ORM rows are inferred (O1). Shape: docs/lang/typescript-models.md, "Call cache fidelity fields".

Edges, unknown records, SQL reader, oracle

Fixed by the task file and recorded here as those units land: the first emission of reads_table/writes_table (owner rule W1, aggregation W2, provenance fact or inferred at confidence 0.9), the CT-Q1/CT-Q2 SQL subset reader, the Postgres analyzer oracle (debug_print_parse permission bits), contract row ids CT- and assumption ids TA-V.

Where the per-edge data lives (task Revision 2). Contract v1 edges have no attributes field (type, kind, source, target, provenance, confidence, evidence; an unknown edge field is dropped with unknown_field), so the edges stay plain v1 edges whose evidence lists every site, and the owner node carries two open attributes, the linker-attributes-on-existing-nodes pattern of the Angular linker:

No contract_version bump and no contract change: the edge kinds exist in contract v1 and node attributes are open.

Step H-B3 notes (sqlx, the reader, the oracle; docs/extract/table-access.md):

Step H-B5 notes (Prisma rows CT-R1..CT-R3, site_partial):

Step H-B6 notes (Drizzle rows CT-Z1..CT-Z4; Revision 4):

Step HF notes (Revision 5, the independent review's findings):

Consequences

Known gaps

Review notes (delegated review, 2026-11-14)

Accepted after the green [ci windows] run 43573327834 on 76f2c11 (Windows and postgres green; postgres job: 0 FAIL, only the env-gated skips; CI's Postgres is 17.12).

Report a problem with this pageSource: docs/adr/0060-code-to-table-payloads.md