Repository navigation
fix(mobile): keep native chat from resizing the covered terminal PTY - #9988
Conversation
Native chat reads the agent transcript stream and never renders the terminal grid, but two paths still pushed phone dimensions into the covered PTY, reflowing the desktop terminal for no benefit: - The covered lease-only subscribe carried the cached viewport, and handleMobileSubscribe phone-fits the PTY whenever a viewport is present. The lease now omits the viewport so the host keeps the desktop baseline and late-binds on return to the terminal tab. - useTerminalViewportRefit measured the still-mounted WebView under the chat overlay and sent terminal.updateViewport on rotation, keyboard, text-scale, reconnect, and iOS-resume triggers. Refits are now suppressed while native chat covers the active terminal; the triggers already mark the viewport stale, and the return-to-terminal resubscribe re-measures.
📝 WalkthroughWalkthroughNative chat coverage now determines whether terminal subscription requests include viewport dimensions. Lease-only subscriptions pass no viewport to mobile subscription handling. The terminal viewport refit hook tracks native chat coverage, skips scheduled refits while chat covers the terminal, and incorporates coverage into target freshness checks. Tests cover subscription viewport selection, lease-only behavior, covered-terminal refit suppression, and session wiring. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
mobile/src/terminal/terminal-viewport-refit.test.ts (1)
138-148: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy liftTest the refit behavior at runtime instead of inspecting source text.
This assertion only verifies string ordering and wiring; it never runs the debounce or proves that measurement, RPC updates, and resubscription are skipped while chat is covered. Add a hook-level test with fake timers and mocked refs/RPC calls, covering both covered and uncovered paths. Verify the repository’s existing React Testing Library setup before choosing the test utility.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 63892a5b-8c2e-4061-bbc3-1d3407375dd0
📒 Files selected for processing (5)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/session/mobile-native-chat-terminal-stream.test.tsmobile/src/session/mobile-native-chat-terminal-stream.tsmobile/src/terminal/terminal-viewport-refit.test.tsmobile/src/terminal/terminal-viewport-refit.ts
…tablyai#9988) * fix(mobile): keep native chat from resizing the covered terminal PTY Native chat reads the agent transcript stream and never renders the terminal grid, but two paths still pushed phone dimensions into the covered PTY, reflowing the desktop terminal for no benefit: - The covered lease-only subscribe carried the cached viewport, and handleMobileSubscribe phone-fits the PTY whenever a viewport is present. The lease now omits the viewport so the host keeps the desktop baseline and late-binds on return to the terminal tab. - useTerminalViewportRefit measured the still-mounted WebView under the chat overlay and sent terminal.updateViewport on rotation, keyboard, text-scale, reconnect, and iOS-resume triggers. Refits are now suppressed while native chat covers the active terminal; the triggers already mark the viewport stale, and the return-to-terminal resubscribe re-measures. * fix(mobile): harden native-chat resize suppression
Summary
Native chat reads the agent transcript and never renders the terminal grid. This change prevents chat-covered mobile sessions from pushing phone dimensions into the host PTY through either the lease-only subscription or viewport-refit paths.
Problem
Opening a worktree in mobile native chat leaked PTY resizes even though native chat renders the agent transcript, never the terminal grid. The desktop terminal could reflow to phone dimensions while nobody on the phone was looking at it.
Two paths caused the leak:
handleMobileSubscribephone-fits the PTY whenever a viewport is present, including on an input-lease-only subscribe.useTerminalViewportRefitstill measured it and sentterminal.updateViewporton rotation, keyboard show/hide, text-scale change, frame resize, reconnect, and iOS resume.Fix
mobileNativeChatSubscribeViewportomits the viewport from covered lease-only subscriptions, preserving compatibility with older hosts.useTerminalViewportRefitskips measurement while native chat covers the active terminal.Out of scope and unchanged: after a user has viewed the terminal tab, returning to chat leaves the PTY phone-fit instead of restoring desktop dimensions. Restoring on chat re-entry would require a separate host-side ownership decision.
Reliability contract
terminal-runtime.mobile-stream-budget/ mobile terminal geometry authority — a native-chat-covered terminal owns only an input lease. It carries no output stream and no viewport capable of phone-fitting the PTY; async refits become stale when coverage begins.terminal-runtime.mobile-stream-budget, exercised with its three registered runtime stream suites plusterminal-subscribe-lease-only.test.ts; the focused mobile stream and viewport-refit suites also passed.handleMobileSubscribearguments and output registration counts.Testing
tsc --noEmit: passed.origin/mainmerge-tree check: clean.Screenshots
Not applicable; this is terminal ownership and resize behavior with no visual UI change.
AI Review Report
Reviewed the complete PR diff, adjacent mobile stream lifecycle, viewport update RPC, mobile presence ownership, stale async refit handling, cleanup paths, reconnect/foreground behavior, current reliability gates, and latest base-branch overlap. Two correctness gaps were found, fixed, and covered by deterministic tests.
Security Audit
No authentication, authorization, credential, persistence, or new protocol surface was added. The host change narrows accepted lease-only behavior by discarding viewport authority.
Notes
The change is backward compatible in both directions: the mobile omission protects current clients paired with older hosts, and the host boundary protects current hosts paired with older or regressed clients.