Skip to content

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

Open
Memtensor-AI wants to merge 1 commit into
dev-20260624-v2.0.22from
bugfix/autodev-1311
Open

Fix #1311: bug(openclaw-plugin): auto-recall contaminates cron runs with prior meta-discuss#1970
Memtensor-AI wants to merge 1 commit into
dev-20260624-v2.0.22from
bugfix/autodev-1311

Conversation

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Description

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.

Related Issue (Required): Fixes #1311

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Automated tests are pending.

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have created related documentation issue/PR in MemOS-Docs (if applicable)
  • I have linked the issue to this PR (if applicable)
  • I have mentioned the person who will review this PR

@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.

Reviewer Checklist

OpenClaw cron jobs reuse a stable session-key namespace
(agent:<id>:cron:<jobId>) and the before_prompt_build hook used the cron
prompt itself as the recall query. Prior meta-discussion about the cron
(prompt tuning, debugging, rerun requests) was therefore highly
retrievable and got injected back as system context, contaminating the
next scheduled run.

Add shouldSkipAutoRecallForSession() and an early-return gate inside the
hook so cron sessions skip the entire memory + skill auto-recall path by
default. Operators can opt out with autoRecall.excludeCron=false or
extend the filter with autoRecall.excludeSessionKeyPatterns.

- New helper apps/memos-local-openclaw/src/recall/session-policy.ts
- New AutoRecallConfig on MemosLocalConfig, defaulted in resolveConfig
- Hook in apps/memos-local-openclaw/index.ts gains the early-return gate
- Unit + integration tests cover cron / non-cron / opt-out / custom
  patterns / invalid-regex paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated bug Something isn't working | 功能异常

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants