You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run a silent agentic memory flush before /new, /reset, and the daily reset destroy the session, using the same mechanism that already runs before compaction.
Problem to solve
When a session nears compaction, OpenClaw runs a silent agentic turn (runMemoryFlushIfNeeded) where the agent writes curated notes to memory/YYYY-MM-DD.md before context is compressed. This works well.
When a user sends /new or /reset — or when the daily reset fires automatically — the session is destroyed with no agentic flush. The only safety net is the session-memory hook, which mechanically dumps the last 15 raw messages into a file. The agent never gets a chance to curate what matters, update MEMORY.md, or write structured notes.
(There's also a separate bug where the hook's output uses slugged filenames that the boot sequence doesn't read — #45607.)
The asymmetry:
Compaction → agentic flush (agent decides what to save) ✅
/new and /reset → mechanical dump (raw messages, no curation) ❌
Daily reset → same mechanical dump, triggered silently every morning ❌
The daily reset is the big one. The default reset mode is daily with atHour: 4 (src/config/sessions/reset.ts:22-23). Every user hits it at least once per day without any manual action. Any context from the previous day that wasn't written to disk is gone.
Proposed solution
Before destroying the session on /new or /reset, run a silent agentic turn (same pattern as runMemoryFlushIfNeeded) that gives the agent a chance to write durable memories to disk.
Behavior:
User sends /new (or /reset)
Gateway detects reset trigger (existing code in initSessionState)
New step: Before minting the new sessionId, run a silent pre-reset memory flush turn against the current session
The agent writes any durable notes to memory/YYYY-MM-DD.md (or MEMORY.md), then replies NO_REPLY
Session is destroyed, new session starts (existing behavior)
session-memory hook fires as before (raw dump is still useful as backup / audit trail)
Most of the infrastructure already exists:
runMemoryFlushIfNeeded in src/auto-reply/reply/agent-runner-memory.ts:253
before_reset plugin hook in src/plugins/types.ts:541
NO_REPLY suppression for silent turns
Daily memory checkpoint (shouldRunDailyMemoryCheckpoint in src/auto-reply/reply/memory-flush.ts:196) already extends the flush beyond compaction
The main work is wiring runMemoryFlushIfNeeded (or a variant) into the reset path before the session is destroyed.
Guards:
Skip for empty sessions (no turns = no flush)
Skip for CLI and read-only workspaces (same as existing compaction flush)
Make session-memory hook agentic: Run an LLM call inside the hook. Viable but the hook is fire-and-forget with no access to the agent's tools or workspace context. The existing pre-compaction flush already has the right infrastructure.
Add a /save command: Explicit user-triggered flush. Works but puts the burden on the user and doesn't help when they forget (or for the daily reset).
Background flush after reset: Destroy session immediately, flush archived transcript in background. Preserves instant /new feel but requires reconstructing agent context from archived JSONL.
Impact
Affected: Every OpenClaw user (daily reset is default behavior)
Severity: Medium — silent memory loss every day
Frequency: At least once per day per user (daily reset), plus every manual /new or /reset
Consequence: Agent loses learned context between sessions; users with memory-heavy workloads (personal assistants) are most impacted
Evidence/examples
I wrote a detailed proposal with source code references, full design history, and recent commit analysis at docs/proposals/pre-reset-memory-flush.md in my fork. Key findings:
The pre-compaction memory flush was designed for compaction (Jan 12 2026, 7dbb21be8) and never extended to resets
When /new was first added (Dec 4 2025, 34eb75f63), there was no workspace memory system
The daily memory checkpoint (1146b3664 by @PotatoParser, Mar 5 2026) was the first acknowledgment that compaction-only wasn't sufficient — but it only covers active sessions, not sessions that ended before the boundary
The session-memory hook and before_reset plugin hook (Feb 14 2026, ab71fdf82) provide mechanical preservation but no agentic curation
The post-reset boot sequence has been carefully built up, but the pre-reset teardown path has no agentic save step
Additional information
Open questions:
Blocking vs background: Should /new block until the flush completes, or start the new session immediately and flush in the background?
Config location:compaction.memoryFlush.onReset (extends existing) vs session.reset.memoryFlush (cleaner separation)?
Daily reset: Should it also get a flush? Options: background flush on next message, proactive "bedtime flush" via heartbeat before atHour, or accept daily checkpoint is good enough for that case.
Interaction with session-memory hook: Keep both? The hook provides raw audit trail; the agentic flush provides curated memory. They serve different purposes and can coexist.
Summary
Run a silent agentic memory flush before
/new,/reset, and the daily reset destroy the session, using the same mechanism that already runs before compaction.Problem to solve
When a session nears compaction, OpenClaw runs a silent agentic turn (
runMemoryFlushIfNeeded) where the agent writes curated notes tomemory/YYYY-MM-DD.mdbefore context is compressed. This works well.When a user sends
/newor/reset— or when the daily reset fires automatically — the session is destroyed with no agentic flush. The only safety net is thesession-memoryhook, which mechanically dumps the last 15 raw messages into a file. The agent never gets a chance to curate what matters, updateMEMORY.md, or write structured notes.(There's also a separate bug where the hook's output uses slugged filenames that the boot sequence doesn't read — #45607.)
The asymmetry:
/newand/reset→ mechanical dump (raw messages, no curation) ❌The daily reset is the big one. The default reset mode is
dailywithatHour: 4(src/config/sessions/reset.ts:22-23). Every user hits it at least once per day without any manual action. Any context from the previous day that wasn't written to disk is gone.Proposed solution
Before destroying the session on
/newor/reset, run a silent agentic turn (same pattern asrunMemoryFlushIfNeeded) that gives the agent a chance to write durable memories to disk.Behavior:
/new(or/reset)initSessionState)sessionId, run a silent pre-reset memory flush turn against the current sessionmemory/YYYY-MM-DD.md(orMEMORY.md), then repliesNO_REPLYsession-memoryhook fires as before (raw dump is still useful as backup / audit trail)Most of the infrastructure already exists:
runMemoryFlushIfNeededinsrc/auto-reply/reply/agent-runner-memory.ts:253before_resetplugin hook insrc/plugins/types.ts:541NO_REPLYsuppression for silent turnsshouldRunDailyMemoryCheckpointinsrc/auto-reply/reply/memory-flush.ts:196) already extends the flush beyond compactionThe main work is wiring
runMemoryFlushIfNeeded(or a variant) into the reset path before the session is destroyed.Guards:
/newdoesn't feel stuckAlternatives considered
/newfeel but requires reconstructing agent context from archived JSONL.Impact
/newor/resetEvidence/examples
I wrote a detailed proposal with source code references, full design history, and recent commit analysis at
docs/proposals/pre-reset-memory-flush.mdin my fork. Key findings:7dbb21be8) and never extended to resets/newwas first added (Dec 4 2025,34eb75f63), there was no workspace memory system1146b3664by @PotatoParser, Mar 5 2026) was the first acknowledgment that compaction-only wasn't sufficient — but it only covers active sessions, not sessions that ended before the boundarysession-memoryhook andbefore_resetplugin hook (Feb 14 2026,ab71fdf82) provide mechanical preservation but no agentic curationAdditional information
Open questions:
/newblock until the flush completes, or start the new session immediately and flush in the background?compaction.memoryFlush.onReset(extends existing) vssession.reset.memoryFlush(cleaner separation)?atHour, or accept daily checkpoint is good enough for that case.Related: #45607 (session-memory naming mismatch bug)