Bug fix: Handle multiline json #29
Closed
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.
Fix multiline JSON parsing in subprocess CLI transport
Problem
The JSON parsing logic in
SubprocessCLITransport.receive_messages()assumed all JSON responses would be contained on single lines. When the CLI output stream splits JSON responses across multiple lines, the current implementation would fail to parse them correctly, leading toCLIJSONDecodeErrorexceptions or completely ignored partial JSON.The original code would:
CLIJSONDecodeErrorfor lines that looked like JSON but were incompleteSolution
This PR adds buffering logic to handle JSON that spans multiple lines, while maintaining the existing single-line performance.
Testing
Added comprehensive test coverage:
test_multiline_json_parsing: Tests normal single-line JSON processingtest_multiline_json_no_error_on_valid_completion: Tests actual multiline JSON reconstructionBoth tests verify:
Verification
All existing tests continue to pass:
python -m pytest tests/test_transport.py -v # 9/9 tests passing