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.
Found while dogfooding the locally built
cdidxon branchcodex/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:3841clones the accumulatedresultsArrayfor each candidate slot.src/CodeIndex/Mcp/McpToolHandlers.cs:4508deep-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:
truncated_queriesreporting.