All integration guidesLifecycle

Replace a memory so recall stops returning the old one

From Heartwood 0.2.10, name the memory a new write replaces and default recall stops returning the old text. History stays available when you ask for it.

The short answer

From version 0.2.10, when a new memory names the memory it replaces, Heartwood’s default recall stops returning the old text, including after a restart. Heartwood does not detect replacements by itself: if you write a new memory without naming the old one, both stay current and the old one can still be recalled.

Before you start

You need heartwood-memory 0.2.10 or newer. Run the example in an empty folder: it creates a new synthetic store and refuses to touch one that already exists. Never run it against a real or customer database.

Two writes, then a replacement

The example writes two plain memories about the same release badge, recalls them, then writes a third that names the first as replaced. Run it with uvx --from heartwood-memory==0.2.10 python replace_demo.py.

python
from pathlib import Path
from heartwood import Heartwood, principal_from

path = Path("./replacement-demo.db")
if path.exists():
    raise SystemExit("Use a new evaluation store; this example will not modify an existing one.")

db = Heartwood(path=path, tenant="tenant:demo")
reader = principal_from("agent:support", tenant="tenant:demo")
try:
    old_id = db.remember(
        "Project Juniper ships with a blue release badge.",
        subject="project:juniper", created_by="agent:support",
    )
    db.remember(
        "Project Juniper ships with a green release badge.",
        subject="project:juniper", created_by="agent:support",
    )
    print("Two plain writes:")
    for item in db.recall("Juniper release badge", principal=reader, k=5)["results"]:
        print(" ", item["content"])

    db.remember(
        "Project Juniper ships with an amber release badge.",
        subject="project:juniper", created_by="agent:support",
        supersedes=old_id,
    )
    print("After naming the blue badge as replaced:")
    for item in db.recall("Juniper release badge", principal=reader, k=5)["results"]:
        print(" ", item["content"])

    history = db.recall(
        "Juniper release badge", principal=reader, k=5,
        filters={"include_review_states": ["superseded"]},
    )
    print("With history requested:")
    for item in history["results"]:
        print(" ", item["content"])
finally:
    db.close()

What recall returns

After the two plain writes, recall returns both the blue and the green badge: neither names the other, so both stay current. After the third write names the blue one, default recall returns the green and the amber badges, and the blue one is gone. With include_review_states set to superseded, recall returns all three.

text
Two plain writes:
  Project Juniper ships with a blue release badge.
  Project Juniper ships with a green release badge.
After naming the blue badge as replaced:
  Project Juniper ships with a green release badge.
  Project Juniper ships with an amber release badge.
With history requested:
  Project Juniper ships with a blue release badge.
  Project Juniper ships with a green release badge.
  Project Juniper ships with an amber release badge.

How it is recorded

One transaction writes the new memory, moves each named memory to review_state "superseded" and adds one remember row to the audit log that names them. If any part fails, nothing is written. To retire a memory without writing a replacement, call db.supersede(ids, actor=..., reason=...): each retired memory gets its own supersede audit row.

History is not erasure

A replaced memory is retired, not erased. It stays reachable when you ask for history, until forget() erases its subject. Erasure is a separate step: a hard forget destroys the subject’s key and purges its records, and the erasure is recorded in the audit log.

Memory-tool files

Through the Heartwood memory tool (the MCP memory tool or MemoryToolBackend), editing, inserting into or renaming a file retires its earlier versions in the same write, so default recall returns only the current text. Deleting a file purges the current version and retires the earlier ones, and a deleted file no longer comes back after a restart.

Existing data: nothing is rewritten at startup. A file whose earlier versions were written by an older release keeps them in default recall until it is next edited, renamed or deleted through the tool, and a file deleted with an older release can come back after a restart; deleting it again retires its history.

Over MCP

The MCP remember tool accepts supersedes too. remember is not in the default read-only tool set, so name it in HEARTWOOD_MCP_ALLOWED_TOOLS first.

Permissions

When you pass principal=, a memory that principal cannot read is refused as if the id were unknown. Retiring another principal’s memory needs the reviewer role, or approver for an approved memory.

Questions

Does Heartwood detect replacement memories automatically?

No. From version 0.2.10 you name the memory a new write replaces, with remember(..., supersedes=old_id), and default recall then stops returning the old one, including after a restart. If you write a new memory without naming the old one, both stay current and the old one can still be recalled. History stays reachable when you ask for it. Make a correction stick in agent memory.

What happens to earlier versions of a memory-tool file?

From 0.2.10, editing or renaming a file through the Heartwood memory tool retires its earlier versions, so default recall returns only the current text. Deleting a file purges the current version and retires the earlier ones, and a deleted file stays deleted after a restart. Retired versions stay reachable only when you ask for history, until the subject is erased; erasure is separate and destroys the subject's key. A file written by an older release keeps its earlier versions in default recall until its next edit, rename or delete.

Is a replaced memory deleted?

No. It is retired: default recall skips it, and you can still reach it by asking for history. To erase it, erase its subject with forget(), which destroys the subject’s key and purges its records. Remember what you ruled out across AI tools.

Adapted from README.md (Replacing a memory) and CHANGELOG.md (0.2.10) in the source-available core.