Documentation

Docs / Reference

ADR 0006 — Cached extraction and snapshot diffs

Status: Accepted (developer review, 2026-10-05) Date: 2026-10-05

Context

T006 makes the complete v1 snapshots from ADR 0005 practical for a built-in indexer. Its developer review requires unchanged sources to avoid parsing and unchanged graph records to avoid database writes. Cross-file links must still respond to deleted or renamed targets. T002 also found repeated WASM compilation and unconstrained worker counts expensive.

Options considered

Decision

Keep contract v1 unchanged. Add fact_cache in schema migration 0002 for both SQLite and Postgres, accessed only through store.Store. Keep the most recent entry per logical repository/path; require matching content hash and extractor version (including the file-size policy) for reuse. Cache source nodes, containment, export/import bindings, call candidates and syntax diagnostics. Do not cache transient parser/extractor failures. Corrupt JSON is a cache miss. Changing grammar/extraction/naming semantics requires an extractor-version bump.

Cache entries are independent source-derived artifacts and may be saved before ingestion. A failed stream can leave useful extraction cached, but cannot publish an incomplete graph. Successful ingestion prunes cache entries for absent files. Rebuild import/call edges on every run against the current inventory, including for cached callers. Do not emit dangling edges; diagnose unavailable imports and count unresolved calls per file. Resolution is intentionally best effort, without TypeScript type checking, path aliases, inheritance or re-export traversal.

Within the serialized repository transaction, retain previous payloads and the keys emitted this run. Upsert only changed payloads; delete absent edges, nodes and files after valid footer/EOF. References must point to keys emitted in the new snapshot, not merely rows left from the preceding run. A changed duplicate file within one stream still deletes its previously emitted graph as v1 requires. Diagnostics and run metadata are republished every run. Transaction.Writes and ingest.StreamWithWrites expose graph-row counts for verification and CLI reporting. The contract remains the sole application fact boundary.

Pin production wasitter v0.1.0 / wazero v1.10.1 and the existing audited JS/TS/TSX assets. Compile each grammar once per process/cache configuration. A shared, thread-safe wazero engine owns compiled code and WASI imports; each worker owns independent guest module memory, wasitter runtime wrapper and parser, reused sequentially. Trees are detached and closed before another parse; modules and parsers close when the batch ends. Compiled engines remain until process exit. This shares compilation, not mutable parser state, as required by ADR 0002.

Use os.UserCacheDir()/graphvein/wazero/wasitter-0.1.0-assets-v1 for compilation. Wazero additionally keys entries by its runtime version and module digest. Unavailable disk caching falls back to memory. On corrupt-cache errors, discard only that owned namespace and compile with a fresh runtime/cache; fall back to memory if rebuilding disk storage fails. Close-on-context-done interrupts WASM; the per-file deadline also bounds tree traversal. Default workers are min(4, CPUs), timeout five seconds, and parsing size limit 2 MiB.

CLI index and status accept a repository path and --repository logical ID (directory basename by default); index also accepts --workers, --timeout, --max-file-size and --emit. The emitted stream is also ingested atomically. Use a temporary stream under the ignored .graphvein/ directory rather than keeping another complete serialized snapshot in CLI memory.

Measurements

Windows/amd64, existing pinned RealWorld React checkout. Both cold and warm measurements use a fresh child process and fresh SQLite store. Only compilation files survive between them; all 73 supported source files are parsed in each. The harness separately primes all three grammars to measure parser startup, then measures full scanning, extraction, linking and ingestion. Process peaks include everything, measured by GetProcessMemoryInfo.

Workers Cache Parser startup ms Index ms Ingest ms Peak resident MiB
1 cold 447.85 721.33 121.85 192.02
1 warm 50.54 740.72 133.07 190.51
4 cold 436.58 541.15 134.19 226.41
4 warm 51.22 553.52 133.92 234.03

The fixture body edit reparses one file and writes one file row/two node rows, with no changed edge rows; its dump matches a fresh full index. The corpus's second CLI run reparses zero files, reuses 73, writes zero graph rows, and takes 134.17 ms to index plus 91.12 ms to ingest (first: 917.89 + 129.45 ms). Diffing is sufficient for this corpus; it does not justify a delta contract.

Consequences

Complete snapshots preserve interchangeability and rollback guarantees while avoiding expensive unchanged work. Link resolution still traverses cached call candidates, and ingestion still reads every wire record. Old-payload and seen-key maps require O(snapshot size) memory; the 128-record write buffer remains bounded, but total ingestion memory is no longer claimed bounded independently of graph size. This is a deliberate measurable tradeoff, not a streaming-delta solution.

Known gaps

Postgres tests are wired to the same production golden and incremental cases, but local execution is unavailable: no configured test URL or running Docker daemon. Linux CI provides the configured Postgres service. Cross-platform runs need CI execution after push; local cross-builds cannot prove those runs. Measurements are individual samples, not statistical guarantees. They cannot be compared as speed ratios with T002's five-language, 678-file parsing-only corpus. Large repositories and long-running engine memory need further profiling. Working-tree overlays, semantic disposition hashes, other languages, external indexers and IDE coordinate conversion remain in their later tasks.

Review notes (developer, 2026-10-05)

Review notes (developer, 2026-10-07, after T008c)

Review notes (developer, 2026-10-08, after T009)

Review notes (developer, 2026-10-08, after T010a)

Review notes (developer, 2026-10-08, after T010b)

Report a problem with this pageSource: docs/adr/0006-incremental-snapshot-indexing.md