Skip to content

Deeply-nested-body test fails on macOS: rejected as INVALID_REQUEST (-32600) instead of PARSE_ERROR (-32700) #3146

Closed

Description

@maxisbey

Running the test suite on macOS (observed on GitHub macos-latest, Python 3.14) fails one test that passes on Ubuntu and Windows:

FAILED tests/server/test_streamable_http_modern.py::test_modern_post_with_deeply_nested_body_is_parse_error_not_a_crash
>       assert response.json()["error"]["code"] == PARSE_ERROR
E       assert -32600 == -32700

async def test_modern_post_with_deeply_nested_body_is_parse_error_not_a_crash() -> None:

The response status is 400 in both cases; only the JSON-RPC error code differs. The test expects the RecursionError raised while parsing the deeply nested body to classify as a parse error, but on Darwin it surfaces as INVALID_REQUEST, so the recursion limit is evidently being hit in a different layer there (macOS threads run with a smaller default stack, which moves where the recursion guard strikes).

This is unrelated to any open PR: it fails identically on current main (3a6f299) and on feature branches, reproduced across repeated runs on macos-latest. Repro:

uv sync --frozen
uv run --frozen pytest tests/server/test_streamable_http_modern.py::test_modern_post_with_deeply_nested_body_is_parse_error_not_a_crash

CI currently runs Ubuntu and Windows only, which is why this has gone unnoticed; worth deciding separately whether macos-latest should join the matrix.

AI Disclaimer

Activity

  1. added
    bug
    P3
    v2
    spec-2026-07-28
    on Aug 14, 2026
  2. JingHao-Leon commented on Sep 22, 2026

    @JingHao-Leon

    Reproduced on a real Mac, but the OS is a red herring — this is a CPython version boundary, and the server behavior on 3.14 is arguably the correct one.

    Machine data — macOS 26.5.1 arm64 (M-series), same commit (6affe5c):

    • Python 3.12.13: test PASSES
    • Python 3.14.6: test FAILS with -32600 (as reported)

    Actual divergence — the recursion guard never fires on 3.14; parsing succeeds:

    body = b"[" * 100_000 + b"]" * 100_000
    # 3.12: json.loads raises RecursionError → caught at _streamable_http_modern.py:403 → PARSE_ERROR (-32700)
    # 3.14: json.loads SUCCEEDS (returns a 100k-deep list)
    #       → JSONRPCRequest.model_validate(list) → ValidationError → _INVALID_BODY (L207, INVALID_REQUEST, -32600)

    Verified the two pieces in isolation: pydantic_core.from_json behaves identically on both (2.41.5, same ValueError), but stdlib json.loads diverges — on 3.14 it parses this depth without raising. So the body is valid JSON that just isn't a valid JSON-RPC request, and INVALID_REQUEST is the spec-correct answer for that. The failure path never touches the PARSE_ERROR branch.

    Two consequences:

    1. Since the divergence is in stdlib json, not the OS, this should reproduce on Linux + 3.14 as well (I only verified the stdlib divergence locally, not the full server test on Linux). Which means "add macos-latest to the matrix" is pointing at the wrong axis — adding 3.14 to the existing Linux matrix would catch this regardless of OS.
    2. The server looks fine on 3.14: structured 400, no crash. What needs maintenance is the test's premise ("deep nesting makes json.loads raise RecursionError"), which stopped being true in 3.14.

    Fix directions for the test:

    1. Make it version-aware (≤3.13: PARSE_ERROR; 3.14+: INVALID_REQUEST), or
    2. Keep the crash-guard intent with input that is unparseable on all versions (e.g., 100k nesting with a truncated tail — never valid JSON anywhere), and assert the parsed-but-wrong-shape case separately as INVALID_REQUEST.

    Happy to send a PR for option 2 — it keeps the crash-guard assertion deterministic across interpreters.

  3. maxisbey commented on Oct 2, 2026

    @maxisbey
    ContributorAuthor

    Fixed in #3610. Thanks for the analysis and the PR offer above: the fix follows your second option, so the test body is now left unterminated and can't parse on any interpreter. The server code is untouched.

    I reproduced the failure on Linux by raising the stack limit, but haven't run the fix on a Mac. If it still fails there, please open a new issue.

    Adding macos-latest to CI has its own issue now, #3597.

    AI Disclaimer

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

    P3bugspec-2026-07-28v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions