[Bug]: Settled threads leave iOS Simulators claimed and block other threads#32930

opened2d agobyEesoxjem

Area

apps/server

Steps to reproduce

  1. In thread A, open an iOS Simulator with device_open and use the returned agent-device command to open an app.
  2. Finish the work and settle thread A without explicitly closing its Device panel.
  3. In thread B, open the same simulator and run an agent-device command.

Expected behavior / scope decision

Settling a finished thread should release its exclusive agent-device claim so another thread can use the simulator, without powering it off.

This intended behavior needs maintainer confirmation: maintainer PR #25832 explicitly retains device sessions on settle, following terminal behavior. The device's exclusive claim makes this costly across threads. This report requests a decision on that remaining settle behavior, rather than treating the earlier PR as approval for it.

Actual behavior

The simulator remains claimed by the settled thread. The next thread gets:

text
1Error (DEVICE_IN_USE): Device is already in use by session "t3-…".
2Waited 15001ms for this device and it stayed busy.

The originating thread was already completed and settled. Closing its Device panel is required to release the claim.

Investigation and deterministic reproduction

At baseline 8e6a7323050e, settlement detaches provider sessions but does not enqueue device cleanup. Archive and deletion also omit that cleanup. DeviceService.close already supports host-owned agent-session release; the lifecycle paths do not call it.

An isolated server integration test opens a device through the real DeviceService, dispatches settle (manual and automatic), archive, or delete through the orchestrator, drains the effect worker, and checks that the thread has no device sessions. All four cases fail before the fix with one session still present.

Cleanup must also target the original session identity: a device reopened after settlement while cleanup is queued must survive, including when both opens have the same millisecond timestamp.

Environment

Reported: macOS, local iOS Simulator (iPhone Air), agent-device through T3 Code. Investigated baseline: 8e6a7323050e. Automated reproduction: Linux Sprite, real orchestration/device services with a simulated device host; no live iOS/Android host was exercised.

Search found #17470 (broader claim lifecycle) and #32511 (same settle symptom on Android/Windows). This is an additional iOS reproduction of the same underlying lifecycle issue, not a claim of a separate root cause.

Workaround

Return to the settled thread and close its device through the Device panel before using that simulator from another thread.

Impact

Blocks device verification in subsequent threads until the old claim is released.