Skip to content

fix(mobile): resize the terminal when Desktop/Phone is toggled on a fresh terminal - #41061

Merged
AmoabaKelvin merged 1 commit into
mainfrom
sta-13790-mobile-terminal-display-mode
Nov 11, 2026
Merged

AmoabaKelvin merged 1 commit into
mainfrom
sta-13790-mobile-terminal-display-mode

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Supersedes #38170 by @zhangxaochen (their phone-side seq change is kept, with credit).

ELI5

On the phone, tapping Desktop or Phone on a freshly opened terminal sometimes did nothing: the terminal didn't resize and the button kept showing the old mode. The phone was throwing away the host's "I resized" message because it compared it against the wrong counter. Now it compares against the right one.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4

What Changed

Before: the phone opens a terminal that has printed only a few characters (a fresh C:\Users\me> prompt, for example). The user taps Desktop. The host resizes the PTY and sends a resized frame, and the phone drops it as stale. The terminal stays phone-sized and the mode button still reads Phone. A second tap gets dropped too, until enough layout changes pile up.

After: the same tap resizes the terminal and the button follows.

Mechanism: the phone filters out-of-order resized frames with a per-terminal high-water mark (acceptTerminalLayoutSeq). It set that mark from the binary scrollback frame's seq. On binary streams, that seq is the PTY output offset, a running character count (terminal-subscribe-binary-snapshot.ts sends serialized.seq). resized frames carry the layout seq, a separate small counter. When the output count was 1–20 above the layout seq, every following resized looked older than the mark and was dropped. That also skipped adoptDisplayMode, so the phone's mode state went stale.

The fix: the mark now comes from the subscribed frame, which on binary streams carries the layout seq (seq: layoutSeq). When subscribed has no seq (the lease-only path or older hosts), the mark is cleared, so nothing gets dropped. Scrollback no longer touches the mark. Each new stream still gets a fresh subscribed, so a reconnect or path switch resets the mark the way the old scrollback reset used to.

Why

The host's frames are correct. The wrong conclusion is made in one place: the phone reads a field whose meaning differs by frame type. Fixing the reader keeps every route covered and works with hosts that have already shipped. The alternative, changing the host's scrollback seq, would break desktop remote clients, which use that field to dedupe output.

#38170 also changed host-side restore logic: a cols < 80 "phone width" heuristic in the restore resolver, skipping notePaneGrid for phone layouts, and dropping restreams whose width differs. None of that is needed for the dropped-resize bug, and the 80-column threshold would misjudge narrow desktop panes. So this PR keeps only the phone-side seq change.

Linked Issue

Fixes #38163
Linear: STA-13819

Visual Proof

N/A. The visible effect is a Desktop/Phone toggle that now resizes on a near-empty terminal. It shows only when the terminal has printed 1–20 characters, and a real capture needs a full simulator pairing. Frame-level evidence instead:

Frame (binary stream) seq carries Example
subscribed layout seq 2
scrollback output offset 14
resized after tapping Desktop layout seq 3

Before: mark = 14 (from scrollback), and 14 − 3 ≤ 20 drops the resize. After: mark = 2 (from subscribed), so the resize is accepted. The new test terminal-stream-layout.test.ts plays exactly this sequence. It fails on main (both cases) and passes with the fix.

Testing

  • mobile: vitest run src/terminal/session/terminal-stream-layout.test.ts: 2 passed; both fail with the fix reverted.

  • pnpm check:changed: 15 checks passed.

  • Reviewed by Codex and a Claude subagent on the binary, multiplex, JSON, path-switch replay, recovery snapshot, resume, older-host and native-chat-covered routes. Both came back with no findings.

  • I manually tested these changes locally

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

  • Every added test fails without this change and avoids the test anti-patterns

Risk

The riskiest part is a stale resized that is now accepted. That could only happen if a resized from before the subscribe reached the new stream, and stream lifetimes already discard those. A phone talking to a host that sends no seq on subscribed runs with no mark until the first resized, which is fail-open. The change is phone page code, so it ships with the desktop's page bundle. No wire change. A plain revert backs it out.

Level: Low

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Phone-only logic, no platform or SSH paths. Works against older hosts (fail-open when subscribed has no seq).

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)
  • I stated the risk: what could break, for whom, and how to back it out
  • 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)

The phone's stale-resize filter took the binary scrollback frame's seq as
its layout high-water mark, but that seq counts output bytes, not layout
changes. A Desktop/Phone toggle on a terminal with little output then
looked older than the mark and was dropped, so the phone never resized
and kept showing the old mode. Seed the mark from the subscribed frame's
layout seq and leave scrollback out of it.

Co-authored-by: zhangxaochen <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The terminal layout sequence mark now updates on subscribed events and remains unchanged on scrollback events. Subscription handling checks the subscribed event before output acknowledgments and resume processing, without using the check’s return value to reject the event. Tests cover acceptance of a resize sequence above the subscription sequence and rejection of one below it.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 46c86

The change tracks layout sequences instead of output offsets. No merge-blocking risk was established.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly and concisely identifies the primary change: fixing terminal resizing when switching between Desktop and Phone modes on a fresh mobile terminal.
Linked Issues check Passed The change satisfies [#38163]. acceptTerminalLayoutSeq now seeds the layout mark from subscribed, clears it when subscribed has no numeric seq, and ignores scrollback for this mark. The subs…
Out of Scope Changes check Passed The changes stay within [#38163]. The implementation changes the mobile terminal stale-resize filter, and the tests directly verify that filter. No unrelated product behavior or platform path changes …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Description check Passed The pull request description is complete and focused. It includes the user impact, mechanism, rationale, linked issue, visual-proof explanation, targeted test results, risk and rollback details, AI di…
Full details: Linked Issues check

Explanation

The change satisfies [#38163]. acceptTerminalLayoutSeq now seeds the layout mark from subscribed, clears it when subscribed has no numeric seq, and ignores scrollback for this mark. The subscription hook records subscribed before later stream handling. The added tests cover acceptance of a resize below the binary scrollback output offset and rejection of an older layout sequence.

Full details: Out of Scope Changes check

Explanation

The changes stay within [#38163]. The implementation changes the mobile terminal stale-resize filter, and the tests directly verify that filter. No unrelated product behavior or platform path changes are present in the reviewed diff.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files.

Full details: Description check

Explanation

The pull request description is complete and focused. It includes the user impact, mechanism, rationale, linked issue, visual-proof explanation, targeted test results, risk and rollback details, AI disclosure section, scope notes, and checklist status. The full lint, typecheck, test, and build commands are not reported as passed, but this is a non-critical omission because targeted tests and changed-file checks are documented.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e0df0750-1c31-4d14-a34d-157e1e985940
Commits

Reviewing files that changed from the base of the PR and between e183ba8 and 46c86cb.

Files selected for processing: 3

  • mobile/src/terminal/session/terminal-stream-layout.test.ts
  • mobile/src/terminal/session/terminal-stream-layout.ts
  • mobile/src/terminal/session/use-mobile-session-terminal-subscription.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@AmoabaKelvin
AmoabaKelvin merged commit 8cac33b into main Nov 11, 2026
25 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.

Bug: Mobile terminal Desktop / Phone display mode toggle fails to resize or drops resized events

1 participant