Skip to content

Harness: treat a direct Anthropic stream that ends without stop_reason as incomplete #269

Open

Description

@GoDiao

Part of #261. Follow-up to #263 (fixed in #268).

Problem

#268 made the proxy report a stream that closes before its end marker as an error, so the CLI retracts the partial reply and starts the stream again. Providers in Anthropic format are called by the CLI directly, without the proxy, and that path still treats such a stream as a normal end.

After the stream ends, the CLI raises an error only when it saw no message_start, or saw no completed content block and no stop_reason (src/services/api/claude.ts:2413). A stream that completed one or more content blocks and then closed without a message_delta carrying stop_reason passes this check.

Scenario: a relay with a read timeout closes the connection halfway through a long answer, after a text block has finished. The user sees half an answer with no notice, the turn ends as if the model had finished, and nothing is retried.

Details, with how Codex CLI and ZCode handle a stream that ends early: P-RES-04.

What to do

  • When the stream ends without a stop_reason, treat it as an incomplete stream: throw a retryable error, so the stream restart added in fix(harness): recover from provider errors, broken streams and context overflow #268 retracts the partial reply and tries again.
  • Keep the existing case where stop_reason is present and there are no content blocks (a legitimate empty reply, see the comment above the check).
  • Update the status line of P-RES-04 in docs/features/harness/proxy/response.md.

Done when

A test streams message_start, a complete text block and then closes without message_delta, and shows the CLI retracting the reply and starting the stream again; the test fails on the current code. The empty reply with stop_reason still ends normally.

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

    area:providerModel providersbugSomething isn't workingdifficulty:2Half a day - 1 dayhelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions