Repository navigation
refactor(mobile): drop the unreachable dispose-before-ready notifications arm - #21293
Conversation
Drives `subscribeToDesktopNotifications` through the real `RpcClientStreamRegistry` so the disposer's effect on a later `ready` reply is stated rather than implied. Both cases pass against the current module, before any code is removed. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…ions arm `disposed` is set only on the first line of the disposer, whose next statement detaches the stream listener in every transport, so the `ready` arm can never observe it. Removing the branch changes no behaviour and moves no golden. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
|
Warning Review limit reachedNext included review available in 9 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
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 |
There was a problem hiding this comment.
Important
The new test adds three type assertions on added lines that fail the blocking "Enforce changed-code quality" CI step (typescript/consistent-type-assertions with assertionStyle: never, which has no test-file exemption). Fixes inline.
Reviewed changes
- Deleted the unreachable dispose-before-ready
readyarm —mobile-notifications.tsdropsif (disposed) { unsubscribeServer(...); unsubscribeStream(); return }, leaving a comment that pins the invariant. I confirmed the arm is genuinely unreachable: the stream registry's genericelsebranch removes the stream synchronously fornotifications.subscribe(buildStreamUnsubscribereturnsnull), the logical client setsrecord.cancelledand fences the listener on it, and the relay'scancelremoves the stream so a latereadyfinds nothing. - Pinned the dispose-before-ready contract — the new tests drive the real
RpcClientStreamRegistry: areadyreply landing afterstop()triggers neither catch-up nor an unsubscribe, while ready-then-dispose still sendsnotifications.unsubscribe. Not vacuous, as the author notes.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
The notifications comment claims every transport detaches a listener inside its disposer, but only the stream registry was pinned. Adds the same live/cancelled differential pair to the relay stream manager and the logical client, the latter against a physical session with an inert disposer so only the logical guard can fence the late event. Drops a self-comparing assertion to a length check. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…ng it The changed-code quality gate rejected three `as` casts. The fake client is now declared `RpcClient`, so the compiler checks it really satisfies the port, and the registry's `unknown` send port is narrowed by a reader that throws on a frame without a string id and method rather than asserting one. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Typed the notifications registry fake instead of asserting it — the
as SentFrameand twoas nevercasts are gone, replaced by a checkedreadSentFrame(request: unknown)reader and a fully typedRpcClientfixture. This clears the previously blocking changed-code quality gate (pnpm run check:code-quality:changednow reports 0 findings across all seven scans). - Pinned relay cancel fencing — new
MobileRelayRpcStreamstests show areadyreply reaching a live subscription and being dropped (handleResponsereturnsfalse, listener silent) once the caller has cancelled. - Pinned logical-client fencing — new
stable-logical-rpc-clienttests drive a physical session with an inert disposer, so only the logicalrecord.cancelledguard fences an event that lands afterunsubscribe().
Both new suites are non-vacuous: the relay case fails if cancel stops removing the stream, and the logical case fails if the record.cancelled guard is dropped. The deferred transport gap (dispose-before-ready leaves the host holding the subscription) remains documented as a follow-up and is asserted rather than hidden by the relay test.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…ions arm (stablyai#21293) * test(mobile): pin the desktop-notification dispose-before-ready contract Drives `subscribeToDesktopNotifications` through the real `RpcClientStreamRegistry` so the disposer's effect on a later `ready` reply is stated rather than implied. Both cases pass against the current module, before any code is removed. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * refactor(mobile): drop the unreachable dispose-before-ready notifications arm `disposed` is set only on the first line of the disposer, whose next statement detaches the stream listener in every transport, so the `ready` arm can never observe it. Removing the branch changes no behaviour and moves no golden. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(mobile): pin cancel fencing in the relay and logical stream layers The notifications comment claims every transport detaches a listener inside its disposer, but only the stream registry was pinned. Adds the same live/cancelled differential pair to the relay stream manager and the logical client, the latter against a physical session with an inert disposer so only the logical guard can fence the late event. Drops a self-comparing assertion to a length check. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(mobile): type the notifications registry fake instead of asserting it The changed-code quality gate rejected three `as` casts. The fake client is now declared `RpcClient`, so the compiler checks it really satisfies the port, and the registry's `unknown` send port is narrowed by a reader that throws on a frame without a string id and method rather than asserting one. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

What this is
The
mobile-notifications.tsticket from the RPC-foundation wrap-up: thereadyarm of thenotifications.subscribestream callback had a dispose-before-ready branch (if (disposed) { unsubscribeServer(...); unsubscribeStream(); return }). A prior review called it dead. This PR proves it, deletes it, and pins the contract it was guessing at.Why the branch could not run
disposedis written at one site, the first statement of the disposer; the next statement callsunsubscribeStream(). Nothing suspends between them, so areadycallback observingdisposed === truewould have to run at or after that call. Every transport detaches the listener synchronously inside it:record.cancelledand deletes the record (stable-logical-rpc-client.ts:131-139); the only site that invokes the listener is guarded by!closed && !record.cancelled && generation === subscriptionGeneration(:308-312), and the deleted record is gone from the migrate/replay loop.dispose(id)removes the stream (rpc-client-stream-registry.ts:198-221); every listener-invoking path looks the stream up first and bails when absent, includingreplayAfterAuthentication.cancel(id)setscancelledand removes (mobile-relay-rpc-streams.ts:187-223);handleResponsebails on a missing stream and the cancelled-subscription branch never calls a listener.DirectRpcClient, the relay session and the recorder only delegate to those three, and none of the disposers re-enter a listener.The subscribe-to-ready window is the same case: disposing mid-flight removes the stream whether or not the request was sent, so the later
readyfinds nothing.Change
test(mobile):mobile-notifications.test.tspins the dispose-before-ready contract (no catch-up, no dismiss handling after dispose). Not vacuous: skipping the dispose fails it on the catch-up assertion.refactor(mobile): the unreachable arm is deleted with a one-line comment. Behaviour-neutral, confirmed by running the suite with the branch restored and removed.Zero goldens moved (recording suites 22 files, 965 passed;
mobile/rpc-foundation/untouched). Notifications tests 4 passed; oxlint and oxfmt clean.Review
Round 1 (adversarial): ship as-is. The reachability argument was re-derived independently from every listener-invoking site in
mobile/src/transport(five in the registry, four in the relay, one in the logical client) and holds fornotifications.subscribe, including the subscribe-to-ready window. Two nits folded: the sent-frames assertion no longer references itself, and the comment's transport claim is now pinned for all three transports (registry in the notifications test; relay and logical client each get a differential cancel-fencing pair, mutation-proved: dropping!record.cancelledin the logical wrapper orremove(id)in the relaycancelfails exactly the new test). CI's changed-code quality gate then flagged three casts in the new test; the fake is now declared as theRpcClientport and the sent-frame reader narrowsunknowninstead of asserting.Round 2 (fresh reviewer): ship as-is, re-derived the same conclusion. It also corrected an earlier claim that the deleted arm hid a temporal-dead-zone hazard:
disposedis false for the whole synchronoussubscribecall, so the arm would have been skipped there too; the same argument that kills the arm kills that hazard, and it is not cited here as a reason. Noted, not changed: the!disposed &&guard on thedismissarm is dead by the identical argument and stays; this PR deletes only what the ticket named.Follow-up, not in this PR
The branch was aiming at a real gap: only this module sends
notifications.unsubscribe, using thesubscriptionIdlearned fromready, and neitherbuildStreamUnsubscribenorbuildReadyStreamUnsubscribeknows the method. Dispose-before-ready therefore leaves the host holding a subscription nobody reads until the socket closes. The fix belongs in the transport, which still holds the latereadyfor a cancelled stream; wiring it intobuildReadyStreamUnsubscribenaively would duplicate the unsubscribe on the normal path and move three goldens. The new test asserts the gap rather than hiding it.