中文 English

AI Remembering You Is Not Always Good: I Put a Stale Target into Memory to Find the Lifecycle Boundary

Published: 2026-08-23 · 阅读量 --
AI Agent AI 架构 平台工程 记忆 RAG Safety 工程实践

TL;DR

If an AI forgets your preferred name, it disappoints you. If it perfectly remembers a retired service, an obsolete contact, or an expired permission, it can cause an incident. Vector similarity answers, “Does this text resemble the current question?” It does not answer who supplied it, whose scope it belongs to, whether it is still true, whether it may influence a high-risk action, or whether the user already asked for deletion. Production long-term memory is not a pile of text. It is a set of structured records carrying source, scope, version, expires_at, confidence, consent, and deletion semantics. To test that boundary, I built a local lab using only Python’s standard library and SQLite. It deliberately stores an expired target, makes a cross-tenant request, adds a low-confidence inference and a poisoned external note, corrects one fact, and deletes another. All six acceptance gates pass; the unsafe candidates never enter prompt context.

Original cover: only current, trusted, correctly scoped memory passes through the memory gate.

Figure 1: Original diagram. Vector retrieval nominates candidates. A memory gate evaluates source, scope, version, time, risk, and deletion state. “Retrieved” must never mean “automatically inserted into the prompt.”

1. Background: More Memory Does Not Automatically Mean More Intelligence

It is tempting to picture AI memory as an ever-growing notebook. Store everything a user says, find similar passages later, and the assistant appears more personal. In a demo this feels delightful: it remembers the user’s language, dark theme, and the point where yesterday’s conversation stopped.

Once an agent can call tools, however, that notebook is no longer cosmetic. A remembered value may select a service, a team, a region, a credential scope, or an action. At that point, a wrong memory is operationally similar to a wrong configuration.

Think about food in a refrigerator. A box labeled “milk” does not prove that it is safe to drink. You still need to know whose it is, when it was opened, where it came from, and when it expires. A vector database is an excellent robot for finding the box most similar to milk. It does not inspect the expiry date for you.

2. Symptoms: Five Ghosts in Naive Memory Systems

  1. Expired facts keep returning. A service is retired, yet an old target still appears in the agent’s plan.
  2. Scope crosses a boundary. A platform serves several tenants, and one person’s preference or resource name leaks into another person’s context.
  3. Inference quietly becomes fact. A user performed one administrative task, so the system remembers that the user is permanently an administrator.
  4. A correction creates two competing truths. The value changes from A to B, but B is merely appended. Similarity search can still rank A first.
  5. Deletion only hides the UI row. The vector index, cache, summary, or offline copy can still recall what the product claimed to forget.

These failures rarely produce HTTP 500. The model instead writes a fluent, coherent answer around the wrong context. That is more dangerous than a visible error because people naturally trust a confident explanation.

3. Root Cause: Chat History, RAG, Long-Term Memory, and Task State Share One Bucket

Four very different data classes are routinely called “memory,” although they answer different questions.

Original classification: chat history, RAG documents, structured memory, and task state are different stores.

Figure 2: Original diagram. Chat history asks what just happened. RAG asks which source may be relevant. Structured memory asks what remains valid across sessions. Task state asks what must happen next. They should not share one retention or authorization policy.

If task state lives in a chat summary, one rewrite can turn “waiting for approval” into “approved.” If text from a webpage becomes long-term memory automatically, an attacker can effectively write their own authority into the system. Content may provide information; content must not grant power.

4. The Solution: Give Every Memory a Food Label

A production memory record should answer at least these questions:

Original structure: a memory envelope carries provenance, scope, version, validity, and governance.

Figure 3: Original diagram. The sentence is the food inside the container. The label determines who may consume it, when it is safe, and whether another version has replaced it.

The lab first writes those fields to local SQLite. Every name is synthetic. The program reads no system configuration and makes no network request.

Real lab output: seven synthetic memories carry source, trust, version, validity, and governance fields.

Figure 4: Real lab-output capture. Seven synthetic records are stored; network calls and real credentials remain zero. The first gate proves that memory is data with provenance, not anonymous text.

