Give memories a working tier, a long-term tier, and a record of what disagrees

A memory used to have one state: present. A session could not be reloaded
without searching, nothing separated what a person said today from what the
store ingested a year ago, and two statements that disagree about a number
were both handed to the reader as if the store believed both.

Schema v10. Atoms gain session_id, importance, recall_count, last_recalled_at
and archived_at; two tables arrive beside them — consolidations (one watermark
per holder+scenario lane) and conflicts (a pair, the term they disagree on,
both values, and whether anyone has settled it). v_atoms_current now also
hides archived rows, and apply() drops the view before rebuilding it because
CREATE VIEW IF NOT EXISTS would keep the old body and ignore the archive.

Working memory is a read, not a store: `working <holder> <session>` returns
what that session recorded, in order, with no search involved. Consolidation
rolls a lane's new memories into one standing summary and moves the watermark
to the newest memory actually rolled up — not to the clock of the pass, which
made a second pass count the same memories twice. The archive rule is stated
in the command that runs it (recorded before N days, never returned by a
search, importance at or under a floor) rather than hidden in a decay formula
nobody measured; --dry-run names the victims first.

A conflict is recorded when a new memory repeats a label with a different
number in the same holder's same scenario. Retrieval drops the older side
while the conflict is open and both sides answer again once it is settled:
settling is not superseding, and a word-only disagreement is left alone
because a reworded sentence would fire on every paraphrase. Numbers are keyed
to both the memory's subject and the nearest preceding label, measured: the
two thermostat sentences share only their subject, so a nearest-word-only rule
found nothing.

Search now counts the memories it handed back, which is the only use estimate
the store has, and the archive rule reads it. The dense index applies the same
currency rules as the view, so an archived memory cannot stay findable through
one leg while the other hides it.

Two reads over HTTP (working, conflicts) and two tools over MCP
(working_set, memory_conflicts); curation stays with the operator because an
agent should not decide what its own past is worth. remember and supersede
carry a session id; importance does not cross MCP, because recall_count is
observed and importance is stated.

Gates: 366 passed; ruff clean; mypy 24 errors in 9 files, the recorded 9cb46c1
baseline, net 0; pyright 0 on the touched files; go build/vet/test and gofmt
clean; mcp_write_smoke PASS.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 07:13:11 -04:00
1 parent 4c6af87fe0
commit dc9cfb5a30
30 files changed
+1814 -229

No files matched your search

+70
View File
@@ -242,3 +242,73 @@ def test_a_second_version_database_rebuilds_its_index_on_upgrade(tmp_path: Path)
assert [atom_id for atom_id, _ in search_fts(upgraded, "钥匙", 5)] == ["key"]
with upgraded.connect() as connection:
assert int(connection.execute("PRAGMA user_version").fetchone()[0]) == SCHEMA_VERSION
def test_a_fresh_database_carries_the_tier_columns_and_their_tables(tmp_path: Path) -> None:
database = _database(tmp_path)
columns = _atom_columns(database)
for column in (
"session_id",
"importance",
"recall_count",
"last_recalled_at",
"archived_at",
):
assert column in columns, column
with database.connect() as connection:
tables = {
row[0]
for row in connection.execute("SELECT name FROM sqlite_master WHERE type = 'table'").fetchall()
}
assert {"consolidations", "conflicts"} <= tables, (
"a lane's watermark and a store's disagreements are state, so they live in tables"
)
def test_the_current_view_hides_an_archived_memory_without_deleting_it(tmp_path: Path) -> None:
database = _database(tmp_path)
_seed_source(database)
database.upsert_atoms([_atom("kept"), _atom("archived")])
with database.connect() as connection:
connection.execute(
"UPDATE atoms SET archived_at = ? WHERE atom_id = 'archived'", (NOW.isoformat(),)
)
visible = connection.execute("SELECT atom_id FROM v_atoms_current ORDER BY atom_id").fetchall()
assert [row[0] for row in visible] == ["kept"], "the archive is a tier, not a deletion"
assert database.atom_count() == 2
def test_a_ninth_version_database_gains_the_tiers_in_place(tmp_path: Path) -> None:
"""A ninth-version store had no tiers at all; the upgrade must add them and rebuild the view."""
database = _database(tmp_path)
_seed_source(database)
database.upsert_atoms([_atom("key")])
with database.connect() as connection:
# The downgrade removes what a ninth build never had, including the view and indexes
# that reference those columns, so the reopened store really is a ninth-version one.
connection.executescript(
"""
DROP VIEW IF EXISTS v_atoms_current;
DROP INDEX IF EXISTS idx_atoms_session;
DROP INDEX IF EXISTS idx_atoms_archived;
ALTER TABLE atoms DROP COLUMN session_id;
ALTER TABLE atoms DROP COLUMN importance;
ALTER TABLE atoms DROP COLUMN recall_count;
ALTER TABLE atoms DROP COLUMN last_recalled_at;
ALTER TABLE atoms DROP COLUMN archived_at;
DROP TABLE consolidations;
DROP TABLE conflicts;
PRAGMA user_version = 9;
"""
)
upgraded = _database(tmp_path)
assert "archived_at" in _atom_columns(upgraded)
assert [atom.atom_id for atom in upgraded.list_atoms()] == ["key"], "the upgrade kept the memories"
with upgraded.connect() as connection:
assert int(connection.execute("PRAGMA user_version").fetchone()[0]) == SCHEMA_VERSION
connection.execute("UPDATE atoms SET archived_at = ? WHERE atom_id = 'key'", (NOW.isoformat(),))
hidden = connection.execute("SELECT count(*) FROM v_atoms_current").fetchone()[0]
assert hidden == 0, (
"the old view body survived the upgrade, so an archived memory would still answer"
)