Scoped JSON document manager supporting latest and rewindable (fork: "as_of") policies.
Rewindable documents store base snapshots and RFC 6902 (Jsonpatch) operational deltas
stamped with the commit seq, enabling exact historical reconstruction on conversation fork
via snapshot_as_of/3. Active snapshots are cached in :ets (:super_pi_doc_cache).
Summary
Functions
Removes cache entries (another node wrote these documents).
Creates or updates a scoped document at seq and caches the new immutable snapshot in ETS.
Writes a fast in-memory ETS overlay for deferred commits (100ms streaming updates).
Reads the latest snapshot of a document, checking ETS first before reconstructing from Ecto.
Reconstructs a rewindable conversation document (pi.agent) as of at_seq, walking
conversation fork ancestry when at_seq predates the fork point (spec.md §3.3).
Reads the latest value of a document from the database, never from the cache, and (on
PostgreSQL) locks its row until the transaction ends. Use it for a read-modify-write inside
SuperPi.Durable.Storage.commit/1: a cached copy may be older than what another node wrote.
Functions
Removes cache entries (another node wrote these documents).
Creates or updates a scoped document at seq and caches the new immutable snapshot in ETS.
Writes a fast in-memory ETS overlay for deferred commits (100ms streaming updates).
Reads the latest snapshot of a document, checking ETS first before reconstructing from Ecto.
Reconstructs a rewindable conversation document (pi.agent) as of at_seq, walking
conversation fork ancestry when at_seq predates the fork point (spec.md §3.3).
Reads the latest value of a document from the database, never from the cache, and (on
PostgreSQL) locks its row until the transaction ends. Use it for a read-modify-write inside
SuperPi.Durable.Storage.commit/1: a cached copy may be older than what another node wrote.