fix: honor project scope in smart search - #806
Conversation
|
@mturac is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds optional ChangesProject-based scoping for MCP search tools
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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
🧹 Nitpick comments (1)
test/mcp-standalone-proxy.test.ts (1)
56-87: ⚡ Quick winAdd a local-fallback project-scoping regression here too.
These assertions only prove the proxy request bodies carry
project.src/mcp/standalone.tsnow has separate local filtering logic inhandleLocal(), so a fallback regression would still leave this suite green. Please add anECONNREFUSEDcase that seeds two projects and verifiesmemory_recall/memory_smart_searchonly return the requested one.Also applies to: 109-127
🤖 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/mcp-standalone-proxy.test.ts` around lines 56 - 87, The test currently only asserts the proxied request body carries project but misses the local fallback branch in handleLocal; modify the test (both the memory_smart_search case and the memory_recall case at lines 109-127) to simulate an ECONNREFUSED upstream (e.g., make installFetch throw or return a connection-refused error) so the code falls back to handleLocal, seed two memories in two different projects, then call handleToolCall("memory_smart_search", ...) and handleToolCall("memory_recall", ...) with project set to one project and assert the returned results include only items from that project; locate references to handleToolCall, installFetch, memory_smart_search, memory_recall and handleLocal to add the error simulation, seeding, and project-scoped assertions.
🤖 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 `@src/functions/smart-search.ts`:
- Around line 315-353: filterExpandedByProject and filterHybridByProject perform
observationMatchesProject serially inside a loop, causing many sequential
kv.get() calls; change them to run the per-item checks in parallel (use
Promise.all over mapped observationMatchesProject promises) and then filter the
original arrays by the resolved boolean results so the functions
(filterExpandedByProject, filterHybridByProject) return the same scoped arrays
but with kv reads performed concurrently to reduce latency.
---
Nitpick comments:
In `@test/mcp-standalone-proxy.test.ts`:
- Around line 56-87: The test currently only asserts the proxied request body
carries project but misses the local fallback branch in handleLocal; modify the
test (both the memory_smart_search case and the memory_recall case at lines
109-127) to simulate an ECONNREFUSED upstream (e.g., make installFetch throw or
return a connection-refused error) so the code falls back to handleLocal, seed
two memories in two different projects, then call
handleToolCall("memory_smart_search", ...) and handleToolCall("memory_recall",
...) with project set to one project and assert the returned results include
only items from that project; locate references to handleToolCall, installFetch,
memory_smart_search, memory_recall and handleLocal to add the error simulation,
seeding, and project-scoped assertions.
🪄 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: 43c4f65c-6811-4896-ba0e-9a7cd104b907
📒 Files selected for processing (7)
src/functions/smart-search.tssrc/mcp/server.tssrc/mcp/standalone.tssrc/mcp/tools-registry.tstest/mcp-standalone-proxy.test.tstest/mcp-surface-default.test.tstest/smart-search.test.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/mcp-standalone-proxy.test.ts (1)
196-232: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for unscoped ("legacy") memories under project-scoped queries.
The local fallback filter (
src/mcp/standalone.ts,handleLocal) only excludes a memory when it has a non-emptyprojectthat mismatches the requested one — memories with noprojectare intentionally preserved. This test only exercises two project-tagged memories (alphavsbeta) and never asserts that an unscoped memory still surfaces under a project-scoped query, so a regression that started dropping unscoped memories wouldn't be caught.✅ Suggested additional coverage
await handleToolCall( "memory_save", { content: "shared-query beta memory", project: "beta" }, localKv, ); + await handleToolCall( + "memory_save", + { content: "shared-query legacy memory" }, + localKv, + ); const smartSearch = await handleToolCall( "memory_smart_search", { query: "shared-query", project: "alpha" }, localKv, ); const smartSearchBody = JSON.parse(smartSearch.content[0].text); - expect(smartSearchBody.results.map((m: { content: string }) => m.content)).toEqual([ - "shared-query alpha memory", - ]); + expect( + smartSearchBody.results.map((m: { content: string }) => m.content), + ).toEqual( + expect.arrayContaining([ + "shared-query alpha memory", + "shared-query legacy memory", + ]), + );🤖 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/mcp-standalone-proxy.test.ts` around lines 196 - 232, The local fallback coverage in handleToolCall does not verify that unscoped legacy memories remain visible when querying with a project. Extend the mcp-standalone-proxy test alongside the existing memory_save, memory_smart_search, and memory_recall assertions by adding an unscoped memory (no project field) and confirming it is still returned for a project-scoped query like alpha. Keep the current scoped alpha/beta checks, but add assertions that the legacy memory survives the handleLocal filtering behavior in src/mcp/standalone.ts.
🤖 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.
Nitpick comments:
In `@test/mcp-standalone-proxy.test.ts`:
- Around line 196-232: The local fallback coverage in handleToolCall does not
verify that unscoped legacy memories remain visible when querying with a
project. Extend the mcp-standalone-proxy test alongside the existing
memory_save, memory_smart_search, and memory_recall assertions by adding an
unscoped memory (no project field) and confirming it is still returned for a
project-scoped query like alpha. Keep the current scoped alpha/beta checks, but
add assertions that the legacy memory survives the handleLocal filtering
behavior in src/mcp/standalone.ts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b907d274-a57e-4f54-b49b-005a27225c03
📒 Files selected for processing (5)
src/functions/smart-search.tssrc/mcp/server.tssrc/mcp/standalone.tssrc/mcp/tools-registry.tstest/mcp-standalone-proxy.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/mcp/tools-registry.ts
- src/mcp/server.ts
- src/mcp/standalone.ts
- src/functions/smart-search.ts
Summary
Tests
Closes #787
Summary by CodeRabbit