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)
📝 WalkthroughWalkthroughAdds an optional ChangesProject-based scoping for MCP search tools
Sequence DiagramsequenceDiagram
participant MCP as MCP Client
participant Server as MCP Server
participant SmartSearch as smart-search fn
participant MemoryKV as MemoryKV
participant SessionKV as SessionKV
MCP->>Server: memory_smart_search(query, project)
Server->>SmartSearch: call with project in payload
SmartSearch->>SmartSearch: extract & trim project
alt Hybrid search branch
SmartSearch->>MemoryKV: fetch overFetch results
SmartSearch->>SmartSearch: apply agent-scope filtering
SmartSearch->>MemoryKV: read Memory/Session for project matching (async)
SmartSearch->>SmartSearch: filter by project and truncate to limit
else expandIds branch
SmartSearch->>MemoryKV: fetch expanded observation ids
SmartSearch->>SessionKV: read Session/Memory for project matching (async)
SmartSearch->>SmartSearch: filter expanded results by project
end
SmartSearch->>Server: filtered observations
Server->>MCP: scoped results
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
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 Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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
Summary
Tests
Closes #787
Summary by CodeRabbit
New Features
Tests