t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: agent-device's iOS runner outlives its daemon and keeps the Simulator booted for hours after the claim is gone

Open yu2001-s opened this issue 2 days ago • 0 comments

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

  1. In a thread, device_open an iOS Simulator (iPhone 17, iOS 27.2) and drive it with the bound agent-device for a few minutes (open, snapshot, press).
  2. 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.
  3. Run pgrep -fl AgentDeviceRunnerUITests and xcrun 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 -i on the runner showed no sockets.
  • The Simulator was still booted, with its whole iOS userland running (Siri, intelligenceflowd / intelligencecontextd, widget extensions, MTLCompilerService and others).
  • The last session that used it (t3-129cdd9ba22419d2748cbf64) logged requests from 14:11 to 14:22, ending with a failed scrollintoview ("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:

  1. 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, start xcodebuild in the daemon's process group and kill that group on shutdown.
  2. 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.
  3. 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

yu2001-s avatar Nov 29 '26 10:11 yu2001-s