31.4 Making memory safe
- Approved by
- Panaversity ·
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:1
- 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.2 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, and as untrusted tool output in 17.7. 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.2 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.1 Versions and hash checks are old software practice. They are built into the product because workers should not improvise them.
Check yourself
Question 1 / 2
0 answered
Two runs draft a change to the same memory note at once. What stops one change from silently replacing the other?
Sources
- Owner
- Panaversity