Repository navigation
fix: expose volatile after broadcast narrowing - #249
Conversation
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
14b8c65 to
09181ac
Compare
Summary
Smocket's
BroadcastOperatorstored its delivery modifier in a private constructor property namedvolatile. 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, andsocket.broadcast.volatilecould not produce another operator or callemit().This separates the internal state from the public surface. The private flag is now
isVolatile, while a publicvolatilegetter returns a newBroadcastOperatorcarrying the same adapter, socket map, target rooms, excluded rooms, and acknowledgement timeout with volatile delivery enabled. The original operator is left untouched. Because every laterto,in,except, andtimeoutalready 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.volatilereturns anotherBroadcastContractwith the current event map and socket-data generic.TimeoutBroadcastContract.volatilereturns another timeout broadcast with its decorated acknowledgement event map intact. This makesio.to(room).timeout(ms).volatile.emit(...)andio.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.
io.to(room).volatileemit,to,in,except,timeout, andvolatileio.of(nsp).to(room).volatilesocket.to(room).volatilesocket.broadcast.volatile.volatilecompared with its source operator.volatiletimeout(ms).volatilevolatile.timeout(ms)The installed Socket.IO source confirms the observed identity rule: the getter clones the current flags with
volatile: trueand 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
volatilegetter carries target and exclusion sets by value into the new operator, just like the existing narrowing methods. Reading it fromio.to(room)cannot widen the target; reading it fromsocket.broadcastcannot remove the sender's id-room exclusion. If a timeout was already added, the getter carriestimeoutMs; if timeout is added after volatile, the existingnarrow()path carriesisVolatile. 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.tsadds paired real-first cases for every affected public entry point. Server and namespace broadcasts compareto(room).volatilewithvolatile.to(room). Socket broadcasts compare bothsocket.to(room).volatileandsocket.broadcast.volatilewith 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/volatileorderings 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.tsexercises narrowed volatile broadcasts on the server, namespace,socket.to, andsocket.broadcastsurfaces. 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.mdis regenerated from the green dual run and links the five new runtime cases. The volatile broadcast narrowing entry is removed fromdocs/differences.mdsection 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