Skip to content

Commit 392b79d

Browse files
committed
fix(memory): prevent forgotten session content from returning
1 parent 116f364 commit 392b79d

38 files changed

Lines changed: 2385 additions & 1239 deletions

‎config/assertion-safety-baseline.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,6 @@ extensions/memory-core/src/short-term-promotion-artifacts.ts 2
793793
extensions/memory-core/src/short-term-promotion-memory-write.ts 4
794794
extensions/memory-core/src/short-term-promotion-record.ts 1
795795
extensions/memory-core/src/short-term-promotion-rehydrate.ts 1
796-
extensions/memory-core/src/short-term-promotion-store.ts 1
797796
extensions/memory-core/src/short-term-promotion-utils.ts 4
798797
extensions/memory-core/src/short-term-promotion.ts 1
799798
extensions/memory-core/src/standing-intents-tool.ts 5

‎docs/cli/memory.md‎

Lines changed: 136 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ read_when:
66
- You want to promote recalled short-term memory into `MEMORY.md`
77
- You need to delete provenance-tracked memories derived from specific sessions or participants
88
title: "Memory"
9+
doc-schema-version: 1
910
---
1011

1112
# `openclaw memory`
@@ -84,75 +85,141 @@ absent.
8485

8586
## `memory forget`
8687

87-
Delete provenance-tracked durable memory entries derived from selected
88-
sessions, together with their indexed and short-term copies. The concepts
89-
behind this command — recorded lineage, admission policy, and the deletion
90-
guarantees and boundaries — are explained in
91-
[Memory provenance and deletion](/concepts/memory-provenance). Select sessions
92-
by ID or session key, their external-content hook source, or a participant's
93-
actor ID:
88+
Remove identifiable memory artifacts derived from selected sessions and record
89+
those sessions as forgotten in one agent's store. See
90+
[Memory provenance and deletion](/concepts/memory-provenance) for the
91+
relationship between lineage, admission policy, and deletion coverage.
92+
93+
<Warning>
94+
This command deletes immediately unless `--dry-run` is set. There is no
95+
confirmation prompt or `--apply` flag. Source session transcripts are retained.
96+
</Warning>
97+
98+
Start with a preview:
9499

95100
```bash
96-
openclaw memory forget --session <id-or-key> [--session <id-or-key> ...]
97-
openclaw memory forget --hook-source gmail [--since 2026-01-01]
98-
openclaw memory forget --participant <actor-id> [--agent <id>] [--dry-run] [--json]
101+
openclaw memory forget --agent <agent-id> --session <id-or-key> --dry-run --json
102+
openclaw memory forget --agent <agent-id> --hook-source gmail --dry-run --json
103+
openclaw memory forget --agent <agent-id> --participant <actor-id> --dry-run --json
99104
```
100105

