Skip to content

Agent-device claims survive a server restart after T3 loses their owning session #38588

Closed as not planned

Description

@bessim-dev

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 requires 0.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

  1. Thread A opens a local simulator through device_open and starts its bound automation session.
  2. The T3 server is replaced without its device-daemon finalizer completing, leaving the T3-owned daemon alive.
  3. Start T3 again with the same home directory.
  4. 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

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

  1. juliusmarminge commented on Nov 18, 2026

    @juliusmarminge
    Member

    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 --json with 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.ts on 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.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions