Repository navigation
fix(atlas-search): cap search neighbor expansion #6328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -523,6 +523,15 @@ fn validate_request(req: &SearchRequest) -> Result<(), ServerError> { | |
| "pool must be between 1 and 400 (design section 2)", | ||
| )); | ||
| } | ||
| if req.expand > atlas_core::MAX_EXPAND_NEIGHBORS { | ||
| return Err(ServerError::bad_request(format!( | ||
| "expand must be at most {}", | ||
| atlas_core::MAX_EXPAND_NEIGHBORS | ||
| ))); | ||
| } | ||
| // Deliberately leave k unbounded: it truncates the candidates produced by | ||
| // the bounded pool, and grouped search caps its consideration window to | ||
| // the available candidates in atlas-core. | ||
| if req.k == 0 { | ||
| return Err(ServerError::bad_request("k must be at least 1")); | ||
| } | ||
|
|
@@ -2478,6 +2487,24 @@ mod tests { | |
|
|
||
| // ----- tests -------------------------------------------------------- | ||
|
|
||
| #[test] | ||
| fn expand_validation_matches_the_core_neighbor_limit() { | ||
| let mut req = SearchRequest { | ||
| expand: atlas_core::MAX_EXPAND_NEIGHBORS, | ||
| ..SearchRequest::default() | ||
| }; | ||
| assert!(validate_request(&req).is_ok()); | ||
|
|
||
| req.expand = atlas_core::MAX_EXPAND_NEIGHBORS + 1; | ||
| let err = validate_request(&req).unwrap_err(); | ||
| assert_eq!(err.status, 400); | ||
| assert!( | ||
| err.body.error.message.contains("100"), | ||
|
Comment on lines
+2501
to
+2502
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept deliberately, same rationale as the CLI test: asserting the literal 100 pins the bound value itself (the #5593 acceptance ties it to the get-chunk cap), so a silent constant change fails here instead of drifting. — repo-worker-code-r |
||
| "got: {:?}", | ||
| err.body | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn paging_reuses_stored_ranking_and_matches_one_shot() { | ||
| let (handle, calls) = start(RuntimeLimits::default(), None); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,6 +142,27 @@ fn cli_search_envelopes_match_python() { | |
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn cli_rejects_expand_above_limit_before_backend_work() { | ||
| let db = std::env::temp_dir() | ||
| .join(format!("atlas-cli-parity-{}-missing", std::process::id())) | ||
| .join("missing.db"); | ||
| let out = run_bin( | ||
| &db, | ||
| &["search", "query", "--backend", "local", "--expand", "101"], | ||
| ); | ||
| assert_eq!(out.status.code(), Some(2)); | ||
| let stderr = String::from_utf8_lossy(&out.stderr); | ||
| assert!( | ||
| stderr.contains("--expand must be between 0 and 100"), | ||
| "{stderr}" | ||
| ); | ||
| assert!( | ||
| !stderr.contains("missing.db"), | ||
| "backend was reached: {stderr}" | ||
|
Comment on lines
+160
to
+162
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept: the missing.db check is a secondary negative assert only — the primary pins are exit code 2 and the exact --expand message, which cannot be produced by any backend path. The backend-open error including the db path is established behavior relied on by the other parity tests in this file. — repo-worker-code-r |
||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn cli_get_chunk_matches_python() { | ||
| let db = build_fixture_db("getchunk"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept deliberately: Ok(100) and the literal error string pin the bounds ACTUAL value, not just its consistency with the constant. The acceptance criteria for #5593 require the bound justified against the get-chunk 100 cap; if MAX_EXPAND_NEIGHBORS ever changes, this test failing is the intended tripwire that forces re-justification. — repo-worker-code-r