Skip to content

refactor(event-stream)!: drop autoclose option#1495

Merged
pi0 merged 1 commit into
mainfrom
refactor/drop-eventstream-autoclose
Jul 22, 2026
Merged

refactor(event-stream)!: drop autoclose option#1495
pi0 merged 1 commit into
mainfrom
refactor/drop-eventstream-autoclose

Conversation

@pi0x

@pi0x pi0x commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Closes #1489

What

Removes the autoclose option from EventStream. The EventStreamOptions interface and the createEventStream(event, opts?) signature are kept (options object is now empty) for future configuration and signature compatibility.

Why

autoclose (default true) existed in v1 to opt out of Node.js event listeners. The v2 rewrite plus the onDispose hook replaced that whole mechanism, leaving the option vestigial:

  • No practical effectautoclose: false did not keep the stream writable after client disconnect; the transport layer fails regardless.
  • Silent leak — a stream created with autoclose: false but never send()-ed never fired its onClosed callbacks, with no user-recoverable workaround.
  • Untested — no test exercised the false path.

Auto-close via onDispose is now always on, which was already the effective default.

Changes

  • src/utils/event-stream.ts — drop the autoclose field from EventStreamOptions (interface kept, now empty); createEventStream(event, opts?) signature unchanged.
  • src/utils/internal/event-stream.ts — drop the autoclose branches; always register onDispose cleanup and mark disposed on writer close. Constructor still accepts an (unused) options arg.
  • src/index.tsEventStreamOptions export retained.

Notes

Breaking only for callers passing autoclose (the SSE API is @experimental and this lands before v2 stable). The public signature and exported types are otherwise unchanged. Existing SSE tests (including client-disconnect auto-close) pass unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Improved event stream cleanup when connections close, including cases where no events were sent.
    • Ensured queued close callbacks run consistently when the underlying connection ends.
    • Removed the configurable automatic-close option in favor of consistent stream lifecycle handling.

@pi0x
pi0x requested a review from pi0 as a code owner July 22, 2026 09:53
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: faeb5f5f-c991-4c5b-bbda-dea70268a5d9

📥 Commits

Reviewing files that changed from the base of the PR and between 06523b0 and 71dd047.

📒 Files selected for processing (2)
  • src/utils/event-stream.ts
  • src/utils/internal/event-stream.ts

📝 Walkthrough

Walkthrough

The autoclose option is removed from the public EventStreamOptions type. EventStream now always marks writer closure as disposed and registers event-disposal cleanup.

Changes

SSE API and lifecycle

Layer / File(s) Summary
Simplified SSE public API
src/utils/event-stream.ts
EventStreamOptions is reduced to an empty placeholder interface without autoclose.
Unified stream disposal
src/utils/internal/event-stream.ts
Writer closure always sets disposal state, and event disposal always invokes close().
Estimated code review effort: 2 (Simple) ~10 minutes

Possibly related PRs

  • h3js/h3#1484: Modifies overlapping event-stream teardown and disposal behavior.

Suggested reviewers: pi0

Poem

I’m a bunny watching streams flow,
No autoclose switch to show.
Writers close, callbacks cheer,
Event disposal hops near.
SSE cleanup, neat and bright! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: removing the autoclose option from event-stream handling.
Linked Issues check ✅ Passed The PR matches #1489 by removing autoclose, dropping the option type export, always registering onDispose, and updating docs.
Out of Scope Changes check ✅ Passed The changes stay focused on the event-stream refactor and documentation update, with no unrelated code paths introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/drop-eventstream-autoclose

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.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/utils/internal/event-stream.ts (1)

28-43: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add regression coverage for never-sent stream disposal.

This constructor adds a new cleanup path for streams that are created but never sent. Add a test that disposes the event without calling send(), verifies onClosed runs, and confirms subsequent pushes are ignored.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/internal/event-stream.ts` around lines 28 - 43, The constructor’s
new event-disposal cleanup path lacks regression coverage for never-sent
streams. Add a test that creates the event stream, registers an onClosed
callback, disposes the event without calling send(), verifies the callback runs,
and confirms pushes made afterward are ignored.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/utils/internal/event-stream.ts`:
- Around line 28-43: The constructor’s new event-disposal cleanup path lacks
regression coverage for never-sent streams. Add a test that creates the event
stream, registers an onClosed callback, disposes the event without calling
send(), verifies the callback runs, and confirms pushes made afterward are
ignored.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 08d72d64-69c4-4b26-add9-b6cd0fbbf771

📥 Commits

Reviewing files that changed from the base of the PR and between ae4d6ee and 06523b0.

📒 Files selected for processing (4)
  • docs/2.utils/2.response.md
  • src/index.ts
  • src/utils/event-stream.ts
  • src/utils/internal/event-stream.ts

The `autoclose` option existed in v1 to opt out of Node.js event
listeners. The v2 rewrite and the `onDispose` hook replaced that
system, leaving the option vestigial:

- `autoclose: false` did not keep streams writable after disconnect
  (the transport still fails), so it had no practical effect.
- A stream created with `autoclose: false` but never `send()`-ed would
  never fire its `onClosed` callbacks — a silent leak with no
  user-recoverable workaround.
- The `false` path was untested.

Remove the option before v2 stable. Auto-close via `onDispose` is now
always on. `EventStreamOptions` and the `createEventStream(event, opts?)`
signature are kept (now empty) for future config and signature compat.

Closes #1489

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@pi0x
pi0x force-pushed the refactor/drop-eventstream-autoclose branch from 06523b0 to 71dd047 Compare July 22, 2026 09:57
@pi0
pi0 merged commit dff245a into main Jul 22, 2026
7 of 9 checks passed
@pi0
pi0 deleted the refactor/drop-eventstream-autoclose branch July 22, 2026 09:58
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.

Consider removing the autoclose option from createEventStream

2 participants