Skip to content

refactor(mobile): drop the unreachable dispose-before-ready notifications arm - #21293

Merged
Jinwoo-H merged 4 commits into
mainfrom
wrapup-tickets
Sep 17, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
wrapup-tickets

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What this is

The mobile-notifications.ts ticket from the RPC-foundation wrap-up: the ready arm of the notifications.subscribe stream 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

disposed is written at one site, the first statement of the disposer; the next statement calls unsubscribeStream(). Nothing suspends between them, so a ready callback observing disposed === true would have to run at or after that call. Every transport detaches the listener synchronously inside it:

  • Logical client: the disposer sets record.cancelled and 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.
  • Stream registry (direct client and the recording harness): 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, including replayAfterAuthentication.
  • Relay: cancel(id) sets cancelled and removes (mobile-relay-rpc-streams.ts:187-223); handleResponse bails 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 ready finds nothing.

Change

  • test(mobile): mobile-notifications.test.ts pins 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 for notifications.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.cancelled in the logical wrapper or remove(id) in the relay cancel fails exactly the new test). CI's changed-code quality gate then flagged three casts in the new test; the fake is now declared as the RpcClient port and the sent-frame reader narrows unknown instead 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: disposed is false for the whole synchronous subscribe call, 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 the dismiss arm 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 the subscriptionId learned from ready, and neither buildStreamUnsubscribe nor buildReadyStreamUnsubscribe knows 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 late ready for a cancelled stream; wiring it into buildReadyStreamUnsubscribe naively would duplicate the unsubscribe on the normal path and move three goldens. The new test asserts the gap rather than hiding it.

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
@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 9 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c5c15195-6c48-49f8-8381-fd5d98cd452d

📥 Commits

Reviewing files that changed from the base of the PR and between 8e8a9b3 and 7fcad89.

📒 Files selected for processing (4)
  • mobile/src/notifications/mobile-notifications.test.ts
  • mobile/src/notifications/mobile-notifications.ts
  • mobile/src/transport/mobile-relay-rpc-streams.test.ts
  • mobile/src/transport/stable-logical-rpc-client.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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ready arm — mobile-notifications.ts drops if (disposed) { unsubscribeServer(...); unsubscribeStream(); return }, leaving a comment that pins the invariant. I confirmed the arm is genuinely unreachable: the stream registry's generic else branch removes the stream synchronously for notifications.subscribe (buildStreamUnsubscribe returns null), the logical client sets record.cancelled and fences the listener on it, and the relay's cancel removes the stream so a late ready finds nothing.
  • Pinned the dispose-before-ready contract — the new tests drive the real RpcClientStreamRegistry: a ready reply landing after stop() triggers neither catch-up nor an unsubscribe, while ready-then-dispose still sends notifications.unsubscribe. Not vacuous, as the author notes.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Typed the notifications registry fake instead of asserting it — the as SentFrame and two as never casts are gone, replaced by a checked readSentFrame(request: unknown) reader and a fully typed RpcClient fixture. This clears the previously blocking changed-code quality gate (pnpm run check:code-quality:changed now reports 0 findings across all seven scans).
  • Pinned relay cancel fencing — new MobileRelayRpcStreams tests show a ready reply reaching a live subscription and being dropped (handleResponse returns false, listener silent) once the caller has cancelled.
  • Pinned logical-client fencing — new stable-logical-rpc-client tests drive a physical session with an inert disposer, so only the logical record.cancelled guard fences an event that lands after unsubscribe().

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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit eabfbaa into main Sep 17, 2026
23 checks passed
@Jinwoo-H
Jinwoo-H deleted the wrapup-tickets branch September 17, 2026 21:34
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…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
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.

1 participant