Repository navigation
fix(mobile): resize the terminal when Desktop/Phone is toggled on a fresh terminal - #41061
Conversation
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]>
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
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.
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 aresizedframe, 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
resizedframes with a per-terminal high-water mark (acceptTerminalLayoutSeq). It set that mark from the binary scrollback frame'sseq. On binary streams, thatseqis the PTY output offset, a running character count (terminal-subscribe-binary-snapshot.tssendsserialized.seq).resizedframes carry the layout seq, a separate small counter. When the output count was 1–20 above the layout seq, every followingresizedlooked older than the mark and was dropped. That also skippedadoptDisplayMode, so the phone's mode state went stale.The fix: the mark now comes from the
subscribedframe, which on binary streams carries the layout seq (seq: layoutSeq). Whensubscribedhas 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 freshsubscribed, 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, skippingnotePaneGridfor 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:
seqcarriessubscribedscrollbackresizedafter tapping DesktopBefore: mark = 14 (from scrollback), and
14 − 3 ≤ 20drops the resize. After: mark = 2 (from subscribed), so the resize is accepted. The new testterminal-stream-layout.test.tsplays 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
resizedthat is now accepted. That could only happen if aresizedfrom before the subscribe reached the new stream, and stream lifetimes already discard those. A phone talking to a host that sends no seq onsubscribedruns with no mark until the firstresized, 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
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
subscribedhas no seq).Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)