Skip to content

Fix zero maxBytes handling in NodeStream - #7233

Merged
tim-smart merged 2 commits into
Effect-TS:mainfrom
AnnaSuSu:agent/fix-nodestream-zero-maxbytes
Aug 13, 2026
Merged

tim-smart merged 2 commits into
Effect-TS:mainfrom
AnnaSuSu:agent/fix-nodestream-zero-maxbytes

Conversation

@AnnaSuSu

Copy link
Copy Markdown
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

NodeStream.toString and NodeStream.toArrayBuffer accepted maxBytes: 0, but truthiness checks treated the value as if no limit had been supplied. Both functions therefore consumed non-empty streams even though the configured maximum was zero.

This replaces the truthiness checks with explicit undefined checks in both sibling implementations, preserving zero as a valid limit. Focused regression tests cover both the string and binary consumers.

Validation:

  • New tests failed on the unmodified implementation by returning one byte.
  • vitest run packages/platform/node-shared/test/NodeStream.test.ts (12 tests passed)
  • tsc -b tsconfig.json
  • oxlint -f unix
  • dprint check

Related

  • Related Issue #
  • Closes #

@changeset-bot

changeset-bot Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f00e098

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@effect/platform-node-shared Patch
effect Patch
@effect/ai-anthropic Patch
@effect/ai-openai Patch
@effect/ai-openai-compat Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/vitest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@AnnaSuSu
AnnaSuSu marked this pull request as ready for review August 13, 2026 15:56
Copilot AI lite review requested due to automatic review settings August 13, 2026 15:56

Copilot AI 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.

Pull request overview

Fixes a bug in @effect/platform-node-shared where maxBytes: 0 was treated as “no limit” in NodeStream consumers due to truthiness checks, and adds regression coverage to prevent reintroduction.

Changes:

  • Replace truthiness checks with explicit undefined checks for maxBytes in NodeStream.toString and NodeStream.toArrayBuffer.
  • Add regression tests ensuring maxBytes: 0 is enforced for both string and binary stream consumption.
  • Add a changeset for a patch release noting the zero-byte limit enforcement.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/platform/node-shared/src/NodeStream.ts Fixes maxBytes: 0 handling by using !== undefined checks in both consumers.
packages/platform/node-shared/test/NodeStream.test.ts Adds regression tests asserting zero-byte limits fail as expected.
.changeset/fix-zero-max-bytes.md Declares a patch release entry for the behavior fix.
Suppressed comments (1)

packages/platform/node-shared/src/NodeStream.ts:300

  • When maxBytes is exceeded, the stream is not destroyed. Since Effect.callback cleanup runs only on interruption, failing via resume(Effect.fail(...)) can leave the stream active and continue pushing chunks into memory even though the effect has already failed. Destroy the stream before resuming the failure, consistent with the "error" handler above.
      if (maxBytesNumber !== undefined && bytes > maxBytesNumber) {
        resume(Effect.fail(onError(new Error("maxBytes exceeded")) as E))
      }

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

Comment thread packages/platform/node-shared/src/NodeStream.ts
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 6.91 KB 6.91 KB 0.00 KB (0.00%)
batching.ts 9.72 KB 9.72 KB 0.00 KB (0.00%)
brand.ts 6.50 KB 6.50 KB 0.00 KB (0.00%)
cache.ts 10.63 KB 10.63 KB 0.00 KB (0.00%)
config.ts 21.05 KB 21.05 KB 0.00 KB (0.00%)
differ.ts 19.99 KB 19.99 KB 0.00 KB (0.00%)
http-client.ts 21.56 KB 21.56 KB 0.00 KB (0.00%)
logger.ts 10.88 KB 10.88 KB 0.00 KB (0.00%)
metric.ts 8.86 KB 8.86 KB 0.00 KB (0.00%)
optic.ts 6.67 KB 6.67 KB 0.00 KB (0.00%)
pubsub.ts 14.90 KB 14.90 KB 0.00 KB (0.00%)
queue.ts 11.57 KB 11.57 KB 0.00 KB (0.00%)
schedule.ts 10.74 KB 10.74 KB 0.00 KB (0.00%)
schema-class.ts 19.61 KB 19.61 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.57 KB 29.57 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 25.81 KB 25.81 KB 0.00 KB (0.00%)
schema-string-transformation.ts 13.49 KB 13.49 KB 0.00 KB (0.00%)
schema-string.ts 10.99 KB 10.99 KB 0.00 KB (0.00%)
schema-template-literal.ts 15.30 KB 15.30 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 21.73 KB 21.73 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.20 KB 24.20 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.96 KB 18.96 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.78 KB 18.78 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.65 KB 18.65 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.81 KB 22.81 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.30 KB 19.30 KB 0.00 KB (0.00%)
schema.ts 18.87 KB 18.87 KB 0.00 KB (0.00%)
stm.ts 12.66 KB 12.66 KB 0.00 KB (0.00%)
stream.ts 9.66 KB 9.66 KB 0.00 KB (0.00%)

@tim-smart
tim-smart merged commit 2ae5a96 into Effect-TS:main Aug 13, 2026
13 of 15 checks passed
@AnnaSuSu
AnnaSuSu deleted the agent/fix-nodestream-zero-maxbytes branch August 14, 2026 01:06

This branch had an error being deployed

1 failed deployment
fork — f00e0985 Deployed Aug 13, 2026 by AnnaSuSu via approval-gate #11852
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.

3 participants