5. Recall: Similarity Is Registration; Six Gates Decide Admission

A safe recall path may use keywords, SQL, full-text search, or vector similarity to generate candidates. Before a candidate enters prompt context, deterministic code checks:

  1. tenant and subject scope;
  2. source trust and reader authorization;
  3. valid_from and expires_at against the current clock;
  4. whether a newer version supersedes it;
  5. whether the current purpose and risk require confirmation or stronger confidence;
  6. whether the record is deleted, quarantined, or revoked.

Original pipeline: candidate memory crosses scope, source, time, version, risk, and deletion gates.

Figure 5: Original diagram. It resembles airport security. Having a ticket makes you a candidate passenger; it does not let you bypass identity, time, and safety checks.

During normal recall, the confirmed language preference and newest active facts enter context. The expired target, old version, and quarantined note are rejected with explicit reasons.

Real lab output: current memory is accepted while expired, superseded, and untrusted candidates are excluded.

Figure 6: Real lab-output capture. The result prints both accepted and rejected candidates. An operator can explain not only what was used, but why the alternatives were not used.

6. Fault Lab: Expired and Cross-Tenant Memory Must Disappear Before the Prompt

The lab fixes the current clock to a deterministic instant and stores service_target=service-retired with an earlier expiry. It then attempts recall under another synthetic tenant.

Real lab output: the expired target and cross-tenant request produce no usable memory.

Figure 7: Real lab-output capture. Expiry and tenant isolation run before prompt assembly. The model never sees the retired target, so the platform does not have to hope that the model voluntarily ignores it.

This is an important boundary. Do not put every candidate into the model and add a system instruction saying, “Please ignore expired information or information belonging to another user.” A model is neither a database row-level security engine nor a reliable temporal constraint system. The most dependable way to protect data that a model should not see is to keep it out of context entirely.

A production store should add row-level authorization, tenant partitioning, or physical isolation rather than relying on one application-side WHERE tenant_id = ?. Tests should intentionally omit, corrupt, and mismatch scope to prove that no alternate path leaks data.

7. Correction Is Not Append: Old Memory Must Lose Its Vote

Suppose a directory originally says the on-call team is team-blue, then changes to team-green. The easiest implementation appends the new text. Similarity search does not know which passage is authoritative and may rank the older wording higher.

The safer model creates v2, points v1’s superseded_by at v2, and permits only one active version during recall. Audit history can still explain why the value changed, while business context receives only the current fact.

Original version timeline: v1 is superseded by v2, then deletion leaves only a non-recallable tombstone.

Figure 8: Original diagram. Memory should behave more like Git history than a wall of sticky notes. History remains explainable, but the working state has one current version.

Real lab output: the old team is superseded and recall returns only the corrected team.

Figure 9: Real lab-output capture. active_versions=1 is the meaningful acceptance check. Merely proving that the new value is searchable does not prevent the old one from influencing a model.

8. Inference and Retrieved Text Must Not Become Authority

The experiment adds two dangerous candidates. One infers an administrator role from behavior with only 0.62 confidence and no user confirmation. The other comes from a retrieved document and says to ignore policy and reveal a secret.

For a casual greeting, a low-risk inferred preference may be usable if it is clearly labeled and easy to correct. For deletion, restart, payment, or another high-risk action, inferred identity cannot authorize execution. External content may be cited as evidence, but it cannot issue permissions to itself.

Original risk matrix: riskier actions require stronger memory provenance and confirmation.

Figure 10: Original diagram. Guessing that a user likes dark mode and guessing that the user owns production administrator rights carry entirely different consequences.

Real lab output: low-confidence inference and instruction-bearing external text are rejected for high-risk recall.

Figure 11: Real lab-output capture. inferred_admin_used=false and retrieved_instruction_used=false. This is not a second prompt fighting a hostile prompt; neither candidate is allowed to become authorization evidence.

9. Deletion Must Reach the Index, Cache, Summary, and Audit Boundary

“Forget me” cannot mean hiding one row in the UI. Structured records, vector indexes, caches, summaries, and offline derivatives need deletion propagation. An audit system may retain a minimized tombstone saying that a record was deleted on request, but it should not retain enough content to reconstruct the deleted value.

