Repository navigation
fix(atlas-search): cap search neighbor expansion - #6328
Conversation
|
Caution Review failedThe pull request is closed.
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. |
Codex Review Summary: ✅ CompletedThis 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. |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
4 open issues
CastingMAX_EXPAND_NEIGHBORSfromusizetoi64withascan silently wrap if the constant… · New This test hard-codes100in both the success value and expected error string, which will drift if… · New The test asserts the error message contains the literal \"100\" even though the limit is defined as… · New Using!stderr.contains(\"missing.db\")as the signal that the backend was not reached is somewhat… · New
What changed in this PR
Caps Atlas search neighbor expansion to a shared 100-neighbor ceiling across CLI, service validation, and atlas-core, preventing oversized expansion requests from reaching backend work.
Changes:
- Added
MAX_EXPAND_NEIGHBORSconstant to atlas-core and enforced it in core search execution. - Updated CLI parsing to reject
--expandvalues above the shared limit (exit 2) and added parity tests. - Updated service request validation and added a regression test for the expand limit.
| File | Description |
|---|---|
| pkgs/atlas-search/crates/atlas-search/tests/cli_parity.rs | Adds a CLI regression test ensuring --expand > 100 fails before backend access. |
| pkgs/atlas-search/crates/atlas-search/src/server.rs | Enforces expand ceiling in service validator and adds a matching test. |
| pkgs/atlas-search/crates/atlas-search/src/main.rs | Applies shared expand max in CLI argument validation and extends unit tests. |
| pkgs/atlas-search/crates/atlas-core/src/search.rs | Adds core-side expand cap and makes neighbor count conversion to backend i64 fallible. |
| pkgs/atlas-search/crates/atlas-core/src/lib.rs | Introduces MAX_EXPAND_NEIGHBORS constant (set to 100). |
Review effort: Lite
| "--expand", | ||
| args.expand, | ||
| 0, | ||
| Some(atlas_core::MAX_EXPAND_NEIGHBORS as i64), |
There was a problem hiding this comment.
Fixed in ab0ac12 (rebase onto current main): the production cast in cmd_search is now i64::try_from(atlas_core::MAX_EXPAND_NEIGHBORS).expect("neighbor cap fits in i64"), so a future oversized constant panics loudly at startup-validation instead of wrapping. — repo-worker-code-r
| // --expand shares the service's 100-neighbor ceiling. | ||
| let max_expand = atlas_core::MAX_EXPAND_NEIGHBORS as i64; | ||
| assert_eq!(count("--expand", max_expand, 0, Some(max_expand)), Ok(100)); | ||
| assert_eq!( | ||
| count("--expand", max_expand + 1, 0, Some(max_expand)).unwrap_err(), | ||
| ( | ||
| 2, | ||
| "--expand must be between 0 and 100 (design section 2)".to_string() |
There was a problem hiding this comment.
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
| assert!( | ||
| err.body.error.message.contains("100"), |
There was a problem hiding this comment.
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
| assert!( | ||
| !stderr.contains("missing.db"), | ||
| "backend was reached: {stderr}" |
There was a problem hiding this comment.
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
52befc2 to
ab0ac12
Compare


Summary
Search expansion now validates the shared 100-neighbor ceiling before any backend work, in the CLI, service, and core API. The core also checks the conversion to the backend's signed neighbor count.
--kremains deliberately unbounded because core truncates it to the bounded candidate set.Fixes #5593.
Evidence
--expand 1000000was accepted; a single hit could return the full message's neighboring chunks.cargo test --manifest-path pkgs/atlas-search/Cargo.toml -p atlas-searchandcargo test --manifest-path pkgs/atlas-search/Cargo.toml -p atlas-corepassed;cargo fmt --manifest-path pkgs/atlas-search/Cargo.toml --all -- --checkpassed.Merge Danger
Door: Two-way.
Blast Radius: Low — only oversized expansion requests are rejected.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.