BM
Bashar ModallalSOFTWARE · AI · SYSTEMS
← All field notes

AI

Designing Long-Term AI Memory Without Preserving Mistakes

A practical design for assistant memory that accepts corrections, rejects stale evidence and does not restore deleted facts after a rollback.

Layered memory cards pass through a validation gate; a correction marker replaces an outdated record.

An engineering assistant remembers that Leila approves staging releases. Three months later, Leila transfers to another team. The assistant has a current roster and an old note, but the old note is shorter, matches the question closely, and gets retrieved first. Asked who can approve a release tonight, it answers “Leila.” The retrieval system found exactly what it was built to find. The memory system failed to decide whether that fact was still usable.

Long-term memory needs rules for what enters, what remains current, who may see it, and what happens when someone corrects it. Start with a record that can be challenged and revoked. Add semantic search after you can control what it is allowed to return.

Separate the active conversation from durable knowledge

A conversation checkpoint helps resume an interrupted task. A compacted conversation helps fit recent turns into the model’s context window. Neither should automatically become evidence in a new conversation. A summary can compress “Leila might be able to approve this” into “Leila approves releases” because the distinction was not important to the summary writer at the time. A cross-session memory system magnifies that error.

MemGPT describes managing information across limited in-context space and external memory tiers. That is a useful architectural distinction. The rules for promoting material between those tiers are a separate product decision. An assistant can remember the user’s preferred report format, but the same promotion rule should not apply to a permission, an unpublished price, or a deadline heard in a forwarded message.

I would start with three lanes: session state for unfinished work; explicitly scoped durable preferences and decisions; and references to live sources for operational facts. The latter can include where to look for the current on-call owner, but not a promise that yesterday’s owner still holds the role. A tool call that mutates a system must independently verify current authority in that system. Memory never grants permission to execute it.

Treat every saved item as a claim with a lifetime

Store tenant_id, subject_id, an explicit fact_key and scope, a typed value, source_ref, source_version, recorded_at, effective_from, any effective_until, and a separate expires_at. Record the source’s authority class and the item’s state, such as candidate, active, superseded or revoked. The W3C PROV Data Model offers a vocabulary for reasoning about who produced information and what it was derived from. You do not need to implement the entire standard to capture those relationships. A reference identifies a source; it does not prove that the interpretation of that source is correct.

recorded_at tells you when the system learned something. effective_from tells you when it became true or applicable. expires_at tells you when the system must stop relying on it without fresh evidence. A roster correction received Monday can say the role changed the previous Friday. A temporary instruction “send the finance report as CSV this month” should expire even if no one sends a second message. Keeping these clocks separate lets you distinguish “what was true on Friday?” from “what did the assistant know on Friday?”

State Eligible for a current answer? Typical next step
Candidate No Validate provenance, scope and eligibility
Active Only if currently authorized and within its usable interval Retrieve and cite, or refresh from source
Superseded No Keep only if permitted; use for explicitly authorized history
Revoked or expired No Block reads, then purge or retain as policy requires

A stable fact key is more reliable for correction than semantic similarity. “Preferred finance export format” and “shareable finance export format” may look almost identical in a vector index but represent different decisions. Scope the key to the subject and project as appropriate. For a genuinely multi-valued key, model each member independently or version the collection explicitly; otherwise an update may accidentally discard a value that was never corrected.

Put rules between retrieval and the model

User statement or source event
  -> classify a scoped candidate
  -> validate authority and record an active revision
  -> update derived search entries

Authenticated question
  -> apply subject, tenant, permission and time constraints
  -> rank eligible search candidates
  -> recheck canonical revision and source access
  -> send bounded evidence to the model

Correction, expiry or deletion
  -> block old revisions in the canonical store
  -> invalidate cached output and remove stale derivatives

The index is a projection, not the authority. Enforce scope before search where possible; if an external index returns IDs before your application can filter them, do not pass its snippets, scores, or identifiers into the model. Join against the canonical rows, enforce current source permissions and exact revision, and fail closed when that check cannot run. A delayed cleanup job should not allow one more response based on the withdrawn fact. Cache by the authorized subject or equivalent visibility boundary, policy revision, memory revision and query shape. Invalidate affected cached answers and conversation summaries too, not only search results.

PostgreSQL’s row-security documentation explains why database roles matter: owners generally bypass row policies unless forced to obey them, and superusers or roles with BYPASSRLS are not constrained by those policies. Use restricted application roles, verify how permission context is attached to pooled connections, and test the same route and role a real request uses. A web handler that filters by tenant cannot repair a previous leak into a global cache. Likewise, a permission change during answer generation needs a defined boundary: for sensitive evidence, recheck before release and discard buffered output if the revision changed. Streaming already delivered content cannot be recalled.

Worked example 1: fix the release owner without losing useful history

Consider a fictional team with the key checkout/staging/release_approver. Revision 11, effective February 1, says Leila. On May 6 a signed roster update says Omar took over May 3. Record revision 12 with the May 3 effective date and the May 6 recording date. In one database transaction, move the current pointer to revision 12, limit revision 11’s applicability to before May 3, and enqueue an index update. If the notification is delivered twice, an idempotency key such as the roster ID plus its revision prevents a duplicate transition. Reject an older roster revision arriving after the newer one instead of letting arrival order decide who approves tonight.

At 09:00 the following day, search still returns revision 11 because the index worker is behind. The final gate rejects it. A structured lookup for the exact key retrieves revision 12, or the assistant consults the live roster before answering. If both are unavailable, the safe output is “I can’t verify the current staging approver,” not the nearest historical match. The current question and “Who held the role on May 1?” are now distinct, and the latter still requires permission to view history. If the user asks the assistant to approve a release, the release system independently checks the caller’s authority.

Give one regression test a negative assertion: add the old name to a previous conversation summary and force the vector index to return it. For the current question, the old name should not enter the model context at all. Merely checking that the final output says “Omar” could conceal a stale evidence path that will resurface with another model or prompt.

Worked example 2: forget a contact preference without restoring it later

A fictional buyer asks for pickup updates at a personal email address. Their company subsequently moves pickup notices to a shared inbox, then the buyer asks to forget the personal address. The company can confirm the shared destination from its account settings, but that is a different source from the individual’s old preference. Revoke the personal item immediately, prevent it from being passed to the model, and emit a scoped deletion job. That job removes vectors, cached answer fragments, and reusable summaries containing the value. Review any copied data in logs, exports and downstream services against your retention rules. Do not retain the old address inside an audit event intended to prove it was removed.

If a backup cannot be edited in place, record a minimal scoped revocation marker without the deleted payload, protect it, and apply it before restored data is exposed to serving traffic. Document the backup’s retention and purge process. Test restoration from a backup older than the deletion: the old vector may physically exist in an isolated restoration environment, but the assistant must never retrieve the address, and repair must not re-index it. That is different from promising every copy disappeared instantly. Never let a rollback, failed index job or fallback provider silently reactivate the item.

Measure updates and refusals, not just recall

LongMemEval includes knowledge updates, temporal reasoning and abstention as distinct abilities. Build a small product-specific test set with those distinctions. Seed a useful preference, a correction with retroactive effect, an expired instruction, a revoked source and a second tenant with similar content. Replay a delayed event and run an index outage. Check which evidence entered the prompt, not just the generated wording. Track accepted current facts, stale or unauthorized items admitted, and cases where the assistant should ask rather than guess. Treat any admission of revoked evidence as a failure even if the answer never repeats it.

Before expanding coverage, make three operations reliable: remember one explicit preference, correct it while an old search result is still present, and remove it without bringing it back through a retry or restore. If those operations work, search quality can improve usefulness without increasing the authority of yesterday’s mistakes.

اقرأ المقال بالعربية

YOUR TAKE

What did you think?

Choose one reaction for this article.

Was this useful?

A cookie helps limit repeat responses. Your feedback is private.

Share this noteLinkedIn ↗X ↗Email ↗

Keep exploring.