fix: skip memory flush on read-only workspace

This commit is contained in:
Peter Steinberger
2026-01-12 06:33:14 +00:00
parent 1ffb0fe787
commit 5b44825cb3
7 changed files with 317 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ read_when:
# Memory
Clawdbot memory is **plain Markdown in the agent workspace**. The files are the
source of truth; the model only remembers what gets written to disk.
source of truth; the model only "remembers" what gets written to disk.
## Memory files (Markdown)
@@ -27,14 +27,14 @@ These files live under the workspace (`agents.defaults.workspace`, default
- Decisions, preferences, and durable facts go to `MEMORY.md`.
- Day-to-day notes and running context go to `memory/YYYY-MM-DD.md`.
- If someone says remember this, write it down (dont keep it in RAM).
- If someone says "remember this," write it down (do not keep it in RAM).
## Automatic memory flush (pre-compaction ping)
When a session is **close to auto-compaction**, Clawdbot triggers a **silent
agentic turn** that reminds the model to write durable memory **before** the
context is compacted. The default prompt encourages the model to respond with
`NO_REPLY` when theres nothing to store, so the user never sees this turn.
`NO_REPLY` when there's nothing to store, so the user never sees this turn.
This is controlled by `agents.defaults.compaction.memoryFlush`:
@@ -61,6 +61,8 @@ Details:
`contextWindow - reserveTokensFloor - softThresholdTokens`.
- **Silent** by default: prompts include `NO_REPLY` so nothing is delivered.
- **One flush per compaction cycle** (tracked in `sessions.json`).
- **Workspace must be writable**: if the session runs sandboxed with
`workspaceAccess: "ro"` or `"none"`, the flush is skipped.
For the full compaction lifecycle, see
[Session management + compaction](/reference/session-management-compaction).

View File

@@ -1382,6 +1382,8 @@ Defaults:
- `memoryFlush.enabled`: `true`
- `memoryFlush.softThresholdTokens`: `4000`
- `memoryFlush.prompt` / `memoryFlush.systemPrompt`: built-in defaults with `NO_REPLY`
- Note: memory flush is skipped when the session workspace is read-only
(`agents.defaults.sandbox.workspaceAccess: "ro"` or `"none"`).
Example (tuned):
```json5

View File

@@ -251,6 +251,7 @@ Notes:
- The default prompt/system prompt include a `NO_REPLY` hint to suppress delivery.
- The flush runs once per compaction cycle (tracked in `sessions.json`).
- The flush runs only for embedded Pi sessions (CLI backends skip it).
- The flush is skipped when the session workspace is read-only (`workspaceAccess: "ro"` or `"none"`).
- See [Memory](/concepts/memory) for the workspace file layout and write patterns.
Pi also exposes a `session_before_compact` hook in the extension API, but Clawdbots