/claim #9810

Proposed changes

Fixes #9810.

This PR fixes an off by one behavior in ZStream.buffer(capacity) where buffer(n) allowed n + 1 elements in flight.

  1. capacity <= 0
    No-op. Returns the original stream unchanged.

  2. capacity == 1
    Uses a synchronous ZStream.Handoff path so exactly one element is buffered ahead.

  3. capacity >= 2
    Uses internal queue size capacity - 1 so queue capacity plus one in-flight element equals exactly capacity.

Tests added

  1. buffer(1) buffers exactly 1 element
  2. buffer(2) buffers exactly 2 elements
  3. buffer(0) is a no-op

These tests use Promise coordination to make assertions deterministic.

Validation

  • sbt "-Dsbt.supershell=false" "streamsTestsJVM/testOnly zio.stream.ZStreamSpec -- -t buffer"
  • sbt "-Dsbt.supershell=false" "streamsTestsJS/testOnly zio.stream.ZStreamSpec -- -t buffer"
  • Native run with Windows toolchain env setup, then:
    • sbt "-Dsbt.supershell=false" "streamsTestsNative/testOnly zio.stream.ZStreamSpec -- -t buffer"

Result:
23 tests passed, 0 failed, 0 ignored on each platform run.

Proof

https://github.com/user-attachments/assets/d789aecb-7644-4812-851d-1b1975bc0125

Demo video attached showing:

  1. git diff for the two changed files
  2. realtime JVM, JS, and Native buffer test runs
  3. passing test summaries

Claim

Total prize pool $250
Total paid $0
Status Pending
Submitted March 24, 2026
Last updated March 24, 2026

Contributors

SA

saurabh

@SaurabhCodesAI

100%

Sponsors

ZI

ZIO

@ZIO

$250