Tiramemsu

Checkpoints for agent memory: tag, diff, revert

Tiramemsu articles · 1 December 2026

Coding agents have learned to undo. Claude Code rewinds to a checkpoint, LangGraph forks from any step, and sandboxes snapshot and restore. The code and the conversation can go back. The agent’s memory usually cannot. Most memory layers only move forward: once a bad sync, a hallucinated fact or a confused session has written to them, the damage stays until someone cleans it by hand.

Tiramemsu never deleted anything in the first place. Every statement keeps the transaction that added it and the one that retracted it, so the memory as of any past transaction is exact. Checkpoints build three tools on that history:

A bad sync, undone

A support agent remembers that Alice works at Acme, with confidence 0.9, and that she prefers email. Before a sync from another tool runs, the agent takes a checkpoint. The session below was run against the Python package; the output is real.

from tiramemsu import Database, Iri
v = lambda x: Iri("urn:tiramemsu:v:" + x)
db = Database("memory.db")

with db.transact() as tx:
    job = tx.assert_(v("alice"), v("worksAt"), v("acme"))
    tx.assert_(job, v("confidence"), 0.9)
    tx.assert_(v("alice"), v("prefers"), "email")

with db.transact() as tx:
    tx.tag("before-sync")          # names the last committed transaction

db.tags()
# [{'name': 'before-sync', 't': 1, 'taggedIn': 2, 'eid': 4}]

The sync then goes wrong. It moves Alice to Globex, adds a second contact preference, and puts her in Atlantis:

with db.transact() as tx:
    tx.supersede(1, o=v("globex"))
    tx.assert_(v("alice"), v("prefers"), "phone")
    tx.assert_(v("alice"), v("livesIn"), v("atlantis"))

What changed?

diff answers with the net change, not the raw log. Removed statements say how they went (here, by supersede), and a correction is reported as a pair:

d = db.diff("before-sync")             # to "now" by default

- 1  v:alice      v:worksAt     v:acme      (supersede)
- 2  stmt 1       v:confidence  0.9         (supersede)
+ 5  v:alice      v:worksAt     v:globex
+ 6  stmt 5       v:confidence  0.9
+ 7  stmt 5       sys:supersedes stmt 1
+ 8  v:alice      v:prefers     "phone"
+ 9  v:alice      v:livesIn     v:atlantis
superseded: [{'removed': 1, 'added': 5}]

Supersede carried the 0.9 confidence over to the new job (statements 2 → 6), as it always does. The diff shows that too, so nothing moves without a trace.

A diff reads only the statements with an event after the earlier moment, through an index. A diff from a checkpoint to now costs the size of the change, not the size of the memory.

Look before you leap

preview_revert runs the revert as a dry run, with every check a real one runs, and writes nothing:

db.preview_revert("before-sync")
# {'wouldCommit': True, 'failure': None,
#  'report': {'target': 1, 'retracted': [5, 6, 7, 8, 9],
#             'restored': [{'from': 1, 'to': 10}, {'from': 2, 'to': 12}], 'erased': []}}

Go back

with db.transact() as tx:
    tx.revert_to("before-sync", tag_before="bad-sync")

# {'t': 4, 'target': 1, 'retracted': [5, 6, 7, 8, 9],
#  'restored': [{'from': 1, 'to': 16}, {'from': 2, 'to': 18}], 'erased': []}

Alice is back at Acme, with her confidence layer, and prefers email again:

SELECT ?p ?o WHERE { v:alice ?p ?o }
# now:            worksAt acme · prefers "email"
# as of bad-sync: worksAt globex · prefers "email" · prefers "phone" · livesIn atlantis

tag_before named the broken state bad-sync, so it can still be inspected and the revert can itself be reverted.

The restored ids are 16 and 18, not 10 and 12. The preview burned the ids it showed, so no id is ever issued twice.

How it works, and why nothing is lost

A revert is one ordinary transaction. It never deletes or rewrites a row. It does three things:

  1. It retracts what is live now but was not live at the target. Here that is statements 5 to 9. Each retraction cascades to the layers on it, as usual.
  2. It asserts again what was live at the target but is not live now, as new statements with their original content and valid time. A restored statement gets a fresh id, because a retraction is permanent: the old statement 1 stays retracted in history, where it belongs.
    • Layers come back on the new copy. The confidence is now about statement 16.
    • Graph memberships and derived beliefs come back the same way.
    • Each copy carries a sys:restoredFrom link to its original.
  3. It records itself. The transaction gets sys:revertedTo, naming its target.

Two consequences follow:

db.diff("before-sync", by_content=True)    # added: [], removed: []

The memory’s rules still apply to the result. Unique and single-valued predicates are checked, enforced Datalog and ELPI constraints run at commit, and a revert that would break one fails as a whole and writes nothing.

The new values are retracted before the old ones come back. So restoring alice email "a@x" works even when a later statement gave that unique address to someone else: the later holder was not there at the target, so it is retracted first.

Tags and transaction metadata are history, not belief, so a revert leaves them alone. The tag you reverted to survives the revert.

A property test checks two claims after random sequences of asserts, layers, corrections, retractions and reverts:

It found one case we had not thought of, a note attached to a restored-from link, and that case is now covered.

From the command line

$ tm tag mem.db clean
tagged 1 as "clean" (in tx 2)
$ tm import mem.db bad.nt
$ tm diff mem.db clean
diff tx 1 → tx 3: 2 added, 0 removed, 0 superseded
+ e3      <urn:tiramemsu:v:alice> <urn:tiramemsu:v:livesIn> <urn:tiramemsu:v:atlantis>
+ e4      <urn:tiramemsu:v:mallory> <urn:tiramemsu:v:worksAt> <urn:tiramemsu:v:acme>
$ tm revert mem.db clean --dry-run
dry run: reverting to tx 1 would retract 2 and restore 0 statement(s); nothing written
$ tm revert mem.db clean --tag-before oops
reverted to tx 1 in tx 4: retracted 2, restored 0
$ tm tags mem.db
clean                    tx 1        (tagged in tx 2)
oops                     tx 3        (tagged in tx 4)

Every command takes --json and prints the same JSON the Node.js and Python packages receive. A moment is a transaction number, now, or a tag name. That is why a tag may not be called now or look like a number.

For agents over MCP

The MCP server (see Give your agent a memory over MCP) has three new tools by default:

An agent can mark the start of a task and show you, at the end, exactly what it learned and what it corrected.

revert is different: one call can retract a great deal at once. The server lists it only when you start it with --allow-revert. MCP clients see it marked as destructive, and read-only mode refuses it even with the flag.

claude mcp add tiramemsu -- tiramemsu-mcp --db ./memory.db --allow-revert

→ checkpoint {"name": "start"}
→ assert     {"s": {"iri": "urn:tiramemsu:v:mallory"}, "p": …, "o": …}
→ diff       {"from": "start"}                      ← one statement added
→ revert     {"target": "start", "preview": true}   ← wouldCommit: true
→ revert     {"target": "start"}                    ← retracted: [that statement]

What it does not do

How diff stays cheap, why a restored statement gets a new id and what the property test found: How checkpoints work.

Next: recall, review, recheck →