Skip to content

fix(setup): a key typed after an unfinished sequence isn't swallowed - #131

Merged
Derrors merged 2 commits into
mainfrom
fix/menu-keys-after-partial-sequence
Nov 15, 2026
Merged

Derrors merged 2 commits into
mainfrom
fix/menu-keys-after-partial-sequence

Conversation

@Derrors

@Derrors Derrors commented Nov 15, 2026

Copy link
Copy Markdown
Owner

What and why

The CI / macos check keeps failing on the "Terminal menus (PTY)" step. In the last 40 CI runs, 11 of the 15 macos failures were that step, while the same script never failed on Linux. Every one of them is in one of two cases:

Case in tests/terminal.py Failures Cause
Fragmented input: ESC [ B sent one byte every 40 ms, expect item 2 9 The script stalled past the 250 ms sequence budget between its own writes, so ↓ came out as "B". Test timing, not the reader.
Partial ESC [, then Ctrl+C after 350 ms, expect cancel 2 (one on #127) A real bug since #120, below.

The bug. #120 made the menu read bytes already there even past the 250 ms budget, so a key whose bytes all arrived isn't split when this process is late. The other side of that: when the process got to the input late, a Ctrl+C (or Enter) typed after an unfinished ESC [ was read as part of that sequence and lost; Ctrl+C then did nothing. A lone Esc followed by Ctrl+C likewise became one unknown key. A C0 control or DEL can't be part of an escape sequence, so read_key now ends the sequence there (Unknown, or Esc after a lone ESC) and queues the byte as the next key. Complete sequences and everything else read as before.

The test. The fragmented case now times its own writes. The behaviour is only guaranteed when they span less than the budget, so an attempt whose writes took over 200 ms is run again, up to five times. That makes the case deterministic: the reader's deadline starts no earlier than the first write, and bytes there at the deadline are read (#120). The split-terminal case waits 8 s for the first frame like the rest of the script, instead of 5 (a run under heavy local load timed out there).

A companion PR splits the macOS PTY step out of the required macos check.

Tests

1. Unit tests

  • cargo test --workspace --all-features --locked (462 passed), cargo clippy --workspace --all-targets --all-features --locked -- -D warnings and cargo fmt -p iphone-control -- --check pass (Rust 1.97.1, macOS).
  • New test a_control_key_after_an_unfinished_sequence_is_its_own_key: ESC [ ^C, ESC O ^C, ESC [ 1 CR, ESC ^C, ESC ESC, plus complete ESC [ B CR and ESC [ 5 ~ ^C, all written before the reader looks (the late case). It fails against main's read_key.
  • No existing test removed, ignored or loosened. The fragmented case asserts the same result; it only discards attempts whose own timing broke its precondition, and fails if five in a row do.
  • #[ignore] tests of the changed area run by hand: pty_menu, through tests/terminal.py.

2. Real-device regression

  • Not needed: the change is in the setup guide's terminal menus and their test; nothing talks to a phone.

tests/terminal.py on macOS (Darwin 27, Apple Silicon), with every core kept busy (yes × 2 × cores) to imitate a loaded runner:

this branch, idle:        5/5 passed
this branch, under load: 20/20 passed (two batches of 10)
main, under load:         9/10 passed (the 5 s split-terminal wait; the two CI failure modes did not reproduce locally)

3. Regression cases (docs/dev/regression-cases.md)

4. Real-device proof of the fix or feature

  • Not applicable: no phone involved. The proof is the unit test above (fails on main, passes here) and the PTY runs.

Checklist

  • MCP tools unchanged
  • No dependency changes
  • CHANGELOG.md and CHANGELOG.zh-CN.md: one line under Fixes
  • No private data

🤖 Generated with Claude Code

Derrors and others added 2 commits November 15, 2026 22:33
Since #120 the menu reads bytes already there even past the 250 ms
sequence budget. When this process got to the input late, a Ctrl+C (or
Enter) typed after an unfinished escape sequence was then taken into
that sequence and lost, and a lone Esc followed by Ctrl+C became one
unknown key. A C0 control or DEL can't be part of a sequence: it now
ends it and is read as the next key.

The PTY test was flaky on macOS runners in two places, both fixed:
- the partial `ESC [` then Ctrl+C case hit the bug above;
- the fragmented-input case sends one byte every 40 ms and relies on
  the script itself not stalling past the 250 ms budget. An attempt
  whose writes took over 200 ms proves nothing and is run again (up to
  five times).
The split-terminal case now waits 8 s for the first frame, like the
rest of the script, instead of 5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit 49e6eee into main Nov 15, 2026
6 checks passed
@Derrors Derrors mentioned this pull request Nov 15, 2026
@Derrors
Derrors deleted the fix/menu-keys-after-partial-sequence branch November 16, 2026 02:21
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