Repository navigation
fix(api): bound context traversal depth and recent page size - #1804
Merged
Merged
Conversation
The memory context endpoints accepted any depth, and the relation CTE walks every simple path up to twice that many steps. On a densely linked project a single build_context or recent_activity call with depth=40 could run until the client timed out, and any authenticated caller, including a read-only key, could repeat it (basicmachines-co/basic-memory-cloud#2640). - Add MAX_CONTEXT_DEPTH (5, matching the prompt API) and MAX_RECENT_ACTIVITY_PAGE_SIZE (100, the recent_activity tool's existing cap). - /memory/{uri} and /memory/recent reject depth outside 1..5 with 422. - /memory/recent also bounds page, page_size, and max_related, like /memory/{uri} already did. - build_context and recent_activity raise the same bound before calling the API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Signed-off-by: phernandez <paul@basicmachines.co>
Member
Author
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
phernandez
added a commit
that referenced
this pull request
Oct 23, 2026
Date the v0.24.0 entry 2026-10-22, add a Security section for GHSA-4gfv-c2mm-mvj2 (DNS rebinding, #1697) and GHSA-pqm2-2wxw-p5hx (host symlink probing, #1807), plus #1804 and #1805, and cover the changes merged since the entry was last edited (#1761 through #1807). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018CoZ3jWnMJsyQsik4tPySk Signed-off-by: phernandez <paul@basicmachines.co>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The memory context endpoints accepted any
depth.ContextServicedoubles it, and the relation CTE blocks cycles only per path, so on a densely linked project a deep traversal walks every simple path. Onebuild_context(depth=40)orrecent_activity(depth=40)call could run until the cloud client timed out, and any authenticated caller, including a read-only API key, could repeat it./memory/recentalso had no bound onpage_size,page, ormax_related. Reported in basicmachines-co/basic-memory-cloud#2640.What
schemas/memory.py: newMAX_CONTEXT_DEPTH = 5andMAX_RECENT_ACTIVITY_PAGE_SIZE = 100.depthcap (schemas/prompt.py) and keeps the documented "1-3 recommended" range well inside it.recent_activitytool's existingpage_sizecap.GET /v2/{project}/memory/{uri}:depthisQuery(1, ge=1, le=5).GET /v2/{project}/memory/recent:depthbounded the same way;page >= 1,1 <= page_size <= 100,0 <= max_related <= 100(the same bounds/memory/{uri}already used forpageandmax_related).build_contextandrecent_activityMCP tools raise a clearValueErrorfor out-of-range depth before calling the API, the same way they already guardpage_size.depth=0keeps meaning "default" in both tools, as before. Docstrings name the maximums.Defaults are unchanged. CLI
bm tool build-context --depthand web/hosted callers all use depth 1-2.How tested
tests/api/v2/test_memory_router.py: over-limitdepth,depth=0, and the new/memory/recentbounds return 422; the inclusive maximums (depth=5,page_size=100/50) return 200.tests/mcp/test_tool_build_context.py,tests/mcp/test_tool_recent_activity.py: depth 6,"6", and -1 raise;depth=5round-trips.Querybounds and the tool guards reverted, all 11 new rejection cases fail; restored, they pass.just lintclean.just typecheckreports only the pre-existingpymilvusunresolved imports (optional extra not installed locally).Follow-up
The cloud side (server-side
statement_timeouton tenant connections) is basicmachines-co/basic-memory-cloud PR for #2640. The cloud core pin bump follows this merge.🤖 Generated with Claude Code