Skip to content

fix(memory-lancedb): prevent cross-agent memory leakage - #103799

Merged
steipete merged 7 commits into
openclaw:mainfrom
lonexreb:fix/103590-lancedb-per-agent-memory-gate
Jul 16, 2026
Merged

steipete merged 7 commits into
openclaw:mainfrom
lonexreb:fix/103590-lancedb-per-agent-memory-gate

Conversation

@lonexreb

@lonexreb lonexreb commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #103590.

What Problem This Solves

Fixes an issue where agents sharing the LanceDB memory plugin could read, list, delete, or automatically recall another agent's memories. Disabling memorySearch only stopped automatic hooks, while the shared tools and backing table still crossed agent boundaries.

Why This Change Was Made

Every LanceDB row now has a normalized owning agent ID, and all store, search, list, query, count, and delete paths require and enforce that owner. Plugin tools are registered per agent, ACP-managed MCP delegates propagate the canonical session agent, and automatic recall/capture use the same live per-agent gate.

Existing shared tables fail closed until openclaw doctor --fix performs the one-time migration. Because legacy rows have no trustworthy owner, the migration assigns them to the configured default agent and verifies the resulting schema and row count.

User Impact

Agents can use the same LanceDB plugin without memories leaking across tool calls, prompt injection, automatic capture, CLI operations, ACP sessions, or gateway restarts. Agents with memorySearch.enabled: false receive no memory tools and perform no automatic memory I/O.

Evidence

  • 202 focused tests pass across the LanceDB store/plugin, doctor migration, ACP runtime, and MCP plugin-tool server.
  • pnpm check:changed passed on the exact PR head, including all TypeScript, lint, formatting, SDK-surface, dependency, database-first, cycle, and ratchet gates: https://github.com/openclaw/openclaw/actions/runs/29484893629
  • Built-gateway live proof used two agents through /tools/invoke, automatic capture, automatic recall, CLI listing, and a gateway restart. Result: LIVE_PROOF_OK agents=2 tools=isolated capture=isolated recall=isolated restart=persistent.
  • Source-blind behavior validation passed every isolation and persistence clause, including distinct stored rows, tool responses, model-request payloads, and post-restart lists.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-lancedb Extension: memory-lancedb size: S labels Jul 10, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 10, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 10, 2026, 7:27 PM ET / 23:27 UTC.

Summary
The PR makes memory-lancedb automatic recall and capture honor each agent’s effective memorySearch.enabled setting, with focused regression tests and documentation.

PR surface: Source +22, Tests +140, Docs +6. Total +168 across 3 files.

Reproducibility: yes. at source level with high confidence: current main passes the resolved agent ID to both automatic hooks but does not consult the effective memorySearch.enabled value before search or capture. This read-only review did not execute the live Gateway/LanceDB scenario.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: unknown-data-model-change: extensions/memory-lancedb/index.test.ts, unknown-data-model-change: extensions/memory-lancedb/index.ts, vector/embedding metadata: extensions/memory-lancedb/index.test.ts, vector/embedding metadata: extensions/memory-lancedb/index.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #103590
Summary: This PR is the direct narrow fix candidate for the open issue; the two older closed PRs partially overlap through broader agent-isolation designs.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

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

Rank-up moves:

  • Post redacted live Gateway/LanceDB output showing disabled-agent recall and capture are skipped while the enabled agent still works.
  • Obtain explicit maintainer approval for the narrow automatic-hook isolation boundary.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR provides after-fix hook-harness evidence with mocked LanceDB and embeddings, not a real two-agent Gateway/LanceDB run; add redacted terminal output or logs, update the PR body to trigger review, or ask a maintainer for @clawsweeper re-review if it does not trigger automatically.

Risk before merge

  • [P1] No after-fix evidence currently shows a real two-agent Gateway and LanceDB setup skipping both recall and capture for the disabled agent while preserving enabled-agent behavior.
  • [P1] The patch intentionally leaves enabled agents and explicit memory tools on the shared store, so maintainers must approve this as a narrow immediate boundary rather than complete agent isolation.

Maintainer options:

  1. Approve and prove the narrow gate (recommended)
    Confirm the limited security contract and require redacted real two-agent Gateway/LanceDB output before merge.
  2. Pause for full isolation design
    Defer this branch until maintainers choose storage, explicit-tool, CLI, legacy-data, and migration semantics for agent isolation.

Next step before merge

  • [P1] The branch has no remaining mechanical correctness finding; the next actions are contributor live proof and maintainer approval of the intended security boundary.

Maintainer decision needed

  • Question: Should memorySearch.enabled define only the automatic recall/capture boundary for this fix, with shared storage and explicit memory tools handled separately?
  • Rationale: The implementation correctly follows the existing core flag semantics, but complete per-agent isolation also requires decisions about tool context, stored-data identity, migrations, legacy memories, and CLI behavior.
  • Likely owner: steipete — The strongest aggregate history across the plugin runtime, tests, docs, and path ownership makes this the best available owner for the scope decision.
  • Options:
    • Approve narrow mitigation (recommended): Land this immediate automatic-path gate and track full storage/tool isolation as separate migration-sensitive work.
    • Require complete isolation first: Hold this PR until automatic hooks, explicit tools, storage records, CLI behavior, and upgrades share one approved isolation model.

Security
Cleared: The diff introduces no concrete security or supply-chain regression and strengthens the disabled-agent boundary; the remaining scope choice is captured as a maintainer decision.

Review details

Best possible solution:

Land the focused automatic-hook gate after a feature owner approves the limited boundary and redacted live two-agent Gateway/LanceDB output proves that the disabled agent neither receives nor contributes memories while the enabled agent still works.

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

Yes, at source level with high confidence: current main passes the resolved agent ID to both automatic hooks but does not consult the effective memorySearch.enabled value before search or capture. This read-only review did not execute the live Gateway/LanceDB scenario.

Is this the best way to solve the issue?

Yes for the reported automatic-hook bypass: the patch reuses the canonical resolver, matches core precedence, and gates before memory I/O. It is not a complete cross-agent isolation solution, so the limited boundary needs explicit maintainer acceptance.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2f9cb9200669.

Label changes

Label justifications:

  • P0: The PR addresses silent cross-agent disclosure of potentially private memory context in an active agent workflow.
  • merge-risk: 🚨 session-state: Merging changes which agent sessions may automatically read from and write to shared long-term memory.
  • merge-risk: 🚨 security-boundary: The patch establishes a limited confidentiality boundary while broader shared-store and explicit-tool access remains unchanged.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides after-fix hook-harness evidence with mocked LanceDB and embeddings, not a real two-agent Gateway/LanceDB run; add redacted terminal output or logs, update the PR body to trigger review, or ask a maintainer for @clawsweeper re-review if it does not trigger automatically.
Evidence reviewed

PR surface:

Source +22, Tests +140, Docs +6. Total +168 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 23 1 +22
Tests 1 140 0 +140
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 169 1 +168

What I checked:

Likely related people:

  • radek-paclt: Introduced the lifecycle-hook infrastructure and LanceDB automatic recall/capture behavior containing the affected paths. (role: introduced behavior; confidence: high; commits: ebfeb7a6bf53; files: extensions/memory-lancedb/index.ts)
  • vignesh07: Authored prior hardening and capture-limit changes on the same automatic memory paths. (role: security hardening contributor; confidence: high; commits: 61725fb37e33, 8cb0373bc1e7; files: extensions/memory-lancedb/index.ts, extensions/memory-lancedb/index.test.ts)
  • steipete: Renamed and repeatedly maintained the plugin path and has the strongest aggregate history across its runtime, tests, and documentation. (role: major area contributor; confidence: high; commits: bf925e575852, ed55b63684b3; files: extensions/memory-lancedb/index.ts, extensions/memory-lancedb/index.test.ts, docs/plugins/memory-lancedb.md)
  • gumadeiras: Migrated memory-lancedb to scoped Plugin SDK imports, directly relevant to the new agent-runtime resolver dependency. (role: SDK boundary contributor; confidence: medium; commits: 6b19b7f37af3; files: extensions/memory-lancedb/index.ts)
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.
Review history (2 earlier review cycles)
  • reviewed 2026-07-10T16:42:16.127Z sha bb4580b2ab7ffcb4e6199f82a697407d7861bfcb :: needs real behavior proof before merge. :: [P1] Normalize agent IDs before applying the memory gate
  • reviewed 2026-07-10T17:47:12.372Z sha 5bd52a4ca4d5ebf8cfefb1eecfb83fc3ca89e768 :: needs real behavior proof before merge. :: [P1] Reuse the canonical agent config resolver

@lonexreb

Copy link
Copy Markdown
Contributor Author

Addressed the P1 finding in 5bd52a4ca4d: agent ids are now normalized on both sides of the per-agent lookup via the SDK normalizeAgentId (case + whitespace variants like " XiaoHuo " hit the override; new assertion in the gate regression covers it). 136/136 plugin tests pass, tsgo/oxfmt clean.

Live two-agent Gateway+LanceDB proof and the isolation-scope confirmation remain with maintainers — I don't have a live LanceDB/Ollama stack in this environment.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

lonexreb added 3 commits July 10, 2026 18:06
…emorySearch.enabled (openclaw#103590)

The before_prompt_build auto-recall hook only checked the plugin-level
autoRecall flag, so agents configured with memorySearch.enabled: false
still received <relevant-memories> injected from the shared LanceDB store
- leaking one agent's private memories into another agent's prompts. Gate
both recall injection and agent_end auto-capture on the current agent's
memorySearch.enabled (per-agent entry wins over agents.defaults; unset
means enabled), mirroring core resolveMemorySearchConfig semantics.
Review follow-up on openclaw#103799: a configured id like 'XiaoHuo' or one with
surrounding whitespace missed the exact-match per-agent override and
inherited the enabled default, leaving the disclosure path active.
Normalize both the hook agent id and configured entry ids with the SDK
normalizeAgentId before comparing.
@lonexreb
lonexreb force-pushed the fix/103590-lancedb-per-agent-memory-gate branch from 5bd52a4 to 419f165 Compare July 10, 2026 23:09
@lonexreb

Copy link
Copy Markdown
Contributor Author

Addressed the P1 (Reuse the canonical agent config resolver) in 419f165 and rebased onto current main:

  • The hand-rolled agents.list scan (a second normalized agent-resolution policy) is gone. The gate now resolves per-agent overrides through the canonical resolveAgentConfig (openclaw/plugin-sdk/agent-runtime), the same resolver core resolveMemorySearchConfig/resolveMemorySearchSyncConfig use, so id normalization and default-agent policy cannot drift from core. Net −9 LOC.
  • Enabled semantics unchanged: per-agent memorySearch.enabled wins over agents.defaults, unset means enabled. The existing regression (including the " XiaoHuo " case/whitespace variants) still passes unmodified.

node scripts/run-vitest.mjs run extensions/memory-lancedb/index.test.ts — 126/126 pass; tsgo:extensions + oxfmt/oxlint clean.

Live two-agent Gateway + LanceDB proof remains outstanding (flagged separately to the PR author).

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@steipete steipete self-assigned this Jul 16, 2026
@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

This PR no longer has blocked security-sensitive file changes. A future security-sensitive change requires a fresh /allow-security-sensitive-change comment after the guard blocks that new head SHA.

  • Current SHA: 1a58e20b695ecbb4d37fc4ab833c3278e41d18cd

@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: acpx extensions: memory-lancedb Extension: memory-lancedb merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory-lancedb auto-recall ignores per-agent memorySearch.enabled, causing cross-agent memory leakage

2 participants