Skip to content

fix(terminal): let the active viewport reclaim PTY sizing - #191

Draft
Lint111 wants to merge 2 commits into
Ark0N:masterfrom
Lint111:agent/split-terminal-viewport
Draft

fix(terminal): let the active viewport reclaim PTY sizing#191
Lint111 wants to merge 2 commits into
Ark0N:masterfrom
Lint111:agent/split-terminal-viewport

Conversation

@Lint111

@Lint111 Lint111 commented Jul 29, 2026

Copy link
Copy Markdown

Summary

Make shared terminal sizing follow the viewport that is actively being used, without letting background restores or reconnects steal the PTY size.

This fixes the mobile-to-desktop recovery failure where the desktop canvas could remain constrained to a prior phone or keyboard layout until the user manually forced a redraw.

Root cause

A Codeman session has one PTY size even when several browser viewports are connected. The previous arbitration treated a desktop WebSocket connection as active simply because it existed, while the browser could also send automatic resizes during restore and tab loading. That made presence, layout announcement, and real user activity indistinguishable.

The browser also repeated fitAddon.fit() during the same keyboard or tab transition, exposing intermediate xterm layouts and adding avoidable visual stutter.

What changed

  • Add an explicit takeControl resize option to the session API and WebSocket protocol.
  • Keep desktop connection presence separate from recent desktop activity.
  • Remember each WebSocket connection's announced viewport and dimensions, then reassert that connection's size before accepted input.
  • Let explicit mobile interaction override a fresh desktop claim, and let explicit desktop interaction reclaim the PTY afterward.
  • Keep automatic startup, reconnect, solo-window, and session restoration resizes passive.
  • Reclaim desktop sizing on terminal/tab interaction and browser focus or visibility recovery.
  • Clear stale mobile keyboard layout state before a desktop tab measurement.
  • Route keyboard open/close sizing through the same resize API.
  • Avoid duplicate xterm fits when the caller already established the current dimensions.

Commit structure

  1. feat(terminal): add explicit viewport sizing ownership
    Adds the server arbitration contract, HTTP/WS protocol support, per-socket dimension reassertion, and focused route/unit coverage.
  2. fix(terminal): let active viewport reclaim PTY sizing
    Adds browser ownership signals, keyboard-aware layout recovery, reduced redundant fitting, and isolated Playwright coverage.

Validation

  • npx vitest run --config config/vitest.config.ts test/session-resize-arbitration.test.ts test/routes/session-routes.test.ts test/routes/ws-routes.test.ts - 126 passed
  • npx vitest run --config config/vitest.config.ts test/terminal-touch-tap.test.ts - 20 passed
  • Focused test/mobile/keyboard.test.ts viewport-control case - 1 passed
  • npx vitest run --config config/vitest.config.ts test/terminal-viewport-ownership.test.ts - 3 passed
  • npm run check:frontend-syntax
  • npm run check:public-assets
  • npm run typecheck
  • npm run lint
  • npm run build
  • Targeted Prettier checks and git diff --check

The complete mobile keyboard file is not claimed green: it currently has four unrelated baseline failures covering the existing accessory list, toolbar transform, CJK/local echo, and SGR tap behavior. The new viewport-control case passes independently.

Scope

This PR is limited to shared PTY viewport ownership and layout recovery. It does not include mobile navigation controls, terminal input persistence, bounded history streaming, response viewing, repository browsing, or session lifecycle caching.

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