Make a correction stick in agent memory

Stop corrected rules from coming back in agent memory. Use supersedes in Heartwood 0.2.10 so old rules drop from recall, while hooks enforce behavior.

By Heartwood MemoryPublished . Dates are Pacific time.

To make a correction stick in agent memory, write the new rule and name the old memory it replaces. From version 0.2.10, Heartwood Memory's remember(..., supersedes=old_id) writes the correction, moves the old memory to review_state "superseded", and appends one remember audit row naming what was replaced, all in one transaction. Default recall stops returning the old rule, including after a restart, while history stays reachable when you ask for it. Memory remembers; hooks and tests enforce. Heartwood doesn't guess which memory replaced which. You name it.

Why corrected rules come back

Most persistent agent memory stores treat every write as one more note in the pile. You correct an agent in one session, the correction gets saved, and the old instruction stays right beside it.

In a later session, the context resets and retrieval searches the store again. Because nothing retired the earlier rule, both records look current, and the old habit comes back into the prompt.

Overwriting or deleting the old note in place trades one failure for another: you lose the trail of what changed, when it changed, and why the agent acted differently last week. What you want instead is an explicit retirement step that removes the old rule from normal recall without erasing its history.

Make a correction stick with supersedes

From Heartwood Memory 0.2.10, pass supersedes=old_id (a single memory ID or a list of IDs) when you write the correction. If you write the new rule without naming the old one, both stay current and default recall can still return the old text.

Run this variation in an empty folder with uvx --from heartwood-memory==0.2.10 python correction_demo.py. It creates a fresh evaluation store, closes it, and reopens it to confirm the old rule stays out of recall after a restart. Never point an evaluation script at a real or customer database.

python
from pathlib import Path
from heartwood import Heartwood, principal_from

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

reader = principal_from("agent:dev", tenant="tenant:demo")

db = Heartwood(path=path, tenant="tenant:demo")
try:
    old_id = db.remember(
        "Skip local lint checks before opening a PR.",
        subject="rules:repo-checks",
        created_by="agent:dev",
    )
    db.remember(
        "Run pnpm lint before opening a PR.",
        subject="rules:repo-checks",
        created_by="agent:dev",
        supersedes=old_id,
    )
finally:
    db.close()

# Reopen the store in a new session to confirm the replacement survives a restart.
reopened = Heartwood(path=path, tenant="tenant:demo")
try:
    print("Default recall after restart:")
    for item in reopened.recall("PR lint check", principal=reader, k=5)["results"]:
        print(" ", item["content"])

    history = reopened.recall(
        "PR lint check",
        principal=reader,
        k=5,
        filters={"include_review_states": ["superseded"]},
    )
    print("With history requested:")
    for item in history["results"]:
        print(" ", item["content"])
finally:
    reopened.close()
text
Default recall after restart:
  Run pnpm lint before opening a PR.
With history requested:
  Skip local lint checks before opening a PR.
  Run pnpm lint before opening a PR.

Default recall returns only the corrected rule after the restart. Ask for superseded records with filters={"include_review_states": ["superseded"]}, and both versions remain reachable for review.

For the full walkthrough comparing two plain writes against a replacement, plus how the Heartwood memory tool retires earlier versions when editing, renaming, or deleting a file, see the memory replacement guide.

What the audit row records

When db.remember(..., supersedes=old_id) runs, three changes happen inside one transaction:

  1. The new memory is written.
  2. Each named memory moves to review_state "superseded".
  3. One remember row is appended to the hash-chained audit log naming the replaced IDs.

If any part of that transaction fails, nothing is written. You do not end up with a half-applied correction where the new rule landed and the old rule stayed active.

If you need to retire a rule without writing a replacement, call db.supersede(ids, actor=..., reason=...). Each retired memory gets its own supersede audit row.

OperationWhat changesAudit row writtenReturned by default recall?Reachable in history?
remember(..., supersedes=old_id)Writes new memory and sets named IDs to review_state "superseded" in one transactionOne remember row naming the replaced IDsNew memory onlyYes, with include_review_states: ["superseded"]
db.supersede(ids, actor=..., reason=...)Moves named IDs to review_state "superseded" with no replacement writeOne supersede row per retired memoryNoYes, with include_review_states: ["superseded"]
forget() (hard erasure)Destroys the subject's key and purges its recordsErasure event on the audit logNoNo

Heartwood's audit log is append-only and hash-chained, so verify_chain() detects a row edited in place or dropped from the middle of the chain. That makes the log tamper-evident, not immutable: catching a cut-off tail or a recomputed chain requires an external anchor configured outside an attacker's reach.

History is not erasure. A superseded memory is retired, not erased. It stays reachable when you ask for history until forget() erases its subject.

The revocation test: granted, then withdrawn

A harder case than a coding preference is a permission that was granted and later withdrawn. Both instructions were real when they were written, so a check that only verifies whether a note came from a real log will accept either one. After a restart, only the revocation should come back in recall, and the record should show who issued it.

This variation writes a permission grant, supersedes it with a revocation, restarts the store, and prints the returned recall item so you can inspect its content and provenance together.

