ReviewOS

home-lang/home

Bun parity: enforce Bun.serve response-stream backpressure

#685
Closed chris opened this 9 days ago ·
9 days ago

Scope

Implement native server backpressure and drain behavior for streamed response bodies. The unchanged Bun corpus currently fails five cases covering ReadableStream, async-generator, and direct-stream producers, including flush(true) re-entry and queued small writes.

Evidence

Validated against Bun checkout 4982b91e3702094330f3be3883354c52b8c01323 in test/js/bun/http/serve.test.ts. The complete Home run reports 188 pass, 1 upstream skip, 1 upstream todo, and 11 failures; five failures belong to this backpressure family.

Acceptance criteria

  • Signal backpressure when clients stall rather than consuming unbounded producer output.
  • Resume production after drain and deliver the complete body without corruption.
  • Prevent direct-stream pull re-entry while flush(true) is pending.
  • Preserve small queued writes across backpressure and drain.
  • Pass all unchanged upstream stress workloads and timing assertions without rewrites, skips, relaxed deadlines, or reduced payloads.
9 days ago

Completed in cf32ab6.

Ported the response-stream backpressure behavior from Bun 4982b91 across the full pipeline:

  • HTTP response writes now surface the negative accepted-but-backpressured sentinel used by the JS stream pump.
  • ReadableStream and async-generator producers await flush(true) before pulling again.
  • RequestContext owns the persistent uWS drain callback and forwards drains to the live sink without replacing response userdata.
  • Streaming drains, tryEnd tails, pending flush promises, and smaller writes queued behind backpressure now preserve their distinct offset/ownership semantics.
  • Sink readiness callbacks use the checked JSC host-call path, and HTML rewriter handling is exhaustive for the new writable result.
  • Removed the whole-file serve.test.ts TODO rewrite and added an exact native regression gate.

Validation:

  • ReleaseFast JSC install build passed.
  • Home corpus copy is byte-identical to the pinned Bun serve.test.ts.
  • Four consecutive full unchanged runs passed: 199 pass, 0 fail, 2 upstream todo each.
  • No assertions, deadlines, payload sizes, or test workloads were changed.

Sign in to comment on this issue.