Skip to content

bug: invalid inline HTTP POST JSON leaves requests waiting #200

Open

Description

@lj1166

Summary

The HTTP transport silently ignores JSON decoding failures in non-empty 200 OK POST responses. Connection.send_request() then keeps waiting on its pending future, although the HTTP response has already arrived and cannot be decoded.

For example, a proxy returning an HTML error page with status 200 hides the useful decoding error behind a later timeout (or waits indefinitely without a caller timeout).

Reproduction steps

Using create_http_stream() and Connection:

  1. Initialize normally and leave the connection-scoped SSE stream open.
  2. Return HTTP 200 with body <html>not an ACP response</html> (or {invalid) for the next POST.
  3. Await connection.send_request("broken", {}).

The HTTP-only failure can also be seen directly: await transport.send(request) returns successfully after receiving that body. _send_post() wraps both response.json() and _handle_incoming() in contextlib.suppress(Exception).

I reproduced this with two regression cases using the existing FakeServer, the real HTTP transport and Connection; only HTTP delivery uses httpx2.MockTransport. Each case expects json.JSONDecodeError from the request within one second, and checks that a subsequent valid inline response still succeeds. Both fail before the patch; the three selected initialization, SSE-delivery and status-error controls pass.

Expected result

The sending caller gets the decoding error promptly and can diagnose the bad response. A later valid request can still use the connection.

Actual result

Both cases reach the outer one-second asyncio.wait_for() deadline and raise TimeoutError. The original JSON decoding error has been discarded.

Versions / environment

  • SDK 0.12.1, main 4fed584775d6a650cd669b63617049e5352297fe
  • Generated schema tag schema-v1.23.0
  • CPython 3.12.16, Windows/amd64, locked httpx2 2.12.0 and Pydantic 2.14.1
  • Offline regression; no model, credentials or external server

Logs

FAILED test_invalid_post_json_rejects_request_without_losing_connection[<html>not an ACP response</html>]
FAILED test_invalid_post_json_rejects_request_without_losing_connection[{invalid]
2 failed, 3 passed, 10 deselected

Open to submitting a fix?

Yes. Removing the broad suppression makes the existing request-failure cleanup propagate the JSON error; the related test file then has 15 passing tests. I also added a short transport documentation note.

Searched existing issues/PRs for HTTP JSON, malformed POST, response.json and 200/hang. #174 concerns malformed incoming frames across transports; this is the separate inline POST-response path.

AI disclosure: Codex found this through source review, ran the reproductions and drafted the patch/report under the account holder's instruction. The proxy example describes the failure scenario; a production incident or independent human verification is not claimed.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions