Skip to content

device_open always fails on a simulator with an empty serve-sim launch lock, and the hub's 500 reason is dropped #31730

Open

Description

@ceolinwill

What happened

Note

🤖 Claude Opus 5.5 opening this issue on behalf of Will

device_open on one iOS simulator (iPhone 17, iOS 27.2) fails every time, 90–100 s after the call:

Device attach stream failed: Could not communicate with device support. Try refreshing devices.

The simulator boots. Only the attach fails. device_list and retries don't help. I hit it on Nov 4 and twice on Nov 5. Other simulators on the same machine open fine.

Diagnosis

An empty serve-sim lock was left for that simulator before the current hub started, and serve-sim never reclaims an empty lock.

  • $TMPDIR/serve-sim/launch-<udid>.lock is 0 bytes, from Nov 4 13:04:24. The running hub started at 13:05:41, so the file predates it. No process has it open. No other simulator has a .lock file.
  • serve-sim takes the lock with openSync(path, "wx") and then writes its pid. If the owner dies between those two calls, the file stays empty. lockHolderIsGone returns false for empty contents (state-lock.ts#L13), so nothing ever removes it. Hub restarts don't clear it either. expo-device-hub main has the same code, and T3 main still pins 0.19.1.
  • On POST /vendor/serve-sim/grid/api/start, clipboard setup waits the full 90 s for the lock and only logs the failure. Publishing the device state then fails on the same lock, and the route returns 500 {"ok":false,"error":"Could not release launch state for <udid>: …/launch-<udid>.lock is still locked. Retry cleanup after the active command finishes."}.
  • T3 drops that reason. hubJson runs filterStatusOk before it reads the body, and it maps every failure to request_failed (DeviceHubOperations.ts#L72-L91). attachIosStream always says "attach stream", even inside boot (L103-L105).

Ruled out:

Possible fixes: treat an empty lock older than a few seconds as stale, and show the hub's error on non-2xx responses.

Steps to reproduce

These steps run the installed hub 0.19.1 code with its own state dir, so they don't touch the running hub.

  1. Pick a shut-down simulator. I used an iPad Pro 13-inch (M5) on iOS 27.2. Create an empty lock: mkdir /tmp/ss && : > /tmp/ss/launch-<udid>.lock
  2. With SERVE_SIM_STATE_DIR=/tmp/ss, call the function behind grid/api/start:
    const { startDeviceInProcess } = await import("<expo-device-hub 0.19.1 package dir>/vendor/serve-sim/dist/middleware.js");
    await startDeviceInProcess(udid, 1, "/vendor/serve-sim", undefined, undefined, async () => {});
    The simulator boots, then the call throws Could not release launch state for <udid>: /tmp/ss/launch-<udid>.lock is still locked. Retry cleanup after the active command finishes. A second run fails the same way, and the empty file is still there.
  3. Delete the empty lock and run it again. It succeeds in 284 ms.

Upstream withStateLock alone, with a 3 s timeout: no file is acquired in 0 ms, a dead pid is reclaimed in 51 ms, and an empty file times out. I didn't plant a lock for the running hub on this shared machine. The iPhone 17 is the live case.

Version

T3 Code (Beta) desktop 0.1.7, expo-device-hub 0.19.1, agent-device 0.21.31

Environment

macOS 27.2 (26B123) arm64, 16 cores, Xcode 27.2 (27B52), iOS 27.2 simulators, local device host

Evidence

# my server.trace.ndjson, before it rotated
DeviceService.open / DeviceHubOperations.boot -> DeviceOperationError
  cause: HttpClientError: StatusCode: non 2xx status code (500 POST http://127.0.0.1:<hub>/vendor/serve-sim/grid/api/start)

# $TMPDIR/serve-sim for the iPhone 17 (844CDB49-…)
2026-11-04 12:43:49  533  server-844CDB49-….json        (pid 21020, gone)
2026-11-04 13:04:20    0  capabilities-844CDB49-….conf
2026-11-04 13:04:22   35  launch-844CDB49-….json
2026-11-04 13:04:24    0  launch-844CDB49-….lock        (not open by any process)

# running hub 0.19.1 started
Wed Nov  4 13:05:41 2026

Related issues

#17470 (stale agent-device claims; present here, not the cause). #25707, #24033 (same request_failed masking for list and screenshot).

Fix applied or workaround

None applied here, because the iPhone 17 is in use by another session. In my repro, deleting the empty launch-.lock fixed it at once. Restarting the hub doesn't help, because the file lives in $TMPDIR.

Filed by

Claude Opus 5.5 (claude-opus-5-5) in Claude Code, following .github/triage/PLAYBOOK.md

Activity

  1. added
    via-triage
    on Nov 5, 2026
  2. ceolinwill commented on Nov 6, 2026

    @ceolinwill
    Author

    Note

    🤖 Claude Opus 5.5 responding on behalf of Will

    Hit this again today on the same iPhone 17, and confirmed the fix on the live device.

    • This machine logged 7 failed device_open calls between 12:54 and 13:23 UTC: 4 of mine on the iPhone 17 and 3 from other threads. Each failed after 90–92 s. Load ranged from about 235 down to 8 on 16 cores.
    • I stopped the hub process, and T3 started a new one right away. The next device_open failed the same way, as expected, since the lock lives in $TMPDIR.
    • Posting {"udid":"<udid>"} straight to the new hub's /vendor/serve-sim/grid/api/start returned after 90.4 s: 500 {"ok":false,"error":"Could not release launch state for <udid>: …/launch-<udid>.lock is still locked. Retry cleanup after the active command finishes."}
    • The empty launch-<udid>.lock from Nov 4 13:04 was still the only .lock in $TMPDIR/serve-sim, and no process had it open. After I moved it aside, the next device_open succeeded at once.

    Still current on main: deviceToolVersions.json pins expo-device-hub 0.19.1, hubJson still runs filterStatusOk before reading the body, and upstream state-lock.ts hasn't changed since Oct 19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    via-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions