Don't Let an AI Agent Remember Its Mistakes: A Memory Commit Gate
A founder protocol for separating agent working state from verified long-term memory, so failed attempts, stale facts, and untrusted tool output cannot silently become future authority.
An onboarding agent reads a trial customer's message: “Use our Singapore entity for this test.” The billing lookup times out, so the agent infers that Singapore is the company's default entity, completes a draft workspace, and saves a summary for later. The customer abandons the trial. A month later, a sales agent retrieves the summary, treats the inferred entity as an approved fact, and prepares a real order form with the wrong contracting party.
The first error was recoverable. The durable memory made it portable.
This guide is for founders and small teams whose AI product keeps facts, summaries, plans, tool results, or lessons across steps, sessions, or agents. Its central judgment is: an agent may record a candidate memory during exploration, but that record must not become durable authority until a separate commit gate validates its evidence, scope, freshness, permissions, and allowed uses. Recording, believing, and acting are different events.
You will leave with a four-state memory model, a validation matrix, a machine-readable commit receipt, rollback rules, tests, and a 48-hour shadow-mode pilot. The method fits support, research, sales, operations, coding, and workflow agents that reuse state. It is unnecessary for a disposable single-turn generator with no persistence or side effects. It is also not enough for medical, legal, financial, safety-critical, or regulated decisions; those require domain controls, accountable human review, and applicable law in addition to memory discipline.
The point is not to make every note pass a heavyweight database ceremony. It is to stop a common shortcut: treating whatever survived a model run as true enough to steer the next one.
A retention policy answers whether a system may keep state and for how long. A retrieval policy answers which state may be recalled. This commit gate answers the missing question between them: when may a retained claim acquire authority over a later decision? Those controls complement one another; none substitutes for the others.
Define the failure: persistence turns local uncertainty into shared authority
An agent run contains many kinds of state. A tool returned a value. A model formed a hypothesis. A user gave a preference for one task. A verifier confirmed an outcome. A workflow retried after a timeout. These records may look equally fluent when compressed into a summary, but they do not deserve equal authority.
Use four terms precisely:
- Working state is temporary material used inside one attempt: observations, scratch notes, partial plans, intermediate tool output, and hypotheses.
- Candidate memory is a proposed durable record with an explicit claim, source, scope, and proposed use. It is still quarantined.
- Committed memory is a candidate that passed named checks and may be retrieved for approved purposes until it expires or is superseded.
- Action authority is permission to use memory as one input to an external side effect. Commitment does not automatically grant it.
store.put proves that bytes were accepted, not that a preference is current, a tool result is authentic, or a hypothesis was verified.
The same distinction applies to a conversation summary, vector record, profile field, project instruction, agent-generated file, or shared blackboard. “Memory” is not one technology. It is any retained state that can influence a future decision after the context that produced it has faded.
Borrow transaction ideas without pretending language is a database row
Database transactions offer a powerful analogy. SQLite defines atomic commit as an all-or-nothing appearance: either all changes in a transaction occur or none do, including recovery after interruption. PostgreSQL's transaction-isolation documentation explains dirty reads, nonrepeatable reads, phantom reads, serialization anomalies, and the need to retry a transaction when concurrency invalidates an attempted serial order.
Agent systems face related shapes of failure:
| Database idea | Useful agent interpretation | What it does not prove |
|---|---|---|
| Atomicity | A memory claim and its evidence, scope, permission, and index entry become visible together—or none do | The claim is factually correct |
| Consistency | A committed record satisfies product invariants and schema rules | The invariants cover every real-world meaning |
| Isolation | One run cannot read another run's tentative memory as committed truth | Concurrent agents will reason identically |
| Durability | An accepted record survives the promised lifecycle and can be audited | The record should remain valid forever |
Three recent preprints make this design space concrete. Agentic Transaction proposes semantic versions of ACID for long-horizon agents. MemTX separates memory writes from belief commits and attaches evidence, permissions, provenance, and validity. SafeCommit focuses on whether a memory-grounded agent has enough evidence to take a side-effectful action.
These are useful research signals, not settled production standards. They are recent preprints, their systems and benchmarks may not match your product, and reported improvements do not establish real-world safety. The durable founder lesson is narrower: state admission and action admission need explicit, inspectable rules outside the model's prose.
Do not label a product “ACID-compliant agent memory” merely because it uses PostgreSQL. The database can isolate row writes while the application commits a confidently wrong sentence. Semantic validation remains a product responsibility.
Map every memory path before changing the prompt
Most teams inspect the obvious memory table and miss the other paths that restore state. Draw a memory surface map before designing controls.
| Surface | Typical producer | Typical consumer | Hidden risk |
|---|---|---|---|
| Thread checkpoint | Workflow runtime | Resumed run | A failed step resumes with contaminated assumptions |
| Cross-thread store | Agent or summarizer | Future sessions and agents | Task-specific statements become global facts |
| User profile | Model extraction or form | Personalization and automation | Preference lacks purpose, expiry, or user confirmation |
| Retrieval index | Ingestion job | Planner or answer generator | Untrusted or stale text receives authority through relevance |
| Generated workspace file | Coding or research agent | Later tools and humans | Scratch conclusions look like project policy |
| Tool cache | Connector layer | Retry or later job | Timeout, partial response, or old permissions survive |
| Evaluation memory | Critic or self-reflection step | Next attempt | A failed strategy is stored as a successful lesson |
| Shared agent board | Specialist agents | Orchestrator and peers | Tentative claims spread faster than corrections |
For each path, record the producer identity, tenant, task, source, retention, readers, writers, delete route, conflict rule, and whether the content can authorize an action. Include framework defaults. LangGraph's subgraph persistence guide shows that per-invocation and per-thread modes have materially different behavior: one starts fresh for each call, while the other accumulates state and can create checkpoint conflicts when the same subgraph is called in parallel.
Also label the current implementation, not only the intended design. If a field is “temporary” in the product specification but is copied into a durable transcript used for future summaries, mark it durable. If a candidate and committed record share one retrieval index, record the filter that prevents ordinary consumers from seeing tentative state—and test the filter under failure and replay.
The mapping exercise often reveals that “long-term memory” was enabled indirectly. A run transcript is summarized into a user profile; a generated notes.md is read as instruction on the next run; or a retry loads a checkpoint that contains a result from a failed branch. Fixing only the vector database leaves the control problem intact.
Give each record a claim, not just content
A raw summary is hard to validate because it mixes events, interpretations, permissions, and advice. Commit the smallest claim that can be independently checked.
Instead of:
Acme uses Singapore, wants annual billing, and approved the enterprise plan.
create three candidates:
- “For workspace
trial_842, the user selected Singapore as the entity for this trial.” - “The user requested an annual-billing quote on 2026-08-23.”
- “Enterprise-plan approval is unverified; the agent inferred it from a pricing-page visit.”
- a stable
memory_idand immutable claim text; - claim type, such as observation, user preference, tool fact, hypothesis, policy, or verified outcome;
- source pointer and producer identity;
- tenant, user, task, and purpose scope;
- observed time, valid-from time, expiry, and freshness rule;
- confidence as a model signal, never as proof;
- permission label and allowed readers;
- proposed action classes the record may influence;
- dependencies on other memories;
- validation method and validator identity;
- supersedes, retracts, and repair status.
Avoid one giant verified: true flag. A user may confirm a shipping preference without authorizing its use for tax residency. A CRM connector may authenticate the source but still return a stale record. Validation should bind a claim to a purpose, scope, time, and evidence version.
Run a six-check commit gate
The gate should be deterministic where possible and risk-weighted where judgment is unavoidable.
1. Evidence check
Can a reviewer or program locate the source? Preserve a redacted tool response, message ID, signed event, test artifact, or human confirmation. Reject memories whose only evidence is “the model concluded.” For summaries, keep pointers to the supporting spans rather than treating the summary itself as its source.
2. Scope check
Does the claim name the tenant, user, task, environment, and purpose where it applies? “Use Singapore for this trial” must not become “company is incorporated in Singapore.” Default to the narrowest scope supported by the evidence.
3. Freshness and conflict check
Compare the candidate with current authoritative sources and existing committed memories. A newer timestamp does not automatically win: late-arriving events, clock skew, imports, and delayed connectors can invert apparent order. If two claims conflict and neither source has clear authority, quarantine both for the disputed purpose instead of asking the model to choose the more persuasive sentence.
4. Permission check
Confirm that retention and reuse are allowed for this actor and purpose. A private support note must not be paraphrased into a shared sales memory. Keep access control on the record and re-check it at retrieval; copying text into a broader namespace must not launder its permission.
5. Consequence check
Classify what the memory may influence. A low-risk UI preference may be committed after source and scope validation. A contracting entity, payment instruction, recipient, deletion request, security exception, or production command should require authoritative revalidation at action time and often human approval.
6. Repairability check
Can the system find consumers, derived memories, queued actions, and completed side effects if the claim is retracted? If not, the memory is not safe to promote for consequential use. Either narrow its authority or build the dependency and audit trail first.
The commit decision should produce commit, quarantine, reject, or escalate—not a free-form paragraph. The model may extract claims and propose evidence. Application code should enforce required fields, tenant boundaries, action classes, expiries, and role checks.
Separate memory commitment from permission to act
A committed memory can still be unsafe at action time. Circumstances change after validation: the user revokes consent, an address expires, a price changes, another agent commits a conflicting record, or a tool's permission is reduced.
Use a second gate for external side effects:
| Proposed action | Memory may assist? | Required action-time evidence |
|---|---|---|
| Adjust interface theme | Yes | Current user scope; easy undo |
| Draft an internal note | Yes | Provenance visible; no automatic send |
| Send a customer email | Yes, as context | Current recipient and send authority |
| Change a subscription | Only as a proposal | Live account state, idempotency key, explicit policy or approval |
| Issue a refund | Only as supporting evidence | Current transaction, eligibility rule, amount cap, receipt |
| Delete user data | Never from remembered intent alone | Fresh authenticated request and deletion workflow |
| Run production code | Only as context for a plan | Current environment, reviewed change, scoped credentials, release control |
Retries deserve special care. A timeout does not reveal whether the remote action happened. AWS's guidance on safe retries explains how caller-provided idempotency tokens let a service recognize repeated intent and avoid duplicate side effects; it also warns that using the same token with different parameters should be rejected. For an agent, the idempotency key belongs to the action intent and parameters, not to the conversational turn.
Memory must not be the sole source of current authorization. Re-fetch volatile facts at the action boundary, compare versions, and bind the action receipt to the committed memory IDs actually used. If revalidation fails, choose a low-side-effect probe, draft, or clarification rather than silently falling back to remembered state.
Walk through the onboarding failure as a transaction
Return to the opening scenario. The agent receives a trial instruction, a billing lookup times out, and it infers a default contracting entity.
Under a naive workflow, the end-of-run summarizer writes “Acme uses Singapore” into a global account profile. The next agent retrieves a highly relevant, confidently phrased sentence without the failed lookup or trial scope. A draft becomes a commercial commitment.
Under a memory commit gate:
- The original message enters working state as an observation tied to
trial_842. - The inferred default entity becomes a separate hypothesis with the failed lookup attached.
- The observation can be proposed as a candidate limited to the trial workspace; the hypothesis cannot cite itself as evidence.
- The scope check rejects promotion to company-wide profile.
- The evidence check marks the contracting entity
quarantinebecause the authoritative billing lookup did not complete. - A future sales run may retrieve the trial observation as context, but an order-form action requires a live CRM/legal-entity check or a named human confirmation.
- If the customer corrects the entity, the system supersedes the trial claim and traces any derived drafts. Unsigned drafts can be regenerated; a sent document triggers an accountable repair workflow.
Make the commit receipt auditable
Store a compact receipt alongside the record. The values below are illustrative, not YBuild customer data or universal thresholds.
memory_commit_receipt:
schema_version: 1
memory_id: mem_01J63TRIAL842
claim:
type: user_instruction
text: "Use the Singapore entity for workspace trial_842"
scope:
tenant: acme_demo
workspace: trial_842
purpose: trial_configuration
observed_at: "2026-08-23T01:14:22Z"
expires_at: "2026-09-06T01:14:22Z"
provenance:
source_type: user_message
source_ref: msg_7781
producer_run: run_4402
validation:
evidence_check: pass
scope_check: pass
freshness_check: pass
conflict_check: pass
permission_check: pass
repairability_check: pass
validator: policy_v3_plus_account_owner
authority:
retrieval: [trial_support, trial_configuration]
prohibited_actions: [contract_generation, billing_change, payment]
dependencies: []
decision: commit
decided_at: "2026-08-23T01:16:09Z"
Keep the immutable original claim and append status changes rather than rewriting history. A correction should create a new record that supersedes the old one. Index only committed records for ordinary retrieval; allow auditors and repair jobs to read quarantined or retracted records through a separate path.
The receipt is an admission record, not an action receipt. When the agent later sends, changes, deletes, deploys, or pays, create a separate action record containing the live checks, idempotency key, approver when required, external result, and exact memory IDs consulted. This prevents an old commit decision from masquerading as permanent permission.
Do not put secrets, full private transcripts, or unnecessary personal data into the receipt. Evidence pointers should respect access and retention policy. Hashes can help identify an artifact, but a hash alone cannot explain its meaning or establish permission.
Design rollback as repair, not deletion
Deleting a bad memory from the primary store does not undo what it already influenced. It may have produced summaries, cached answers, queued jobs, emails, files, tickets, model feedback, or new memories. Treat retraction as the start of a repair workflow.
Maintain a dependency edge when one memory materially supports another record or action. On retraction:
- mark the original record retracted and remove it from normal retrieval;
- find derived memories and change them to
needs_revalidation; - cancel queued side effects when safe;
- identify completed effects and assign a repair owner;
- re-run affected decisions against current committed state where appropriate;
- notify impacted users when product policy or consequence requires it;
- record what could not be reversed.
This is also why rollback should not mean “ask the same model to write a better summary.” The system needs an external record of which version was visible to which consumer and what action occurred.
Test contamination, concurrency, and retries
Happy-path memory tests prove that recall works. A commit gate needs tests that prove bad state fails closed.
Use at least these cases:
- Failed-tool contamination: a partial or timed-out tool result is summarized as fact. Expect quarantine.
- Task-to-global scope leak: a one-task instruction is proposed as a durable user preference. Expect scope rejection or narrowing.
- Late stale write: an older agent finishes after a newer correction. Expect conflict handling, not last-write-wins.
- Dirty read: agent B retrieves agent A's uncommitted candidate. Expect invisibility outside the transaction.
- Permission laundering: a private note is paraphrased into a shared store. Expect denial with provenance preserved.
- Retry duplication: an action times out after succeeding and is retried. Expect one external effect under the same idempotency key.
- Same key, changed intent: retry parameters differ. Expect a validation error, not reuse.
- Retraction cascade: a committed claim is corrected after producing a draft and queued email. Expect invalidation and cancellation.
- Checkpoint resume: a run restarts after failure. Expect tentative hypotheses to remain tentative.
- Expired authority: a once-valid address is retrieved after expiry. Expect fresh lookup or clarification.
- Cross-tenant collision: identical names appear in two accounts. Expect hard namespace isolation.
- Verifier self-approval: the producing run attempts to validate its own unsupported claim. Expect an independence rule or explicit low-risk exception.
Track outcomes, not memory volume. Useful measures include the percentage of consequential memories with locatable evidence; quarantine and conflict rates by producer; expired records still retrieved; action-time revalidation failures; mean time from retraction to repair; unrepaired downstream effects; and false-rejection samples reviewed by a human. High quarantine is not automatically bad during a pilot—it may reveal that the old system was committing unsupported claims invisibly.
Know where the pattern stops helping
This framework adds state, latency, storage, and operational work. It is not the right default everywhere.
Do not build durable memory when the product can satisfy the need with explicit user settings, an authoritative database field, or fresh retrieval. Do not store a sensitive fact merely because a commit gate could validate it. Minimize collection first.
The transaction analogy also breaks at important boundaries:
- Natural-language claims can be ambiguous; database constraints cannot settle meaning.
- External side effects may not be reversible or part of one atomic transaction.
- Human sources can be authorized but mistaken.
- Independent validators can share the same blind spot.
- Provenance can be authentic while the underlying information is stale.
- Strict isolation can reduce useful collaboration and increase latency.
Run a 48-hour shadow-mode pilot
You can test the design without changing production behavior.
Hours 0–4: map one consequential path. Choose one agent and one memory type that can influence an external action. List every write, summarization, retrieval, cache, checkpoint, and consumer. Name the authoritative source and repair owner. Hours 4–12: introduce candidate state. Keep current production reads unchanged, but mirror proposed writes into a quarantined candidate store. Require claim, source, scope, purpose, expiry, permission, and proposed action classes. Hours 12–24: implement the six checks. Use deterministic validators for schema, tenant, expiry, permissions, conflict versions, and evidence presence. Route ambiguous semantics to a bounded human queue. Produce receipts without granting new authority. Hours 24–36: replay recent runs. Apply the 12-case pack and a small redacted sample of real runs. Compare what the old pipeline saved with what the gate would commit, quarantine, reject, or escalate. Inspect false accepts and false rejects; do not optimize only for a higher commit rate. Hours 36–48: drill one retraction. Correct a synthetic committed memory, trace its consumers, cancel a queued action, and generate a repair report. If you cannot identify downstream effects, keep the memory read-only for consequential workflows.At the end, choose one of four decisions: remain in shadow mode, enable only low-risk retrieval, enable a narrow action class with revalidation, or stop and redesign. Do not deploy broad cross-session authority just because the storage layer works.
Use the founder launch checklist
Before a persistent-memory feature can steer real actions, confirm:
- [ ] Working state, candidate memory, committed memory, and action authority are distinct states.
- [ ] Every memory surface—not only the primary vector store—is mapped.
- [ ] Claims are atomic enough to validate independently.
- [ ] Source, producer, scope, purpose, time, permission, and expiry are present.
- [ ] Tentative state is invisible to unrelated runs and agents.
- [ ] Conflicts quarantine rather than silently resolve by fluency or last write.
- [ ] Action authority is narrower than retrieval authority.
- [ ] Volatile facts and permissions are revalidated at the side-effect boundary.
- [ ] Retried actions use idempotency keys bound to intent and parameters.
- [ ] Retractions identify derived memories, queued actions, completed effects, and repair owners.
- [ ] Cross-tenant and private-to-shared leaks fail closed.
- [ ] A human can inspect, correct, export, and delete appropriate user-facing memory.
- [ ] Metrics reveal unsupported commits and unrepaired effects, not just recall success.
- [ ] High-stakes uses have additional domain controls and accountable review.
References
- Sun, Wang, and Li, Agentic Transaction: Towards ACID-Compliant Agent Systems, 2026 preprint.
- Li et al., MemTX: Transactional Belief Commit for Stateful Agent Memory, 2026 preprint.
- Akewar and Ranjan, SafeCommit: Certifying When Memory-Grounded Agents May Safely Act, 2026 preprint.
- LangChain, LangGraph persistence.
- LangChain, LangGraph subgraph persistence.
- PostgreSQL, Transaction isolation.
- SQLite, Atomic Commit in SQLite.
- AWS Builders' Library, Making retries safe with idempotent APIs.
- OWASP GenAI Security Project, Top 10 for Agentic Applications.
- NIST, Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile.