fix multi-line buffering issue

Signed-off-by: Bradley-Butcher <brad@phoebe.ai>
This commit is contained in:
Bradley-Butcher 2025-06-13 19:36:14 +01:00
parent 7efa8b3987
commit 87e2699f6a
No known key found for this signature in database
GPG key ID: 4399A81BB23270AF
2 changed files with 97 additions and 10 deletions

View file

@ -188,17 +188,25 @@ class SubprocessCLITransport(Transport):
if not line_str:
continue
try:
data = json.loads(line_str)
# Split on newlines in case multiple JSON objects are buffered together
json_lines = line_str.split("\n")
for json_line in json_lines:
json_line = json_line.strip()
if not json_line:
continue
try:
yield data
except GeneratorExit:
# Handle generator cleanup gracefully
return
except json.JSONDecodeError as e:
if line_str.startswith("{") or line_str.startswith("["):
raise SDKJSONDecodeError(line_str, e) from e
continue
data = json.loads(json_line)
try:
yield data
except GeneratorExit:
# Handle generator cleanup gracefully
return
except json.JSONDecodeError as e:
if json_line.startswith("{") or json_line.startswith("["):
raise SDKJSONDecodeError(json_line, e) from e
continue
except anyio.ClosedResourceError:
pass