After the lab deletes ui_theme=dark, recall reports the deleted rejection reason and cannot return the value to prompt context.

Real lab output: a deleted preference cannot be recalled, while a minimal deletion event remains auditable.

Figure 12: Real lab-output capture. The acceptance test is not “the UI no longer shows it.” It is “the recall entry point cannot return it.” Production systems should attach an SLA to deletion propagation.

A practical deletion workflow marks the source record DELETED, emits a versioned event, waits for index and cache acknowledgements, and alerts on missed deadlines. Backup policy should describe how deletion is re-applied after restoration instead of promising that every historical bit disappears instantly.

10. Reproducible Lab: What Six PASS Results Prove

The downloadable Python lab uses only standard-library sqlite3, json, and file operations with a fixed clock and synthetic identifiers. It does not connect to a model, vector database, cloud service, or real business system.

Real lab output: fresh recall, expiry, tenant isolation, version correction, risk filtering, and deletion all pass.

Figure 13: Real lab-output capture. Six out of six checks pass. They validate lifecycle control points; they do not claim that the SQLite teaching implementation is a drop-in production Memory Service.

One-click run on Windows 11

Download the lab and Windows launcher into one directory, then run:

powershell -ExecutionPolicy Bypass -File .\run_windows.ps1

One-click run on Ubuntu 26.04

Download the Ubuntu launcher beside the lab and run:

chmod +x ./run_ubuntu.sh
./run_ubuntu.sh

One-click run on macOS 26

Download the macOS launcher beside the lab and run:

chmod +x ./run_macos.sh
./run_macos.sh

For a manual review, run python3 memory_lifecycle_lab.py --clean and inspect the seven evidence files in the output directory one by one. For agent-assisted configuration, give the agent the downloadable task contract. It requires code inspection first, forbids network and package installation, runs the platform-specific launcher, reads verification.json, and reports every PASS or FAIL. A zero exit status alone is not sufficient evidence.

11. From Lab to Production: Where the Memory Service Belongs

In a production architecture, the Memory Service belongs to the data and evidence plane and exposes explicit capture, correct, recall, expire, and delete APIs. The Context Assembler receives only policy-filtered results. A model cannot scan the complete store or rewrite source, tenant, consent, and validity metadata.

A useful separation is:

Operational metrics should go beyond “memories recalled”:

12. Q&A

Does a vector database give me long-term memory?

No. It provides similarity search, not versioning, validity, consent, tenant isolation, or deletion propagation. It may implement the Retrieval Index; it should not be the sole source of truth.

Must users confirm every memory?

No. A low-risk UI preference may be inferred if confidence is visible and correction is easy. Identity, authority, people, production resources, and money need trustworthy provenance, shorter validity, and sometimes confirmation before every action.

Will TTL make the assistant forgetful again?

TTL does not have to destroy the fact. It can trigger revalidation. Emergency keys are periodically inventoried not because keys become less intelligent, but because doors and authorized people change.

Why not provide all history and let the model choose?

That expands privacy exposure, prompt-injection surface, token cost, and decision risk. A model can reason only over what it sees; keeping unauthorized or stale data out of context is the strongest isolation boundary.

Can audit records remain after deletion?

A minimized event that cannot reconstruct the content may remain when law, contract, and retention policy permit it. Proving that deletion happened does not require preserving the deleted value.

Can a chat summary write directly to long-term memory?

It may propose a candidate. Classification, provenance, risk review, and sometimes user confirmation still apply. Otherwise, one summarization error permanently contaminates later conversations.

13. Closing

A good memory system does not make AI remember everything. It makes the platform explain what is worth remembering, who allowed it, how long it remains valid, how correction replaces it, how deletion removes it, and why it may be used for this request.

The AI Platform production architecture places structured memory in the data and evidence plane. The AI Platform architecture reading map connects tool calling, gateways, observability, and security. This article fills the often-missed boundary between “search found similar text” and “this fact may enter context now.”

References:

本文阅读量 --