Skip to content

Commit f9ef9c8

Browse files
committed
fix(memory): enforce shared-session privacy boundary
1 parent 79d2e56 commit f9ef9c8

273 files changed

Lines changed: 13010 additions & 643 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
acdf418738f79d29f58cb6cfe5b7ab2d353cbcce2252861a4f527f85ea0c54af config-baseline.json
1+
d3b5bcf476814978208cc2f5dd1815a4199b4ae53b2f5cea39c976110e32868e config-baseline.json
22
4c98c716bc78e65c274ec374757357c1dcc9b5ec75c9e00ea4c20851531b7d1a config-baseline.core.json
3-
c68853362689981ac1cc1e55b9061286c2002104ff1c10bc44ee99a6080e169e config-baseline.channel.json
4-
859aa272b0dad53b7080c6fefcf775347ae79a1998ec39dd18b732c90d9df90c config-baseline.plugin.json
3+
d27ac1e30c6f3ef7292f33ad9737d4372dd140675293cbddc38364e476f06410 config-baseline.channel.json
4+
e228f29f17758763a098b0ccd10c6db7fc9df84840437ed3f88a88cf945b8078 config-baseline.plugin.json
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
729181bf726ea51bebfa51c760eff8d5016933c21815e47197b5d05db8d549d5 plugin-sdk-api-baseline.json
2-
d8add92c9c5445e8bdd8a8361cdd5a42e1ab5baa45cd16ea640152d6f577f1bf plugin-sdk-api-baseline.jsonl
1+
10f9a222a67dcedce3953f3677b8bf27500743a75af25dc3760cae7a99ae24a8 plugin-sdk-api-baseline.json
2+
f6f9f16f66db496c828a08676864554dd68797d5c697fe815805cc7aedff6b27 plugin-sdk-api-baseline.jsonl

‎docs/automation/hooks.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ Extracts the last 15 user/assistant messages and saves to `<workspace>/memory/YY
243243
}
244244
```
245245

246-
Paths resolve relative to workspace. Only recognized bootstrap basenames are loaded (`AGENTS.md`, `SOUL.md`, `TOOLS.md`, `IDENTITY.md`, `USER.md`, `HEARTBEAT.md`, `BOOTSTRAP.md`, `MEMORY.md`).
246+
Paths resolve relative to workspace. Only recognized bootstrap basenames are loaded (`AGENTS.md`, `SOUL.md`, `TOOLS.md`, `IDENTITY.md`, `USER.md`, `HEARTBEAT.md`, `BOOTSTRAP.md`, `MEMORY.md`). Session bootstrap policy still applies after hooks run, so shared group/channel sessions do not receive hook-added `MEMORY.md` by default.
247247

248248
<a id="command-logger"></a>
249249

‎docs/automation/standing-orders.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Each program specifies:
4141
The agent loads these instructions every session via the workspace bootstrap files (see [Agent Workspace](/concepts/agent-workspace) for the full list of auto-injected files) and executes against them, combined with [cron jobs](/automation/cron-jobs) for time-based enforcement.
4242

4343
<Tip>
44-
Put standing orders in `AGENTS.md` to guarantee they're loaded every session. The workspace bootstrap automatically injects `AGENTS.md`, `SOUL.md`, `TOOLS.md`, `IDENTITY.md`, `USER.md`, `HEARTBEAT.md`, `BOOTSTRAP.md`, and `MEMORY.md` - but not arbitrary files in subdirectories.
44+
Put standing orders in `AGENTS.md` to guarantee they're loaded every session. `MEMORY.md` is private/direct long-term memory, so shared group/channel sessions do not receive it by default. Put stable shared instructions in `AGENTS.md` or `USER.md`; use memory tools on demand for long-term notes.
4545
</Tip>
4646

4747
## Anatomy of a standing order

‎docs/channels/discord.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Once DMs are working, you can set up your Discord server as a full workspace whe
287287
</Step>
288288

289289
<Step title="Plan for memory in guild channels">
290-
By default, long-term memory (MEMORY.md) only loads in DM sessions. Guild channels do not auto-load MEMORY.md.
290+
By default, long-term memory (MEMORY.md) only loads in private/direct sessions. Guild channels do not auto-load MEMORY.md; they follow the same shared-session memory boundary as other group/channel surfaces.
291291

292292
<Tabs>
293293
<Tab title="Ask your agent">