101-
`--session`, `--hook-source`, and `--participant` are repeatable. At least one
102-
selector is required. `--agent` selects one agent and otherwise defaults to the
103-
default agent. Explicit session IDs and keys match both live sessions and
104-
retained archived sessions. An unknown explicit value is still treated as an
105-
exact session ID, purged where matching artifacts exist, and durably excluded
106-
from future memory ingestion. The report identifies each selected session as
107-
`live`, `archived`, or `unresolved`. Hook-source and participant selectors only
108-
match sessions whose corresponding metadata still exists; archived sessions do
109-
not retain those facts, so select them by ID or key instead. `--since <date>`
110-
filters live sessions by their creation time and archived sessions by their
111-
archive creation time; unresolved explicit IDs have no timestamp and remain
112-
selected.
113-
114-
Run with `--dry-run` before deleting. It computes the same complete report as
115-
the real purge without changing memory files, SQLite indexes, plugin state, or
116-
durable deletion records. `--json` prints that report as machine-readable JSON.
117-
118-
A purge removes matching pipeline-promoted entries, session-corpus lines,
119-
selected-session transcript index chunks, full-text and vector index records,
120-
embedding-cache entries, short-term recall, seen-hash scopes, dreaming rewrite
121-
backups, and recorded origins. It also clears stale index records for internal
122-
dreaming-narrative, cron, or heartbeat sessions. An entry derived from both
123-
selected and unselected sessions is deleted whole and reported as a
124-
mixed-lineage entry; dreaming can regenerate supported facts from surviving
125-
sessions later. Entries without recorded origins remain searchable and are not
126-
deleted by an unrelated selector; the report lists them as untargetable.
127-
128-
A real purge records each selected session as forgotten in the agent's SQLite
129-
database. Future dreaming sweeps record that session as excluded with reason
130-
`forgotten`; `memory session-backfill` and transcript indexing, including
131-
`memory index --force`, also reject it. Repeating the purge is safe and does
132-
not undo this exclusion.
133-
134-
Dream diaries and other workspace memory files can quote source-session corpus
135-
lines without retaining a session reference. The purge removes any whole line
136-
containing an exact purged corpus-line snippet from files such as
137-
`memory/dreaming/**/*.md` and `DREAMS.md`, as well as matching dreaming
138-
backups. `artifacts.memoryLines` reports the number of these additional removed
139-
memory-file lines. Model-paraphrased prose that does not contain the exact
140-
source text cannot be attributed reliably and is not removed automatically.
141-
142-
Direct agent edits to memory files are tracked at the file level, not per
143-
entry. When such a write happened during a selected session, `curatedWrites`
144-
lists its `relativePath` and `observedAt` without modifying the file. Evidence
145-
comes from native write-observer records and the selected sessions' live or
146-
archived transcripts, including writes performed by external agent harnesses.
147-
Review those files separately: a freeform edit cannot be attributed to
148-
individual lines safely enough for automatic deletion.
106+
After checking the report, repeat the intended command without `--dry-run`.
107+
108+
| Flag | Effect |
109+
| -------------------------- | -------------------------------------------------------------------------------------------------------------- |
110+
| `--agent <id>` | Select one agent. Defaults to the default agent, not all agents. |
111+
| `--session <id-or-key>` | Select by session ID or key; repeatable. |
112+
| `--hook-source <source>` | Select live sessions with this recorded external-content hook source; repeatable. |
113+
| `--participant <actor-id>` | Select live sessions with this recorded participant actor ID; repeatable. |
114+
| `--since <date>` | Include sessions created on or after the date. Use an ISO timestamp with a timezone for an unambiguous cutoff. |
115+
| `--dry-run` | Compute a report without changing memory files, indexes, plugin state, or forgotten-session records. |
116+
| `--json` | Print the full report as JSON. |
117+
118+
### Session selection
119+
120+
At least one selector is required. Repeated values and different selector
121+
types combine with **OR**: a session matching any selector is selected, subject
122+
to `--since`. Selectors match recorded identifiers, not names or text in
123+
messages. A participant selector selects the whole session, including other
124+
participants' contributions.
125+
126+
Explicit IDs and keys resolve against live sessions and retained archives.
127+
The report labels each result `live`, `archived`, or `unresolved`. An
128+
unresolved explicit value is recorded literally as a session ID for future
129+
exclusion; it does not prove that the requested session was found. IDs match
130+
exactly and case-sensitively, including when matching retained archive names.
131+
An abbreviation does not select a longer session ID.
132+
133+
Hook-source and participant selectors require live metadata; archived-only
134+
records do not retain those facts. Select those archives by full ID or key.
135+
`--since` uses the live session's creation time or the archive's creation time,
136+
not individual message timestamps. Unresolved explicit IDs have no timestamp
137+
and remain selected.
138+
139+
### Read the report
140+
141+
| Field | Meaning |
142+
| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
143+
| `agentId`, `dryRun` | Store selected and whether this was a preview. |
144+
| `sessionIds`, `sessionResolutions` | Selected IDs and how each resolved; a resolution may also include `sessionKey`. |
145+
| `entryKeys` | Entry keys with at least one origin in the selected sessions. |
146+
| `mixedLineageEntryKeys` | Selected entries that also have unselected origins; they are removed whole. |
147+
| `untargetableEntryKeys` | Promotion markers found without origin rows in this agent's store. This does not enumerate unmarked prose. |
148+
| `curatedWrites` | Files to review, with `relativePath` and `observedAt` (Unix milliseconds). Includes supported recorded write attempts, which may not have succeeded. |
149+
| `artifacts` | Counts of matching files, entries, lines, and store rows described below. |
150+
| `refusals` | Reserved report list; currently empty. An empty list does not establish complete deletion coverage. |
151+
152+
Preview and apply use the same matching logic, but each reads current state;
153+
a preview is not an immutable plan or a lock on subsequent writes. Apply
154+
coordinates with the memory plugin's staging and file mutations. Indexing
155+
discards stale results instead of restoring purged chunks or cached embeddings;
156+
rerun an index command that reports a source change. Direct agent edits and
157+
external writers do not share that lock, so pause them during a sensitive
158+
cleanup. Rerun the preview afterward. An empty selection or zero counts do not
159+
prove that no related data remains.
160+
161+
### Artifacts removed
162+
163+
The purge removes matching promotion-marker entries and session-reference
164+
sections from scanned memory files, selected session-corpus lines, and
165+
selected-session transcript index chunks. It clears associated full-text and
166+
vector rows, cached embeddings, matching short-term state, ingestion seen-hash
167+
scopes, and origin rows. Matching content is scrubbed from dreaming rewrite
168+
backups, rather than deleting every backup.
169+
170+
It also clears stale index records for internal dreaming-narrative, cron, or
171+
heartbeat sessions when the selection is nonempty. Index cleanup can therefore
172+
include more than the selected sessions, and all chunks from a changed memory
173+
file may be invalidated for later reindexing.
174+
175+
The `artifacts` counters are:
176+
177+
- `memoryFiles`, `memoryEntries`, `memoryLines`: changed memory files,
178+
removed marked entries or session-reference sections, and extra whole lines
179+
containing exact selected corpus snippets.
180+
- `sessionCorpusFiles`, `sessionCorpusLines`: changed corpus files and
181+
removed corpus lines.
182+
- `indexChunks`, `indexSources`, `ftsRows`, `vectorRows`,
183+
`embeddingCacheRows`: removed index and cache records.
184+
- `shortTermEntries`, `seenHashScopes`, `backups`, `originRows`: removed
185+
short-term entries and deduplication scopes, rewritten backup records, and
186+
deleted source-origin rows.
187+
188+
Entries with mixed lineage are deleted whole; the command does not rewrite
189+
them to preserve only unselected contributions. Surviving sources may support
190+
new entries later, but regeneration is not guaranteed.
191+
192+
### Readmission and retained data
193+
194+
A real purge records the selected session IDs as forgotten in the agent's
195+
SQLite database before removing artifacts. Automatic dreaming ingestion,
196+
`memory session-backfill`, and transcript indexing, including
197+
`memory index --force`, check those records. Automatic ingestion records the
198+
reason `forgotten`. Repeating the purge does not remove the exclusion, and
199+
removing an admission-policy rule does not undo it. Future sessions with new
200+
IDs are not excluded by a previous purge.
201+
202+
Exact corpus quotations in dream diaries such as `DREAMS.md` and
203+
`memory/dreaming/**/*.md` can be removed as whole lines. Untracked paraphrases
204+
cannot be reliably attributed and remain.
205+
206+
A `curatedWrites` record alone does not delete a file or its freeform edits.
207+
The latest file-level write-observer record and supported `write`, `edit`,
208+
and `apply_patch` calls in retained transcripts identify files to review.
209+
This is not a complete audit of shell writes or external editors. A reported
210+
file may still be changed by the separate marker, session-reference, or
211+
exact-quotation cleanup.
149212

