Skip to content

feat(memory-core): configurable MEMORY.md injection mode + per-turn autoRecall#63662

Open
ZardLi1115 wants to merge 10 commits into
openclaw:mainfrom
ZardLi1115:codex/memory-injection-auto-recall
Open

feat(memory-core): configurable MEMORY.md injection mode + per-turn autoRecall#63662
ZardLi1115 wants to merge 10 commits into
openclaw:mainfrom
ZardLi1115:codex/memory-injection-auto-recall

Conversation

@ZardLi1115

Copy link
Copy Markdown

Summary

  • add agents.defaults.memoryInjection with full, core-only, and recall-only modes
  • add agents.defaults.memorySearch.autoRecall for per-turn memory recall injection in memory-core
  • update memory docs and schema metadata for the new configuration

Validation

  • corepack pnpm build
  • corepack pnpm test src/agents/bootstrap-files.test.ts src/agents/memory-search.test.ts src/config/config.schema-regressions.test.ts extensions/memory-core/src/auto-recall.test.ts extensions/memory-core/index.test.ts src/config/schema.base.generated.test.ts

Closes #24624

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core agents Agent runtime and tooling size: L labels Apr 9, 2026
@greptile-apps

greptile-apps Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds agents.defaults.memoryInjection ("full" | "core-only" | "recall-only") to control whether MEMORY.md is injected into the bootstrap context, and agents.defaults.memorySearch.autoRecall to automatically prepend semantically-relevant memory hits before each prompt build. Schema, types, Zod validation, labels, and help text are all updated consistently, and the memory-core extension registers the new before_prompt_build hook with safe HTML-escaping for injected memory snippets.

Two P2 concerns worth revisiting before wider adoption: (1) \"core-only\" and \"full\" are currently identical in the implementation — applyMemoryInjectionFilter branches only on \"recall-only\", contrary to the docs that imply \"core-only\" enforces truncation limits while \"full\" doesn't; (2) the startup warning for recall-only-without-autoRecall fires only when no agent has autoRecall enabled, which could silently leave per-agent gaps uncovered.

Confidence Score: 5/5

Safe to merge; all remaining findings are P2 style/clarity issues.

The core logic is sound: recall-only filtering, autoRecall resolution with clamping, safe HTML escaping of injected memory, and graceful error degradation all work correctly. Both noted issues are semantic (mode equivalence) and warning-scope (partial coverage), neither of which causes wrong data, data loss, or runtime errors.

src/agents/bootstrap-files.ts — core-only vs full equivalence; extensions/memory-core/src/auto-recall.ts — warning scope for mixed autoRecall configurations.

Vulnerabilities

  • Memory snippet injection in auto-recall.ts HTML-escapes &, <, >, ", and ' before inserting into the <relevant-memories> XML context block, preventing untrusted memory content from escaping the boundary or injecting arbitrary prompt instructions.
  • No secrets, credentials, or sensitive paths are exposed in the new code paths.
  • The before_prompt_build hook reads config fresh per-turn via api.runtime.config.loadConfig(), which is consistent with existing patterns and does not introduce new attack surfaces.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/bootstrap-files.ts
Line: 43-53

Comment:
**`core-only` and `full` modes are currently identical**

`applyMemoryInjectionFilter` only gates on `"recall-only"`, so `"core-only"` passes through unchanged — the same as `"full"`. The docs describe them differently ("core-only keeps it inside the normal bootstrap size limits"), but the code applies identical truncation in both cases. Users who set `"core-only"` get no behavioural difference from `"full"`, which could cause confusion.

If the intent is to diverge them later (e.g. `"full"` will eventually bypass `bootstrapMaxChars` for `MEMORY.md`), that should be noted in the doc comment. Otherwise, one of the modes or the documentation description should be updated to match reality.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/memory-core/src/auto-recall.ts
Line: 59-61

Comment:
**Warning suppresses when any single agent enables `autoRecall`**

`shouldWarnForRecallOnlyWithoutAutoRecall` fires only when *no* agent at all has `autoRecall` enabled. If `memoryInjection: "recall-only"` is global but only one specific agent has `autoRecall` enabled (while others rely on the default `false`), the warning is suppressed — leaving the other agents with no memory context silently. Consider checking whether the defaults also enable `autoRecall` before suppressing the warning, or narrowing the message to indicate that only some agents may lose memory context.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "feat(memory-core): add configurable memo..." | Re-trigger Greptile

Comment on lines +43 to +53
function applyMemoryInjectionFilter(
files: WorkspaceBootstrapFile[],
config?: OpenClawConfig,
): WorkspaceBootstrapFile[] {
if (resolveMemoryInjectionMode(config) !== "recall-only") {
return files;
}
return files.filter(
(file) => file.name !== DEFAULT_MEMORY_FILENAME && file.name !== DEFAULT_MEMORY_ALT_FILENAME,
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 core-only and full modes are currently identical

applyMemoryInjectionFilter only gates on "recall-only", so "core-only" passes through unchanged — the same as "full". The docs describe them differently ("core-only keeps it inside the normal bootstrap size limits"), but the code applies identical truncation in both cases. Users who set "core-only" get no behavioural difference from "full", which could cause confusion.

If the intent is to diverge them later (e.g. "full" will eventually bypass bootstrapMaxChars for MEMORY.md), that should be noted in the doc comment. Otherwise, one of the modes or the documentation description should be updated to match reality.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/bootstrap-files.ts
Line: 43-53

Comment:
**`core-only` and `full` modes are currently identical**

`applyMemoryInjectionFilter` only gates on `"recall-only"`, so `"core-only"` passes through unchanged — the same as `"full"`. The docs describe them differently ("core-only keeps it inside the normal bootstrap size limits"), but the code applies identical truncation in both cases. Users who set `"core-only"` get no behavioural difference from `"full"`, which could cause confusion.

If the intent is to diverge them later (e.g. `"full"` will eventually bypass `bootstrapMaxChars` for `MEMORY.md`), that should be noted in the doc comment. Otherwise, one of the modes or the documentation description should be updated to match reality.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +59 to +61
function shouldWarnForRecallOnlyWithoutAutoRecall(cfg: OpenClawConfig): boolean {
return cfg.agents?.defaults?.memoryInjection === "recall-only" && !hasAnyAutoRecallEnabled(cfg);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Warning suppresses when any single agent enables autoRecall

shouldWarnForRecallOnlyWithoutAutoRecall fires only when no agent at all has autoRecall enabled. If memoryInjection: "recall-only" is global but only one specific agent has autoRecall enabled (while others rely on the default false), the warning is suppressed — leaving the other agents with no memory context silently. Consider checking whether the defaults also enable autoRecall before suppressing the warning, or narrowing the message to indicate that only some agents may lose memory context.

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/memory-core/src/auto-recall.ts
Line: 59-61

Comment:
**Warning suppresses when any single agent enables `autoRecall`**

`shouldWarnForRecallOnlyWithoutAutoRecall` fires only when *no* agent at all has `autoRecall` enabled. If `memoryInjection: "recall-only"` is global but only one specific agent has `autoRecall` enabled (while others rely on the default `false`), the warning is suppressed — leaving the other agents with no memory context silently. Consider checking whether the defaults also enable `autoRecall` before suppressing the warning, or narrowing the message to indicate that only some agents may lose memory context.

How can I resolve this? If you propose a fix, please make it concise.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec9c365b86

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +47 to +48
if (resolveMemoryInjectionMode(config) !== "recall-only") {
return files;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Implement distinct behavior for memoryInjection core-only

applyMemoryInjectionFilter only branches on "recall-only", so "core-only" and "full" currently follow the exact same path and inject the same bootstrap files. That makes the new core-only mode effectively a no-op for runtime behavior, so users who select it won’t get a different memory-injection policy. Please add explicit core-only handling (or collapse the option) so the setting has observable effect.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c05d65e5b8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +63 to +64
if (cfg.agents?.defaults?.memorySearch?.autoRecall?.enabled) {
return undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Warn when recall-only is paired with disabled memory search

This early return assumes autoRecall.enabled means recall is active, but resolveMemorySearchConfig returns null whenever memorySearch.enabled is false (src/agents/memory-search.ts:410-412). With memoryInjection: "recall-only", memorySearch.enabled: false, and autoRecall.enabled: true, bootstrap memory is removed and auto-recall never injects anything, yet startup emits no warning, so users can end up with zero memory context and no clear signal about the misconfiguration.

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Apr 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf7a675778

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +80 to +82
if (!hasAnyAutoRecallEnabled(api.config)) {
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Always register auto-recall hook

This early return makes autoRecall impossible to enable via hot config reload: if the gateway starts with auto-recall off, the before_prompt_build hook is never registered, so later toggling agents.defaults.memorySearch.autoRecall.enabled (or agent-level overrides) has no runtime effect until a process/plugin restart. That is a functional regression for live config updates, especially since this hook already reads api.runtime.config.loadConfig() per turn and agents.* changes are generally treated as non-restart config paths.

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle Bot added app: macos App: macos app: web-ui App: web-ui labels Apr 9, 2026
…ion-auto-recall

# Conflicts:
#	src/auto-reply/reply/followup-runner.test.ts
@openclaw-barnacle openclaw-barnacle Bot removed app: macos App: macos app: web-ui App: web-ui labels Apr 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17e65a7e67

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +118 to +121
if (channel && isThreadChild) {
if (channel === "slack" || channel === "mattermost" || channel === "telegram") {
return {
to: formatConversationTarget({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Let plugin resolver run before Telegram thread fallback

This new early return executes for Telegram thread children before pluginTarget is consulted, so messaging.resolveDeliveryTarget in the Telegram plugin is skipped for exactly the cases where channel-specific normalization is needed. For topic conversations, this returns threadId as the raw conversationId instead of the plugin-normalized topic id, which can produce inconsistent routing keys and thread targeting compared with the plugin contract.

Useful? React with 👍 / 👎.

Comment on lines +63 to +64
if (cfg.agents?.defaults?.memorySearch?.autoRecall?.enabled) {
return undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Warn when agent overrides disable autoRecall in recall-only mode

resolveRecallOnlyAutoRecallWarning returns early as soon as defaults have memorySearch.autoRecall.enabled=true, but agent-level overrides can still set autoRecall.enabled=false. In that configuration, those agents run with memoryInjection: "recall-only" plus no auto-recall (because resolveMemorySearchConfig applies the override), so they lose all automatic memory context without the startup warning this guard is meant to provide.

Useful? React with 👍 / 👎.

@vincentkoc vincentkoc added the triage: dirty-candidate Candidate: broad unrelated surfaces; may need splitting or cleanup. label Apr 26, 2026
@clawsweeper

clawsweeper Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 5, 2026, 1:02 AM ET / 05:02 UTC.

Summary
Review failed before ClawSweeper could summarize the requested change.

PR surface: Source +228, Tests +378, Docs +67, Generated +94, Other +23. Total +790 across 24 files.

Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

Review metrics: none identified.

Merge readiness
Overall: 🌊 off-meta tidepool
Proof: 🌊 off-meta tidepool
Patch quality: 🌊 off-meta tidepool
Result: rating does not apply to this item.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] No close action taken because the review did not complete.

Maintainer options:

  1. Decide the mitigation before merge
    Retry the Codex review after fixing the execution failure.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Review did not complete, so no work-lane recommendation was made.
Review details

Best possible solution:

Retry the Codex review after fixing the execution failure.

Do we have a high-confidence way to reproduce the issue?

Unclear. The review failed before ClawSweeper could establish a reproduction path.

Is this the best way to solve the issue?

Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model gpt-5.5, reasoning high; reviewed against e0018382eb00.

Label changes

Label changes:

  • add rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.
  • remove mantis: telegram-visible-proof: Current Telegram visible-proof status is not_needed.
  • remove P2: Current review triage priority is none.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🌊 off-meta tidepool, so this older rating label is no longer current.
  • remove merge-risk: 🚨 automation: Current PR review selected no merge-risk labels.
  • remove merge-risk: 🚨 message-delivery: Current PR review selected no merge-risk labels.
  • remove merge-risk: 🚨 security-boundary: Current PR review selected no merge-risk labels.
  • remove status: 📣 needs proof: Current PR status no longer selects a status label.

Label justifications:

  • rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.
Evidence reviewed

PR surface:

Source +228, Tests +378, Docs +67, Generated +94, Other +23. Total +790 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 14 250 22 +228
Tests 6 389 11 +378
Docs 1 68 1 +67
Config 0 0 0 0
Generated 1 94 0 +94
Other 2 25 2 +23
Total 24 826 36 +790

What I checked:

  • failure reason: codex execution failed.
  • codex failure detail: Codex review failed for this PR with exit 1.
  • codex stdout: Per-item Codex failure; continuing with the rest of the shard.

Likely related people:

  • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@ramezgaberiel

Copy link
Copy Markdown
Contributor

Real user data point — running 2026.5.7 with active-memory denied (per latency triage 2026-04-29: 10-11s elapsed + 16k cache_read + 19k cache_create per call on a 25-char message via stock model). Per-turn autoRecall would let us re-enable with a sane frequency (e.g. every-3rd-turn) instead of all-or-nothing. We're a multi-channel deployment (Discord direct + channel + Telegram); the lack of memory recall is causing real engineering rework — agents re-discover prior decisions on every conversation. +1.

@clawsweeper clawsweeper Bot added the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 12, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 19, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 4, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Jun 4, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jun 5, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: memory-core Extension: memory-core extensions: qa-lab merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. scripts Repository scripts size: L triage: dirty-candidate Candidate: broad unrelated surfaces; may need splitting or cleanup. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Configurable MEMORY.md injection mode (full / core-only / recall-only)

3 participants