Skip to content

fix: idle MCP servers don't block updates; native video survives HID closing - #190

Merged
Derrors merged 2 commits into
mainfrom
fix/mcp-update-lease
Nov 25, 2026
Merged

Derrors merged 2 commits into
mainfrom
fix/mcp-update-lease

Conversation

@Derrors

@Derrors Derrors commented Nov 25, 2026

Copy link
Copy Markdown
Owner

What and why

From the architecture review of 0.2.14 (operations, native unlocking):

  • An idle MCP server no longer blocks updates. iphone-control mcp held the shared maintenance lease for its whole life, and agents (Claude Desktop, Cursor, Claude Code) keep it running for hours, so update, and auto-patch in particular, was almost always busy on a desktop: on the test host five idle mcp processes of other sessions held it. The stdio server now takes the lease for each tool call (waiting up to 15 s while an update holds the lock, then going on without it; the daemon takes its own lease per device request anyway). The updater's check for older clients lets an iphone-control [--data-dir D] [--socket S] mcp … process be: one of this version is idle if the exclusive lease could be taken, and its next call reconnects to the new daemon (protocol::connect waits for a restarting one). mcp --url talks to another machine and takes nothing. Older mcp processes still hold the lease for life, so they keep blocking until their client restarts them.
  • The page's native video survives the HID session closing. Unlocking natively reads the lock screen with the HID session closed (iOS hides the keypad from accessibility while the screen is streamed), and a bitrate change for a low-bandwidth page reopens it. Each time, every ScreenStream ended and the page reconnected. Now the connection waits for the next media stream (once the device is free: unlocking holds it until done) at the same device and rate, asks for a keyframe and goes on. Ten closes in a row without a frame in between, or a changed device, still end it.

Tests

1. Unit tests

  • fmt (per package), cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, cargo test --workspace --all-features --locked: 535 passed
  • New: only_mcp_servers_idle_without_the_lease; the stream reopening has no unit test (it needs a HID session), see 4.
  • No existing test removed, ignored or loosened
  • #[ignore] tests of the changed area: none apply

2. Real-device regression

  • Devices, host: iPhone 15 Pro Max (iPhone16,2), iOS 27.2.1, native control; iPad mini 5 (iPad11,1), iPadOS 26.7.3, WDA; Debian 12
  • The device runs were made on a local branch combining this PR with the other pull requests from the same review (and a WDA keep-alive change that was then dropped); the lock scenario was also run on this branch alone (see below)
  • tests/device/run.py: iPhone 3 rounds, 48 calls, 0 failed; iPad 15 rounds, 240 calls, 0 failed
  • tests/device/scenarios.py: iPhone tools typing delivery collect editing fresh batch menu idle url 64/64 and lock 13/13; iPad tools typing delivery collect editing fresh batch menu url 60/60
  • Compared with main (run.py --repeat, compare.py): iPad 23.71 s → 24.01 s total, no step clearly slower; iPhone 17.09 s → 18.21 s, iphone_status and iphone_wait_for flagged slower on medians of 3, but main's own rounds range over the same values (status 0.02–0.29 s, wait_for 0.23–0.57 s)
  • This branch alone: iPad scenarios.py --lock lock 3 runs, 39/39 (before the video commit was added); iPhone native-video lock/unlock check (section 4) with this branch alone, both commits

On the iPad, scenarios.py --lock lock now and then fails one lock: the IOHID power press takes 5.4 s instead of 0.4 s (XCTest waiting for the app to go idle) and the screen stays on. It happens in stretches and on main too: in the same hour main passed 7 runs and failed 1 the same way. Not caused by this change; noted in the regression notes for later.

run.py output
this branch (combined):
### iPhone16,2, iOS 27.2.1, 430x932 pt, native
--- 48 calls, 0 failed, 64.4s in all        (3 rounds; the first step includes a 10 s automatic unlock)
### iPad11,1, iOS 26.7.3, 1024x768 pt, WDA
--- 80 calls, 0 failed, 120.6s in all       (5 rounds)
--- 80 calls, 0 failed, 120.7s in all       (5 rounds)
--- 80 calls, 0 failed, 118.5s in all       (5 rounds)

main (25a0333):
### iPhone16,2, iOS 27.2.1, 430x932 pt, native
--- 48 calls, 0 failed, 52.0s in all        (3 rounds)
### iPad11,1, iOS 26.7.3, 1024x768 pt, WDA
--- 80 calls, 0 failed, 122.3s in all       (5 rounds)

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

4. Real-device proof of the fix or feature

  • Devices, host: as above
  • Lease: with this build, a freshly started idle iphone-control mcp is not among the holders of maintenance.lock in /proc/locks; the five older ones are
  • Video, this branch alone: two /video?src=device connections open, lock button, then an action that unlocks first (10.3 s): neither connection ended; while locked the phone sent about a frame a second, during the unlock none for 10.1 s, then both resumed from a keyframe. On the combined branch the same (9.7 s unlock). Before this change the stream ended whenever the HID session closed (RecvError::Closed returned)
  • Untested: an actual update run with an idle new mcp (needs a signed release install), the low-bandwidth bitrate switch, macOS

Checklist

  • MCP tool names, parameters and default outputs stay compatible (D10)
  • No new dependencies
  • CHANGELOG.md and CHANGELOG.zh-CN.md (Unreleased); website/guide/cli.md (both languages) no longer asks to close MCP before updating
  • No private data in the outputs above

🤖 Generated with Claude Code

Derrors and others added 2 commits November 25, 2026 10:56
`iphone-control mcp` held the shared maintenance lease for its whole
life, and agents (Claude Desktop, Cursor, Claude Code) keep it running
for hours, so an update, and auto-patch in particular, was almost always
busy on a desktop. The server now takes the lease for each tool call
(waiting up to 15 s while an update holds the lock), and the updater's
check for older clients lets an `iphone-control … mcp` process be: one
of this version is idle if the exclusive lease could be taken, and its
next call reconnects to the new daemon (protocol::connect waits for a
restarting one). `mcp --url` talks to another machine and takes nothing.

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

Unlocking natively reads the lock screen with the HID session closed
(iOS hides the keypad from accessibility while the screen is streamed),
and a bitrate change for a low-bandwidth page reopens it. Each time,
every ScreenStream ended and the page reconnected. Now the connection
waits for the next media stream (once the device is free: unlocking
holds it until done) at the same device and rate, asks for a keyframe
and goes on; the page sees a pause. Ten closes in a row without a frame
in between, or a changed device, still end it.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors force-pushed the fix/mcp-update-lease branch from b906141 to bfcd181 Compare November 25, 2026 02:57
@Derrors
Derrors merged commit 460f0c1 into main Nov 25, 2026
9 checks passed
@Derrors
Derrors deleted the fix/mcp-update-lease branch November 25, 2026 03:02
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