Skip to content

Avoid deep-clone response budgeting in batch_query #3792

@Widthdom

Description

@Widthdom

Found while dogfooding the locally built cdidx on branch codex/search-audit-issues-20260619.

Duplicate check: no open issue found for batch_query response byte estimate CloneJsonArray DeepClone O(n^2).

Evidence:

  • src/CodeIndex/Mcp/McpToolHandlers.cs:3841 clones the accumulated resultsArray for each candidate slot.
  • src/CodeIndex/Mcp/McpToolHandlers.cs:4508 deep-clones every existing item when estimating whether another result fits the response byte budget.

Problem:
Batch response budgeting can become O(n^2) in result count and JSON node size, even though the final payload is bounded.

Acceptance criteria:

  • Track incremental response byte estimates without cloning the full accumulated result array for each slot.
  • Preserve conservative truncation semantics and deterministic truncated_queries reporting.
  • Add tests with many near-limit batch slots to verify runtime and truncation behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions