Repository navigation
Conversation
Greptile SummaryThis PR fixes cross-agent memory contamination in Confidence Score: 5/5Safe to merge; the isolation logic is correct and backward compatible. All findings are P2: path sanitization for agentId and missing cleanup of dbMap on service stop. Neither blocks correctness for normal usage. The core fix is clean, the backward-compat fallback is correctly handled, and the new tests provide meaningful coverage of the isolation contract. extensions/memory-lancedb/index.ts — getAgentDb path construction and service stop handler.
|
| function getAgentDb(agentId: string | undefined): MemoryDB { | ||
| const key = agentId ?? ""; | ||
| if (!dbMap.has(key)) { | ||
| const agentDbPath = agentId ? join(resolvedDbPath, agentId) : resolvedDbPath; |
There was a problem hiding this comment.
Unsanitized
agentId used as path component
agentId is passed directly to path.join, so a value containing .. segments (e.g. "../other") would silently produce a DB path that escapes resolvedDbPath. path.join("/base/db", "../evil") resolves to /base/evil. Because agentId comes from the operator's config file the attack surface is low, but defensive validation is still worth adding.
| const agentDbPath = agentId ? join(resolvedDbPath, agentId) : resolvedDbPath; | |
| const agentDbPath = agentId ? join(resolvedDbPath, agentId.replace(/[/\\]/g, "_").replace(/\.\./g, "_")) : resolvedDbPath; |
Alternatively, reject any agentId that contains path-separator or .. characters and surface a clear error at registration time.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/memory-lancedb/index.ts
Line: 307
Comment:
**Unsanitized `agentId` used as path component**
`agentId` is passed directly to `path.join`, so a value containing `..` segments (e.g. `"../other"`) would silently produce a DB path that escapes `resolvedDbPath`. `path.join("/base/db", "../evil")` resolves to `/base/evil`. Because `agentId` comes from the operator's config file the attack surface is low, but defensive validation is still worth adding.
```suggestion
const agentDbPath = agentId ? join(resolvedDbPath, agentId.replace(/[/\\]/g, "_").replace(/\.\./g, "_")) : resolvedDbPath;
```
Alternatively, reject any `agentId` that contains path-separator or `..` characters and surface a clear error at registration time.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee677bc305
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const key = agentId ?? ""; | ||
| if (!dbMap.has(key)) { | ||
| const agentDbPath = agentId ? join(resolvedDbPath, agentId) : resolvedDbPath; |
There was a problem hiding this comment.
Preserve root DB path for default single-agent runs
This logic routes any truthy agentId into a subdirectory, but runtime tool contexts always include an agent id (defaulting to "main" even when agents.list is unset). resolveOpenClawPluginToolInputs sets context.agentId from resolveSessionAgentId, and that resolver falls back to main by default, so single-agent runs now use <dbPath>/main instead of the historical root <dbPath>. As a result, existing single-agent memories become invisible after upgrade, which is a backwards-compatibility regression introduced by this commit.
Useful? React with 👍 / 👎.
|
Closing this as duplicate or superseded after Codex automated review. Close PR #63726 as duplicate/superseded by the earlier open memory-lancedb agent-scoping implementation track in PR #40578. Current main still has the shared LanceDB memory behavior, so this is not implemented-on-main; the remaining fix and review should be consolidated on the canonical PR. Best possible solution: Close #63726 as duplicate/superseded and keep memory-lancedb agent isolation work consolidated on PR #40578. The eventual fix should scope recall/store/forget and auto hooks by agent, preserve legacy single-agent root DB behavior, validate or normalize agent IDs before storage/filter use, add regression tests for multi-agent isolation and default-agent compatibility, and update plugin config docs/changelog if a user-visible option or migration is introduced. What I checked:
So I’m closing this here and keeping the remaining discussion on the canonical linked item. Codex Review notes: model gpt-5.5, reasoning high; reviewed against d54d2d6b9b8a. |
Summary
memory-lancedbplugin, all configured agents in a single openclaw instance share one LanceDB instance. When multiple agents are defined viaagents.list, agent A's stored memories are recalled by agent B, leaking context across agents.MemoryDBinstance with aMap<string, MemoryDB>keyed byagentId. Each agent now gets an isolated subdirectory<dbPath>/<agentId>/. All three tools (memory_recall,memory_store,memory_forget) and both lifecycle hooks(
before_agent_start,agent_end) are migrated toOpenClawPluginToolFactorysoctx.agentIdis available at execution time.agents.list) are fully backward compatible — whenagentIdis absent, the originaldbPathis used unchanged. CLI commands (ltm list/search/stats) also fall back to the root path.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
register()function constructed a singlenew MemoryDB(resolvedDbPath, vectorDim)at plugin load time and captured it in closure. All toolexecutecallbacks and lifecycle hooks referenced this shared instance regardless of which agent triggeredthem. The old
AnyAgentToolpattern used by the tools had no access toagentIdat call time;OpenClawPluginToolFactorywas available but not used.DEFAULT_AGENT_ID = "main"means single-agent users are never affected, which masked the bug in practice.Regression Test Plan (if applicable)
extensions/memory-lancedb/index.test.tsagentIds must calllancedb.connect()with distinct paths; sameagentIdmust reuse a single instance; missingagentIdmust fall back to the rootdbPathexactly.lancedb.connectcall is the boundary — mocking it and asserting the path argument is sufficient to verify isolation without requiring a real LanceDB installation.per-agent memory isolationdescribe block.User-visible / Behavior Changes
agents.list): each agent now writes to and reads from<dbPath>/<agentId>/instead of the shared root. Existing memories in the root are not migrated automatically — users upgrading with a multi-agent setup should beaware their pre-existing data remains in the root path and is no longer visible to named agents.
Diagram (if applicable)