Skip to content

fix: scope GET /agentmemory/memories by the project query param (#918)#988

Open
ShubhamArora073 wants to merge 1 commit into
rohitg00:mainfrom
ShubhamArora073:fix/918-memories-project-filter
Open

fix: scope GET /agentmemory/memories by the project query param (#918)#988
ShubhamArora073 wants to merge 1 commit into
rohitg00:mainfrom
ShubhamArora073:fix/918-memories-project-filter

Conversation

@ShubhamArora073

@ShubhamArora073 ShubhamArora073 commented Jun 28, 2026

Copy link
Copy Markdown

Summary

Fixes #918. GET /agentmemory/memories advertised no project filter, so on multi-project installs it returned the entire corpus regardless of ?project= and clients had to over-fetch and filter client-side.

This honors project the same way the existing agentId filter works:

  • Reads + trims the project query param.
  • Filters the list payload by exact m.project === project.
  • Applies the same scope to the ?count=true totals (they reuse the same filtered array), so counts match the list scope — consistent with POST /agentmemory/search.
  • Blank/whitespace project is ignored (returns all), preserving back-compat with the no-param behavior.

Behavior

Request Before After
(no param) all memories all memories (unchanged)
?project=witto all memories only witto
?project=nonexistent-xyz all memories 0
?count=true&project=foo unscoped totals totals scoped to foo

Test plan

  • New behavioral test test/memories-project-filter.test.ts drives the real api::memories handler with the issue's fixture (9 memories across witto/_shared), covering project match, nonexistent project, ?count=true scoping, and blank-param back-compat. Mirrors the existing cross-project-isolation.test.ts / remember-project-scope.test.ts pattern.
  • Confirmed the new test fails on the unpatched handler (returns all 9) and passes with the fix.
  • Full suite green: npm test → 1420 passing.

Made with Cursor

Summary by CodeRabbit

  • New Features
    • Added support for filtering memories by project in the memories API.
    • Results, totals, and paginated counts now reflect the selected project.
  • Bug Fixes
    • Blank or whitespace-only project filters are ignored, preserving the full result set.
    • Requests for non-matching projects now correctly return no memories and a total of zero.
  • Tests
    • Added coverage for project-scoped memory queries, including count handling and empty-result cases.

…tg00#918)

The memories list endpoint advertised no project filter, so multi-project
installs got the entire corpus back regardless of `?project=` and had to
filter client-side. Honor `project` the same way `agentId` is honored,
applying it to both the list payload and the `?count=true` totals so the
counts match the list scope, consistent with POST /agentmemory/search.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown

@shubhamarora0 is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The api::memories handler in src/triggers/api.ts now reads and applies a project query parameter, filtering the memories list (and count totals) to entries matching that project. A new Vitest test file seeds 9 memories across two projects and verifies five filtering scenarios.

Project filter for memories list endpoint

Layer / File(s) Summary
Project filter implementation
src/triggers/api.ts
Derives projectFilter from the trimmed project query param and applies it to the filtered list before count, limit, offset, and response construction.
Project filter tests
test/memories-project-filter.test.ts
Registers API triggers, seeds mock data for witto and _shared projects, and asserts correct scoping for no param (all 9), named project (5), nonexistent project (0), count=true totals, and blank/whitespace input.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A query once lost in the field,
?project=witto — no result revealed.
Now the filter is found, the list is trimmed neat,
Nine memories sorted, no over-fetch feat.
The rabbit hops on, all projects in seat!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: scoping GET /agentmemory/memories by the project query parameter.
Linked Issues check ✅ Passed The PR matches #918 by filtering memories by project, preserving no-param behavior, scoping count=true, and handling blank values.
Out of Scope Changes check ✅ Passed The changes stay within the issue scope: one API handler update plus tests validating the new project filter behavior.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/triggers/api.ts (1)

1851-1853: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Drop the WHAT-comment here.

projectFilter plus the predicate already make this self-explanatory, so the new comment just restates the code and conflicts with the TS comment guideline. As per coding guidelines, "In TypeScript source code, avoid code comments explaining WHAT — use clear naming instead".

🤖 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 `@src/triggers/api.ts` around lines 1851 - 1853, Remove the WHAT-style comment
in the project filtering logic and rely on the existing naming and predicate
structure to make it clear; update the relevant section in api.ts around
projectFilter so the code remains self-explanatory without a redundant
explanatory comment.

Source: Coding guidelines

🤖 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 `@src/triggers/api.ts`:
- Around line 1851-1853: Remove the WHAT-style comment in the project filtering
logic and rely on the existing naming and predicate structure to make it clear;
update the relevant section in api.ts around projectFilter so the code remains
self-explanatory without a redundant explanatory comment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 993af871-481b-4577-b752-cd4da659aa21

📥 Commits

Reviewing files that changed from the base of the PR and between f6f9e3c and cbac810.

📒 Files selected for processing (2)
  • src/triggers/api.ts
  • test/memories-project-filter.test.ts

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET /agentmemory/memories ignores the project query param — returns all projects

2 participants