Skip to content

fix: ignore SSE pushes after stream close#1411

Open
ccai40359-wq wants to merge 1 commit into
h3js:mainfrom
ccai40359-wq:test/event-stream-ignore-post-close
Open

fix: ignore SSE pushes after stream close#1411
ccai40359-wq wants to merge 1 commit into
h3js:mainfrom
ccai40359-wq:test/event-stream-ignore-post-close

Conversation

@ccai40359-wq

@ccai40359-wq ccai40359-wq commented Jun 8, 2026

Copy link
Copy Markdown

Summary

  • Treat disposed SSE event streams as closed before writing
  • Add matrix coverage that later pushes/comments are ignored after close

Verification

  • pnpm vitest run test/sse.test.ts --coverage=false
  • pnpm lint (passes with existing typescript(await-thenable) warning in test/bench/bench.ts)
  • git diff --check
  • Added-line security scan: 0 findings
  • Independent review: passed

Closes #1410

Summary by CodeRabbit

  • Bug Fixes

    • Fixed event stream closure handling to consistently ignore push operations after the stream is closed.
  • Tests

    • Added test coverage verifying push operations are properly ignored after stream closure.

@ccai40359-wq ccai40359-wq requested a review from pi0 as a code owner June 8, 2026 06:40
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9981e4e9-b66a-40ca-beb8-4306de46d83f

📥 Commits

Reviewing files that changed from the base of the PR and between 7eb018e and 84a5278.

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

📝 Walkthrough

Walkthrough

EventStream consolidates "closed" state detection into a private _isClosed getter that treats both writer closure and disposal as effectively closed. All write operations (pushComment, _sendEvent, _sendEvents, flush) and the close() method now use this single guard, ensuring consistent no-op behavior after closure. A new test validates that post-close push calls are ignored.

Changes

Post-Close Stream Behavior

Layer / File(s) Summary
Unified closed-state getter and method guards
src/utils/internal/event-stream.ts
_isClosed getter centralizes both _writerIsClosed and _disposed as effectively closed; all previous closed checks in pushComment, _sendEvent, _sendEvents, flush, and close() now use this single getter instead of _writerIsClosed alone.
Test validation for post-close idempotency
test/sse.test.ts
Test removes an inline TODO comment and adds a case verifying that push and pushComment calls after eventStream.close() are silently ignored, with only pre-close events appearing in the response body.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰 A getter so wise centralizes the way,

Both closed and disposed now share the same say,

No more scattered checks through the stream's sunny days,

With tests standing guard on the post-close pathways! 🌿✨

🚥 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 summarizes the main change: preventing SSE pushes after stream closure.
Linked Issues check ✅ Passed The PR meets #1410's request for a small behavior-test PR without snapshot padding, mock-only assertions, threshold changes, or excluded file modifications.
Out of Scope Changes check ✅ Passed All changes are scoped to testing the behavior of ignoring pushes after stream close; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

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.

Open to a small behavior-test PR?

1 participant