MemOS icon indicating copy to clipboard operation
MemOS copied to clipboard

bug(openclaw-plugin): auto-recall contaminates cron runs with prior meta-discussion

Open dreamcoin1998 opened this issue 8 months ago • 5 comments

Pre-submission checklist

  • [x] I have searched existing issues and this hasn't been mentioned before
  • [x] I have read the project documentation and confirmed this issue doesn't already exist
  • [x] This issue is specific to MemOS and not a general software issue

Bug Description

When @memtensor/memos-local-openclaw-plugin is used as the OpenClaw memory slot, cron runs can be contaminated by prior meta-discussion about the cron itself.

The plugin performs auto-recall in before_agent_start for every turn. For cron runs, it uses the cron prompt as the recall query, which causes it to retrieve previous conversations about prompt tuning, policy changes, debugging, and rerun requests for that same cron job.

Those recalled memories are then injected back into the scheduled run as system context, so the cron output drifts away from the actual task and starts replying with unrelated meta-discussion.

Observed effects include:

  • cron output says things like “I already changed the cron”
  • output summarizes previous human discussions about task policy
  • output mentions rerun/debugging status instead of only executing the scheduled task
  • session logs contain injected memory blocks beginning with:
    • ## User's conversation history (from memory system)

This is especially harmful for autonomous scheduled jobs because it changes task semantics.

How to Reproduce

  1. Install and enable @memtensor/memos-local-openclaw-plugin as the OpenClaw memory slot.
  2. Create an OpenClaw cron job with a stable name and repeated scheduled runs.
  3. Run the cron normally at least once.
  4. In regular chat, discuss this cron job several times, for example:
    • ask why its output is wrong
    • ask to rewrite its prompt or policy
    • discuss whether it should trade or not trade
    • ask for reruns, debugging, or cron body changes
  5. Let the cron run again.
  6. Observe that the cron output begins to include prior meta-discussion instead of only the intended scheduled task output.

A representative session key pattern is:

  • agent:main:cron:<jobId>

Relevant observations during reproduction:

  • runtime logs showed auto-recall queries derived from the cron prompt itself
  • session logs showed injected memory blocks starting with:
    • ## User's conversation history (from memory system)
  • disabling the plugin and resetting the cron session immediately stopped the contamination

Environment

  • Repository: MemTensor/MemOS
  • Plugin package: @memtensor/memos-local-openclaw-plugin
  • Plugin version: 1.0.3
  • OpenClaw version: v2026.3.11
  • Node.js runtime observed in gateway logs: v22.20.0
  • Deployment: self-hosted OpenClaw gateway on Linux via systemd --user
  • Plugin role: configured as the OpenClaw memory slot
  • OpenClaw built-in memory search: disabled

Additional Context

This appears to be in the same problem family as existing issues/PRs around auto-recall and injected prompt contamination, but I could not find one specific to cron sessions.

From local investigation, the root cause appears to be:

  1. auto-recall runs for cron turns without any cron/session exclusion
  2. the recall query is built from the cron prompt itself
  3. the cron uses a stable session key namespace like agent:main:cron:*
  4. prior meta-discussion about the cron becomes highly retrievable and is injected back into later runs

Suggested fixes:

  • skip auto-recall by default for cron sessions, e.g. agent:*:cron:*
  • or add config such as:
    • autoRecall.excludeCron = true
    • autoRecall.excludeSessionKeyPrefixes
  • or avoid using full cron prompts as recall queries
  • or suppress recall of memories that are clearly meta-discussion about the current cron/job itself

Willingness to Implement

  • [ ] I'm willing to implement this myself
  • [x] I would like someone else to implement this

dreamcoin1998 avatar Mar 20 '26 21:03 dreamcoin1998

me too

Vran9 avatar Mar 21 '26 01:03 Vran9

This issue has been automatically marked as stale due to inactivity.

github-actions[bot] avatar Apr 23 '26 03:04 github-actions[bot]

💬 我也在做记忆系统相关的工作:CausaMem,可以来看看,说不定有能借鉴的地方 🙂

MaiHHConnect avatar Jun 02 '26 04:06 MaiHHConnect

🤖 AutoDev has picked up this issue and started working on it.

Task ID: 361246167d2f06ab Working branch: bugfix/autodev-1311 Target branch: latest dev* branch Workflow: opsp (analysis → coding → testing → PR)

I will post the PR link here once done. If I need more information, I will ask in the comments.

Memtensor-AI avatar Jun 29 '26 15:06 Memtensor-AI

✅ AutoDev task 361246167d2f06ab completed.

Summary: Fixed GitHub issue #1311 (openclaw-plugin cron-run contamination by auto-recall).

Root cause: the before_prompt_build hook in apps/memos-local-openclaw/index.ts ignored hookCtx.sessionKey and used the cron prompt itself as the recall query. Because cron jobs reuse stable session keys of the form agent:<id>:cron:<jobId> and prior meta-discussion about the cron (prompt tuning, debugging, rerun requests) lives under the same agent owner with vocabulary that mirrors the cron body, those discussions ranked highest and got injected back as a ## User's conversation history (from memory system) system block on the next scheduled run, derailing the cron output.

Fix: added a new pure helper shouldSkipAutoRecallForSession(sessionKey, cfg) in apps/memos-local-openclaw/src/recall/session-policy.ts and an early-return gate at the top of the hook that short-circuits the entire memory + skill auto-recall path for cron / excluded session keys. Behaviour is controlled by a new optional autoRecall config block on MemosLocalConfig with excludeCron (default true) and excludeSessionKeyPatterns (default empty). The cron-segment matcher is /(?:^|:)cron(?::|$)/i, which is :-boundary aware so identifiers like cronos are not caught. Capture and the explicit memory_search / memory_get tools are intentionally untouched — only the automatic injection is suppressed inside cron runs.

Tests: 9 unit cases for the policy helper (default behaviour, cron-segment matching, boundary guard, opt-out, custom regex, invalid regex fallback) plus 4 integration cases that drive the actual hook with mocked storage/engine/summarizer and assert RecallEngine.search is/isn't called depending on session key + config. npx vitest run tests/{session-policy,auto-recall-cron-gate,config,plugin-openclaw-wiring,openclaw-fallback}.test.ts → 5 files, 32 tests pass. npx tsc --noEmit → exit 0.

Diff is contained to 6 files inside apps/memos-local-openclaw/: index.ts (8-line early-return gate + 1 import), src/recall/session-policy.ts (new helper), src/types.ts (new AutoRecallConfig interface), src/config.ts (default autoRecall block in resolveConfig), tests/session-policy.test.ts (new), tests/auto-recall-cron-gate.test.ts (new). No DB schema change, no public tool-API change, no data migration.

Base branch: main Branch: bugfix/autodev-1311 Commit: befb899 PR: https://github.com/MemTensor/MemOS/pull/1970 Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller

Memtensor-AI avatar Jun 29 '26 16:06 Memtensor-AI