fix: make deeply-nested-body test platform-independent (fixes #3146)#3147
Open
g0rdonL wants to merge 1 commit into
Open
fix: make deeply-nested-body test platform-independent (fixes #3146)#3147g0rdonL wants to merge 1 commit into
g0rdonL wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3146.
Root cause
The test assumed a 100k-deep body always makes
json.loadsraiseRecursionError. 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:RecursionErrorat depth ~74k → deep body fails to parse →PARSE_ERRORINVALID_REQUESTmacOS runner threads get a smaller default stack than the main thread, which is why
macos-latestsees-32600while 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 eitherPARSE_ERRORorINVALID_REQUEST— the invariant that actually matters is "rejected, not crashed".test_modern_post_recursion_error_during_parse_is_parse_error: monkeypatches the body parse to raiseRecursionError, pinning theRecursionError → PARSE_ERRORmapping 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.py52/52, ruff + pyright clean.AI Disclaimer