Skip to content

DiscoveryEngineSearchTool auto-detect sends redundant CHUNKS searches under concurrent first use #6101

Closed

Description

@glaziermag

Summary

DiscoveryEngineSearchTool(search_result_mode=None) appears to use CHUNKS-first auto-detect and cache _search_result_mode only after the structured-datastore fallback. Under concurrent first use of a fresh shared tool instance, multiple callers can enter the auto-detect branch before the cache is set, emitting redundant failing CHUNKS SearchService.Search calls before the DOCUMENTS retries.

Environment

  • google-adk: 2.2.0
  • google-cloud-discoveryengine: 0.20.0
  • google-api-core: 2.31.0
  • google-auth: 2.53.0
  • grpcio: 1.81.1
  • Python: 3.14.4
  • OS: macOS arm64
  • Relevant source: src/google/adk/tools/discovery_engine_search_tool.py

Evidence

  • A fresh gh search of open and closed issues/PRs found no clear duplicate.
  • Current source still appears to try SearchResultMode.CHUNKS before SearchResultMode.DOCUMENTS when search_result_mode=None, then mutates self._search_result_mode to DOCUMENTS after the structured-datastore fallback. I did not find an obvious single-flight lock around that transition.
  • The evidence run used a tiny temporary structured JSON datastore. Project, account, datastore, and document identifiers are intentionally omitted here.
  • Total actual SearchService.Search calls in the evidence run: 4092 / cap 5000.
  • 429 count: 0.
  • Max rolling 60s Search starts: 120 / effective cap 120.
  • Direct explicit DOCUMENTS control passed.
  • Direct no-content-search-spec control passed.
  • ADK explicit DOCUMENTS control: 1000 wrapper calls, 1000 DOCUMENTS searches, 0 CHUNKS.
  • ADK auto concurrent cold start: 1000 wrapper calls, 2000 low-level searches.
  • ADK auto CHUNKS calls: 1000.
  • ADK auto DOCUMENTS calls: 1000.
  • Redundant CHUNKS total above a single-flight expectation: 950.
  • Auto calls per wrapper: 2.0x.
  • Explicit DOCUMENTS calls per wrapper: 1.0x.
  • Cleanup verified temporary datastore deletion by 404 NOT_FOUND.

User Impact

This can multiply SearchService.Search calls and therefore increase quota usage, latency, and potentially billable request volume.

Expected Behavior

For a structured datastore, concurrent first use of a fresh shared DiscoveryEngineSearchTool(search_result_mode=None) should single-flight auto-detection. At most one caller should need to probe CHUNKS and learn the DOCUMENTS fallback for that tool instance; concurrent callers should reuse the detected result mode.

Possible fixes:

  • Guard auto-detection with a per-instance single-flight lock.
  • Default to DOCUMENTS for structured datastores when that can be known without probing.
  • Document that structured datastore users should set search_result_mode=SearchResultMode.DOCUMENTS to avoid extra calls.

Minimal Repro Shape

This can be reproduced without live Discovery Engine calls:

  1. Instantiate one fresh shared DiscoveryEngineSearchTool(search_result_mode=None).

  2. Replace _discovery_engine_client with a fake client.

  3. Have the fake client sleep briefly on CHUNKS requests, then raise the same structured-datastore InvalidArgument message:

    content_search_spec.search_result_mode must be set to
    SearchRequest.ContentSearchSpec.SearchResultMode.DOCUMENTS
    when the engine contains structured data store.
    
  4. Have DOCUMENTS requests return one fake document result.

  5. Release N worker threads through a threading.Barrier.

Current behavior emits more than one CHUNKS probe for a single fresh shared tool instance. Fixed behavior should emit at most one.

Control: explicit SearchResultMode.DOCUMENTS emits exactly one DOCUMENTS call per wrapper call and zero CHUNKS calls.

Scope of Run

The evidence run used only discoveryengine.googleapis.com SearchService.Search against a tiny temporary structured JSON datastore. It did not use Gemini, an ADK agent loop, VertexAiSearchTool model calls, process_llm_request, AnswerQuery, SummarySpec, Search Summary, Grounded Generation, Ranking API, Cloud Storage, BigQuery, Document AI, Compute, Cloud Run, GKE, custom Vertex endpoints, OCR, or layout parsing.

No project IDs, billing IDs, local filesystem paths, datastore names, document names, or user-specific identifiers are included in this report.

Activity

  1. added
    tools[Component] This issue is related to tools
    on Jun 13, 2026
  2. added theissue type on Jun 13, 2026
  3. sanketpatil06 commented on Jun 17, 2026

    @sanketpatil06

    Hi @glaziermag, thanks for reporting this.
    As a quick workaround, you can bypass the auto-detect step entirely by manually setting search_result_mode to DOCUMENTS or CHUNKS, depending on your datastore type. Additionally, a PR has been opened to address this, could you please test the changes in PR #6106 and confirm if they resolve the issue on your end?

  4. added
    request clarification[Status] The maintainer need clarification or more information from the author
    on Jun 17, 2026
  5. glaziermag commented on Jun 17, 2026

    @glaziermag
    Author

    Thanks, I tested PR #6106 against a live temporary structured Discovery Engine datastore.

    Result: it resolves the concurrent cold-start issue on my side. With 16 concurrent first-use calls on the PR branch, I saw 1 CHUNKS probe total and 16 DOCUMENTS searches. On current main against the same datastore, I reproduced the issue with 16 CHUNKS probes and 16 DOCUMENTS retries. Explicit DOCUMENTS mode also worked with 0 CHUNKS calls. Temporary datastore was cleaned up and verified deleted.

  6. removed
    request clarification[Status] The maintainer need clarification or more information from the author
    on Jun 18, 2026
  7. added
    needs review[Status] The PR/issue is awaiting review from the maintainer
    on Jul 22, 2026
  8. added a commit that references this issue on Jul 28, 2026
    3a9a88c
  9. added a commit that references this issue on Aug 11, 2026
    7883d1b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

needs review[Status] The PR/issue is awaiting review from the maintainertools[Component] This issue is related to tools

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions