Skip to content

[Bug] Anthropic search sidecar can return partial text as success after an error or truncated stream #8158

Closed

Description

@tackle-me

Client or integration

Routed hosted search using the Anthropic sidecar; credential-free parser reproduction.

Area

Tools / MCP / web search / Streaming

Summary

parseAnthropicSidecarSSE() keeps collected text after a read failure or the wire-byte cap, and returns that text without an error when it is non-empty. It also does not recognize a streamed error event as a failed search. A web_search_tool_result_error followed by explanatory text can likewise be returned without a structured failure indicator. Even if the text explains the failed search, the caller cannot programmatically distinguish that result from a successful search.

The comments make partial-text retention intentional. I am proposing a completion/error contract consistent with the later native Messages and vision handling in #7928 and #4752: retain partial text if useful, but identify that the search failed or was incomplete.

Reproduction

Save as repro-anthropic-search.ts at the repository root and run bun repro-anthropic-search.ts. This parses in-memory frames only.

import { parseAnthropicSidecarSSE } from './src/web-search/anthropic-executor.ts';
const frame = (x: unknown) => 'data: ' + JSON.stringify(x) + '\n\n';
const text = { type: 'content_block_delta', delta: { type: 'text_delta', text: 'partial' } };
const stop = { type: 'message_stop' };
const cases: Record<string, unknown[]> = {
  errorAfterText: [text, { type: 'error', error: { type: 'overloaded_error' } }],
  eofBeforeCompletion: [text],
  toolErrorWithExplanation: [{ type: 'content_block_start', content_block: {
    type: 'web_search_tool_result', content: {
      type: 'web_search_tool_result_error', error_code: 'max_uses_exceeded',
    },
  } }, text, stop],
  wireCapAfterText: [text, { type: 'content_block_start', content_block: {
    type: 'web_search_tool_result', content: [{ type: 'web_search_result',
      url: 'https://example.com/', title: 'Synthetic', encrypted_content: 'x'.repeat(80000) }],
  } }, stop],
};
for (const [name, events] of Object.entries(cases)) {
  const result = await parseAnthropicSidecarSSE(new Response(events.map(frame).join('')));
  console.log({ name, text: result.text, error: result.error ?? null });
}

Actual on unmodified 2.97.0: partial text is retained with error: null in these unsuccessful cases. The wire-cap case exceeds the existing 64 KiB raw-SSE bound; the issue is silent success after truncation, not that bounded parsing is wrong.

Completion compatibility and proposed scope

Please keep the compatible clean-EOF rule already accepted in #7928: a final complete message_delta with a non-error stop_reason, followed only by pings/comments/whitespace, can establish transport completion even without message_stop.

A strict check that accepts only message_stop would reject the clean-EOF shape accepted by #7928. Separately, max_tokens + message_stop completes the transport but can contain a truncated answer. The completion rule should preserve #7928 compatibility and define a caller-visible partial-result policy, rather than treating every stop notification as proof of a complete answer.

The current shared 64 KiB wire cap can also be consumed by search-result metadata before the answer. Responses-side parsing already separates wire and decoded-text limits. A bounded, separate wire/answer budget would help, but no particular new numeric limit is required by this report.

This issue is limited to the Anthropic search parser. The OpenAI parser's legacy terminal behavior is a separate compatibility question.

Version

OpenCodex 2.97.0; Bun 1.4.4.

src/web-search/anthropic-executor.ts matches inspected dev commit ad6a80e5cd5cf347097dbd0572e2410f92e7604b.

Operating system

Windows 10 Pro, x64, build 19045.

Related work and checks

#3839 introduced bounded Anthropic search reads; #4752 addressed incomplete vision captions; #7928 documents native Messages completion compatibility.

  • I searched existing issues and related fixes.
  • The frames are synthetic. No private stream, account, credentials or conversation content is attached.

Activity

  1. github-actions commented on Nov 4, 2026

    @github-actions
    Contributor

    Automated translation bookkeeping — detected language: English.

  2. added
    bug
    streaming
    tools
    on Nov 4, 2026
  3. github-actions commented on Nov 4, 2026

    @github-actions
    Contributor

    Issue reopened

    The report now contains the information required by the automated check. Thanks for updating it.

  4. lidge-jun commented on Nov 6, 2026

    @lidge-jun
    Owner

    Fixed on dev by #8210 (708cd06): the Anthropic search sidecar no longer reports partial text as success after a tool error or a truncated stream. It ships in the next release from dev.

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

    bugstreamingtools

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions