Skip to content

fix(stream-parser): initialize the readable object-mode buffer - #723

Merged
jeswr merged 1 commit into
rdfjs:mainfrom
jeswr:codex/fix-stream-parser-object-buffer
Sep 5, 2026
Merged

fix(stream-parser): initialize the readable object-mode buffer#723
jeswr merged 1 commit into
rdfjs:mainfrom
jeswr:codex/fix-stream-parser-object-buffer

Conversation

@jeswr

@jeswr jeswr commented Sep 5, 2026

Copy link
Copy Markdown
Member

Construct StreamParser with readableObjectMode: true so its readable high-water mark is initialized in objects. Previously the constructor initialized a byte-mode buffer, then changed the private object-mode flag; that left the threshold at 16,384 quads instead of the normal 16-object default. Writable input remains in byte mode.

A regression test pipes 30,000 one-triple chunks into a parser without consuming the output. It checks readableHighWaterMark directly and verifies that the source pauses with at most 16 queued quads. The revised test fails against unfixed main with a high-water mark of 16,384 and passes after the patch. The high-water mark is a buffering threshold; a single large input chunk can still produce more quads synchronously.

Validation: all 6,892 tests pass with 100% coverage; ESLint, Node/browser builds, and git diff --check pass.

This fixes pre-existing behavior on main and is independent of #721. The base includes the merged import() backpressure change from #724 and the lexer optimization from #725.

Copilot AI lite review requested due to automatic review settings September 5, 2026 15:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new test asserts stream properties (readableObjectMode/writableObjectMode) that are not consistently implemented by readable-stream in this repo, making the test likely brittle or failing.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes StreamParser backpressure by constructing N3StreamParser with readableObjectMode: true so the readable high-water mark is initialized in object units (preventing the readable buffer from defaulting to a 16,384 “object” threshold after toggling object mode post-construction).

Changes:

  • Initialize N3StreamParser with readableObjectMode: true at super(...) time to get the correct object-mode high-water mark.
  • Add a regression test that pipes many single-triple chunks without consuming output and asserts unread-quad buffering stays bounded.
File summaries
File Description
src/N3StreamParser.js Initializes the readable side in object mode via super({ ..., readableObjectMode: true }) to fix backpressure thresholds.
test/N3StreamParser-test.js Adds a backpressure regression test to ensure unread quad buffering is bounded by the object-mode high-water mark.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/N3StreamParser-test.js Outdated
Initialize the readable high-water mark through the public object-mode constructor option. Cover bounded unread quads and assert readableHighWaterMark directly.
@jeswr
jeswr force-pushed the codex/fix-stream-parser-object-buffer branch from 3e35223 to 98cbfdc Compare September 5, 2026 19:52
@jeswr
jeswr merged commit 4607e09 into rdfjs:main Sep 5, 2026
55 checks passed
@jeswr
jeswr deleted the codex/fix-stream-parser-object-buffer branch September 5, 2026 20:00
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.7.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants