Skip to content

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

Closed

Description

@dreamcoin1998

Pre-submission checklist

  • I have searched existing issues and this hasn't been mentioned before
  • I have read the project documentation and confirmed this issue doesn't already exist
  • 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
  • I would like someone else to implement this

Activity

  1. changed the title [-]fix:[/-] [+]bug(openclaw-plugin): auto-recall contaminates cron runs with prior meta-discussion[/+] on Mar 20, 2026
  2. Vran9 commented on Mar 21, 2026

    @Vran9

    me too

  3. github-actions commented on Apr 23, 2026

    @github-actions
    Contributor

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

  4. added
    status:staleAuto-marked stale after 30d inactivity; closes 7d later unless exempt.
    on Apr 23, 2026
  5. MaiHHConnect commented on Jun 2, 2026

    @MaiHHConnect
  6. removed
    status:staleAuto-marked stale after 30d inactivity; closes 7d later unless exempt.
    on Jun 19, 2026
  7. added
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Jun 29, 2026
  8. self-assigned this
    on Jun 29, 2026
  9. Memtensor-AI commented on Jun 29, 2026

    @Memtensor-AI
    Collaborator

    🤖 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.

  10. Memtensor-AI commented on Jun 29, 2026

    @Memtensor-AI
    Collaborator

    ✅ 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: #1970
    Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller
    Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller

  11. added
    ai:testingAI agent is running tests | AI 正在运行测试
    and removed
    ai:codingAI agent is coding | AI 正在编码
    on Jun 29, 2026
  12. added a commit that references this issue on Jul 2, 2026
    3b65dae
  13. added and removed
    ai:testingAI agent is running tests | AI 正在运行测试
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:pluginOpenClaw & Hermestypes:bugSomething isn't working | 功能异常

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions