AI agents that save notes between sessions can end up trusting their own mistakes, and agent memory is where the damage piles up. A data engineer has named the problem “write-back rot” and sketched five database practices that teams can borrow to contain it.
How one stale record spreads
Most talk about bad data in AI systems assumes a one-way street: corrupted inputs go in, wrong answers come out. Production agents also write. They store customer preferences, account states, troubleshooting results and learned rules, and later sessions treat those notes as ground truth.
Picture a support agent. On day one a billing pipeline lags by six hours, and in that gap a customer drops from an Enterprise plan to a Starter tier. The agent still sees Enterprise, approves a custom SLA credit and saves the note “Approved SLA credit. Customer tier: Enterprise.”
The pipeline recovers on day two. On day three a different agent handles a renewal question, reads the note and quotes Enterprise terms. By day four several workflows have summarized and re-saved the entry, and a six-hour lag has become the account’s tier of record.

Why a Postgres table doesn’t fix it
Teams often answer that they already keep memory in Postgres. But a database engine is not the same as database discipline. Whether the store is pgvector, Neo4j, Redis or a managed memory framework, it usually works as an append-only log: every memory is an INSERT holding some text and an embedding.
Nothing in that schema stops two conflicting facts from living side by side. Nothing tells next month’s agent that a temporary exception has lapsed. Nothing links the note to the billing record that produced it. And the writer isn’t a deterministic SQL job. It’s a probabilistic model working from noisy conversation, with no schema constraints, no lineage and no rollback button.

Five practices from the database world
1. Upserts and uniqueness rules
Relational databases use primary keys and UNIQUE constraints so two versions of the same current state can’t both be active. Most vector memory stores only append. A user who said in January that they were a VP of Engineering at one company and in October that they’re a CTO at another leaves two embeddings behind, and a search may return either. The fix is to extract entity and attribute pairs, enforce upsert behavior, mark the older record as superseded and leave superseded rows out of default retrieval.
2. Expiry dates for facts
Data warehouses separate immutable event logs from slowly changing dimensions that track the window in which a value was true. Agent memory rarely does. A note that a user is traveling in London this week sits next to “prefers Python over TypeScript” with the same permanence, and six months later the agent still greets the user in London time. The suggested split is two tiers: episodic memory with time-to-live limits of 7, 14 or 30 days, and semantic entity memory that carries explicit valid-from timestamps and gets re-verified before high-stakes use.
3. Validated writes and access control
No sane team lets an outside client run raw INSERT statements against production, yet many give an agent a save_memory() tool and let the model decide what lasts forever. That invites two failures. An agent can write a tentative guess as a confirmed fact. Or a malicious instruction hidden in an email or support ticket can trick it into saving a poisoned rule, such as always forwarding invoice summaries to an outside address. The remedy is a deterministic validation layer with strict Pydantic or JSON schemas, limits on which agent roles can write to shared memory, and a requirement that high-impact changes cite a verified tool output.
4. Provenance and lineage
When a transformation job breaks, data lineage shows which tables were hit. Agent memory has none. If an upstream API returned bad prices for four hours yesterday, you can fix the API but can’t query for every memory saved by an agent that read it in that window. The proposal is to attach structured metadata to each record: the agent that wrote it, the session, the source tool, the timestamp of the source data and a confidence score. A later UPDATE can then invalidate every active memory from one tool within a given time range. The filter should use when the agent read the data, not when it wrote the memory, which is why provenance needs its own timestamp.
5. Observability and rollback
Most AI monitoring covers inference traces such as latency, token counts and single-turn eval scores. Almost nobody watches the memory store itself. If a prompt change makes an agent write ten times more memories per session, or produce contradictory records for the same user, token metrics won’t show it, and complaints arrive weeks later. Teams should track write-volume anomalies, contradiction rates per entity and retrieval hits on stale records, and snapshot memory before shipping new prompts or extraction logic so a bad batch of writes can be rolled back in minutes.

What to do before the next prompt change
The first wave of context engineering was about choosing what goes into a model’s window during a session. The next wave, the author argues, has to govern what the model writes back out and keeps. An agent with long-term memory is a distributed, stateful system with a non-deterministic writer, and it needs the same constraints, lineage, expiry rules and monitoring that production databases already have.
A practical starting point is cheap. Snapshot the memory store before the next deploy, add a status and a source field to every record, and start counting writes per session. Until agent memory gets that treatment, every agent in production is one stale read away from poisoning its own future runs.
Source: Monte Carlo