Repository navigation
laya serve: answer undecodable /v1/decisions bodies with 400 - #745
Merged
joshuaswarren merged 1 commit intoNov 23, 2026
Merged
Conversation
Invalid UTF-8 (UnicodeDecodeError), over-long integer literals (ValueError) and deep nesting (RecursionError) escaped the JSONDecodeError handler, so the server printed a traceback and closed the connection without a response. Catch ValueError and RecursionError and reply 400 "invalid JSON: ...".
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Reviewed by free · Input: 77.7K · Output: 3.1K · Cached: 262.4K |
Owner
|
GREEN at 76d5e82 |
Owner
|
GREEN at 76d5e82 |
Owner
|
Thanks @only21mil — request bodies on /v1/decisions that fail to decode now get a proper error response instead of dropping the connection on ValueError/RecursionError. Merged at 8f2adbd. |
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.
Problem
When a client posts a
/v1/decisionsbody that is not valid UTF-8, nests too deeply, or holds an integer literal longer than 4300 digits, the Laya server closes the connection without an HTTP response.do_POSTcaught onlyjson.JSONDecodeError. For these bodiesjson.loadsraisesUnicodeDecodeError,RecursionErrororValueError, so the handler thread printed a traceback and the client gotRemoteDisconnected. All three fit well insideMAX_BODY_BYTES.Change
Contract: a body that
json.loadscannot decode gets HTTP 400{"error": "invalid JSON: <reason>"}.serve/mlx_omarchy_laya/server.pycatches(ValueError, RecursionError)aroundjson.loads.JSONDecodeErrorandUnicodeDecodeErrorare bothValueErrorsubclasses.DecisionsValidationTests.test_undecodable_body_is_400posts the three raw bodies and expects that 400.Verification
Tested by: AI agent.
ThreadingHTTPServerbuilt with_make_handlerand a stub engine.POST /v1/decisionsoverhttp.clientwithb'{"state": "\xff"}',b"[" * 200000and a 5000-digit integer.Before,
003aadc70:After,
76d5e82b2:003aadc70(all 3 subtests) and passes at head, on both Pythons.collectors.ymlLinux steps pass on Python 3.14 and 3.11 at76d5e82b2:pytest tests(1845 passed, 179 skipped on each), the--no-depsclosure (3.14), and the installer-backed CPU regressions (3.11, 42 passed, 0 skipped).Generated with Claude Opus 5.5 in T3 Code Nightly