# 31.4 Making memory safe (/building-ai-workers/self-improving-ai-workers/making-memory-safe)

---
type: Document
title: "31.4 Making memory safe"
description: "Four guardrails for shared memory: versions, a hash check, read-only shared memory and one interface, and what each prevents."
status: stable
order: 331.04
ksor:
  owner: team:panaversity
  audience: [ public ]
  approval:
    by: process:panaversity
    at: 2026-11-25T09:06:43Z
chapter: "31"
part: III
expert_status: co-build
concepts: [ "31.4" ]
last_verified: 2026-11-24
sources:
  - id: ma-memory
    title: "Memory stores (Claude Managed Agents documentation, verified 2026-11-24)"
    resource: https://platform.claude.com/docs/en/managed-agents/memory
  - id: mukta-talk
    title: "Learning while you sleep: Beyond memory to dreaming (Lamis Mukta, Anthropic, AI Native DevCon London, June 2026)"
    resource: https://www.youtube.com/watch?v=tTcxVv8HHNw
generated:
  at: 2026-11-25T09:06:43Z
  by: process:panaversity
trust_tier: unverified
build_id: sha256:0decb5023f044061076dd533dd5b490739d442d95c609ce2fff5ad3af880174c
dirty: true
ksor_version: 0.0.60
---

**In everyday life.** A shared family recipe book sits in a kitchen where many people cook. If two cousins edit the same page at once, one loses their change. If a child scribbles "add a cup of salt", everyone who cooks from it ruins the dish. So the family writes each change with a date and a name, and checks that the page has not changed before writing on it. The master copy stays where only the grandparents can write.

**What you will learn.** Four guardrails that every shared memory needs, and what each one prevents. You practise them in Lab 31, Tasks 1 and 2.

**Why it matters.** Memory that is safe on one laptop breaks when many runs and many people share it.

### What goes wrong at scale?

The talk lists four failures that appear when memory is shared:[^mukta-talk]

- Many runs write to one file at once.
- One run's mistake spreads to every other run.
- People and workers edit the same memory, with no record of who changed what.
- Memories are wrong, out of date, or planted by text the worker read.

Four guardrails answer them. The second relies on a **hash**, a short fingerprint of a file's content: change one letter and the fingerprint changes.

| Guardrail | What it does | What it prevents |
| --- | --- | --- |
| **Versions** | Keep every version, with the session or person that made it | A bad change that nobody can trace or undo |
| **A hash check** | Check, just before writing, that the note has not changed since you read it | Two writers, one lost change |
| **Read-only shared memory** | Shared memory is read-only. Each run writes only to its own space | One run's mistake reaching every run |
| **One clean interface** | Memory is reached the same way from every tool | Memory locked inside one tool |

A hash check works like this. Read the note's hash before you draft a change. Check the hash again just before you write. If it has changed, someone else wrote first: read the note again, redraft and retry.

Claude Managed Agents provides all four.[^ma-memory] Every write makes a memory version with an audit trail. Versions are kept for 30 days, except the recent versions of a live memory. There is no restore button: to roll back, you write an old version's content again. A write can carry the hash it read, and it applies only if the stored content still has that hash. A store attaches read-only or read-write, and a read-only store rejects writes. All stores are managed through one API.

Checking a hash before writing is called **optimistic concurrency**: assume nobody else is writing, and check before you commit.

### Why does it matter that shared memory is read-only?

**Because a worker reads text it did not write.** Invoices, vendor emails and tool results are written by others. You met this risk as the risky pair in [7.3](../../managing-ai-workers/the-authority-envelope/untrusted-input.md), and as untrusted tool output in [17.7](../connectors-and-mcp/untrusted-output.md). Anthropic's documentation warns that if a worker with write access processes such text, a successful prompt injection could write into the store, and later sessions would read it as trusted memory.[^ma-memory] At Brightline, the published memory is mounted read-only in every run: each run sees it as a folder it can read but not change. A run may write only to its own scratch folder, and nothing in a scratch folder is read by another run until it passes 31.6.

### Is this reinventing a database?

**In part, and on purpose.** Asked this in the talk's questions, Mukta said the real work is choosing. Some parts the worker decides on its own. Others the harness enforces with fixed rules.[^mukta-talk] Versions and hash checks are old software practice. They are built into the product because workers should not improvise them.

[^mukta-talk]: Learning while you sleep: Beyond memory to dreaming (Lamis Mukta, Anthropic, AI Native DevCon London, June 2026).
[^ma-memory]: Memory stores (Claude Managed Agents documentation).
