Repository navigation
fix(mobile): restart the streamed browser pane on every return to the app - #22694
Conversation
… 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.
There was a problem hiding this comment.
✅ 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 —
MobileBrowserPanereplaces theappActiveboolean withforegroundVisit: number | null(nullwhile away, a new id per return), so abackground/activepair 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 —
useMobileBrowserStreamnow takesforegroundVisitand gates the subscribe onforegroundVisit === nullrather than!appActive; the effect dependency list is swapped accordingly. - Busy-flag cleanup (second commit) — drops the now-redundant unconditional
busyRef.current = falseat the top of the stream effect; both branches still assign it (early returnfalse, normal pathtrue), so behaviour is unchanged. - Behavioural test — new
mobile-browser-app-resume.test.tsxrenders 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.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe 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 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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 |

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
appActiveboolean. If the "left" and "came back" events are handled in the same React render, React seesfalsethentrue, 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
foregroundVisitinstead:nullwhile 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
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.tsxrenders the real pane with a fake client and fires AppState events: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
docs/reference/agent-skill-sharing-upstream-boundary.mdand 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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)