Skip to content

fix(sources): parse JSON from non-seekable zip-entry streams - #1768

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/inherited-failures-tail2
May 31, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/inherited-failures-tail2

Conversation

@Sinity

@Sinity Sinity commented May 31, 2026

Copy link
Copy Markdown
Owner

Problem

Every JSON conversation export packaged inside a .zip (ChatGPT/Claude web exports) silently failed to ingest with File or stream is not seekable and was skipped.

process_zip opens each entry via zipfile.ZipExtFile (non-seekable). For individual-JSON entries the path is emit → _emit_individual → _iter_json_stream → iter_json_stream_with, which rewinds with handle.seek(0) between its ijson multi-strategy attempts. A zip entry can't seek, so the parse raised and the file was dropped at the acquisition boundary. (_emit_grouped already materialized to BytesIO; the individual path did not.)

This is a real ingestion regression for zipped exports — surfaced once the suite could collect again (#1765) and confirmed by tracing the swallowed exception at source_parsing.py:163.

Solution

In iter_json_stream_with, before the seeking strategies, materialize a non-seekable handle into a BytesIO once (the function inherently requires seeking; bounded zip entries are safe to read fully). Added the missing import io.

Verification

pytest tests/unit/sources/test_source_laws.py tests/unit/sources/test_acquisition_encoding.py  # 123 passed (was 5 failing)

Fixes the zip round-trip, raw-capture, multi-conversation-zip, BOM-in-zip, and partial-corruption cases.

iter_json_stream_with rewinds via handle.seek(0) for its ijson multi-strategy
parse, but a zip entry (zipfile.ZipExtFile, reached via process_zip ->
_emit_individual) is not seekable, so every JSON export inside a .zip failed with
'File or stream is not seekable' and was skipped at ingest. Materialize a
non-seekable handle into a BytesIO once before the seeking strategies.

Fixes test_source_laws (zip round-trip + raw-capture) and test_acquisition_encoding
(zip BOM/partial-corruption).
@Sinity
Sinity merged commit 1ee0907 into master May 31, 2026
4 of 5 checks passed
@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 16 minutes and 47 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: aca22281-bfe6-4e28-9b4c-96b0a3e8e9a0

📥 Commits

Reviewing files that changed from the base of the PR and between ee3a759 and bf331a1.

📒 Files selected for processing (1)
  • polylogue/sources/decoder_json.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/inherited-failures-tail2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity
Sinity deleted the feature/fix/inherited-failures-tail2 branch May 31, 2026 09:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf331a10fb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# into a seekable buffer once before the seeking strategies run.
seekable = getattr(handle, "seekable", None)
if callable(seekable) and not seekable():
handle = io.BytesIO(handle.read())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid buffering full non-seekable JSON entries in memory

For ZIP ingestion, open_bounded_zip_entry() provides a non-seekable stream and the configured decompression ceiling is 10 GiB, so a large but valid .json entry now gets fully decompressed into a BytesIO here before any records are yielded. This removes the existing streaming behavior for root-array exports where the first ijson.items(..., "item") strategy can succeed without rewinding, and can OOM on multi-GB archives that are still below the allowed entry size; consider spooling to a bounded temp file or only materializing when a fallback actually needs a rewind.

Useful? React with 👍 / 👎.

Sinity added a commit that referenced this pull request May 31, 2026
## Summary

Three more inherited-failure fixes (continuing #1765/#1767/#1768).

## Changes

- **`blackboard list --limit`**: used `-n`, violating the repo-wide
`-l/--limit` convention enforced by `test_flag_aliases_consistent`.
Aligned to `-l` (small CLI fix).
- **`exercise_catalog`**: dropped the `insights analytics` nested path
from the pin — that command path no longer exists.
- **`config source_roots`**: the TOML serializer now renders arrays
multi-line (`roots = [\n "/a",\n "/b",\n]`); the test pinned the old
single-line spelling. Assert the array shape + members robustly.
(Confirmed the cli-override is correctly applied — it was purely a
formatting-style drift.)

## Verification

```
pytest <theme_aliases, exercise_catalog, config source_roots, help/terminal snapshots>  # all pass
```

## Deferred (intentionally not touched)

The remaining inherited failures cluster on the **in-flux
`provider`/`source_name` vocabulary** (#1743 is actively redesigning
this) and a product decision — editing them blind risks encoding the
wrong interpretation:
- `resilience` (4), `ingestion_chaos`, `parsing_service`,
`pipeline_probe` (2), `parsers_local_agent` — all turn on parsed
`source_name` being the source-config name (`'test'`) vs the detected
origin (`'claude-code'`/`'codex'`). Likely a real regression in the
origin-vs-source conflation, but it belongs to the #1743 redesign or an
explicit operator call.
- `ASSURANCE_REGISTRY` — the 6 new commands need declared output
contracts (#1272), a per-command product decision.
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.

1 participant