fix(openclaw): scope recall and capture by project#598
Conversation
|
@MackDing is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe PR adds project-scoped memory operations to the OpenClaw plugin integration. It introduces helpers to derive a project identifier from multiple event fields, then uses that derived project to augment smart-search recall requests and observe session-tracking requests, with appropriate fallback values. ChangesOpenClaw Project Scoping
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/openclaw-project-scope.test.ts`:
- Around line 34-40: The test setup deletes process.env["AGENTMEMORY_SECRET"] in
beforeEach but never restores it, risking state leakage; modify the setup to
capture the original value (e.g., const originalAgentMemorySecret =
process.env["AGENTMEMORY_SECRET"] or similar) before deleting in beforeEach and
then restore process.env["AGENTMEMORY_SECRET"] = originalAgentMemorySecret (or
delete it if undefined) in afterEach alongside restoring globalThis.fetch =
originalFetch; update the beforeEach/afterEach blocks in
test/openclaw-project-scope.test.ts to use these variables.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 18de1097-da1a-4435-85e1-83a08def6653
📒 Files selected for processing (2)
integrations/openclaw/plugin.mjstest/openclaw-project-scope.test.ts
| beforeEach(() => { | ||
| delete process.env["AGENTMEMORY_SECRET"]; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| globalThis.fetch = originalFetch; | ||
| }); |
There was a problem hiding this comment.
Restore AGENTMEMORY_SECRET after each test for isolation.
Line 35 deletes the env var, but it is never restored. This can leak state to other test files.
Suggested fix
describe("OpenClaw plugin project scoping", () => {
const originalFetch = globalThis.fetch;
+ const originalAgentMemorySecret = process.env["AGENTMEMORY_SECRET"];
beforeEach(() => {
delete process.env["AGENTMEMORY_SECRET"];
});
afterEach(() => {
globalThis.fetch = originalFetch;
+ if (originalAgentMemorySecret === undefined) {
+ delete process.env["AGENTMEMORY_SECRET"];
+ } else {
+ process.env["AGENTMEMORY_SECRET"] = originalAgentMemorySecret;
+ }
});📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| beforeEach(() => { | |
| delete process.env["AGENTMEMORY_SECRET"]; | |
| }); | |
| afterEach(() => { | |
| globalThis.fetch = originalFetch; | |
| }); | |
| describe("OpenClaw plugin project scoping", () => { | |
| const originalFetch = globalThis.fetch; | |
| const originalAgentMemorySecret = process.env["AGENTMEMORY_SECRET"]; | |
| beforeEach(() => { | |
| delete process.env["AGENTMEMORY_SECRET"]; | |
| }); | |
| afterEach(() => { | |
| globalThis.fetch = originalFetch; | |
| if (originalAgentMemorySecret === undefined) { | |
| delete process.env["AGENTMEMORY_SECRET"]; | |
| } else { | |
| process.env["AGENTMEMORY_SECRET"] = originalAgentMemorySecret; | |
| } | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/openclaw-project-scope.test.ts` around lines 34 - 40, The test setup
deletes process.env["AGENTMEMORY_SECRET"] in beforeEach but never restores it,
risking state leakage; modify the setup to capture the original value (e.g.,
const originalAgentMemorySecret = process.env["AGENTMEMORY_SECRET"] or similar)
before deleting in beforeEach and then restore process.env["AGENTMEMORY_SECRET"]
= originalAgentMemorySecret (or delete it if undefined) in afterEach alongside
restoring globalThis.fetch = originalFetch; update the beforeEach/afterEach
blocks in test/openclaw-project-scope.test.ts to use these variables.
Summary
smart-searchprojectandcwdon OpenClaw observe payloads so captured sessions are grouped consistentlyProblem
The OpenClaw integration recalled memory using only the prompt text and captured turns with only a session id. In shared agentmemory deployments, that makes it too easy for the OpenClaw plugin to query global memory without any project/workspace scoping.
Fix
This PR keeps the change deliberately small and backward-compatible:
before_agent_startnow derives a project value from the OpenClaw event (project, nested workspace metadata, or cwd fallback) and passes it to/agentmemory/smart-searchagent_endnow includesprojectandcwdin/agentmemory/observeThis is not full principal/tenant isolation, but it is a practical hardening step that restores existing project-based filtering support in the backend and reduces cross-project leakage risk for the OpenClaw integration.
Verification
npm test -- --run test/openclaw-plugin.test.ts test/openclaw-project-scope.test.ts test/integration-plaintext-http.test.tsRefs #596
Summary by CodeRabbit
New Features
Tests