python
from pathlib import Path
from heartwood import Heartwood, principal_from

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

agent = principal_from("agent:ops", tenant="tenant:demo")

db = Heartwood(path=path, tenant="tenant:demo")
try:
    grant_id = db.remember(
        "Staging deploys are allowed automatically.",
        subject="permissions:staging-deploy",
        created_by="owner:operator",
        source={"uri": "policy://staging/grant"},
    )
    db.remember(
        "Stop automatic staging deploys; wait for operator approval.",
        subject="permissions:staging-deploy",
        created_by="owner:operator",
        source={"uri": "policy://staging/revoke"},
        supersedes=grant_id,
    )
finally:
    db.close()

# Restart and recall as the operating agent.
reopened = Heartwood(path=path, tenant="tenant:demo")
try:
    result = reopened.recall("staging deploy permission", principal=agent, k=5)
    for item in result["results"]:
        print(item)
finally:
    reopened.close()

After the restart, default recall returns only the "Stop automatic staging deploys" record; the earlier grant is retired. Each item in result["results"] carries its source_ids and provenance — its author, its source, and a signature check that Heartwood signs at write time and re-verifies when recalled.

Permissions apply on the write path too. When you pass principal=, a memory that principal cannot read is refused as if the ID were unknown. Retiring another principal's memory requires the reviewer role, or approver for an approved memory.

Using supersedes over MCP

The MCP remember tool accepts supersedes as well. Because Heartwood's local MCP server starts fail-closed with only recall, explain_recall, and health, you must name remember in HEARTWOOD_MCP_ALLOWED_TOOLS first.

From version 0.2.10, the MCP server takes its tenant and principal from its own configuration and rejects tool calls that try to pass a different tenant or principal. If any server on the store writes, give every server that opens it — including servers that only read — the same custody root and the same key ID from your secret store. Without the root, a writer cannot write again after a restart and a reader sees none of the memories written with it; with a different key ID, recall fails with an error. Full setup steps are in the MCP server guide.

What memory does — and what it does not

Memory remembers; hooks and tests enforce.

Keep two limits clear when you wire this into an agent workflow:

  • Heartwood does not detect replacements by itself. Heartwood doesn't guess which memory replaced which. You name it. Nothing is replaced silently, which means a correction written without supersedes leaves both rules current and recallable.
  • Recall does not enforce behavior. Retiring an old rule keeps stale guidance out of default recall, and signed provenance shows who wrote the current instruction. A model can still ignore what it recalls. Use tests, pre-commit hooks, tool allowlists, and approval gates to enforce actions outside memory. Heartwood governs what an agent can recall and change in memory; it does not govern actions outside memory or replace human review.

Try it locally or run hosted recall

Heartwood Memory's core is source-available under BSL 1.1 (not OSI open source). You can read the source, evaluate it, and self-host it for non-production use at any organization size at no charge, and qualifying small organizations (fewer than 100 people and under $1,000,000 in prior-year revenue as defined in the license) can run it in production at no charge too.

Start locally with the memory replacement guide or the 5-minute quickstart, or browse the FAQ for more on audit trails and permissions. When your team is ready for an authenticated hosted recall gateway or a dedicated isolated tenant, see plans and pricing (Team at $349/month or $3,490/year, Professional at $6,000/year, and Enterprise quoted in writing from $24,000/year).

Questions

Does Heartwood detect corrected or contradicting memories automatically?

No. Heartwood doesn't guess which memory replaced which. From version 0.2.10, you pass remember(..., supersedes=old_id) to name the memory a correction replaces. If you write a new memory without naming the old one, both stay current and the old one can still be recalled.

Does a superseded rule stay gone after a restart?

Yes, from default recall. One transaction writes the new memory, moves each named memory to review_state "superseded", and appends one remember audit row naming them. Default recall skips superseded memories, including after a restart, while history stays reachable with filters={"include_review_states": ["superseded"]}.

If Heartwood returns only the new rule, does that enforce how the agent acts?

No. Memory remembers; hooks and tests enforce. Heartwood governs what an agent can recall and change in memory, and re-checks each recalled memory’s provenance signature, but a model can still ignore a recalled instruction. Enforcement outside memory belongs in hooks, tests, tool allowlists, and human review.

Is a superseded memory deleted from the store?

No. History is not erasure. A superseded memory is retired from default recall and stays reachable when you ask for history until forget() erases its subject. Hard erasure is a separate step that destroys the subject's key, purges its records, and records the erasure in the audit log.

  1. Remember what you ruled out across AI tools

    Keep what you ruled out across Claude Code and Codex. Compare a repo decisions file with a shared Heartwood store, client identity, and supersedes.

  2. Jev shadow mode still sends your data

    In Jev shadow mode your local ranking is kept and Jev's scores are only recorded. The query and candidate memories still go out to TypeSafe AI.

  3. What to record when a model ranks memory

    An agent memory audit trail for ranked recall: which ranker ordered the results, the egress decision, a hash of the request, and no query or memory text.