GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: raise on an empty HTTP-200 split chunk in NDJSON mode (0.46.1) by badGarnet · Pull Request #348 · Unstructured-IO/unstructured-python-client

Conversation

@badGarnet

@badGarnet badGarnet commented Aug 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

The bug

In NDJSON elements-file mode, a split-PDF chunk that returned HTTP 200 with an empty body was logged and skipped, so the combined elements_file was silently short by that chunk's pages while the call still returned 200.

Nothing downstream could detect it: combine_chunk_files_to_ndjson hands back only the combined path, and split_pdf_allow_failed=False does not cover the case because an empty 200 counts as a successful chunk. The buffered path fails outright on the same response (res.json() raises JSONDecodeError), so enabling NDJSON mode converted a hard failure into silent truncation.

The fix

Recombination now raises EmptyChunkResponseError (a ValueError, matching where the buffered path's JSONDecodeError lands) instead of skipping.

Emptiness is judged against the chunk's own Content-Type, because the two formats disagree about what an empty body means:

  • JSON has no empty document — a chunk with no elements is [] — so an empty body is malformed and raises.
  • application/x-ndjson encodes zero records as zero lines, so an empty body is well formed. It contributes nothing and does not fail the partition; otherwise a split whose pages are blank would break once a server honors the accept header.
  • An unknown or missing media type is read as JSON. That is what the deployed API returns, and guessing NDJSON would reinstate the silent truncation.

combine_chunk_files_to_ndjson takes an optional media_types list, positionally matched to chunk_paths; omitting it keeps the strict reading. _elements_from_task_responses collects each chunk's Content-Type before the cached branch overwrites the body with a temp-file path — the header survives both cache branches, so the cached case carries a real media type too.

Tests

_test_unstructured_client/unit/test_ndjson_elements_file.py:

  • empty JSON chunk raises, over 3 empty-ish bodies × application/json / unset / with-charset
  • empty NDJSON chunk is zero records, over 3 bodies × 3 media-type spellings (parameters, casing)
  • every chunk empty yields an empty output rather than an error
  • ValueError parity with the buffered path, and the strict default when media_types is omitted
  • hook level, both cache modes: an empty JSON chunk fails the operation and leaves no partial, spilled, or combined file behind; an empty NDJSON chunk is accepted with the surrounding chunks' elements intact

Mutating _is_ndjson_media_type to return False fails 12 of these, including both hook-level cache-mode tests, so the coverage is load-bearing.

271 unit + 64 contract tests pass; pylint 10/10 on both changed modules.

Release

Bumped to 0.46.1 with CHANGELOG and RELEASES entries. Consumers that pin unstructured-client >=0.46.0 for NDJSON elements-file mode should raise the floor to >=0.46.1.

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
badGarnet and others added 2 commits August 4, 2026 18:55
@badGarnet @claude
fix: raise on an empty HTTP-200 split chunk in NDJSON mode (0.46.1)
0539741
In NDJSON elements-file mode a split-PDF chunk that returned 200 with an
empty body was logged and skipped, so the combined elements_file was short
by those pages while the call still succeeded. `split_pdf_allow_failed`
does not cover it -- an empty 200 counts as a successful chunk -- and
`combine_chunk_files_to_ndjson` returns only a path, so nothing downstream
could detect the truncation.

Recombination now raises `EmptyChunkResponseError` (a `ValueError`) instead,
matching the buffered path, which raises `JSONDecodeError` on the same
response. An empty JSON array is still accepted: `[]` and an empty body are
different responses on the wire and only the latter is a defect.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@badGarnet @claude
fix: judge an empty chunk body against its own media type
36be018
The previous commit raised on every empty HTTP-200 chunk body, which is
wrong for NDJSON: zero records is zero lines, so an empty body is a
well-formed result and a split whose pages are blank would have failed.

Recombination now takes each chunk's Content-Type. An empty body raises
only when the chunk is not application/x-ndjson -- JSON has no empty
document, so an empty JSON 200 stays a defect, and an unknown media type
is read as JSON, which is what the deployed API returns.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@badGarnet
badGarnet force-pushed the yao/ml-1672-sdk-ndjson-mode-silently-drops-an-empty-http-200-split-chunk branch from b17ccee to 36be018 Compare August 4, 2026 23:55
cubic-dev-ai[bot]
cubic-dev-ai Bot reviewed Aug 5, 2026
View reviewed changes

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Shadow auto-approve: would auto-approve. Bug fix: empty JSON split-PDF chunks now raise ValueError instead of silent truncation; empty NDJSON chunks remain valid. Parametrized tests pin the corrected behavior; no human-owned tradeoff remains.

Re-trigger cubic

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@awalker4

awalker4 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

LGTM! The splitting code was always so ugly because we had to work around the autogen code. I.e. we could only intercept the request, pull the file out, and hijack the outgoing payload. Now that that's all behind us, we can make this so much nicer. Now that I'm thinking about it let me make sure we have a ticket.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

awalker4
awalker4 approved these changes Aug 5, 2026
View reviewed changes
@badGarnet
badGarnet merged commit 56d2aaa into main Aug 5, 2026
19 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@badGarnet
badGarnet deleted the yao/ml-1672-sdk-ndjson-mode-silently-drops-an-empty-http-200-split-chunk branch August 5, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cubic-dev-ai cubic-dev-ai[bot] cubic-dev-ai[bot] left review comments
@awalker4 awalker4 awalker4 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@badGarnet @awalker4
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.