Repository navigation
perf(mobile): pause the session-screen fallback poll while backgrounded - #9875
Conversation
Co-authored-by: Orca <help@stably.ai>
📝 WalkthroughWalkthroughUpdated session polling to check for an active app state before fetching session tabs and terminals. The session screen now refreshes immediately when the app returns to the foreground, schedules guarded polling every two seconds, and removes the interval and app-state listener during cleanup. Added source-based tests covering foreground transitions, polling cadence, subscription registration, and teardown. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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.
🧹 Nitpick comments (1)
mobile/src/session/mobile-session-startup-source.test.ts (1)
32-50: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftPrefer behavioral coverage for the polling lifecycle.
This test only matches source strings, so it cannot detect runtime regressions in AppState gating, listener registration, interval behavior, or cleanup. Extract the polling lifecycle into a small testable helper (or add a runtime harness), and document why source-level testing is required here.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 99905198-2b76-4d1d-9652-2c9a37b92a49
📒 Files selected for processing (2)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/session/mobile-session-startup-source.test.ts
Co-authored-by: Orca <help@stably.ai>
What
The mobile session screen (
session/[worktreeId].tsx) runs a fallback poll that sends bothsession.tabs.listANDterminal.listevery 2 seconds while the route is focused.useFocusEffectstops it when you navigate away, but not when the app goes to background — so a connected phone in your pocket kept firing ~60 RPC/min (plus host work + a radio wakeup) on this screen.This applies the same fix as #9857 (host screen): gate the 2s poll on
AppState.currentState === 'active'and immediately reconcile both lists on foreground return.refreshOnForegroundthat returns early unless the app is active.AppState'change'listener (attached before the immediate focus refresh, to cover the attach race) refetches both lists on return to'active'.The live
session.tabs.subscribesubscription and the terminal streams are untouched — those carry live data with no polling replacement.ELI5
When you had a terminal session open on your phone and put the phone away, it kept asking the computer "what tabs and terminals exist?" twice a second forever. Now it pauses that while the app is backgrounded and instantly catches up the moment you return. The live terminal output stream is never touched.
Proof of zero regression
session.tabs.subscribe, terminal streams) and existing in-flight / modal / optimistic-reconciliation behavior are preserved; only the fallback list poll is background-gated.pnpm typecheckclean, full mobile suite 2228 pass / 2 skipped (306 files),oxlintclean (screen stays within its frozen max-lines budget),oxfmt --checkclean. Added test covers: early background return, both fetches while active, listener-before-refresh ordering, resume refresh, the 2s interval, and both cleanup paths.Proof of perf improvement
While backgrounded this stops ~60 RPC/min (
session.tabs.list+terminal.list) and the associated host work + radio wakeups on the session screen; the added test asserts the poll body returns without issuing either RPC whileAppState !== 'active', and refetches on resume. Foreground steady-state keeps the exact 2s fallback cadence. Companion to #9857 (host screen).Made with Orca 🐋