Skip to content

fix(mobile): restart the streamed browser pane on every return to the app - #22694

Merged
Jinwoo-H merged 3 commits into
mainfrom
mobile-browser-resume-restart
Sep 24, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
mobile-browser-resume-restart

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​151 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​151
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6

ELI5

On the phone, a browser tab from the desktop is shown as a live video of the page. When you leave the Orca app and come back, the phone is supposed to start that video again. If you left and came back quickly, it sometimes didn't, and the tab stayed frozen on an old picture.

What Changed

Before: after switching away from Orca and back, a browser tab could stay on a stale picture with no error, and taps showed no visible result. Leaving and returning again, or switching tabs, fixed it. On an Android emulator this happened in 1 of 26 leave-and-return cycles. It stayed stale for more than 45 seconds.

After: every return to the app starts a fresh stream, and the desktop sends a current picture as soon as it starts.

Mechanism: the pane stops its screencast subscription when the app leaves the foreground and opens a new one on return. That effect depended on an appActive boolean. If the "left" and "came back" events are handled in the same React render, React sees false then true, treats that as no change, and never re-runs the effect. This happens when the JS thread is held for the whole trip, as it is while the app is suspended or frozen. The old subscription is kept and no new one opens. If the desktop dropped that subscription while the phone was away, the pane keeps the last frame indefinitely and nothing restarts it. The desktop drops a viewer after 90 refused frames in a row. The transport's own recovery doesn't cover this case, because it only replays subscriptions after a socket reconnect.

The pane now keeps foregroundVisit instead: null while the app is away, and a new id on each return. A batched leave-and-return still changes the value, so the stream effect re-runs on every return. Nothing on the wire changes. The phone sends the same subscribe and unsubscribe calls it already sent on a normal return.

Why

  • Restart, not just request a fresh frame: the pane already restarts on a normal return. A restart is also the only fix when the desktop has ended the old subscription, because asking a dead subscription for a frame gets nothing back.
  • One nullable id, not a boolean plus a counter: one value carries both facts the effect needs, whether to stream and which visit this is. That leaves no second state to keep in sync.
  • Not in the transport: the transport can't tell that a live-looking subscription was ended on the desktop while the socket stayed up. The pane is what owns "stream while visible".

Linked Issue

Related: Linear STA-8024

Visual Proof

N/A. This is a timing fix with no new UI, and the stale frame is intermittent. It is covered by the behavioural test below, which fails on main.

Testing

  • New mobile/src/browser/mobile-browser-app-resume.test.tsx renders the real pane with a fake client and fires AppState events:

    • leave, then return in separate renders: the stream stops, then a new one starts (passes on main and with the fix).
    • leave and return batched into one render: the old stream closes and a new one opens. This fails on main (no new subscription) and passes with the fix.
  • Mobile: tsc --noEmit, full vitest (877 files / 9520 tests), tests-typecheck ratchet, oxfmt --check ., oxlint.

  • Repo: pnpm run check:code-quality:changed (0 new findings, including React Doctor), check:react-doctor:changed, and the mobile web closure/browser-pane config suites.

  • No emulator or device run of the fixed build.

  • I manually tested these changes locally

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

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Mobile only. No RPC, wire, or desktop change, so mixed client and desktop versions behave the same. SSH and relay hosts are unaffected beyond getting the same resubscribe a normal return already sends.

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)
  • 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)

… app

The browser pane stops its screencast when the app leaves the foreground and
starts a new one when it comes back, keyed on an `appActive` boolean. When the
leave and the return are handled in one React render (the JS thread was held
across the whole trip, as a suspended or frozen app is), React applies
false-then-true as no change, so the stream effect never re-runs: the old
subscription is kept and no new one starts. If the desktop ended that
subscription while the phone was away (it evicts a viewer whose socket
refuses 90 frames in a row), the pane shows the last frame it had
indefinitely, with no error and nothing that would restart it.

The pane now keeps `foregroundVisit`: null while the app is away and a new id
on each return. A batched leave-and-return still moves it to a new value, so
every return starts a fresh stream, and the host's start snapshot repaints the
pane.
@Jinwoo-H
Jinwoo-H marked this pull request as ready for review September 24, 2026 18:08

@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 — a mobile-only timing fix that makes the browser pane reopen its screencast on every return to the foreground, plus the behavioural test that pins it.

  • Per-return stream restart — MobileBrowserPane replaces the appActive boolean with foregroundVisit: number | null (null while away, a new id per return), so a background/active pair batched into one React render still changes the stream effect's dependency and reopens the subscription instead of netting the two changes out.
  • Hook rename through the same seam — useMobileBrowserStream now takes foregroundVisit and gates the subscribe on foregroundVisit === null rather than !appActive; the effect dependency list is swapped accordingly.
  • Busy-flag cleanup (second commit) — drops the now-redundant unconditional busyRef.current = false at the top of the stream effect; both branches still assign it (early return false, normal path true), so behaviour is unchanged.
  • Behavioural test — new mobile-browser-app-resume.test.tsx renders the real pane against a fake client with a retained AppState listener set, asserting the separate-render case stops then reopens, and the batched case closes the old subscription and opens a new one.

I verified the coverage empirically after installing mobile deps: the batched case passes on head and, with the two source files reverted to base 060743d8, fails exactly as advertised (expected [ { closed: false } ] to have a length of 2 but got 1). The full mobile/src/browser suite (20 files / 113 tests) and the mobile tests-typecheck ratchet both pass.

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

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 97aa4a1b-1cbf-4ec3-82d4-e89aacc13b7d

📥 Commits

Reviewing files that changed from the base of the PR and between 70c3128 and a463811.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 2822d166-d2f7-4064-96de-779a9892a23b

📥 Commits

Reviewing files that changed from the base of the PR and between 060743d and 70c3128.

📒 Files selected for processing (3)
  • mobile/src/browser/MobileBrowserPane.tsx
  • mobile/src/browser/mobile-browser-app-resume.test.tsx
  • mobile/src/browser/use-mobile-browser-stream.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The mobile browser pane replaces its app-active boolean with a foreground visit identifier. The stream hook uses that identifier to control stream activity. New tests cover stream closure on backgrounding, stream reopening on return, and a batched background-and-return transition.

Merge Risk: ⚪ Minimal · up to 70c31

The browser stream restarts after a return to the app, including a batched leave-and-return. No issue remains that should block merging after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: restarting the mobile streamed browser pane on every return to the app.
Description check ✅ Passed The description is mostly complete. It explains the user impact, mechanism, rationale, linked issue, testing, scope, and checklist status. It provides N/A with a reason for visual proof and documents …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

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.

@Jinwoo-H
Jinwoo-H merged commit c4e58fa into main Sep 24, 2026
24 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