fix: preserve exact namespace filter in semantic search fallback#334
fix: preserve exact namespace filter in semantic search fallback#334ns-jlizarraga wants to merge 2 commits into
Conversation
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
There was a problem hiding this comment.
Pull request overview
This PR adjusts long-term semantic search fallback behavior to respect exact namespace scoping and updates the Docker image to avoid embedding a single healthcheck in a multi-purpose runtime image.
Changes:
- Preserve
namespacewhen it is an exacteqfilter during semantic-search soft-filter fallback, while still relaxing other strict filters. - Remove the baked-in Docker
HEALTHCHECKfrom shared runtime stages, relying on per-service healthchecks (e.g., indocker-compose.yml).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Dockerfile | Removes image-level HEALTHCHECK because the image is used for multiple process types with different health semantics. |
| agent_memory_server/api.py | Changes soft-filter fallback to keep exact namespace.eq scoping instead of always dropping namespace. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ns_filter = filters.get("namespace") if filters else None | ||
| if ns_filter is None or getattr(ns_filter, "eq", None) is None: | ||
| fallback_kwargs.pop("namespace", None) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Problem
When a semantic search returns zero results and the server falls back to a broader query, the existing code unconditionally strips the
namespacefilter along withtopics,entities,memory_type, andextraction_strategy.This is correct for broad filters (
any/all), but wrong for exact filters (eq). If the caller passednamespace: {eq: "troubleshooting:service-a"}, they are asking a precise, scoped question. Returning a memory from a completely different namespace in the fallback is more harmful than returning zero results — it silently crosses a trust boundary the caller explicitly set.Change
Instead of always dropping the namespace filter in the fallback, we now check its type:
any/all) → drop it in the fallback (existing behavior, correct)eq) → preserve it in the fallback so results stay scoped to the namespace the caller asked forWhy not just always preserve namespace?
Because the fallback exists precisely to widen the search when strict filters yield nothing. A broad namespace filter like
any: ["troubleshooting:service-a", "troubleshooting:service-b"]is still a reasonable thing to relax. Only an exacteqmatch represents a hard scope boundary that should survive the fallback.Note
Medium Risk
Search fallback behavior changes what clients see when strict filters return no hits (scope vs empty results). Dockerfile healthcheck removal shifts responsibility to compose/orchestration.
Overview
Semantic search fallback no longer always strips
namespace. When the zero-hit fallback widens other strict filters, an exactnamespaceeqis kept so results stay in the caller’s scope; broad or missing namespace filters are still dropped as before.Docker images (
standardandaws) no longer define aHEALTHCHECKagainst/v1/health, since the same image runs API, MCP, and task-worker with different needs. Health checks are expected per service indocker-compose.yml.Reviewed by Cursor Bugbot for commit a3ae51e. Bugbot is set up for automated code reviews on this repo. Configure here.