Skip to content

laya serve: answer undecodable /v1/decisions bodies with 400 - #745

Merged
joshuaswarren merged 1 commit into
joshuaswarren:mainfrom
only21mil:fix/laya-decisions-bad-json
Nov 23, 2026
Merged

joshuaswarren merged 1 commit into
joshuaswarren:mainfrom
only21mil:fix/laya-decisions-bad-json

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

Problem

When a client posts a /v1/decisions body 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_POST caught only json.JSONDecodeError. For these bodies json.loads raises UnicodeDecodeError, RecursionError or ValueError, so the handler thread printed a traceback and the client got RemoteDisconnected. All three fit well inside MAX_BODY_BYTES.

Change

Contract: a body that json.loads cannot decode gets HTTP 400 {"error": "invalid JSON: <reason>"}.

  • serve/mlx_omarchy_laya/server.py catches (ValueError, RecursionError) around json.loads. JSONDecodeError and UnicodeDecodeError are both ValueError subclasses.
  • DecisionsValidationTests.test_undecodable_body_is_400 posts the three raw bodies and expects that 400.

Verification

Tested by: AI agent.

  • Setup: Linux x86_64, Python 3.14.4 and 3.11.18; a ThreadingHTTPServer built with _make_handler and a stub engine.
  • Steps: raw POST /v1/decisions over http.client with b'{"state": "\xff"}', b"[" * 200000 and a 5000-digit integer.

Before, 003aadc70:

invalid UTF-8       RemoteDisconnected   server traceback: UnicodeDecodeError
deep nesting        RemoteDisconnected   server traceback: RecursionError
5000-digit integer  RemoteDisconnected   server traceback: ValueError

After, 76d5e82b2:

invalid UTF-8       400  invalid JSON: 'utf-8' codec can't decode byte 0xff in position 11 ...
deep nesting        400  invalid JSON: maximum recursion depth exceeded ... (3.11)
                         invalid JSON: Stack overflow ... (3.14)
5000-digit integer  400  invalid JSON: Exceeds the limit (4300 digits) for integer string conversion ...
  • The new test fails on 003aadc70 (all 3 subtests) and passes at head, on both Pythons.
  • collectors.yml Linux steps pass on Python 3.14 and 3.11 at 76d5e82b2: pytest tests (1845 passed, 179 skipped on each), the --no-deps closure (3.14), and the installer-backed CPU regressions (3.11, 42 passed, 0 skipped).

Generated with Claude Opus 5.5 in T3 Code Nightly

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: ...".
@kilo-code-bot

kilo-code-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge


Reviewed by free · Input: 77.7K · Output: 3.1K · Cached: 262.4K

@joshuaswarren

Copy link
Copy Markdown
Owner

GREEN at 76d5e82
Model: cognition/swe-2

@joshuaswarren

Copy link
Copy Markdown
Owner

GREEN at 76d5e82
Model: zai/glm-5.3-flash

@joshuaswarren
joshuaswarren merged commit 8f2adbd into joshuaswarren:main Nov 23, 2026
5 checks passed
@joshuaswarren

Copy link
Copy Markdown
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.

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.

2 participants