150213
<Warning>
151-
`memory forget` removes selected-session transcript chunks from the memory
152-
index and permanently prevents their memory-pipeline readmission, but does not
153-
delete the original source session transcripts. The report identifies the
154-
selected sessions so you can remove transcript data separately through its
155-
owning session-management workflow when required.
214+
Entries staged before source-session tracking may lack origin rows and remain
215+
after a purge; review them separately. Current session backfill preserves
216+
origins, but does not reconstruct missing historical lineage.
217+
`untargetableEntryKeys` does not enumerate every untracked candidate or memory.
218+
219+
Source transcripts, retained archives, other agents' indexes, exports, and
220+
external backups also require separate review. In particular,
221+
[session deletion](/cli/sessions#delete-sessions) ordinarily retains a
222+
deleted-transcript archive; it is not an erasure of every conversation copy.
156223
</Warning>
157224

158225
## `memory promote`
@@ -231,8 +298,12 @@ openclaw memory rem-backfill --rollback [--rollback-short-term] [--json]
231298

232299
## `memory session-backfill`
233300

234-
Distill retained session history through the same provenance and short-term
235-
staging pipeline used by dreaming. The default is a read-only preview, ordered
301+
Distill retained session history into grounded short-term candidates. It shares
302+
transcript trust classification, admission policy, and corpus storage with
303+
dreaming. Staged candidates retain every contributing session's origin so
304+
`memory forget` can select them later. Configured exclusions apply in preview,
305+
REM, and apply modes; forgotten sessions remain excluded in every mode.
306+
The default is a read-only preview, ordered
236307
from the oldest unprocessed day to the newest.
237308

238309
```bash

‎docs/concepts/dreaming.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Dreaming runs three cooperative phases per sweep, in order: light -> REM -> deep
6969

7070
Dreaming can ingest redacted session transcripts into the dreaming corpus. Only interactive sessions are eligible. Cron, heartbeat, subagent, and unknown sessions stay out of durable candidate ingestion. Personal and sensitive content is redacted before ingestion, and runtime-marked recalled context is removed so recalled snippets cannot be learned again as new memory.
7171

72-
Two operator controls remove whole sessions from ingestion, each with a recorded reason: the [memory admission policy](/concepts/memory-provenance#admission-keeping-sources-out-of-memory) excludes sessions by external-content hook source, channel, or chat type, and [`memory forget`](/cli/memory#memory-forget) durably excludes purged sessions as `forgotten` so a later sweep cannot re-learn what was deleted.
72+
Two operator controls exclude sessions from automatic ingestion, each with a recorded reason: the [memory admission policy](/concepts/memory-provenance#admission-keeping-sources-out-of-memory) matches retained hook-source, channel, or chat-type metadata, and [`memory forget`](/cli/memory#memory-forget) records selected session IDs as `forgotten` for future scans. Policy changes do not erase existing candidates or prevent direct file writes. Manual session backfill applies both controls in preview, REM, and apply modes, and preserves source-session origins when staging candidates.
7373

7474
## Consolidation safety
7575

‎docs/concepts/memory-architecture.md‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,13 @@ noise, and recall feedback loops:
9696
structurally marked and never re-extracted as a new memory. A fact recalled
9797
one hundred times stays one fact.
9898

99-
Beyond per-chunk trust metadata, every pipeline-promoted durable entry also
100-
records **which sessions it came from**, and that lineage survives
101-
consolidation merges. Session lineage is what makes two operator guarantees
102-
possible: excluding configured sources (an email hook, a channel) from
103-
durable memory by policy, and purging everything derived from a session, a
104-
person, or a source with `openclaw memory forget` — including a durable
105-
exclusion that keeps purged sessions from ever being re-ingested. That
106-
policy story is covered end to end in
99+
Beyond per-chunk trust metadata, automatic session ingestion records source
100+
sessions for its staged entries. Consolidation carries those origins forward,
101+
so `openclaw memory forget` can remove tracked entries derived from selected
102+
sessions and exclude those session IDs from future ingestion. Separately,
103+
admission policy can exclude matching sources from dreaming ingestion and session backfill.
104+
Neither control covers every workspace write or retained copy; see the
105+
coverage, retained-data boundaries, and operator workflow in
107106
[Memory provenance and deletion](/concepts/memory-provenance).
108107

109108
## Trust boundaries and limits

‎docs/concepts/memory-builtin.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ only injects curated or promoted-trusted entries.
9696
Each indexed chunk also has SQLite-owned provenance: origin class (`owner`,
9797
`agent`, `untrusted`, or `system`), session kind, observation time, and an
9898
optional supersession key. This metadata is stored separately from Markdown
99-
so recalled prose cannot rewrite its own trust classification. Durable
100-
entries additionally record their source sessions, which powers admission
101-
policy and selective deletion — see
99+
so recalled prose cannot rewrite its own trust classification. Automatic
100+
session ingestion also records source-session origins for its staged entries,
101+
which support selective deletion after promotion. For coverage and limits, see
102102
[Memory provenance and deletion](/concepts/memory-provenance).
103103

104104
- **Index location:** the owning agent database at

0 commit comments

Comments
 (0)