Fix #1311: bug(openclaw-plugin): auto-recall contaminates cron runs with prior meta-discuss#1970
Open
Memtensor-AI wants to merge 1 commit into
Open
Fix #1311: bug(openclaw-plugin): auto-recall contaminates cron runs with prior meta-discuss#1970Memtensor-AI wants to merge 1 commit into
Memtensor-AI wants to merge 1 commit into
Conversation
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
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixed GitHub issue #1311 (openclaw-plugin cron-run contamination by auto-recall).
Root cause: the
before_prompt_buildhook inapps/memos-local-openclaw/index.tsignoredhookCtx.sessionKeyand used the cron prompt itself as the recall query. Because cron jobs reuse stable session keys of the formagent:<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)inapps/memos-local-openclaw/src/recall/session-policy.tsand 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 optionalautoRecallconfig block onMemosLocalConfigwithexcludeCron(default true) andexcludeSessionKeyPatterns(default empty). The cron-segment matcher is/(?:^|:)cron(?::|$)/i, which is:-boundary aware so identifiers likecronosare not caught. Capture and the explicitmemory_search/memory_gettools 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.searchis/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 (newAutoRecallConfiginterface), src/config.ts (defaultautoRecallblock inresolveConfig), 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.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.
Reviewer Checklist