Added buffer in receive_messages() so partial json can be stored in a buffer and then decoded, once complete

This commit is contained in:
Phantom168 2025-06-30 23:15:22 +05:30
parent 5d05650c85
commit 591202dd31

View file

@ -182,6 +182,8 @@ class SubprocessCLITransport(Transport):
async with anyio.create_task_group() as tg:
tg.start_soon(read_stderr)
json_buffer = ""
try:
async for line in self._stdout_stream:
line_str = line.strip()
@ -197,14 +199,17 @@ class SubprocessCLITransport(Transport):
continue
try:
data = json.loads(json_line)
json_buffer += json_line
data = json.loads(json_buffer)
json_buffer = ""
try:
yield data
except GeneratorExit:
# Handle generator cleanup gracefully
return
except json.JSONDecodeError as e:
if json_line.startswith("{") or json_line.startswith("["):
if (json_buffer.startswith("{") and json_buffer.endswith("}")) or (
json_buffer.startswith("[") and json_buffer.endswith("]")):
raise SDKJSONDecodeError(json_line, e) from e
continue