openclaw - 💡(How to fix) Fix [Feature]: Nudge agents to flush memory before session.ended when significant work occurred (per-turn sessionId rotation breaks continuity for in-flight tasks)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

OpenClaw 2026.5.6 rotates sessionId per user turn after ~5 minutes of idle time (same sessionKey, new sessionId and runId). The in-session transcript is bound to the rotated sessionId, so when the next turn opens a fresh session it sees only the bootstrap project files (MEMORY.md, AGENTS.md, memory/YYYY-MM-DD.md).

If the prior turn performed significant work but exited without writing a memory note to disk, the next turn wakes up blind — even though the same human is still talking, on the same channel, with no /reset in between.

This is distinct from the cross-channel sessionMemory problem (#51386), the lineage discovery seams (#79903), and the compaction-loop issues (#76938). It's a behavior-shaping gap: the runtime knows the prior turn just commited code / wrote large files / called external APIs, but it doesn't nudge the agent to flush a continuity note before the session ends.

Root Cause

Every multi-session agent in the wild — Phoenix, Griffin, etc. — is hitting this. The bootstrap template's AGENTS.md says "write things down" as a best practice, but doesn't enforce it at the moment it matters most (session.ended after significant work). Result: agents look like they have amnesia even when they're carefully maintaining project files, because the exiting session forgot to update them.

Happy to help draft a PR for option 1 or 3 if there's interest. Option 2 needs more design discussion (what counts as "state-changing tool action" is provider-specific).

Fix Action

Fix / Workaround

We patched it on our end (added a mandatory "flush memory before final response" rule to AGENTS.md and a HEARTBEAT.md job that flags days with commits but no memory file). That helps for future agents reading the updated bootstrap, but it doesn't help the session that's currently exiting — the agent has to remember to apply the rule on the way out, and there's no enforcement.

Before emitting session.ended with status=success, if the turn touched any of these:

  • git commit (detect via shell-side or git plumbing observation)
  • File writes >100 lines via the write tool
  • External API writes (any non-GET HTTP call through a tool that the runtime classifies as state-changing)
  • A cron add/update
  • A gateway config.patch / config.apply

Code Example

{
  "agents": {
    "defaults": {
      "sessionContinuity": {
        "mode": "stitch",
        "stitchWithinMs": 600000
      }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Summary

OpenClaw 2026.5.6 rotates sessionId per user turn after ~5 minutes of idle time (same sessionKey, new sessionId and runId). The in-session transcript is bound to the rotated sessionId, so when the next turn opens a fresh session it sees only the bootstrap project files (MEMORY.md, AGENTS.md, memory/YYYY-MM-DD.md).

If the prior turn performed significant work but exited without writing a memory note to disk, the next turn wakes up blind — even though the same human is still talking, on the same channel, with no /reset in between.

This is distinct from the cross-channel sessionMemory problem (#51386), the lineage discovery seams (#79903), and the compaction-loop issues (#76938). It's a behavior-shaping gap: the runtime knows the prior turn just commited code / wrote large files / called external APIs, but it doesn't nudge the agent to flush a continuity note before the session ends.

Reproducer (real-world, 2026-05-15)

User and agent are working on a substantial task in webchat:

Time (UTC)Event
03:26:21Session b34dfdd5 starts (Opus 4.7) — task planning
03:26–03:358 short turns, each a session.started/session.ended pair, same sessionKey agent:main:main
03:50:19User: "Please build the orphan scanner"
03:55:07Agent makes a git commit (3 new files, 987 lines)
03:55:28session.ended (status=success) — agent does NOT write to memory/YYYY-MM-DD.md
04:00:33User sends a follow-up message → new session d8a3f6e5 spawned
04:00:33New agent bootstraps from project files. Has zero context of the commit, the task, or the user's prior instructions.

User experience: "I didn't start a new session. Why don't you remember what we were doing 5 minutes ago?"

Verified via agents/main/sessions/*.trajectory.jsonl — no compaction event, no reset event in logs/commands.log, just normal session.ended → new sessionId on next prompt.

Why workspace-level fixes only partly work

We patched it on our end (added a mandatory "flush memory before final response" rule to AGENTS.md and a HEARTBEAT.md job that flags days with commits but no memory file). That helps for future agents reading the updated bootstrap, but it doesn't help the session that's currently exiting — the agent has to remember to apply the rule on the way out, and there's no enforcement.

This is the same class of problem #66612 is brushing against: prompt instructions for memory flush are easy to miss when the agent thinks it's done.

Proposed fixes (any one would help; all three would be ideal)

1. Session-end memory nudge (lowest effort, highest impact)

Before emitting session.ended with status=success, if the turn touched any of these:

  • git commit (detect via shell-side or git plumbing observation)
  • File writes >100 lines via the write tool
  • External API writes (any non-GET HTTP call through a tool that the runtime classifies as state-changing)
  • A cron add/update
  • A gateway config.patch / config.apply

…the runtime injects one final system turn:

"Before this session ends: did this turn make changes worth remembering across sessions? If yes, write a short note to memory/YYYY-MM-DD.md (or the project's configured memory location) summarizing what changed, where the artifacts live, and what's next."

Agents that already flushed can ignore. Agents that forgot get a second chance.

2. Continuity prelude on session start

When session.started fires and the prior session in the same sessionKey ended <30 min ago, auto-inject a system turn:

"Previous session for this sessionKey ended at HH:MM after these tool actions: [commit X, wrote Y lines to Z, called endpoint W]. Verify that memory/YYYY-MM-DD.md reflects this work before responding to the user; backfill if it doesn't."

This makes the new agent aware that continuity is at risk instead of trusting its own (now-empty) state.

3. Optional sticky-sessionId mode

A workspace config like:

{
  "agents": {
    "defaults": {
      "sessionContinuity": {
        "mode": "stitch",
        "stitchWithinMs": 600000
      }
    }
  }
}

If the next user turn arrives within stitchWithinMs of the prior session.ended, reuse the same sessionId and append to the existing transcript instead of rotating. Default off (preserves current behavior), but available for use cases where short idle gaps shouldn't sever the thread.

This is the cleanest fix from a user-mental-model perspective: "I didn't start a new session" matches "the runtime didn't start a new session."

Why this matters

Every multi-session agent in the wild — Phoenix, Griffin, etc. — is hitting this. The bootstrap template's AGENTS.md says "write things down" as a best practice, but doesn't enforce it at the moment it matters most (session.ended after significant work). Result: agents look like they have amnesia even when they're carefully maintaining project files, because the exiting session forgot to update them.

Happy to help draft a PR for option 1 or 3 if there's interest. Option 2 needs more design discussion (what counts as "state-changing tool action" is provider-specific).

Environment

  • OpenClaw 2026.5.6 (gitSha 2539e41)
  • Provider: anthropic-direct, model claude-opus-4-7 (also seen on sonnet-4-5)
  • Channel: webchat
  • Container: Linux 6.12.74+deb13+1-amd64, Node v22.22.2

Related

  • #51386 (sessionMemory cross-channel — different problem, but lineage-aware)
  • #79903 (sessionId lineage discovery — would make option 2 easier to implement)
  • #66612 (memory flush write blocked by sandbox — adjacent enforcement gap)
  • #75037 (compaction/flush metadata advances updatedAt — different but adjacent)

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Feature]: Nudge agents to flush memory before session.ended when significant work occurred (per-turn sessionId rotation breaks continuity for in-flight tasks)