Skip to content

Conversation

@arun-pathiban-ddog
Copy link

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 to CLIJSONDecodeError exceptions or completely ignored partial JSON.

The original code would:

  • Try to parse each line individually as complete JSON
  • Raise CLIJSONDecodeError for lines that looked like JSON but were incomplete

Solution

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 processing
  • test_multiline_json_no_error_on_valid_completion: Tests actual multiline JSON reconstruction

Both tests verify:

  • ✅ Single-line JSON parsing works as expected
  • ✅ Multi-line JSON gets properly reconstructed
  • ✅ Buffer state management is correct
  • ✅ Error handling for incomplete JSON
  • ✅ Non-JSON lines are ignored appropriately

Verification

All existing tests continue to pass:

python -m pytest tests/test_transport.py -v
# 9/9 tests passing

@ltawfik
Copy link
Collaborator

ltawfik commented Jun 27, 2025

thanks @arun-pathiban-ddog . This issue was already fixed in PR #5. The current implementation correctly handles multiple JSON objects on one line

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