Skip to content

Close JSONL responses when decoding or reading fails - #1929

Open
betacatsling wants to merge 1 commit into
anthropics:mainfrom
betacatsling:fix/jsonl-response-cleanup
Open

Close JSONL responses when decoding or reading fails#1929
betacatsling wants to merge 1 commit into
anthropics:mainfrom
betacatsling:fix/jsonl-response-cleanup

Conversation

@betacatsling

Copy link
Copy Markdown

Batch-result JSONL decoders leave the HTTP response open when parsing or reading fails. Add finally cleanup to both decoder variants so those exceptions release the response, as SSE streams already do.

The regressions exercise messages.batches.results() through an in-memory HTTP transport, cover invalid JSON, read failures and successful exhaustion, and check that the underlying stream closes exactly once. On the unchanged base: 4 failed, 2 passed. With the fix: decoder and SSE tests 35 passed, with no live API calls. Ruff and changed-file Pyright checks passed. Mypy reports the same 67 pre-existing diagnostics in three unchanged dependency modules on the base and patched versions.

The newline parsing itself is unchanged; #1778 addresses a separate CRLF boundary issue in this decoder.

AI assistance was used for implementation and local verification.

Fixes #1928.

@betacatsling
betacatsling requested a review from a team as a code owner September 11, 2026 17:13
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.

Batch result decoders leave responses open after parsing or transport errors

1 participant