Documentation

Docs / Reference

ADR 0039 - Node name columns and cheaper freshness

Status: Accepted (delegated review, 2026-11-03) Date: 2026-11-03

Context

ADR 0009's review note (2026-10-08) measured 10-11 s per CLI graph read on Langflow regardless of result size. T016 onwards adds an HTTP API and web UI that issue these reads per click. T016a re-measured on Langflow (504c02fc, 10,233 files, 68,647 nodes, 150,032 edges; SQLite; see the T016a task record (internal)): every query, callers and impact call took 8.4-10.6 s and status about as long. About 70% was freshness: the scan walk (dominated by the ignore matcher's regular expressions, not hashing) and Store.Dump, which decodes every file, node, edge and diagnostic although freshness needs only file hashes. The rest was JSON decoding of whole tables: names live only in the node payload, so a name lookup decoded all nodes, and callers/impact decoded every node to build an identity map.

Options considered

Decision

Schema version 3 (migrations/{sqlite,postgres}/0003_graph.sql) adds nullable name and qualified_name to nodes (Postgres COLLATE "C") and the covering index nodes_names. UpsertNode, the only statement that writes nodes.payload, writes the columns from the payload it writes. The migration backfills existing rows in Go inside the migration transaction.

NULL rule, identical on both backends: both columns are NULL when either value contains U+0000 (Postgres text cannot hold it) or when len(repository)+len(identity)+len(name)+len(qualified_name) exceeds 1536 bytes. The task suggested identity, name and qualified name; repository is added because it is part of every nodes_names entry and has no length bound of its own, and Postgres b-tree entries are limited to about 2.7 kB. A payload whose name fields cannot be decoded also leaves NULL columns, so a term read decodes it and reports the error. A NULL row is always a term candidate and never excluded. A payload whose name fields decode but whose full node does not (for example a wrongly typed level) gets columns and can be excluded; see Known gaps.

Nodes with a term selects candidate identities with the other filters plus (qualified_name IS NULL OR name = t OR qualified_name = t OR qualified_name LIKE '%' || escaped(t) ESCAPE '!') in a subquery, reads their payloads in identity order, then applies the unchanged Go predicate and the limit. The SQL is a prefilter that must be a superset of the Go matches. SQLite's LIKE folds ASCII case, which only widens the set; Postgres LIKE under COLLATE "C" is exact. ! is the escape character so the SQL needs no backslash, whose meaning depends on Postgres's standard_conforming_strings. Terms that contain U+0000, are not valid UTF-8 or are longer than 1536 bytes (no non-NULL row can match them; SQLite also limits LIKE pattern length) use the full read every term used before. Reads filtered by kind, file or level use the same identity subquery shape, because with ORDER BY identity both SQLite and the old flat query walked the primary key instead of nodes_kind_level/nodes_file. Edges drops its SQL ORDER BY kind,source,target for the same reason (SQLite walked the edges primary key for the repository instead of edges_incoming/edges_outgoing); the Go sort it already applied over the primary-key columns defines the same total order.

The store interface gains FileHashes(repository), path to stored content hash in one read transaction, and NodesByIdentity(repository, identities), identity-ordered, deduplicated, missing identities omitted, chunked inside one read transaction like Edges. Freshness (status and every query's freshness) uses FileHashes; IDE presentation reads and hashes source lazily for presented nodes' files with the same normalization and contract.ContentHash; callers/impact fetch each level's new endpoints and result files' file nodes with NodesByIdentity; impact alone reads all file nodes for blind spots, after its target is found.

The scan's ignore matcher precompiles each rule: a pattern without / whose body cannot match / (no **, no bracket expression) is matched against the last path segment only, as a string comparison when it has no other metacharacter; anchored literal patterns are string comparisons; other anchored patterns check their leading literal before the regular expression. Byte comparisons agree with the regular expression only for valid UTF-8 (the expression reads each invalid byte as U+FFFD), so a path that is not valid UTF-8 always takes the full regular expression. Rules are searched from the last one, and the first match decides, which is the same as "last matching rule wins". The previous matcher is kept as a test-only reference with a differential test.

Consequences

Known gaps

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

Report a problem with this pageSource: docs/adr/0039-node-name-columns-and-cheaper-freshness.md