[Bug]: agent-device's iOS runner outlives its daemon and keeps the Simulator booted for hours after the claim is gone
Before submitting
- [x] I searched existing issues and did not find a duplicate.
- [x] I included enough detail to reproduce or investigate the problem.
Related to #32511, which covers a device session that stays claimed after its thread ends. This report is a different case: no claim remained, but the agent-device daemon that owned the iOS runner had exited. Its xcodebuild runner was orphaned, and the Simulator stayed booted for hours with nothing using it.
Area
apps/desktop
Steps to reproduce
- In a thread,
device_openan iOS Simulator (iPhone 17, iOS 27.2) and drive it with the boundagent-devicefor a few minutes (open, snapshot, press). - The thread finishes. Later the agent-device daemon that started the runner exits. In my case T3 Code started a new daemon, and the old one was gone.
- Run
pgrep -fl AgentDeviceRunnerUITestsandxcrun simctl list devices booted.
Expected behavior
When the daemon (or the session) that owns the runner exits, crashes or is replaced, it stops its xcodebuild runner. If T3 Code booted the Simulator for that session, T3 Code shuts it down, or at least shows it as idle and offers to shut it down.
Actual behavior
The runner survived its owner by more than 4 hours:
PID 93154 PPID 1 started 14:10:05 local, still running at 18:29 (elapsed 4:19:26)
xcodebuild test-without-building
-only-testing AgentDeviceRunnerUITests/RunnerTests/testCommand
-parallel-testing-enabled NO -test-timeouts-enabled NO -collect-test-diagnostics never
-maximum-concurrent-test-simulator-destinations 1 -destination-timeout 20
-xctestrun ~/.agent-device/apple-runner/derived/ios-simulator/cache-c52feefa3c06b487/Build/Products/AgentDeviceRunner.env.session-4765193F-03D6-4772-98B8-9279CE814781-owner-92654-28be0812-54905.xctestrun
-destination platform=iOS Simulator,id=4765193F-03D6-4772-98B8-9279CE814781
- PPID 1: the runner had been reparented to launchd.
- The owner named in the xctestrun file name (
owner-92654) no longer existed. - The running agent-device daemon (started by T3 Code) was only 21 minutes old, so it was not the owner.
~/.agent-device/device-claims/was empty, so no session held the device.lsof -ion the runner showed no sockets.- The Simulator was still booted, with its whole iOS userland running (Siri,
intelligenceflowd/intelligencecontextd, widget extensions,MTLCompilerServiceand others). - The last session that used it (
t3-129cdd9ba22419d2748cbf64) logged requests from 14:11 to 14:22, ending with a failedscrollintoview("Unknown command"). No close, release or detach event was logged after that.
Impact: this Mac has 8 cores and 16 GB of RAM, and a second Simulator was running tests. The leaked Simulator pushed the machine into heavy swapping: load average 210–280, 7.7 GB of 9 GB swap in use, up to 105 processes stuck, sys CPU time 28–54%. T3 Code showed the "… is overloaded" banner. After kill 93154 and xcrun simctl shutdown 4765193F-…, the load fell from about 280 to 56 within a minute, and swap use dropped to 2.8 GB.
Suggested fixes:
- Tie the runner's lifetime to its owner. For example, the runner (or a small watchdog) polls the
owner-<pid>process and exits once it is gone. Alternatively, startxcodebuildin the daemon's process group and kill that group on shutdown. - On daemon startup, find
AgentDeviceRunner…owner-<pid>…runners whose owner PID is dead and stop them. The owner PID is already in the file name. - Shut down a Simulator or emulator that T3 Code booted once no claim has held it for an idle period, or show it in the Device panel as leftover, with a shutdown button.
A minor, related point about the overload banner on macOS: it said "Work waits for a free CPU most of the time", but CPU was 15–45% idle. The real bottleneck was memory (swap nearly full, high sys time). When swap or memory pressure is high, a message such as "low on memory" would point users at the right cause. See #44899 for a similar mismatch on Linux.
Impact
Major degradation or frequent failure
Version or commit
T3 Code (Nightly) 0.1.14-nightly.20261129.5425, agent-device 0.21.41
Environment
macOS 27.3, Xcode 27.2, iOS 27.2 Simulator runtime, 8 cores / 16 GB RAM, Claude thread
Logs or stack traces
$ ps -o pid,ppid,etime -p 93154
PID PPID ELAPSED
93154 1 04:19:26
$ ps -p 92654 # owner named in the xctestrun file
(no such process)
$ ls ~/.agent-device/device-claims/
(empty)
$ xcrun simctl list devices booted
iPhone 17 (4765193F-03D6-4772-98B8-9279CE814781) (Booted)
Screenshots, recordings, or supporting files
No response
Workaround
Kill the orphaned runner (pkill -f AgentDeviceRunnerUITests) and shut the Simulator down with xcrun simctl shutdown <udid>.
🤖 Generated with Claude Code