Repository navigation
Description
atlas-search: expand has no upper bound anywhere — one search hit can return its whole message, bypassing the 100-neighbor cap the service enforces on get-chunk
Summary
Atlas search's neighbor expansion is bounded on exactly one surface and unbounded on the search surfaces that use the same backend call:
- The service's get-chunk endpoint caps
neighborsat 100:pkgs/atlas-search/crates/atlas-search/src/server.rs:2078-2079—if neighbors > 100 { return Err(bad_request("neighbors must be at most 100")) }. - The service's search validation caps
pool(1..=400) and rejectsk == 0andpage_limit == 0, but places no bound onexpand:validate_request,pkgs/atlas-search/crates/atlas-search/src/server.rs:509-525. - The CLI, whose
count()is documented as validating "against the service's request contract" (pkgs/atlas-search/crates/atlas-search/src/main.rs:578-591), likewise validates--expandonly as non-negative, no maximum (main.rs:606). expandfeeds the same neighbor machinery as get-chunk'sneighbors:atlas-coresearch.rs:391-392callsneighbor_map(backend, d, opts.expand)for every kept hit, andneighbor_map(search.rs:401-402) issuesbackend.neighbors(message_id, chunk_idx, n)— achunk_idx ± nrange query in both backends (atlas-core/src/local.rs:631-639,atlas-core/src/turso.rs:624-631). So one request's response can carry up tok × 2 × expandchunk texts, andkitself has no upper bound invalidate_requesteither (onlyk >= 1).
Verified this run (2026-11-04, laptop probe)
Probe DB ~/git/fleet/probe-atlas-expand/probe.db (fixture schema; one message with 300 chunks, chunk 150 carrying the unique term zebraquux), run with the installed atlas-search binary, local backend, FTS mode, --k 1:
--expand 2→ context: 2 before + 2 after (control, as expected).--expand 250→ context: 150 before + 149 after = 299 neighbor chunks for a single hit — nearly 3× the per-request neighbor total the get-chunk endpoint allows, from one hit alone.--expand 1000000→ accepted identically (whole message returned).
The code at HEAD (aa06c420d) has the same unbounded paths cited above; the probe corroborates them at the CLI surface, and validate_request is the service-side gate a wire request passes through (server.rs:1299).
Secondary: expand is a usize on the wire (atlas-proto/src/lib.rs:181); neighbor_map casts it n as i64, so a JSON expand above i64::MAX wraps negative and silently yields an empty/inverted neighbor range instead of a validation error.
Why it matters
- The 100-neighbor cap exists because neighbor context is the response-size multiplier; the search path defeats it — one job with a large
kandexpandcan force the service to materialize and return effectively whole messages per hit, with no validation error. - This is the same CLI↔service contract family as atlas-search(CLI): --k/--pool 0 and negative (=form) counts silently clamp to 0 — standalone returns empty success where the service rejects the same request #5407 (closed): counts the service rejects must not silently pass on other surfaces, and vice versa. atlas-search(CLI): --k/--pool 0 and negative (=form) counts silently clamp to 0 — standalone returns empty success where the service rejects the same request #5407 fixed the 0/negative clamps for
--k/--pool; the missing upper bound forexpandwas left behind on both sides.
Acceptance criteria
-
validate_request(server.rs) rejects a search request whoseexpandexceeds a stated maximum, with abad_requestmessage naming the bound — the bound should be justified against the get-chunk neighbors cap (100) or a documented reason for a different value recorded in the code. - The CLI's
count()validation for--expandenforces the same maximum (exit 2, same message shape as--pool), keeping the CLI↔service contract in lockstep per atlas-search(CLI): --k/--pool 0 and negative (=form) counts silently clamp to 0 — standalone returns empty success where the service rejects the same request #5407. - A test pins both surfaces:
expandat the bound accepted, above it rejected (service validation test and/or CLI parity test). - Consider the same treatment for
k's missing upper bound invalidate_request; if left unbounded, the code comment says why (e.g. bounded by corpus/ranking size) — not silent. - The
usize as i64wrap inneighbor_mapcan no longer be reached with an out-of-range value (validation makes it moot, or the cast becomes a checked conversion).
Evidence
pkgs/atlas-search/crates/atlas-search/src/server.rs:509-525(validate_request: pool/k/page_limit only),:1299(submit gate),:2073-2081(get-chunk neighbors cap 100),:1410(page limit clamped ≤ the results length)pkgs/atlas-search/crates/atlas-search/src/main.rs:578-607(count() contract comment;--expandmin 0, no max;--poolmax 400 by contrast)pkgs/atlas-search/crates/atlas-core/src/search.rs:391-392, 401-402(per-hit neighbor_map,n as i64)pkgs/atlas-search/crates/atlas-core/src/local.rs:631-639andturso.rs:624-631(chunk_idx ± nrange, no LIMIT)- Probe:
~/git/fleet/probe-atlas-expand/(make_probe_db.py, probe.db, out-e2.json / out-e250.json / out-e1000000.json) on the laptop, 2026-11-04 - Related: atlas-search(CLI): --k/--pool 0 and negative (=form) counts silently clamp to 0 — standalone returns empty success where the service rejects the same request #5407 (CLI count clamps, closed), atlas-core: topics/projects filters are unescaped SQL LIKE patterns — % and _ act as wildcards, a quote crosses JSON element boundaries #5375 (atlas LIKE filters — different mechanism)
Activity
developing-today commentedon Nov 4, 2026
CODE-1383
dezren39 commentedon Nov 4, 2026
🤖 Agent note · filed
expandis unbounded on the search surfaces while get-chunk caps the same neighbor expansion at 100; verified with a laptop probe (one hit,--expand 250→ 299 neighbor chunks returned).validate_request+ CLIcount()parity, with pinning tests; done when the acceptance criteria on issue atlas-search: expand has no upper bound — one hit returns its whole message, bypassing the 100-neighbor cap get-chunk enforces #5593 hold.~/git/fleet/probe-atlas-expand/(laptop); body evidence in the issue.dezren39 commentedon Nov 4, 2026
Sibling filed: issue #5600 covers the CLI
get-chunk --neighborspath (standalonecount()has no maximum, main.rs:664), which this issue's--expandscope does not include. The service cap at server.rs:2078-2079 is the shared oracle for both; if this fix introduces a shared neighbor-bound constant, issue #5600's acceptance asks that the CLI get-chunk cap use it too.36 remaining items
dezren39 commentedon Nov 7, 2026
Picked up by
repo-worker-code-r— working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live whilerepo-worker-code-rposts progress markers; after 30 minutes of silence any other worker may pick this up.)dezren39 commentedon Nov 7, 2026
Progress from
repo-worker-code-r: claimed: reviewing existing PR 6328 against issue 5593 acceptance; next verify diff, CI, Codexdezren39 commentedon Nov 7, 2026
Progress from
repo-worker-code-r: verified: PR 6328 diff meets acceptance, Codex clean; PR is CONFLICTING with main - rebasing branch queue/9679-5593-expand-cap in a fleet worktree, resolving, targeted tests, then mergedezren39 commentedon Nov 7, 2026
Progress from
repo-worker-code-r: targeted_tests_passed: cargo test -p atlas-core -p atlas-search all green incl cli_parity 8/8 after rebase ab0ac12; next push + merge PR 6328dezren39 commentedon Nov 7, 2026
Progress from
repo-worker-code-r: merge_ready: PR 6328 rebased ab0ac12 MERGEABLE, tests green, Codex clean on prior head + Copilot threads dispositioned; merging nowdezren39 commentedon Nov 7, 2026
Released by
repo-worker-code-r(outcome: done). fixed_merged: PR #6328 merged ac40b67 after rebase ab0ac12 onto main (conflict in main.rs vs #5600 neighbors cap resolved: uncapped loop now --trunc only); expand capped at shared MAX_EXPAND_NEIGHBORS=100 in validate_request + CLI count() + core run_search, checked i64 cast; Copilot threads dispositioned (1 fixed, 3 pinned-value replies); cargo test -p atlas-core -p atlas-search green (cli_parity 8/8 x3; one transient cli_text_goldens flake under full parallel load, passes isolated/repeated); issue auto-closed by merge. Remote branch delete failed on app rate limit - branch queue/9679-5593-expand-cap may remain.