Repository navigation
fix(screen): don't cancel opening the HID session when a page goes away - #195
Merged
Merged
Conversation
#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>
This was referenced Nov 25, 2026
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>
This was referenced Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
#194 raced the whole of
reopen_feedagainst the page closing (page_gone). Once it holds the device lock,reopen_feedopens 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_AFTERpause 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_feedtakes 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 --checkper packagea_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)2. Real-device regression
tests/device/run.py: 2 rounds, 32 calls, 0 failedtests/device/scenarios.py --lock tools batch lock: 31/313. Regression cases
4. Real-device proof of the fix
/video?src=deviceconnections, 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, itshid-openmarker was removed, and the Dynamic Island showed no "viewed" iconChecklist
🤖 Generated with Claude Code