Skip to main content

Module memory_archive

Module memory_archive 

Source
Expand description

Multi-store, lossless memory archive (#995 Phase 1).

Every memory store — facts, history, procedures, patterns — archives the items it evicts here before dropping them, so capacity management is never lossy and anything reclaimed can be restored. This is the single archive subsystem behind crate::core::memory_capacity and the recall-miss rehydrate path.

§On-disk layout

  • Facts keep their legacy global location memory/archive/archive-*.json for backward compatibility (pre-#995 archives stay readable).
  • Every other store lives under memory/archive/<store>/<scope>/archive-*.json, where <scope> is the per-project hash so a restore lands in the right project.

§Format

A single envelope (ArchiveEnvelope) is used for all stores. The item collection serializes as items; the facts alias keeps legacy facts archives (which used that key) deserializable.

Structs§

ArchiveConfig
Tunable archive bounds. rehydrate_reach is how many of the newest archives the recall-miss path scans; it defaults to max_files so every retained archive is actually reachable (closing the pre-#995 16-retained / 4-reachable gap). Both are overridable via env for ops tuning.
ArchiveEnvelope
Unified archive envelope for reading every store. The collection is keyed items; the facts alias keeps legacy facts archives (which used that key) deserializable.

Enums§

MemoryStore
Which memory store an archive belongs to. Drives the on-disk path only — the archive is generic over the item type, so this stays decoupled from the concrete fact/insight/procedure/pattern structs.

Functions§

archive_items
Archive items for store/scope, then prune the directory to cfg.max_files newest. Returns the written path, or None when there was nothing to archive. Best-effort prune: a prune failure never fails the write.
list_archives
All archive files for store/scope, sorted ascending (lexical == chronological for the zero-padded timestamp filename prefix).
reachable_archives
The newest cfg.rehydrate_reach archives for store/scope — the set a recall miss should scan. Aligned with retention so nothing retained is unreachable.
restore_items
Restore the items from a single archive file.