Skip to content

feat: support except chaining on the broadcast operator - #138

Merged
electrohyun merged 2 commits into
mainfrom
feat/except-chaining
Aug 5, 2026
Merged

electrohyun merged 2 commits into
mainfrom
feat/except-chaining

Conversation

@electrohyun

@electrohyun electrohyun commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

except was an entry point only, so io.except(sid).to(room) worked and io.to(room).except(sid) did not exist, which is the ordering most socket.io code is written in. It now sits on the broadcast operator next to to / in / timeout, so the order they are chained in no longer changes the recipients. in joins the operator for the same reason, since the operator had to and lacked in while real socket.io has both.

Chaining returns a new operator over the merged sets and leaves the one it was called on alone, measured against real socket.io 4.8.3. An operator held in a variable stays the target it was built as, and a later chained call on it builds another operator. Only the two room sets and the timeout ever differ between operators, so each chaining method is one call to a private narrow() that carries the adapter, the socket map, and the volatile flag over.

Measured on the real target first, then matched. A second except unions with the first. socket.to(room).except(other) keeps the automatic sender exclusion and adds to it. except composes with timeout in either order, and the ack collection then covers exactly the surviving recipients. in is an alias of to on the operator as it is at the entry point. New dual-run tests cover the chaining orders, the namespace form, and the two timeout combinations, with non-receipt proven by the marker pattern.

Related issue

Closes #137

Checklist

  • Tests added or updated
  • Behavior verified against real socket.io

@electrohyun electrohyun added this to the v0.4.0 milestone Aug 5, 2026
@electrohyun electrohyun linked an issue Aug 5, 2026 that may be closed by this pull request
1 task done
@electrohyun electrohyun self-assigned this Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@electrohyun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1c239c27-a61f-4222-bcef-73ffed25d015

📥 Commits

Reviewing files that changed from the base of the PR and between 54e0c01 and eb8712a.

📒 Files selected for processing (6)
  • docs/glossary.ko.md
  • docs/glossary.md
  • src/broadcast-chaining.test.ts
  • src/broadcast-timeout.test.ts
  • src/contract.ts
  • src/mock-server.ts
📝 Walkthrough

Walkthrough

Broadcast operators now support immutable chaining for to, in, except, and timeout. Contracts, implementation, integration tests, timeout tests, and English and Korean glossary entries were updated.

Changes

Broadcast chaining

Layer / File(s) Summary
Broadcast operator contracts
src/contract.ts
BroadcastContract and TimeoutBroadcastContract now expose chainable in and except methods.
Immutable operator narrowing
src/mock-server.ts
Chained methods return derived operators with merged target and exclusion sets while preserving operator settings.
Broadcast behavior validation and documentation
src/broadcast-chaining.test.ts, src/broadcast-timeout.test.ts, docs/glossary.md, docs/glossary.ko.md
Tests cover chaining order, cumulative exclusions, immutability, sender exclusion, aliases, namespaces, and timeout acknowledgements. Glossaries describe the updated behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant BroadcastOperator
  participant Recipients
  Caller->>BroadcastOperator: chain to/in/except/timeout
  BroadcastOperator->>BroadcastOperator: create derived operator with merged sets
  BroadcastOperator->>Recipients: emit to included recipients
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation, API updates, documentation, and tests satisfy the requirements in issue #137.
Out of Scope Changes check ✅ Passed The changes remain within issue #137 and cover broadcast routing, API contracts, documentation, and related tests only.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly identifies the main change: support for chaining except on the broadcast operator.
Description check ✅ Passed The description directly explains the added except and in chaining behavior, compatibility goals, tests, and linked issue.

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.

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@src/broadcast-timeout.test.ts`:
- Around line 143-159: Update the excluded-recipient broadcast test around the
ask emission to use the ordering helpers from src/test-events.ts: track b’s ask
event, send a later marker to b, and await receive for that marker before
asserting ask was not received. Preserve the existing err and responses
assertions to validate acknowledgement collection, and apply the same
marker-based ordering approach to the additional covered block.

In `@src/contract.ts`:
- Around line 71-77: Update TimeoutBroadcastContract in src/contract.ts to
restore the timeout(ms: number): TimeoutBroadcastContract method so the type
remains chainable after to(), in(), and except(). Then update the Ensure<> proof
in the same file to include timeout() as part of the contract surface, keeping
the existing emit/to/in/except members unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7fa04fa9-383b-443f-8205-f4db25322f3a

📥 Commits

Reviewing files that changed from the base of the PR and between 54e0c01 and f9aac82.

📒 Files selected for processing (6)
  • docs/glossary.ko.md
  • docs/glossary.md
  • src/broadcast-chaining.test.ts
  • src/broadcast-timeout.test.ts
  • src/contract.ts
  • src/mock-server.ts

Comment thread src/broadcast-timeout.test.ts Resolved
Comment thread src/contract.ts Resolved
@electrohyun
electrohyun force-pushed the feat/except-chaining branch from f9aac82 to f2157cb Compare August 5, 2026 13:48
@electrohyun

electrohyun commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner Author

@coderabbitai Neither finding is applied. Reasons below.

excludedGot without a marker

A null err already settles the recipient set. The excluded socket never acks, so a collection that still included it would stay one ack short and could only answer with an Error once the timer expired. The flag is read after that. The socket.broadcast.timeout(ms) test above proves senderGot the same way. I added a comment at each new test so the reasoning sits next to it.

timeout() on TimeoutBroadcastContract

That member was never on the interface, so there is nothing to restore, and no Ensure<> line covers it. The contract stays a hand-picked subset of what the dual-run tests touch. The runtime operator does accept a second timeout, and declaring it needs a test that measures it on the real target first. Out of scope here.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@electrohyun The err === null assertion proves that the excluded socket is not in the acknowledgement set. The added local comments make this test contract clear. I withdraw that finding.

TimeoutBroadcastContract is intentionally a selected contract surface. Since it never declared timeout(), this PR does not remove that API. I withdraw that finding.


✏️ Learnings added
Learnt from: electrohyun
URL: https://github.com/electrohyun/smocket/pull/138

Timestamp: 2026-08-05T13:52:17.400Z
Learning: In this repository, `TimeoutBroadcastContract` is an intentionally hand-picked subset of the runtime broadcast operator API. Do not require it to declare runtime methods, such as a second `timeout()`, unless dual-run tests verify that contract behavior against real Socket.IO.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

Add except and in to the broadcast operator, so a broadcast can be narrowed in
any order. Real socket.io carries to / in / except / timeout on the operator
itself, while smocket had except as an entry point only. io.except(sid).to(room)
worked and io.to(room).except(sid) did not exist, which breaks the substitution
path for server code written in the common ordering. TypeScript users get a type
error and JavaScript users get `.except is not a function`. The gap was recorded
nowhere a user can see, and neither guard looks in this direction, since the
dual-run suite only exercises the forms the tests use and Ensure<> proves that
everything smocket declares exists on socket.io.

Chaining returns a new operator over the merged sets and leaves the one it was
called on alone, measured against real socket.io 4.8.3. An operator held in a
variable stays the target it was built as, and a later chained call on it builds
another operator. Only the two room sets and the timeout ever differ, so every
chaining method is one call to a private narrow() that carries the adapter, the
socket map, and the volatile flag over.

Measured and matched before the mock changed. A second except unions with the
first. socket.to(room).except(other) keeps the automatic sender exclusion and
adds to it. except composes with timeout in either order, and the collection
then covers exactly the surviving recipients. in is an alias of to on the
operator as it is at the entry point.

Add dual-run tests for the chaining orders, including the namespace form, and
the two timeout combinations. Non-receipt is proven with the marker pattern.
The broadcast operator entry described the object as holding the two room sets
and exposing emit. It carries to / in / except / timeout as well, each returning
a further operator over the merged sets, which is what lets a broadcast be
narrowed in any order.
@electrohyun
electrohyun force-pushed the feat/except-chaining branch from f2157cb to eb8712a Compare August 5, 2026 13:54
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@electrohyun The err === null assertion proves that the excluded socket is not in the acknowledgement set. The local comments document this test contract. I withdraw that finding.

TimeoutBroadcastContract intentionally exposes a selected contract surface. This PR does not remove timeout(). I withdraw that finding.

🐇

You are interacting with an AI system.

@electrohyun
electrohyun merged commit 39c4f2e into main Aug 5, 2026
2 checks passed
@electrohyun
electrohyun deleted the feat/except-chaining branch August 5, 2026 13:59
@electrohyun electrohyun added the enhancement New feature or request label Aug 5, 2026
@electrohyun electrohyun removed this from the v0.4.0 milestone Aug 5, 2026
@github-project-automation github-project-automation Bot moved this to Done in smocket Aug 6, 2026
@electrohyun electrohyun added the 📏 l Pull request changes 200–999 lines label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request 📏 l Pull request changes 200–999 lines

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

feat: support except chaining on the broadcast operator

1 participant