Skip to content

fix(screen): don't cancel opening the HID session when a page goes away - #195

Merged
Derrors merged 1 commit into
mainfrom
fix/screen-reopen-cancel
Nov 25, 2026
Merged

Derrors merged 1 commit into
mainfrom
fix/screen-reopen-cancel

Conversation

@Derrors

@Derrors Derrors commented Nov 25, 2026

Copy link
Copy Markdown
Owner

What and why

#194 raced the whole of reopen_feed against the page closing (page_gone). Once it holds the device lock, reopen_feed opens the HID session (Tunnel::hid → HidSession::open), which must not stop halfway: a media stream started and never stopped. Found in review.

Now only the wait races the page: the REOPEN_AFTER pause and taking the device lock, both safe to cancel. A page that goes away while an unlock holds the device still gets nothing opened for it; once the lock is taken nothing is cancelled. reopen_feed takes the reader to do this.

Tests

1. Unit tests

  • cargo test --workspace --all-features --locked: 554 passed; cargo clippy --workspace --all-targets --all-features --locked -- -D warnings; cargo fmt --check per package
  • New: a_page_that_goes_away_stops_waiting_for_the_next_stream (with the device lock held, a closed page ends the wait within 2 s without taking the lock)
  • No existing test removed, ignored or loosened

2. Real-device regression

  • Device, host: iPhone 15 Pro Max (iPhone16,2), iOS 27.2.1, native control; Debian 12
  • tests/device/run.py: 2 rounds, 32 calls, 0 failed
  • tests/device/scenarios.py --lock tools batch lock: 31/31

3. Regression cases

4. Real-device proof of the fix

  • Device: iPhone 15 Pro Max, iOS 27.2.1
  • Two /video?src=device connections, lock, then an action that unlocks first (10.3 s). One connection closed at 20.9 s, inside the 16.9–27 s stretch where the stream was closed and the daemon waited for the next one. The other resumed from a keyframe; no warning or error in the daemon's log. With both closed, the HID session closed after 31 s idle, its hid-open marker was removed, and the Dynamic Island showed no "viewed" icon
  • The halfway-opened stream itself (the page closing in the few hundred ms while the session opens) couldn't be provoked by hand; the fix removes the cancellation point

Checklist

🤖 Generated with Claude Code

#194 raced the whole of reopen_feed against the page closing. Once it
holds the device lock, reopen_feed opens the HID session (Tunnel::hid),
which must not stop halfway: a media stream started and never stopped.
Now only the wait (the pause, then the device lock) races the page; a
page that goes away while an unlock holds the device still gets nothing
opened for it, and once the lock is taken nothing is cancelled.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit 2f2242b into main Nov 25, 2026
7 checks passed
@Derrors
Derrors deleted the fix/screen-reopen-cancel branch November 25, 2026 07:49
Derrors added a commit that referenced this pull request Nov 25, 2026
…dening

From a full review of main after #195:

- Request heads: the target must be a path (`GET @evil.example/` made the
  HTTPS redirect `https://host:port@evil.example/`), no control
  characters or lone CR/LF (a header line in `Location`), HTTP/1.0 or
  1.1 only, one Host, one Content-Length of digits only, never a length
  and Transfer-Encoding together. Anything else gets 400. A chunked body
  outside /mcp gets 411 instead of being read as empty.
- Nothing of a body is read before the login, and the connection counts
  against its machine's limit until then: a keep-alive request read its
  whole body first, so 64 bodies that never came, from one machine
  without a token, held every place.
- Video acks past what was sent are taken as all of it (u64 underflow:
  a panic in debug, a frozen picture in release).
- Origin without a port: the scheme's default (443/80).
- AI task agents: the prompt goes last after `--` (claude's -p is a flag,
  so a prompt starting with `--permission-mode=...` was an option); the
  task's token reaches the MCP server through a 0600 file
  (`mcp --task-token-file`, hidden) instead of the command line every
  user can read; notification keys and the viewer login aren't passed
  to the agent; output lines that aren't UTF-8 are skipped instead of
  ending the run, and a run that ends early stops the agent's group.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Derrors added a commit that referenced this pull request Nov 25, 2026
…dening (#196)

* fix(viewer): request head checks, no body before the login, agent hardening

From a full review of main after #195:

- Request heads: the target must be a path (`GET @evil.example/` made the
  HTTPS redirect `https://host:port@evil.example/`), no control
  characters or lone CR/LF (a header line in `Location`), HTTP/1.0 or
  1.1 only, one Host, one Content-Length of digits only, never a length
  and Transfer-Encoding together. Anything else gets 400. A chunked body
  outside /mcp gets 411 instead of being read as empty.
- Nothing of a body is read before the login, and the connection counts
  against its machine's limit until then: a keep-alive request read its
  whole body first, so 64 bodies that never came, from one machine
  without a token, held every place.
- Video acks past what was sent are taken as all of it (u64 underflow:
  a panic in debug, a frozen picture in release).
- Origin without a port: the scheme's default (443/80).
- AI task agents: the prompt goes last after `--` (claude's -p is a flag,
  so a prompt starting with `--permission-mode=...` was an option); the
  task's token reaches the MCP server through a 0600 file
  (`mcp --task-token-file`, hidden) instead of the command line every
  user can read; notification keys and the viewer login aren't passed
  to the agent; output lines that aren't UTF-8 are skipped instead of
  ending the run, and a run that ends early stops the agent's group.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* fix(viewer): review of #196 (token file fails closed, stricter heads, token dir, stderr)

- mcp --task-token-file: an empty file, or one given with --url (also from
  IPHONE_CONTROL_URL), stops the server instead of running it outside the task;
  the viewer no longer passes IPHONE_CONTROL_URL/CA to its agents
- request heads: the target is visible ASCII only; header names are tokens
  (`Content-Length : 1` and a name with blanks are 400); a line without a
  colon (folded or garbage) is 400 instead of skipped
- token files live in the private directory's `tokens/`, beside the agent's
  `work/`, named with a counter, and removed if writing fails
- the agent's stderr is read by bytes like its stdout
- the login form is read within the head timeout (10 s), not the body's 60 s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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