fix(client/stdio): default encoding_error_handler to 'replace' for resilient UTF-8 decoding
Closed
SA
3mo ago+25+25+01234567890123456789-1-1-0123456789
Summary
- Changes the default
encoding_error_handlerinStdioServerParametersfrom"strict"to"replace". - Malformed UTF-8 bytes from a child server stdout previously crashed the client transport with
UnicodeDecodeError. - With
"replace", invalid bytes become U+FFFD and the line fails JSON-RPC validation, which is surfaced as an in-streamExceptionthat the session can handle. - This mirrors the server-side stdio hardening from PR #2302.
Test Plan
- Reproduced the crash with a child process emitting
\xff\xfe\nfollowed by valid JSON-RPC. - Verified the fix: first item is a
ValidationError, second item is the validSessionMessage. - Added regression test
test_invalid_utf8_from_the_server_surfaces_as_an_in_stream_exception. - Full
tests/client/test_stdio.pysuite passes (34 passed, 1 skipped).
Notes
- Fixes #2454
- Scope intentionally small.