Skip to content

Batched web-search truncation silently drops later queries and sources #6621

Closed

Description

@jlave-dev

Client or integration

Codex App

Area

Tools / MCP / web search

Summary

Batched web-search results are concatenated and then truncated at 8,000 characters. With sufficiently long results, this removes entire later query blocks and their sources. The answering model cannot distinguish omitted results from absent results.

I reproduced this live using the Exa sidecar and independently with synthetic inputs to the shared formatter. In the live three-query turn, the result ended partway through the second query, and the model subsequently claimed the third query had returned no usable results.

Expected: preserve a representation of every query, including its status, bounded excerpt, and source information, while retaining a bounded total prompt size. Explicitly indicate content omitted by formatting.

Reproduction

Deterministic reproduction without credentials or network calls:

  1. In an OpenCodex source checkout corresponding to v2.77.0, save the following as repro-search-truncation.ts at the repository root.
  2. Run bun repro-search-truncation.ts.
  3. Observe that the third query and its source are absent, even though all three outcomes were supplied to the formatter.
import { formatWebSearchResults } from './src/web-search/format-result';

const results = [1, 2, 3].map(n => ({
  query: `query-${n}`,
  outcome: {
    text: 'x'.repeat(4000),
    sources: [{ title: `Source ${n}`, url: `https://example.com/${n}` }],
  },
}));

const output = formatWebSearchResults(results);
console.log(JSON.stringify({
  length: output.length,
  firstQueryPresent: output.includes('query-1'),
  secondQueryPresent: output.includes('query-2'),
  thirdQueryPresent: output.includes('query-3'),
  thirdSourcePresent: output.includes('https://example.com/3'),
  endsWithTruncationMarker: output.endsWith('…[truncated]'),
}, null, 2));

The synthetic reproduction was run against the installed 2.77.0 formatter using the package's bundled Bun runtime, with the import pointed at that installed file. The relative import above is for a source checkout.

Live confirmation: a routed model invoked web_search with three previously unused queries. The captured tool result had 8,013 characters including the truncation marker, ended within the second result block, and contained no third-query block. The answering model said: "The third query returned no usable results in this search." This does not establish that the third search returned no results; the formatter had removed its representation.

Version

2.77.0 (@bitkyc08/opencodex)

Operating system

macOS 26.5.1

Provider and model

Live reproduction: Exa web-search sidecar; GLM-5.3-Flash through an OpenAI-compatible chat endpoint. The deterministic reproduction is provider-independent. Other sidecar backends use the same formatter, but were not live-tested for this failure.

Logs or error output

{
  "length": 8013,
  "firstQueryPresent": true,
  "secondQueryPresent": true,
  "thirdQueryPresent": false,
  "thirdSourcePresent": false,
  "endsWithTruncationMarker": true
}

Relevant code in src/web-search/format-result.ts:

const MAX_TOTAL_CHARS = 8000;
// ...
return clamp(blocks.join("\n\n"), MAX_TOTAL_CHARS);

Screenshots and supporting files

The credential-free synthetic reproduction and observed output above provide the supporting evidence. No raw chat captures, credentials, or configuration files are attached.

Redacted configuration

{
  "webSearchSidecar": {
    "backend": "exa",
    "exaApiKey": "<redacted>"
  }
}

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Suggested approach

Allocate the existing total budget across queries before formatting, preserving each query's heading/status, a bounded excerpt, source information, and an explicit truncation notice. A focused regression with three oversized outcomes should confirm that later queries remain represented. Increasing the cap alone would postpone the failure and increase prompt-processing cost.

Activity

  1. added
    bug
    tools
    on Oct 5, 2026
  2. added a commit that references this issue on Oct 5, 2026
    7e7468a
  3. lidge-jun commented on Oct 5, 2026

    @lidge-jun
    Owner

    Fixed on dev by #6638 (7e7468a): batched web-search results now split the output budget across queries before truncating, so every query keeps its status and source count, truncated content is marked explicitly, and structured output stays valid JSON. Closing manually because PRs target dev; it ships in the next release. Thanks for the report.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtools

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions