Skip to content

Agent incorrectly acts on cross-session memory context in new sessions #1532

@rongtianhua

Description

@rongtianhua

Problem Description

When a new OpenClaw session starts, the memos-local-openclaw-plugin's auto-recall mechanism (before_agent_start hook) injects relevant memories from all historical sessions into the agent's context via memory_search. This causes the agent to:

  1. Act unprompted — sees historical context (e.g., a cron job misconfiguration from a previous session) and takes action without the user's first instruction
  2. Mix up session contexts — references facts from other sessions as if they were from the current session
  3. Give contextually inappropriate responses — starts a conversation with information the user never provided in this session

Specific example

  1. User starts a new session and says nothing yet
  2. Auto-recall fires, finds a chunk from a different session (task_id A) about "a-stock-trader-pro投递配置问题"
  3. Agent sees this as relevant, and without being asked, reports the cron configuration issue and asks the user to confirm
  4. User is confused — they haven't said anything, yet the agent is already responding to something from an old conversation

This violates the expected turn-taking behavior: the user's first message should trigger the agent's action, not the memory system's auto-injection.


Expected Behavior

In a new session where the user has not yet spoken:

  • Auto-recall may run, but the agent should treat injected memories as background knowledge only
  • The agent should not proactively act, query, or reply based solely on auto-recalled memories
  • The agent should wait for the user's first instruction before taking any action
  • If the agent needs to reference a recalled memory, it should explicitly note the source (e.g., "根据之前的会话...")

Root Cause Analysis

The issue stems from how auto-recall is integrated into the agent loop:

  • The before_agent_start hook runs memory_search with the user's message and injects results into the agent's context
  • When the user hasn't said anything in a new session, the "user's message" may be empty or a system greeting
  • Auto-recall still returns historical chunks that are topically relevant from other sessions
  • The agent's system prompt does not have a clear instruction to only use recalled memories passively (as background) and not act on them without user prompting

Proposed Solutions (Pick One or Combine)

Option A: Session-level memory scope (recommended)

Add a session-aware flag to auto-recall. When a session is freshly started (first user message in a new session), auto-recall results should be tagged as "background only". The agent's system prompt should include:

If injected memories are from a previous session, treat them as background knowledge only. Do not act on them unprompted. Wait for the user's first instruction.

Option B: Suppress auto-recall on empty/first-turn messages

If the user's message is empty (new session, no user input yet), skip auto-recall injection entirely, or inject with a special marker that tells the agent "these memories are from previous sessions — do not act on them."

Option C: Agent instruction in system prompt

Add a clear instruction to the agent's system context when memories are injected:

[memory_search results from auto-recall — these are from PREVIOUS sessions.
Treat as background knowledge only. Do not proactively act or reply.
Wait for the user to send a message before taking any action.]

Environment

  • Plugin: @memtensor/memos-local-openclaw-plugin v1.0.9
  • OpenClaw: (latest)
  • Node.js: >=22
  • OS: macOS

Additional Context

This issue is particularly problematic because:

  1. Users expect a fresh session to start with a clean slate until they speak
  2. The agent appears to "know things unprompted" which breaks the conversational flow
  3. It makes the agent seem like it's "jumping ahead" or "not listening" to the current user
  4. Cross-session memory should enhance future conversations, not trigger unprompted actions in new ones

Relevant code area: before_agent_start hook + auto-recall injection logic in index.ts / plugin-impl.ts.


Severity: Medium — degrades user experience and trust in the memory system, but does not cause data loss or system failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions