Skip to content

fix: make deeply-nested-body test platform-independent (fixes #3146)#3147

Open
g0rdonL wants to merge 1 commit into
modelcontextprotocol:mainfrom
g0rdonL:repro-3146-macos
Open

fix: make deeply-nested-body test platform-independent (fixes #3146)#3147
g0rdonL wants to merge 1 commit into
modelcontextprotocol:mainfrom
g0rdonL:repro-3146-macos

Conversation

@g0rdonL

@g0rdonL g0rdonL commented Jul 22, 2026

Copy link
Copy Markdown

Fixes #3146.

Root cause

The test assumed a 100k-deep body always makes json.loads raise RecursionError. Since CPython 3.12 the C json scanner guards recursion by remaining C-stack headroom, not a fixed depth — so the outcome depends on the thread's stack size. Measured on Apple Silicon macOS, CPython 3.14:

  • main thread: flips to RecursionError at depth ~74k → deep body fails to parse → PARSE_ERROR
  • thread with a 64 MB stack: depth 100k parses fine → giant list fails request validation → INVALID_REQUEST

macOS runner threads get a smaller default stack than the main thread, which is why macos-latest sees -32600 while Ubuntu/Windows see -32700. Both are correct 400 rejections of the same hostile body; the old assertion was pinning a platform accident.

Change (test-only)

  • test_modern_post_with_deeply_nested_body_is_rejected_not_a_crash: asserts 400 with either PARSE_ERROR or INVALID_REQUEST — the invariant that actually matters is "rejected, not crashed".
  • New test_modern_post_recursion_error_during_parse_is_parse_error: monkeypatches the body parse to raise RecursionError, pinning the RecursionError → PARSE_ERROR mapping deterministically on every platform (this is what the old test was really trying to cover).

Verified locally on macOS arm64: both tests pass on CPython 3.13 and 3.14, full test_streamable_http_modern.py 52/52, ruff + pyright clean.

AI Disclaimer

…rotocol#3146)

Since CPython 3.12 the C json scanner guards recursion by remaining
C-stack headroom rather than a fixed depth, so whether a 100k-deep
body raises RecursionError (-> PARSE_ERROR) or parses into a giant
list that fails request validation (-> INVALID_REQUEST) depends on
the thread's stack size. macOS threads run with a smaller default
stack, which is why the test failed there while passing on Ubuntu
and Windows.

Split the test in two: the nested-body test now asserts a 400 with
either rejection code (both are correct; neither is a crash), and a
new monkeypatch-based test pins the RecursionError -> PARSE_ERROR
mapping deterministically on every platform.

Fixes modelcontextprotocol#3146

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant