Skip to content

fix(mobile): replay a page's streams only after its connection verdict - #39419

Merged
AmoabaKelvin merged 3 commits into
mainfrom
replay-streams-after-verdict
Nov 7, 2026
Merged

AmoabaKelvin merged 3 commits into
mainfrom
replay-streams-after-verdict

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

When the phone loses its connection to the desktop and gets it back, a page that was open has to wait until the phone has checked that the desktop and the page still understand each other. New requests from the page already waited for that check. The page's live feeds (terminal output, chat, status) did not: the phone re-opened them by itself the moment the connection came back, before the check. Now those wait for the check too, and they come back right after it, before anything else the page asked for in the meantime.

Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​148 $\color{#cf222e}{\Huge{\mathbf{−}}}$​82 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66

What Changed

  • Before: after a reconnect, or a switch to another path after a drop (for example LAN to relay), the native client re-sent every stream a page had open as soon as the new connection authenticated. That went around the bridge's verdict hold from perf(mobile): render the cached page build first and talk only after the connection's verdict #39174, so a page whose cached build was now outside the desktop's protocol window still sent its subscribes to that desktop.
  • After: the client asks a stream's owner before re-sending it. Subscribe options gain one optional callback, holdReplay(resend) => boolean. Both places that re-send without being asked call it: the stream registry's re-auth replay and the logical client's cutover. The bridge passes it for page streams. While the page's verdict is closed, or anything else is waiting, the verdict hold stores the resend under the page's stream id. When the verdict opens, it runs the stored re-sends first and then the page's parked frames. A page that walls or closes first never sends them.
  • Unsubscribes: a stream that was never sent on the current connection no longer sends an unsubscribe when it's cancelled. Nothing exists on the desktop for it to remove, and for a held stream that frame would also have reached the desktop before the verdict.
  • Native screens are unchanged. They pass no hook, so they replay as before.
  • Two pure moves keep the transport files under the 300-line cap: the stream request types go to rpc-client-stream-request.ts and the cutover error to logical-client-cutover-error.ts, which is still re-exported from its old path.

Why

The verdict belongs to each page document: it checks the cached page build's own window, and two documents can share one client. So the client can't decide on its own whether a page may talk. It has to ask the stream's owner, and the bridge already holds that answer. The re-send machinery stays in the client (latest terminal viewport, screencast bookkeeping, routing reset), so the bridge only decides when.

Ruled out:

  • A verdict at client level (status check before any replay). It would judge with the native build's window instead of the page's, and it would change native screens, which have no verdict hold.
  • Having the page resubscribe after an end. Older cached pages don't do that, so their streams would die.
  • Having the bridge drop and re-open its own streams. That duplicates replay, loses the viewport carried into it, and sends frames during teardown.

Linked Issue

No issue. Follow-up from #39174 (W7), item 103 in the mobile speed program's follow-ups sweep.

Numbers

Method: a local probe test, not committed. It runs a real DirectRpcClient over a mock socket, wrapped in the real logical client, with a real bridge host. The page holds 3 open terminal streams. Counts are exact; one run per arm because the scenario is deterministic. Base is this branch's merge-base f5f45784e28 with this change reverted in the four owning files, and head is this branch.

Desktop-bound stream frames Base Head
Re-auth on the same endpoint: subscribes sent before the page's verdict 3 0
Same: subscribes sent once the verdict opens 0 (already sent) 3
Cutover to a new session after a drop: subscribes before the verdict 3 0
Same: subscribes once the verdict opens 0 (already sent) 3
Page walls/closes before the verdict: frames reaching the new connection 6 (3 subscribe, 3 unsubscribe) 0

Round trips: unchanged. The re-sends move behind the status.get the page already makes, so a resumed stream's first frame waits about one status round trip longer after a reconnect than before. That wait is the point of the change.

Bundle (pnpm build:mobile-web, verify OK): 191 assets and 110 chunks on both, 12,840,253 total bytes and 9,724,145 of 9,961,472 budget bytes on both (+0).

Visual Proof

N/A. Nothing on screen changes. A page keeps showing "connecting" through the reconnect, as it already does after #39174. The only difference is when the phone sends stream frames, which the Numbers table counts.

Testing

  • New tests, each failing with its side of the change reverted:

    • Stream registry: a stream whose owner holds it is not re-sent on re-auth, goes out when the owner calls resend, and sends no unsubscribe if it's cancelled first.
    • Logical client: a held record is not attached at cutover and attaches on resume.
    • Verdict hold: a held re-send runs only once the verdict opens, before a request the page sent meanwhile.
  • Updated bridge-execution-host.test.ts to expect the hold on a page stream's subscribe options.

  • Ran npx vitest run src/transport src/mobile-web-shell src/test-support/rpc-recording src/session src/browser src/home src/notifications --maxWorkers=2. Everything passed except four tests that timed out under machine load (load average about 70) and pass when run alone. The RPC recording goldens are unchanged, because the harnesses model no verdict.

  • Checks: mobile typecheck, pnpm check:changed and pnpm build:mobile-web pass.

  • Not run: no simulator run. The change is in transport timing, which the probe above counts exactly.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

Risk

The riskiest part is a held stream that never resumes. Re-sends are stored only while the verdict is closed or something else is waiting. The bridge re-checks on every committed change of the verdict, so they run as soon as it opens. If the verdict never opens (status unreadable, or an incompatible desktop), the page's streams stay quiet, as its requests already do. That is fail-closed. A stored re-send that has gone stale does nothing: the stream was cancelled, the connection moved on, or the client closed.

What it doesn't cover: a live cutover, where the old session is still connected, never closes the verdict, so streams re-attach right away as before. That's a separate gap: the host status gates don't re-judge on a cutover between two connected sessions. The bridge's request hold has the same gap.

Mixed versions: the wire is unchanged, so old and new desktops behave the same. Old cached pages need no change, because they still rely on the native side to resume their streams. A plain revert undoes it.

Ships with the next store release (native shell JS).

Level: Medium

AI Disclosure

Review

Two review rounds, Codex and Claude. Round 1 found that bridge-execution-host.test.ts expected the exact subscribe options; fixed. Round 2 was clean from both. A design challenge before building (two rounds) added the no-unsubscribe-for-unsent-streams rule. It also made held re-sends count as waiting, so a page frame admitted between the verdict opening and the flush can't overtake them.

Rejected:

  • Asking the hold only in the registry, including on first subscribe, so the logical client needs no change. A cutover to relay attaches through the relay session's own streams, which have no registry, so that path would need its own hook. Bigger, not smaller.
  • Restoring the screencast's pending id inside resendHeld. That needs a socket write to fail with no close event while the verdict is publishing. No reachable case was found.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Mobile only. iOS and Android share this code, and there is no desktop change. Remote and SSH hosts go through the same per-connection verdict. Cost is one closure per stream per reconnect.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

Next included review available in 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7ddbd303-fbd0-4922-99dc-ffb45ab22dda
Commits

Reviewing files that changed from the base of the PR and between aed52aa and 8282484.

Files selected for processing: 14

  • mobile/src/mobile-web-shell/bridge-host-subscriptions.ts
  • mobile/src/mobile-web-shell/bridge-host-test-fakes.ts
  • mobile/src/mobile-web-shell/bridge-host-verdict-hold.test.ts
  • mobile/src/mobile-web-shell/bridge-host-verdict-hold.ts
  • mobile/src/mobile-web-shell/bridge-host.ts
  • mobile/src/mobile-web-shell/bridge/bridge-execution-host.test.ts
  • mobile/src/transport/direct-rpc-client.ts
  • mobile/src/transport/logical-client-cutover-error.ts
  • mobile/src/transport/rpc-client-stream-registry.test.ts
  • mobile/src/transport/rpc-client-stream-registry.ts
  • mobile/src/transport/rpc-client-stream-request.ts
  • mobile/src/transport/rpc-client.ts
  • mobile/src/transport/stable-logical-rpc-client.test.ts
  • mobile/src/transport/stable-logical-rpc-client.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A reconnect or a cutover after a drop re-sent every stream the page held
before the page's verdict for the new connection, bypassing the bridge's
hold. The client now asks the stream's owner before re-sending; the bridge
holds the re-send until the verdict opens. An unsent stream's cancel no
longer sends an unsubscribe.
@AmoabaKelvin
AmoabaKelvin force-pushed the replay-streams-after-verdict branch from 02815a8 to 8282484 Compare November 7, 2026 09:58
@AmoabaKelvin
AmoabaKelvin merged commit bdeb388 into main Nov 7, 2026
26 checks passed
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