Skip to content

fix(python): preserve final JSON Lines records without a trailing newline - #126

Draft
Kayvan-Zahiri wants to merge 1 commit into
speakeasy-api:mainfrom
Kayvan-Zahiri:codex/preserve-jsonl-final-record
Draft

Kayvan-Zahiri wants to merge 1 commit into
speakeasy-api:mainfrom
Kayvan-Zahiri:codex/preserve-jsonl-final-record

Conversation

@Kayvan-Zahiri

@Kayvan-Zahiri Kayvan-Zahiri commented Oct 21, 2026 •

Copy link
Copy Markdown

Why

The Python JSON Lines reader drops the final record when the response ends without a trailing newline. The EOF check uses position, but that cursor is reset to zero after each chunk. The remaining buffer is therefore never decoded. A single-record response can silently produce no events, and a malformed final record is silently discarded.

The JSON Lines format recommends a final newline but does not require one.

What changed

Check for non-whitespace buffered data at EOF in both synchronous and asynchronous reader templates, then pass it through the existing decoder. Empty streams and whitespace-only tails retain their existing behavior; malformed final JSON raises the decoder's error.

Add 50 offline regression cases to the existing Python primary streaming tests: newline/no-newline, multiple records, LF/CRLF, UTF-8, empty input, whitespace tails, malformed final JSON, and different byte-chunk boundaries. Add the jsonlResponses patch changeset using the repository command.

Regenerated the Python review SDK with the supported command; it contains no JSON Lines operation and produces no tracked diff. Separately generated a minimal synthetic JSON Lines SDK before and after the template change and regenerated the primary test SDK.

Testing

  • Unmodified generated stream utility: 26 failed, 24 passed. Fixed generated utility: all 50 passed.
  • The committed tests run unchanged from the generated primary SDK: 50 passed, six existing service-dependent tests deselected. Pytest reports one unknown timeout configuration warning because pytest-timeout is not installed in the isolated test environment.
  • Public methods of the independently generated synthetic SDK, through HTTPX MockTransport: 24 failed/24 passed before; all 48 passed after.
  • Generated synthetic SDK: full mypy passes across 39 source files; wheel and source distribution build.
  • Generator binary build, npm run format, make check-template-pythonv2, review SDK regeneration/integrity validation, and git diff --check pass.
  • make lint passed its public-input guard, then stopped because golangci-lint is unavailable. The repository-wide lint gate and Docker-backed multi-target integration matrix are not claimed as passing.
  • No live service, account, or customer inputs. All responses and specifications are synthetic.

Public-safety check

  • This change contains no credentials, customer documents, private repository URLs, private filesystem paths, or unredacted private logs.
  • Title, body, comments, and commit messages name no customers or customer-derived identifiers, private paths or trackers, or workflow provenance, and are understandable without private context.
  • Generated fixtures and review SDK changes are public-safe.
  • I reviewed git diff --check.

Summary by cubic

Fixes the Python JSON Lines reader dropping the final record when a response ends without a trailing newline. The EOF check relied on a position cursor that resets to zero after each chunk, so remaining buffered data was never decoded. Buffered non-whitespace data at EOF now passes through the existing decoder; empty streams and whitespace-only tails behave as before, and malformed final JSON raises the decoder's error instead of being silently discarded.

Adds 50 offline regression cases covering newline/no-newline, multiple records, LF/CRLF, UTF-8, empty input, whitespace tails, malformed final JSON, and chunk boundaries, plus a patch changeset for jsonlResponses.

Written for commit 1a007a5. Summary will update on new commits.

View guided diff

@github-actions github-actions Bot added the python Trigger (106) snapshot tests for python label Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Kayvan-Zahiri

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Trigger (106) snapshot tests for python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant