Skip to content

fix(mobile): keep native chat from resizing the covered terminal PTY - #9988

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-mobile-native-chat
Jul 23, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-mobile-native-chat

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

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:

  1. The covered lease-only subscribe carried the cached viewport. handleMobileSubscribe phone-fits the PTY whenever a viewport is present, including on an input-lease-only subscribe.
  2. The terminal WebView stays mounted beneath the chat overlay, so useTerminalViewportRefit still measured it and sent terminal.updateViewport on rotation, keyboard show/hide, text-scale change, frame resize, reconnect, and iOS resume.

Fix

  • mobileNativeChatSubscribeViewport omits the viewport from covered lease-only subscriptions, preserving compatibility with older hosts.
  • The host RPC boundary independently ignores a viewport on every lease-only subscription, so older or regressed clients cannot resize a PTY through that path.
  • useTerminalViewportRefit skips measurement while native chat covers the active terminal.
  • Refit freshness now includes native-chat coverage, so a measurement already in flight is discarded if chat covers the terminal before it resolves.
  • Returning to the terminal still re-measures and phone-fits through the existing resubscribe path.

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

  • Invariant: 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.
  • Failure source: the reported path of opening native chat after a terminal viewport had been cached, plus rotation, keyboard, frame, reconnect, or foreground refits while chat covered the terminal.
  • Oracle: deterministic tests assert that covered client subscriptions omit the viewport, the host discards a supplied viewport for lease-only subscriptions, lease-only setup creates no output delivery, and refit freshness rejects native-chat coverage. The full mobile suite also covers pause/resume and late WebView readiness.
  • Gate: terminal-runtime.mobile-stream-budget, exercised with its three registered runtime stream suites plus terminal-subscribe-lease-only.test.ts; the focused mobile stream and viewport-refit suites also passed.
  • Provider/platform coverage: the client decision and host RPC contract are platform-neutral. The host boundary runs before local, daemon, SSH, or remote PTY resize behavior, so those provider paths receive no viewport from a lease-only request. Local macOS deterministic evidence is complete; live iOS/Android, SSH, WSL, Linux, and Windows device evidence remains uncollected.
  • Performance budget: covered refits perform zero WebView measurements and zero viewport RPCs. Lease-only subscriptions perform zero viewport resize and zero output-stream registration. No polling, timers, provider scans, subprocesses, stream listeners, or retained buffers were added.
  • Diagnostics: existing mobile terminal diagnostics retain subscription arm/skip, viewport measurement, and first-stream-event evidence; the host tests expose the exact handleMobileSubscribe arguments and output registration counts.
  • Residual gaps: no physical-device rotation/background artifact is attached. An update RPC already dispatched before chat becomes covered cannot be canceled, but in-flight measurement is now rejected before dispatch and covered lease resubscription cannot introduce another resize.

Testing

  • Mobile format, oxlint, and tsc --noEmit: passed.
  • Full mobile suite: 306 files passed; 2,235 tests passed and 2 skipped.
  • Runtime terminal stream gate plus lease-only contract: 4 files / 49 tests passed.
  • Node typecheck: passed.
  • Max-lines ratchet and diff checks: passed.
  • Latest origin/main merge-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.

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.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Native 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)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title is concise and accurately summarizes the main change to prevent native chat from resizing covered terminal PTYs.
Description check ✅ Passed The description includes the required sections and gives detailed summary, testing, review, security, and notes, though the testing checklist is not in template form.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
mobile/src/terminal/terminal-viewport-refit.test.ts (1)

138-148: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy lift

Test 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

📥 Commits

Reviewing files that changed from the base of the PR and between 56a31a5 and 59e5c48.

📒 Files selected for processing (5)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/mobile-native-chat-terminal-stream.test.ts
  • mobile/src/session/mobile-native-chat-terminal-stream.ts
  • mobile/src/terminal/terminal-viewport-refit.test.ts
  • mobile/src/terminal/terminal-viewport-refit.ts

@brennanb2025
brennanb2025 merged commit 4fce2de into main Jul 23, 2026
2 of 3 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
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