‎docs/concepts/context-engine.md‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export default function register(api) {
126126
info: {
127127
id: "my-engine",
128128
name: "My Context Engine",
129+
supportsSharedSessionScope: true,
129130
ownsCompaction: true,
130131
},
131132

@@ -134,13 +135,23 @@ export default function register(api) {
134135
return { ingested: true };
135136
},
136137

137-
async assemble({ sessionId, messages, tokenBudget, availableTools, citationsMode }) {
138+
async assemble({
139+
sessionId,
140+
sessionKey,
141+
chatType,
142+
messages,
143+
tokenBudget,
144+
availableTools,
145+
citationsMode,
146+
}) {
138147
// Return messages that fit the budget
139148
return {
140149
messages: buildContext(messages, tokenBudget),
141150
estimatedTokens: countTokens(messages),
142151
systemPromptAddition: buildMemorySystemPromptAddition({
143152
availableTools: availableTools ?? new Set(),
153+
sessionKey,
154+
chatType,
144155
citationsMode,
145156
}),
146157
};
@@ -158,6 +169,11 @@ The factory `ctx` includes optional `config`, `agentDir`, and `workspaceDir`
158169
values so plugins can initialize per-agent or per-workspace state before the
159170
first lifecycle hook runs.
160171

172+
Set `info.supportsSharedSessionScope` only when every lifecycle hook treats
173+
`chatType: "group"` and `chatType: "channel"` as restrictive shared-session
174+
scope. Engines that omit it are treated as private-only and OpenClaw bypasses
175+
them for shared sessions, using the legacy pass-through engine instead.
176+
161177
Then enable it in config:
162178

163179
```json5

‎docs/concepts/memory.md‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ hidden state.
1515
Your agent has three memory-related files:
1616

1717
- **`MEMORY.md`** — long-term memory. Durable facts, preferences, and
18-
decisions. Loaded at the start of every DM session.
18+
decisions. Loaded by default for private/direct sessions, not shared group or
19+
channel sessions.
1920
- **`memory/YYYY-MM-DD.md`** (or **`memory/YYYY-MM-DD-<slug>.md`**) — daily notes.
2021
Running context and observations. Today and yesterday's notes are loaded
21-
automatically, and slugged variants such as those written by the bundled
22-
session-memory hook on `/new` or `/reset` are now picked up alongside the
23-
date-only file.
22+
automatically only for eligible private/direct sessions, and slugged variants
23+
such as those written by the bundled session-memory hook on `/new` or
24+
`/reset` are picked up alongside the date-only file.
2425
- **`DREAMS.md`** (optional) — Dream Diary and dreaming sweep
2526
summaries for human review, including grounded historical backfill entries.
2627

@@ -44,11 +45,14 @@ instructions and heartbeat flow can do that periodically; you do not need to
4445
manually edit `MEMORY.md` for every remembered detail.
4546

4647
If `MEMORY.md` grows past the bootstrap file budget, OpenClaw keeps the file on
47-
disk intact but truncates the copy injected into the model context. Treat that as
48-
a signal to move detailed material back into `memory/*.md`, keep only the
49-
durable summary in `MEMORY.md`, or raise the bootstrap limits if you explicitly
50-
want to spend more prompt budget. Use `/context list`, `/context detail`, or
51-
`openclaw doctor` to see raw vs injected sizes and truncation status.
48+
disk intact but truncates the copy injected into eligible private/direct model
49+
context. Shared group and channel sessions do not receive raw `MEMORY.md` by
50+
default; ask the agent to use memory tools when you want long-term memory in a
51+
shared conversation. Treat truncation as a signal to move detailed material back
52+
into `memory/*.md`, keep only the durable summary in `MEMORY.md`, or raise the
53+
bootstrap limits if you explicitly want to spend more prompt budget. Use
54+
`/context list`, `/context detail`, or `openclaw doctor` to see raw vs injected
55+
sizes and truncation status.
5256

5357
<Tip>
5458
If you want your agent to remember something, just ask it: "Remember that I
@@ -115,6 +119,10 @@ The agent has two tools for working with memory:
115119
- **`memory_get`** — reads a specific memory file or line range.
116120

117121
Both tools are provided by the active memory plugin (default: `memory-core`).
122+
In shared group and channel sessions, memory tools are explicit/on-demand: the
123+
agent should not run long-term memory recall by default, but it can use
124+
`memory_search` or `memory_get` when you ask for long-term memory or a visible
125+
session instruction requests it.
118126

119127
## Memory Wiki companion plugin
120128

‎docs/concepts/system-prompt.md‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ prompt surface that matches their lifetime:
176176
- `USER.md`
177177
- `HEARTBEAT.md`
178178
- `BOOTSTRAP.md` (only on brand-new workspaces)
179-
- `MEMORY.md` when present
179+
- `MEMORY.md` when the session is eligible for long-term memory by default
180180

181181
On the native Codex harness, OpenClaw avoids repeating stable workspace files
182182
in every user turn. Codex loads `AGENTS.md` through its own project-doc
@@ -193,15 +193,21 @@ search is unavailable, or the active workspace differs from the agent memory
193193
workspace, `MEMORY.md` falls back to the normal bounded turn-context path. Active
194194
`BOOTSTRAP.md` content keeps the normal turn-context role for now.
195195

196+
Long-term memory eligibility is session-aware. Private/direct sessions and main
197+
local sessions keep the documented default behavior. Shared group and channel
198+
sessions do not receive raw `MEMORY.md` by default; memory tools remain available
199+
for explicit/on-demand reads. Sub-agent and cron sessions keep their existing
200+
minimal bootstrap policies.
201+
196202
On non-Codex harnesses, bootstrap files continue to be composed into the
197203
OpenClaw prompt according to their existing gates. `HEARTBEAT.md` is omitted on
198204
normal runs when heartbeats are disabled for the default agent or
199205
`agents.defaults.heartbeat.includeSystemPromptSection` is false. Keep injected
200-
files concise, especially non-Codex `MEMORY.md`. `MEMORY.md` is intended to stay
201-
a curated long-term summary; detailed daily notes belong in `memory/*.md` where
202-
`memory_search` and `memory_get` can retrieve them on demand. Oversized
203-
non-Codex `MEMORY.md` files increase prompt usage and can be partially injected
204-
because of the bootstrap file limits below.
206+
files concise, especially non-Codex `MEMORY.md` in private/direct sessions.
207+
`MEMORY.md` is intended to stay a curated long-term summary; detailed daily
208+
notes belong in `memory/*.md` where `memory_search` and `memory_get` can
209+
retrieve them on demand. Oversized non-Codex `MEMORY.md` files increase prompt
210+
usage and can be partially injected because of the bootstrap file limits below.
205211

206212
<Note>
207213
`memory/*.md` daily files are **not** part of the normal bootstrap Project Context. On ordinary turns they are accessed on demand via the `memory_search` and `memory_get` tools, so they do not count against the context window unless the model explicitly reads them. Bare `/new` and `/reset` turns are the exception: the runtime can prepend recent daily memory as a one-shot startup-context block for that first turn.
@@ -218,11 +224,12 @@ default: `always`). Detailed raw/injected counts stay in diagnostics such as
218224

219225
For memory files, truncation is not data loss: the file remains intact on disk.
220226
On native Codex, `MEMORY.md` is read on demand through memory tools when
221-
available, with bounded prompt fallback when tools cannot run. On other
222-
harnesses, the model only sees the shortened injected copy until it reads or
223-
searches memory directly. If `MEMORY.md` is repeatedly truncated there, distill
224-
it into a shorter durable summary and move detailed history into `memory/*.md`,
225-
or intentionally raise the bootstrap limits.
227+
available, with bounded prompt fallback only for sessions that are eligible for
228+
long-term memory by default. On other harnesses, eligible private/direct sessions
229+
only see the shortened injected copy until they read or search memory directly.
230+
If `MEMORY.md` is repeatedly truncated there, distill it into a shorter durable
231+
summary and move detailed history into `memory/*.md`, or intentionally raise the
232+
bootstrap limits.
226233

227234
Sub-agent sessions only inject `AGENTS.md` and `TOOLS.md` (other bootstrap files
228235
are filtered out to keep the sub-agent context small).

‎docs/plugins/architecture-internals.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,12 +1049,14 @@ export default function (api) {
10491049
async ingest() {
10501050
return { ingested: true };
10511051
},
1052-
async assemble({ messages, availableTools, citationsMode }) {
1052+
async assemble({ messages, sessionKey, chatType, availableTools, citationsMode }) {
10531053
return {
10541054
messages,
10551055
estimatedTokens: 0,
10561056
systemPromptAddition: buildMemorySystemPromptAddition({
10571057
availableTools: availableTools ?? new Set(),
1058+
sessionKey,
1059+
chatType,
10581060
citationsMode,
10591061
}),
10601062
};
@@ -1098,12 +1100,14 @@ export default function (api) {
10981100
async ingest() {
10991101
return { ingested: true };
11001102
},
1101-
async assemble({ messages, availableTools, citationsMode }) {
1103+
async assemble({ messages, sessionKey, chatType, availableTools, citationsMode }) {
11021104
return {
11031105
messages,
11041106
estimatedTokens: 0,
11051107
systemPromptAddition: buildMemorySystemPromptAddition({
11061108
availableTools: availableTools ?? new Set(),
1109+
sessionKey,
1110+
chatType,
11071111
citationsMode,
11081112
}),
11091113
};

‎docs/reference/token-use.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ OpenClaw assembles its own system prompt on every run. It includes:
2020
prompt surface. It is bounded by `skills.limits.maxSkillsPromptChars`, with
2121
optional per-agent override at `agents.list[].skillsLimits.maxSkillsPromptChars`.
2222
- Self-update instructions
23-
- Workspace + bootstrap files (`AGENTS.md`, `SOUL.md`, `TOOLS.md`, `IDENTITY.md`, `USER.md`, `HEARTBEAT.md`, `BOOTSTRAP.md` when new, plus `MEMORY.md` when present). Native Codex turns do not paste raw `MEMORY.md` from the configured agent workspace when memory tools are available for that workspace; they include a small memory pointer in turn-scoped collaboration developer instructions and use memory tools on demand. If tools are disabled, memory search is unavailable, or the active workspace differs from the agent memory workspace, `MEMORY.md` uses the normal bounded turn-context path. Lowercase root `memory.md` is not injected; it is legacy repair input for `openclaw doctor --fix` when paired with `MEMORY.md`. Large injected files are truncated by `agents.defaults.bootstrapMaxChars` (default: 20000), and total bootstrap injection is capped by `agents.defaults.bootstrapTotalMaxChars` (default: 60000). `memory/*.md` daily files are not part of the normal bootstrap prompt; they remain on-demand via memory tools on ordinary turns, but reset/startup model runs can prepend a one-shot startup-context block with recent daily memory for that first turn. Bare chat `/new` and `/reset` commands are acknowledged without invoking the model. The startup prelude is controlled by `agents.defaults.startupContext`. Post-compaction AGENTS.md excerpts are separate and require explicit `agents.defaults.compaction.postCompactionSections` opt-in.
23+
- Workspace + bootstrap files (`AGENTS.md`, `SOUL.md`, `TOOLS.md`, `IDENTITY.md`, `USER.md`, `HEARTBEAT.md`, `BOOTSTRAP.md` when new, plus `MEMORY.md` only for sessions that receive long-term memory by default). Private/direct sessions keep the documented `MEMORY.md` behavior; shared group and channel sessions do not receive raw `MEMORY.md` by default and use memory tools only when explicitly requested. Native Codex turns do not paste raw `MEMORY.md` from the configured agent workspace when memory tools are available for that workspace; they include a small memory pointer in turn-scoped collaboration developer instructions and use memory tools on demand. If tools are disabled, memory search is unavailable, or the active workspace differs from the agent memory workspace, `MEMORY.md` uses the normal bounded turn-context path only for eligible sessions. Lowercase root `memory.md` is not injected; it is legacy repair input for `openclaw doctor --fix` when paired with `MEMORY.md`. Large injected files are truncated by `agents.defaults.bootstrapMaxChars` (default: 20000), and total bootstrap injection is capped by `agents.defaults.bootstrapTotalMaxChars` (default: 60000). `memory/*.md` daily files are not part of the normal bootstrap prompt; they remain on-demand via memory tools on ordinary turns, but reset/startup model runs can prepend a one-shot startup-context block with recent daily memory for that first turn. Bare chat `/new` and `/reset` commands are acknowledged without invoking the model. The startup prelude is controlled by `agents.defaults.startupContext`. Post-compaction AGENTS.md excerpts are separate and require explicit `agents.defaults.compaction.postCompactionSections` opt-in.
2424
- Time (UTC + user timezone)
2525
- Reply tags + heartbeat behavior
2626
- Runtime metadata (host/OS/model/thinking)

0 commit comments

Comments
 (0)