Skip to content

atlas-search: expand has no upper bound — one hit returns its whole message, bypassing the 100-neighbor cap get-chunk enforces #5593

Closed

Description

@dezren39

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 neighbors at 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 rejects k == 0 and page_limit == 0, but places no bound on expand: 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 --expand only as non-negative, no maximum (main.rs:606).
  • expand feeds the same neighbor machinery as get-chunk's neighbors: atlas-core search.rs:391-392 calls neighbor_map(backend, d, opts.expand) for every kept hit, and neighbor_map (search.rs:401-402) issues backend.neighbors(message_id, chunk_idx, n) — a chunk_idx ± n range 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 to k × 2 × expand chunk texts, and k itself has no upper bound in validate_request either (only k >= 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

Acceptance criteria

  • validate_request (server.rs) rejects a search request whose expand exceeds a stated maximum, with a bad_request message 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 --expand enforces 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: expand at the bound accepted, above it rejected (service validation test and/or CLI parity test).
  • Consider the same treatment for k's missing upper bound in validate_request; if left unbounded, the code comment says why (e.g. bounded by corpus/ranking size) — not silent.
  • The usize as i64 wrap in neighbor_map can no longer be reached with an out-of-range value (validation makes it moot, or the cast becomes a checked conversion).

Evidence

Activity

  1. developing-today commented on Nov 4, 2026

    @developing-today
    Contributor
  2. added
    source/creatorFiled by the new-issue-creator job
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    priority/normalOrdinary priority (the default)
    app/atlas-searchpkgs/atlas-search (Atlas search service + atlas-embed)
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    on Nov 4, 2026
  3. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator-code-b (new-issue-creator job, Lane B)
    • Session / ID: cron job new-issue-creator-code-b, run 2026-11-04 ~17:10 UTC
    • Found via: filed this run
    • Task: Filed this issue — atlas-search expand is 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).
    • Expectation: effort s — validation bound in validate_request + CLI count() 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.
    • Links: probe ~/git/fleet/probe-atlas-expand/ (laptop); body evidence in the issue.
  4. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    Sibling filed: issue #5600 covers the CLI get-chunk --neighbors path (standalone count() has no maximum, main.rs:664), which this issue's --expand scope 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.

  5. added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed on Nov 4, 2026
  6. 36 remaining items

  7. added
    queue/claimedQueue worker lifecycle state
    and removed
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 5, 2026
  8. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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 while repo-worker-code-r posts progress markers; after 30 minutes of silence any other worker may pick this up.)

  9. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Progress from repo-worker-code-r: claimed: reviewing existing PR 6328 against issue 5593 acceptance; next verify diff, CI, Codex

  10. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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 merge

  11. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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 6328

  12. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Progress from repo-worker-code-r: merge_ready: PR 6328 rebased ab0ac12 MERGEABLE, tests green, Codex clean on prior head + Copilot threads dispositioned; merging now

  13. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/atlas-searchpkgs/atlas-search (Atlas search service + atlas-embed)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions