Skip to content

fix(terminal): retry PTY write on EINTR instead of silently truncating user input#1145

Merged
datlechin merged 1 commit into
mainfrom
fix/terminal-write-retry-eintr
May 9, 2026
Merged

fix(terminal): retry PTY write on EINTR instead of silently truncating user input#1145
datlechin merged 1 commit into
mainfrom
fix/terminal-write-retry-eintr

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • TerminalProcessManager.write(_:) no longer treats every non-positive return from Darwin.write as "we're done". It distinguishes three cases: written > 0 (advance), written == 0 (log + abort, this should not happen on a regular fd), written < 0 with errno == EINTR (retry). Any other errno logs the byte position + errno and returns.
  • The static logger is marked nonisolated so it can be referenced from the nonisolated func write(_:) path under Swift 6 strict concurrency. Logger is Sendable, so this is correct.

Why this matters

This is bug B6 from the full-app audit. A signal interrupting write(2) mid-keystroke previously caused the inner loop to exit silently. The user's typed input was partially sent, and there was no log line to point at the cause. After this PR, EINTR retries (which is the standard POSIX contract), and any other failure leaves a Console line PTY write failed errno=<n> after <X> of <Y> bytes that names exactly how much input made it through.

The PTY here is created by forkpty(3) without O_NONBLOCK, so EAGAIN/EWOULDBLOCK should not occur. If a future change makes it non-blocking, the Console line will surface the issue and a proper poll(2)-based path can be added then.

Test plan

  • Manual: launch a terminal session, hold a key down, send kill -USR1 <pid> (or any signal that races) at the host process. Confirm input is not truncated and no error log is emitted.
  • Manual: write to a closed PTY (close fd from outside) and confirm the log line appears with the failing errno + offset.
  • swiftlint --strict clean.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@datlechin datlechin merged commit bbfee7f into main May 9, 2026
2 checks passed
@datlechin datlechin deleted the fix/terminal-write-retry-eintr branch May 9, 2026 16:15
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