Repository navigation
Description
What happened
Several threads could no longer use an iPhone simulator because their bound agent-device open command repeatedly returned:
Error (DEVICE_IN_USE): Device is already in use by session "<thread-A-session>".
The owning thread had completed and settled almost three days earlier. Restarting T3 had not released the claim.
Observed environment and timeline
- T3 Code Nightly desktop
0.1.11-nightly.20261117.4825, macOS 27.2.1 arm64, local iOS 27.0 simulator. - Thread A's final device command completed on Nov 15 at 17:44 UTC. The thread settled at 17:52 UTC.
- The current desktop/server processes started Nov 17.
- On Nov 18, thread B's repeated opens still named A's session. The claim's owner PID and process start time matched a surviving detached agent-device daemon started Nov 14.
- The surviving daemon reports
0.21.31, while this T3 build requires0.21.36.
Paths, simulator IDs, credentials and private conversation details have been omitted. No sessions were taken over or closed during this investigation.
Diagnosis
On current main, LocalDeviceHost.startAgentDeviceDaemon adopts a recorded endpoint whenever /health answers 200. It does not distinguish a daemon already owned by the current local host from one inherited from an earlier server process.
At the same time, DeviceService initializes its session list and bound-launcher map in memory. After restart, these records are gone, so thread-scoped cleanup cannot find the earlier daemon sessions. The old daemon can therefore keep devices claimed while T3 has no corresponding connection to close.
Source inspected at 2c4622efb429dfe68c9dc1ef3cd08668803f874b:
The precise event that originally left the daemon alive was not established. This report concerns adopting that surviving daemon on the next server instance.
Reproduction shape
- Thread A opens a local simulator through
device_openand starts its bound automation session. - The T3 server is replaced without its device-daemon finalizer completing, leaving the T3-owned daemon alive.
- Start T3 again with the same home directory.
- Thread B opens the same simulator and runs its own bound
open <app>.
Expected: T3 reconciles or retires the inherited automation sessions before exposing usable automation on the new server.
Actual: the old endpoint is considered ready because its health check passes; B receives DEVICE_IN_USE. Waiting does not release the claim.
These steps describe the observed restart failure mode; I did not deliberately crash the user's running server to reproduce it.
Related work
- [Bug]: Settling a thread doesn't release the Android device session, blocking other threads from using it #32511 / fix(server): settling a thread releases its devices #32524 concern releasing sessions when a thread settles. They do not reconstruct the records lost by a server restart.
- [Bug]: Archived or deleted threads keep holding their devices #34165 / fix(server): archiving or deleting a thread releases its devices #34175 concern archive/delete cleanup.
- agent-device daemon survives graceful Quit under the T3 app executable #33552 / fix(server): quitting stops an agent-device daemon left by an earlier server #33587 concern stopping an inherited daemon on graceful quit. This report concerns the next server accepting it before quit.
- [Bug]: Thread device claims are never released — device_close and thread settle leave simulators "in use" indefinitely #17470 is the original broader stale-claim report, now closed as a duplicate of the settlement issue.
Workaround
Restarting device support should retire the daemon, but also ends other device sessions. No workaround was applied to this user's live install.
Prepared by GPT-6.1-Sol through the Codex harness in T3 Code at the user's request.
Activity
juliusmarminge commentedon Nov 18, 2026
I tried to reproduce this on the current build and could not.
Commit 2c4622e (origin/main). A full DEVICE_IN_USE run needs a local iOS simulator or Android emulator driven by the server's local device host; this VM has neither (pool devices go through the Simlock host, not the local daemon). Tried to plant a real inherited daemon: installed agent-device 0.21.31 in scratch and ran
agent-device devices --jsonwith AGENT_DEVICE_STATE_DIR set to a scratch state dir, HTTP server mode, idle timeout 0 and a clean HOME. It answered in-process ({"devices":[]}), left no daemon.json and no daemon process, so the server's adoption path could not be exercised with real processes here. Confirmed the defect with a test instead: added 'replaces a healthy daemon left by an earlier server instead of adopting it' to apps/server/src/device/LocalDeviceHost.test.ts. It seeds daemon.json with a record from an earlier server (pid alive, version 0.0.1) whose /health answers 200, then calls ensureAgentReady.vp test run src/device/LocalDeviceHost.test.tson main: the new test fails (expected +0 to be 1: the startup command never runs and the old endpoint is returned); the other 25 tests pass.Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.