Repository navigation
fix(api): cap memory message limit and top_n at REST_API_MAX_PAGE_SIZE - #15376
Conversation
Co-authored-by: Cursor <[email protected]>
📝 WalkthroughWalkthroughMemory API endpoints now enforce maximum bounds on ChangesParameter Bounds Validation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 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. 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: 0
🧹 Nitpick comments (1)
api/apps/restful_apis/memory_api.py (1)
264-267: ⚡ Quick winAdd error logging in the new
ValueErrorbranches.Line 266 and Line 298 return argument errors directly but skip logging, which makes these new rejection paths less observable in production.
Proposed patch
try: top_n = validate_rest_api_page_size(int(args.get("top_n", 5))) except ValueError as exc: + logging.warning("Invalid top_n in /messages/search: %s", exc) return get_error_argument_result(str(exc)) @@ try: limit = validate_rest_api_page_size(int(args.get("limit", 10))) except ValueError as exc: + logging.warning("Invalid limit in /messages: %s", exc) return get_error_argument_result(str(exc))As per coding guidelines, "**/*.py: Add logging for new flows".
Also applies to: 296-299
🤖 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 `@api/apps/restful_apis/memory_api.py` around lines 264 - 267, The ValueError branches that return get_error_argument_result(...) in the top_n parsing/validation (validate_rest_api_page_size called with int(args.get("top_n", 5))) and the similar branch at the later block must log the error before returning; update those catch blocks to call the module logger (e.g., logger.error or logger.exception) with a clear message including the exception details (or use exc_info=True) and context (argument name and value) and then return get_error_argument_result(str(exc)) so the rejection is observable in production.
🤖 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 `@api/apps/restful_apis/memory_api.py`:
- Around line 264-267: The ValueError branches that return
get_error_argument_result(...) in the top_n parsing/validation
(validate_rest_api_page_size called with int(args.get("top_n", 5))) and the
similar branch at the later block must log the error before returning; update
those catch blocks to call the module logger (e.g., logger.error or
logger.exception) with a clear message including the exception details (or use
exc_info=True) and context (argument name and value) and then return
get_error_argument_result(str(exc)) so the rejection is observable in
production.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 48c6c6f0-63ba-474e-bdda-438b5dd60c8a
📒 Files selected for processing (2)
api/apps/restful_apis/memory_api.pytest/testcases/test_web_api/test_message_app/test_message_routes_unit.py
|
@jony376 |
|
@JinHai-CN @yingfeng @yuzhichang Can any one of you help to trigger CI? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15376 +/- ##
==========================================
- Coverage 94.56% 93.16% -1.40%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 668 -10
- Misses 25 29 +4
- Partials 14 20 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Related issues
Closes #15375
What problem does this PR solve?
GET /api/v1/messagesandGET /api/v1/messages/searchaccepted unboundedlimit/top_nquery parameters while other REST list endpoints enforceREST_API_MAX_PAGE_SIZE(100) viavalidate_rest_api_page_size(). Oversized values can trigger expensive memory index queries and large result sets (DoS risk).Type of change
Changes
api/apps/restful_apis/memory_api.pylimitandtop_nwithvalidate_rest_api_page_size; return argument error when exceededtest/testcases/test_web_api/test_message_app/test_message_routes_unit.pylimit/top_nTest plan
pytest test/testcases/test_web_api/test_message_app/test_message_routes_unit.py