openclaw - 💡(How to fix) Fix Feature: guarantee last N raw messages in agent context (survive compaction and session reset) [1 participants]

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…
GitHub stats
openclaw/openclaw#58818Fetched 2026-04-08 02:32:22
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

Root Cause

Personal assistants, coding agents, and any long-running agent benefit from conversational continuity. Today, the daily reset creates an artificial amnesia boundary that forces users to either:

  • Disable daily resets (sessions grow unbounded)
  • Accept that the agent forgets everything each morning
  • Build workarounds (memory files, boot scripts)

minTailMessages provides a clean middle ground: bounded sessions with guaranteed recent context.

Fix Action

Fix / Workaround

Personal assistants, coding agents, and any long-running agent benefit from conversational continuity. Today, the daily reset creates an artificial amnesia boundary that forces users to either:

  • Disable daily resets (sessions grow unbounded)
  • Accept that the agent forgets everything each morning
  • Build workarounds (memory files, boot scripts)

Code Example

Session A (yesterday): 200 messages, last message at 23:45
  ↓ daily reset at 04:00
Session B (today): starts with last N messages from Session A as context seed
Agent immediately knows what was discussed yesterday evening

---

// openclaw.json
{
  session: {
    // Minimum raw messages preserved in context (survives compaction + reset)
    minTailMessages: 30,
    
    // Optional: carry forward across resets (default: true when minTailMessages > 0)
    carryForwardOnReset: true,
  }
}
RAW_BUFFERClick to expand / collapse

Problem

When an agent wakes up in a session, its context window is built from the current session's JSONL transcript. Two mechanisms destroy or compress older messages:

  1. Daily reset (default 4am): mints a new sessionId → the agent starts with zero messages. Previous conversation is gone from context entirely.
  2. Compaction: summarizes older messages into a compact entry → the agent sees a lossy summary instead of the actual messages.

This means the agent has no guarantee of seeing the last N actual messages from the conversation. A session that was active yesterday evening starts fresh at 4am with zero raw messages. A long-running session that compacted may have replaced recent-ish messages with a summary.

For personal assistant use cases (and many others), the agent needs continuity: the last N messages should always be present in the context window as raw messages, not summaries, regardless of when they were sent.

Desired Behavior

A configurable session.minTailMessages (or similar) that guarantees the agent always sees at least the last N raw messages in its context window:

  1. Across compaction: compaction should never summarize the last N messages. The summary covers everything before the tail.
  2. Across daily/idle reset: when a new session is created, the last N messages from the previous session's transcript should be carried forward as seed messages into the new session's context (not as a summary, but as actual user/assistant message pairs).
  3. Configurable N: default could be ~20-50 messages. Users with large context windows might want more.

Example

Session A (yesterday): 200 messages, last message at 23:45
  ↓ daily reset at 04:00
Session B (today): starts with last N messages from Session A as context seed
  → Agent immediately knows what was discussed yesterday evening

Compaction behavior change

Currently compaction summarizes everything older than the internal keepRecentMessages threshold. With this feature:

  • minTailMessages acts as a floor: compaction must preserve at least N raw messages
  • The compaction summary covers messages before the tail
  • This is different from the existing internal keep-recent logic because it's a user-facing guarantee, not an implementation detail

Reset behavior change

Currently, session reset = clean slate. With this feature:

  • On reset (daily, idle, or manual /new), read the last N messages from the outgoing session's JSONL
  • Inject them as seed context into the new session (either as actual JSONL entries or as a structured "previous context" block)
  • The agent sees continuity without needing to read files or rely on session-memory dumps

Configuration

// openclaw.json
{
  session: {
    // Minimum raw messages preserved in context (survives compaction + reset)
    minTailMessages: 30,
    
    // Optional: carry forward across resets (default: true when minTailMessages > 0)
    carryForwardOnReset: true,
  }
}

Interaction with existing features

  • Pre-reset memory flush (#45608): complementary. The flush lets the agent write durable notes; minTailMessages ensures it can read recent conversation. Both are needed.
  • Compaction: minTailMessages sets a floor on what compaction can touch. The existing compaction logic already has a concept of "recent messages to keep" — this makes it explicit and configurable.
  • Session pruning: unaffected (pruning only touches tool results, not user/assistant messages).
  • Context engine plugins: the assemble() method should respect minTailMessages as a contract. Plugins can exceed it but not go below.

Why this matters

Personal assistants, coding agents, and any long-running agent benefit from conversational continuity. Today, the daily reset creates an artificial amnesia boundary that forces users to either:

  • Disable daily resets (sessions grow unbounded)
  • Accept that the agent forgets everything each morning
  • Build workarounds (memory files, boot scripts)

minTailMessages provides a clean middle ground: bounded sessions with guaranteed recent context.

Edge cases

  • N exceeds context window: cap at what fits after system prompt + tools
  • Short sessions: if session has fewer than N messages, carry all of them
  • Manual /new: respect carryForwardOnReset setting (user might want a truly clean slate — could add /new --clean to override)
  • Compaction model: the compaction summary should still reference that the tail messages exist, to avoid the summary contradicting the raw messages

extent analysis

TL;DR

Implement a configurable session.minTailMessages setting to guarantee the agent sees the last N raw messages in its context window, surviving compaction and daily resets.

Guidance

  1. Introduce session.minTailMessages configuration: Add a setting to control the minimum number of raw messages preserved in the context window.
  2. Modify compaction logic: Update the compaction mechanism to respect minTailMessages and preserve the specified number of recent raw messages.
  3. Update reset behavior: Modify the session reset logic to carry forward the last N messages from the previous session's transcript as seed context into the new session.
  4. Ensure compatibility with existing features: Verify that the new minTailMessages setting interacts correctly with features like pre-reset memory flush, compaction, session pruning, and context engine plugins.

Example

// openclaw.json
{
  session: {
    minTailMessages: 30,
    carryForwardOnReset: true,
  }
}

Notes

The implementation should handle edge cases, such as when N exceeds the context window or when sessions have fewer than N messages.

Recommendation

Apply the workaround by implementing the session.minTailMessages setting, as it provides a clean and configurable solution for ensuring conversational continuity in personal assistant and other long-running agent use cases.

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: guarantee last N raw messages in agent context (survive compaction and session reset) [1 participants]