When toggling a terminal to desktop mode on mobile, the server restores
the PTY to its correct size and sends a terminalFitOverrideChanged IPC.
This triggers the desktop renderer's React re-render cascade, which
runs safeFit on ALL terminal panes — including background tabs measured
at incorrect widths. Those stale pty:resize IPCs would overwrite the
correct PTY size and corrupt previousCols for future toggles.
Key changes:
- Add global 500ms suppress window that blocks all desktop renderer
pty:resize events after a mode change (the cascade takes ~360ms to
propagate through IPC → React → rAF → DOM → IPC)
- Track desktop renderer pane geometry in lastRendererSizes map so
handleMobileSubscribe uses actual split-pane width instead of stale
full-width PTY size
- Clear lastRendererSizes on desktop restore to prevent stale values
from persisting across subscribe cycles
- Register mobile subscriber even in desktop mode so toggling to
auto/phone can find the viewport
- Add onExternalPtyResize to update previousCols live when the desktop
renderer corrects pane geometry after restore
- Add comprehensive debug logging to /tmp/mobile-fit-debug.log
- Guard toggleDisplayMode against concurrent taps
- Add integration tests for onExternalPtyResize scenarios
Co-authored-by: Orca <help@stably.ai>