Expand description
Multi-store, lossless memory archive (#995 Phase 1).
Every memory store — facts, history, 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 the memory-capacity module and the recall-miss rehydrate path.
§On-disk layout
- Facts live under
memory/archive/facts/<project hash>/archive-*.json; the partition is always the request project’s. Releases before 3.11.5 kept unprotected facts in one installation-widememory/archive/archive-*.jsonwithout a provable project: those files are left in place, unread, and are never listed, rehydrated or restored into any project. - 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§
- Archive
Config - Tunable archive bounds.
rehydrate_reachis how many of the newest archives the recall-miss path scans; it defaults tomax_filesso every retained archive is actually reachable (closing the pre-#995 16-retained / 4-reachable gap). Both are overridable via env for ops tuning. - Archive
Envelope - Unified archive envelope for reading every store. The collection is keyed
items; thefactsalias keeps legacy facts archives (which used that key) deserializable.
Enums§
- Memory
Store - 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/pattern structs.
Constants§
- RETIRED_
PROCEDURES_ STORE_ NOTICE - Reply to a restore that names
store=procedures: that archive belonged to the procedure memory retired in 3.13.0 (DEPRECATIONS.tomlmcp-ctx-session-episodes-procedures). Nothing is restored; archived procedure files stay on disk untouched.
Functions§
- adopt_
legacy_ facts - Copy legacy archived
factsinto the facts partition ofproject_root(an explicit, canonical root) through the admission of a normal facts archive write. Each fact is admitted on its own; the admitted ones are archived together. Returns one flag per fact:trueadopted,falsewithheld. A fact the partition already holds is not archived again, so a rerun after an interrupted adoption (copied, not yet journaled) leaves exactly one copy. - archive_
items - Archive
itemsforstore/scope, then prune the directory tocfg.max_filesnewest. Returns the written path, orNonewhen there was nothing to archive. Ordering must be inspectable before writing; removal of old files remains best-effort. - legacy_
facts_ archives - The installation-wide facts archives of releases before 3.11.5, as
(path, envelope). They are served to no project; only the explicitlean-ctx migrate legacy-contextadoption reads them. - list_
archives - All archive files for
store/scope, sorted by their recorded archive time. Uninspectable files remain listed, but prevent retention from deleting files. - orphaned_
facts_ archives - Facts archives left in a partition that is no longer the current one of the root they recorded: that project’s identity (remote, package name) changed since. Served to no project until adopted.
- reachable_
archives - The newest
cfg.rehydrate_reacharchives forstore/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.
- restore_
knowledge_ items