Skip to content

Engineer compact semantic graph snapshots and lifecycle-aware persistence #817

Description

@DavidBakerEffendi

Parent: #813
Depends on: #814
Builds on: #748, #754, PR #798, and PR #802

Description

Define and implement the artifact-lifecycle policy for CFG, ICFG, value-flow, and solver-summary data.

Bifrost already has the right two primitives: CompactRows / CompactDirectedGraph for hot immutable traversal, and generation-aware AnalyzerStore snapshots for stable, expensive, reusable products. Generalize those mechanics without forcing every relation into one graph type or persisting every intermediate.

Base semantic topology should normally be built or hydrated once, assigned dense snapshot-local IDs, and traversed through CSR or CSR+CSC. Query-specific exploded states, worklists, truncations, and witness paths should remain ephemeral. Per-callable semantic facts, CFG fragments, language-semantic summaries, and client summaries may earn SQLite persistence only through measured reuse.

Storage policy

  • CSR for forward-hot relations; CSR+CSC when both directions are hot.
  • Incoming edge IDs may reference outgoing payload rows to avoid duplicating payloads.
  • Functional reverse relations should use dense arrays rather than general CSC.
  • Durable keys include content/workspace identity, language adapter version, semantic-IR version, solver/summary version, configuration, dependency fingerprint, and protocol hash where applicable.
  • Stale, corrupt, incomplete, or budget-truncated entries are cache misses, not valid empty analysis.
  • Coordinate surfaced cache failures with Surface analyzer store and watcher initialization failures #695.

Relevant code

  • src/compact_graph.rs
  • src/analyzer/structural/facts.rs
  • src/analyzer/structural/provider.rs
  • src/analyzer/store/mod.rs
  • src/analyzer/store/liveness.rs
  • src/cache_db.rs
  • migrations/cache/0007-structural-facts-snapshots.sql
  • src/relevance.rs

Suggested work

  1. Publish an artifact matrix: owner, lifetime, identity, invalidation, representation, expected reuse, and observability.
  2. Add typed compact relation builders and payload side tables only when concrete CFG/ICFG consumers establish their shape.
  3. Benchmark mutable construction, freeze cost, traversal, retained bytes, serialization, cold hydration, warm reuse, and invalidation.
  4. Add packed versioned SQLite DTOs only for artifacts that pass explicit promotion criteria.
  5. Test source changes, adapter/rule/version changes, overlay generations, corruption, partial writes, GC, and concurrent readers/writers.

Acceptance criteria

  • Every promoted artifact has a documented lifecycle and cache key.
  • Hot relations demonstrate behavior parity and measured memory/traversal benefit.
  • Persisted artifacts demonstrate meaningful warm reuse and safe targeted invalidation.
  • Temporary query state is not persisted without evidence.
  • Cold/warm benchmarks report commit, fixture, node/edge/fact counts, elapsed time, retained bytes or RSS, hit/miss status, and serialized size.
  • The implementation remains lazy and does not hydrate a whole workspace eagerly.

Non-goals

  • Replacing SQLite.
  • Persisting a monolithic CPG.
  • Keeping rich and compact duplicate full-workspace graphs indefinitely.
  • Treating snapshot-local dense IDs as durable identities.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions