Fix SSH PTY terminal ownership and reject mismatched daemons

Merged
AU
2mo ago
+1526-577

Fixes #12713.

SSH attaches could restore canonical input and echo while still forwarding. Each attach now owns one original termios snapshot, checks the connected daemon's version before mutating stdin, and enters raw forwarding once. Reconnects discard detached input; incompatible versions are rejected without changing queued caller input.

Review fixes preserve the remote lifecycle until authoritative reconciliation confirms its end, make output backpressure cancellable, and restore terminal settings for HUP/INT/TERM/QUIT. The terminal owner, compatibility policy and cancellation/output primitives live in CmuxFoundation; localized errors remain in the CLI. Test readers use one idempotent EOF-based stop-pipe owner.

Verified at 294a1c394bd5656c40224e4965a7caf5e16f0eef:

  • Tagged Debug app built on a leased macOS 26.5.1 / Xcode 26.3 Mac with committed package pins. The downloaded, signed local app reports [294a1c394] and was launched for dogfood.
  • 47 package SSH PTY tests pass.
  • 11 CLI behavior tests / 26 cases pass against the actual tagged app's bundled CLI. The checked-in tests/helpers run in an isolated SwiftPM host with only the executable/version locator replaced; the CLI, real PTYs and socket boundaries are unchanged.
  • The same harness reproduces earlier lifecycle-retirement, SIGQUIT restoration and queued-input bugs. A saturated output pipe also demonstrates the old HUP/INT/TERM hang. Test-only commits precede the fixes.
  • 21 real SSH checks pass through the running tagged app: fresh raw mode, arrows, Tab before Enter, Ctrl-C, Unicode multiline bracketed paste, forced transport loss, reconnect with preserved shell state, exactly-once replay, session-lost respawn, and exact original termios after exit/disconnect.
  • All seven inline review threads have replies and are resolved. The current base merged cleanly. Hosted native SSH run passes all 12 tests (11 attach tests plus resize-before-input) in run 35189508606. Notification integration passes 101 native tests in run 35189288965. Required checks are green.
  • Localization audit: both new errors and the existing flush diagnostics have all nine supported macOS locales. Six catalogs, zero parity errors. Pbxproj wiring/normalization and whitespace checks pass.

The synchronous CLI transport remains synchronous. Nonblocking output waits once on readiness or cancellation in the kernel; there is no timed polling or sleep-based synchronization. Bounded callback locks coordinate descriptor/signal ownership. Original output flags are restored. Mechanical policy candidates and the contradictory locale suggestions are triaged with code and repository-contract evidence in the PR comments.

Daemon packaging stays in #12720. Live verification uses its matching 0.64.24 daemon fixture; packaging changes are not duplicated here. workspace.remote.pty_bridge remains denied by the remote relay; no allowlist entries or ID parameters are added.

Two CloudSurface test compile errors and a stale pairing test referencing removed APIs from main were aligned with the current test target so native CI can compile. No pairing runtime behavior changes are included.

Evidence: cmux-assets/issue-12713-ssh-pty-cooked/closeout/validation-status.md, tagged-build identity/signature, test logs and raw PTY transcripts. Earlier before/after screenshots and after-demo.mp4 remain in the parent evidence directory. Dev build: http://127.0.0.1:17320/issue-12713-ssh-pty-cooked.