Skip to content

fix: expose volatile after broadcast narrowing - #249

Merged
electrohyun merged 2 commits into
mainfrom
fix/volatile-broadcast-narrowing
Aug 12, 2026
Merged

electrohyun merged 2 commits into
mainfrom
fix/volatile-broadcast-narrowing

Conversation

@electrohyun

Copy link
Copy Markdown
Owner

Summary

Smocket's BroadcastOperator stored its delivery modifier in a private constructor property named volatile. TypeScript's private modifier hid that boolean from declarations, but the property still occupied the runtime name. Every narrowed broadcast therefore stopped at a boolean: io.to(room).volatile, io.of(nsp).to(room).volatile, socket.to(room).volatile, and socket.broadcast.volatile could not produce another operator or call emit().

This separates the internal state from the public surface. The private flag is now isVolatile, while a public volatile getter returns a new BroadcastOperator carrying the same adapter, socket map, target rooms, excluded rooms, and acknowledgement timeout with volatile delivery enabled. The original operator is left untouched. Because every later to, in, except, and timeout already constructs a new operator from the current state, volatile now composes in either direction with every supported narrowing instead of being available only as the first modifier.

The contract follows the same model. BroadcastContract.volatile returns another BroadcastContract with the current event map and socket-data generic. TimeoutBroadcastContract.volatile returns another timeout broadcast with its decorated acknowledgement event map intact. This makes io.to(room).timeout(ms).volatile.emit(...) and io.to(room).volatile.timeout(ms).emit(...) expose the same typed callback shape while ordinary narrowed broadcasts keep their original payload types.

Socket.IO reference

The common surface and operator behavior were probed independently against Socket.IO 4.7.5 and 4.8.3 before the mock changed. Both supported versions produced the same result.

Observation Socket.IO 4.7.5 and 4.8.3
io.to(room).volatile a broadcast operator with emit, to, in, except, timeout, and volatile
io.of(nsp).to(room).volatile the same operator surface, scoped to the namespace
socket.to(room).volatile the same operator surface, retaining sender exclusion
socket.broadcast.volatile the same operator surface, retaining sender exclusion
.volatile compared with its source operator a new object
two reads of .volatile two different objects
narrowing a volatile operator another new object; the volatile operator is unchanged
timeout(ms).volatile timeout and volatile flags are both present
volatile.timeout(ms) the same two flags are present

The installed Socket.IO source confirms the observed identity rule: the getter clones the current flags with volatile: true and constructs a new broadcast operator over the existing room sets. Smocket does not copy Socket.IO's internal flags object, but it reproduces the observable result with its existing immutable constructor state.

One real-first test detail exposed the delivery semantics ADR 0016 already records. Sending two volatile broadcasts to the same real client in the same turn can make the second see a temporarily non-writable transport and be dropped. The ordering-pair cases therefore complete the first public form before exercising its reversed form. They compare the operator surface and routing rule without accidentally turning the test into a backpressure race. The pre-connect case separately proves that the volatile flag itself survives the full narrowing chain.

Operator state and ordering

The volatile getter carries target and exclusion sets by value into the new operator, just like the existing narrowing methods. Reading it from io.to(room) cannot widen the target; reading it from socket.broadcast cannot remove the sender's id-room exclusion. If a timeout was already added, the getter carries timeoutMs; if timeout is added after volatile, the existing narrow() path carries isVolatile. Repeated reads and later narrowings never mutate the held operator.

This remains the delivery behavior accepted in ADR 0016. Connected recipients receive volatile broadcasts through the normal per-socket send path. A recipient still in the pre-connect window is skipped. The change only makes that existing flag reachable after narrowing; it does not add a transport, simulate network backpressure, or change when Smocket itself considers a volatile packet droppable.

Runtime and type coverage

src/volatile.test.ts adds paired real-first cases for every affected public entry point. Server and namespace broadcasts compare to(room).volatile with volatile.to(room). Socket broadcasts compare both socket.to(room).volatile and socket.broadcast.volatile with their volatile-first forms, while proving the sender remains excluded. Every non-recipient is checked with the marker pattern rather than a timeout.

A pre-connect case holds a narrowed base operator, reads its volatile derivative twice, and proves each read is a new object. The base sends a normal event that arrives, while both to/in/except/timeout/volatile orderings send events that are dropped before the client finishes reconnecting. The later normal marker establishes that both missing events would already have arrived if either chain had lost the volatile flag.

src/event-maps.typecheck.ts exercises narrowed volatile broadcasts on the server, namespace, socket.to, and socket.broadcast surfaces. It covers timeout-before-volatile and volatile-before-timeout callbacks and includes a negative payload case so a broad fallback type cannot make the fixture pass accidentally. The same expressions compile against the real Socket.IO generic surface through the existing parity fixture.

docs/conformance.md is regenerated from the green dual run and links the five new runtime cases. The volatile broadcast narrowing entry is removed from docs/differences.md section C because #231 is no longer an outstanding accidental gap. Locally, the Node dual run passes 428 tests across 48 files, the Chromium mock run passes 214 tests across 24 files, and typecheck, ESLint, Prettier, and the conformance drift check are green.

Related issue

Closes #231

Checklist

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

@github-actions github-actions Bot added the bug Something isn't working label Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 43 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: 673c72d1-610e-4818-90db-d687ea846d42

📥 Commits

Reviewing files that changed from the base of the PR and between d0bd7cf and 09181ac.

📒 Files selected for processing (6)
  • docs/conformance.md
  • docs/differences.md
  • src/contract.ts
  • src/event-maps.typecheck.ts
  • src/mock-server.ts
  • src/volatile.test.ts

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.

@github-actions github-actions Bot added the 📏 l Pull request changes 200–999 lines label Aug 12, 2026
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@electrohyun
electrohyun force-pushed the fix/volatile-broadcast-narrowing branch from 14b8c65 to 09181ac Compare August 12, 2026 06:08
@electrohyun
electrohyun merged commit bc0dd4d into main Aug 12, 2026
14 checks passed
@electrohyun
electrohyun deleted the fix/volatile-broadcast-narrowing branch August 12, 2026 06:09
@electrohyun electrohyun self-assigned this Aug 12, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in smocket Aug 27, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in smocket Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working 📏 l Pull request changes 200–999 lines

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix: expose volatile after broadcast narrowing

1 participant