Skip to content

fix: review leftovers (task id escaping, transcoder limit, fewer polls, leftover HID state) - #193

Merged
Derrors merged 5 commits into
mainfrom
fix/review-leftovers
Nov 25, 2026
Merged

Derrors merged 5 commits into
mainfrom
fix/review-leftovers

Conversation

@Derrors

@Derrors Derrors commented Nov 25, 2026

Copy link
Copy Markdown
Owner

What and why

The last items left from the architecture review of 0.2.14:

  1. Escape task ids in the task list. A task's id is the page's own (t<n>) but is read back from localStorage on reload, and went into attributes (turnHtml, the run bar) and querySelector strings unescaped. Now esc() in HTML, CSS.escape() in selectors.
  2. At most 4 pages get the phone's HEVC transcoded at once. A page whose browser can't decode HEVC gets its own ffmpeg (decode 60 fps HEVC, encode H.264): a core or more each, and hardware encoders take few sessions. There was no limit. transcode::Slots gives out 4 places; a 5th page gets 503 with Retry-After: 10, shows "picture lost · retrying" and gets in once another page closes. Logged at most once a minute.
  3. Fewer polls from the control page. The task list comes with /api/info?tasks=1 (asked only while the page wants to pick up a task, at most every 3 s as before) instead of its own poll; /api/daemon carries the device list (devices, fixed, auto; /api/devices stays), so the device panel asks two requests a round instead of three; a background tab doesn't poll /api/info or the device panel and catches up when shown.
  4. Clear the "viewed remotely" a dead daemon leaves behind. A daemon that ends with the HID session open (the watchdog's exit(1) while a request is stuck holding the device lock, a crash, SIGKILL) never stops the screen media stream. On main, after kill -9 with a HID session open, the Dynamic Island kept the "viewed" icon and the phone didn't auto-lock for 5 minutes and more. The watchdog can't close the session first (the stuck request holds the lock), so the next daemon does: hid-open/<udid> is written when a session opens and removed when it closes properly; markers left over are cleared once that phone is ready, by opening a session and closing it (3 tries at most), with a line in the event log.

Not in this PR: moving the idevice pin. The latest release is still 0.1.68 (2026-09-15), which doesn't contain our pinned commit 89702099; master has 6 more commits but no release.

Tests

1. Unit tests

  • cargo test --workspace --all-features --locked: 553 passed; cargo clippy --workspace --all-targets --all-features --locked -- -D warnings; cargo fmt --check per package; node --test tests/viewer/*.test.mjs: 36 passed; tests/check_regression_cases.py: 0 missing
  • New: a task id from storage stays inside its attributes (fails on main, passes here), transcoding_pages_are_limited_and_their_places_come_back, a task list from the info poll is used as it is, markers_outlive_the_process_until_cleared
  • No existing test removed, ignored or loosened (the task tests now also load wantsTasks)
  • #[ignore] tests of the changed area: none apply

2. Real-device regression

  • Device, host: iPhone 15 Pro Max (iPhone16,2), iOS 27.2.1, native control; Debian 12
  • The device runs used this branch up to e8e011f; the last commit (asking for the task list at most every 3 s) only changes the page and was checked with the page tests
  • tests/device/run.py: 2 rounds, 32 calls, 0 failed
  • tests/device/scenarios.py --lock --url tools typing delivery batch menu idle lock url: 52/52
  • Not run on the iPad (WDA): item 4 only concerns the HID session (iOS 27+); the page changes are the same code on both

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

4. Real-device proof of the fix or feature

  • Device: iPhone 15 Pro Max, iOS 27.2.1
  • Item 4, before / after: on main, kill -9 of the daemon with a HID session open left the "viewed" icon and no auto-lock for 5+ minutes (checked by status without unlocking, then a screenshot). On this branch, the marker was there while the session was open; after kill -9 the new daemon was ready 13 s later, logged "cleared the phone's leftover viewed remotely", the marker was gone and so was the icon. After a normal 30 s idle close the marker is removed too
  • Item 2: five GET /video?udid=… at once: four got H.264 (one VAAPI ffmpeg each), the fifth 503 with Retry-After: 10, one warning in the log; when they closed the ffmpegs ended and a new /video got 200
  • Item 3: /api/info?tasks=1 carries tasks, /api/info doesn't; /api/daemon carries the same devices/fixed/auto as /api/devices
  • Untested: a page in a real background tab (no browser on the test host), the iPad, a macOS host

Checklist

  • MCP tool names, parameters and default outputs stay compatible (D10)
  • No new dependencies
  • CHANGELOG.md and CHANGELOG.zh-CN.md (Unreleased)
  • No private data in the outputs above

🤖 Generated with Claude Code

Derrors and others added 5 commits November 25, 2026 13:53
A task's id is the page's own (`t<n>`), but it is read back from
localStorage on reload and was put into attributes unescaped (turnHtml,
the run bar) and into querySelector strings (the elapsed-time timer). It
now goes through esc() in HTML and CSS.escape() in selectors, so an
edited stored record can't add attributes or break the timer.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
A page whose browser can't decode HEVC gets the phone's own video
(iOS 27+) as H.264 from an ffmpeg of its own, which decodes 60 fps HEVC
and encodes again: a core or more each without a hardware decoder, and
hardware encoders only take a few sessions. There was no limit. Now
`transcode::Slots` gives out 4 places; a page past that gets 503 with
Retry-After, shows "picture lost, retrying" and gets in once another
page closes. Logged at most once a minute.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Each page polled /api/info every 2 s, the task list every 3 s and the
device panel every 10 s with three requests, two of which
(/api/daemon, /api/devices) read the same daemon snapshot, and kept
doing so in a background tab. Now:

- the task list comes with /api/info (`?tasks=1`, asked only while the
  page wants to pick up a task: the same condition adoptTask had), so
  it has no poll of its own; adoptTask takes the list it is given
- /api/daemon carries the device list (`devices`, `fixed`, `auto`, as
  /api/devices, which stays), so the device panel asks two requests
- a page in a background tab doesn't poll /api/info or the device panel
  (the alert check already didn't) and catches up when shown again

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

A daemon that ends with the HID session open (the watchdog's exit(1)
while a request is stuck holding the device lock, a crash, SIGKILL)
never stops the screen media stream. On an iPhone 15 Pro Max (iOS
27.2.1) the Dynamic Island then kept the "viewed" icon and the phone
didn't auto-lock for 5 minutes and more, until something opened a HID
session again and closed it properly, which clears it.

The watchdog can't close the session first: the lock it is behind is
held by the stuck request. So the next daemon does it: a marker
`hid-open/<udid>` is written when a session opens and removed when it
closes properly (close_hid, drop_tunnel, and so shutdown). Markers found
at start are cleared in the supervision round once that phone is ready,
by opening a session and closing it (3 tries at most), with a line in
the event log.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
With the list in /api/info on every poll an idle page fetched its
10 KB (50 tasks) every 2 s instead of every 3 s. It is asked for at
most every 3 s again, as when it had a poll of its own.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit 5132eae into main Nov 25, 2026
9 checks passed
@Derrors
Derrors deleted the fix/review-leftovers branch November 25, 2026 06:33
@Derrors Derrors mentioned this pull request Nov 25, 2026
13 of 15 tasks
Derrors added a commit that referenced this pull request Nov 25, 2026
- /mcp chunked bodies: the raw body is bounded too (the decoded 1 MB plus
  64 KB of framing; endless trailer lines or long chunk extensions got
  413 instead of growing for a minute), read in 64 KB pieces (about 16
  decoding passes for 1 MB instead of 256), and a broken chunk gets 400
  instead of a closed connection
- /mcp answers: 1xx, 204 and 304 are never sent chunked (they have no
  body, RFC 9112 6.3)
- MjpegStream errors are in the page's language (the stream ran outside
  the request's language scope)
- the scoped-task foreground check matches `Route` like the other
  dispatch sites
- a page's native video connection that closes while it waits for the
  next media stream (an unlock holds the device for seconds) no longer
  opens the stream again for nobody
- the viewer lets its port go before stopping the agents
- media.rs's comment and the changelog no longer say unwatched frames
  aren't assembled: they are depacketized and scanned, only not copied
  or queued
- CONTRIBUTING's per-package fmt list includes ictl-ax, as CI does
- the Unreleased changelog: PR numbers on every line, the iOS 17-18 disk
  image fix (#186), sections and wording per CONTRIBUTING

Not changed: a TTL in front of the token file's stat (microseconds per
request; a revoked token would keep working for the TTL).

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