Skip to content

[Bug]: Bound agent-device launcher omits --project-root, failing with self-inflicted DEVICE_IN_USE across working directories #38603

Description

@Illyism

Before submitting

  • I searched existing issues and did not find a duplicate. (Checked #31303 and #38588 — both involve cross-thread or post-restart claims, whereas here a single thread's own bound launcher rejects itself when invoked from a second cwd.)
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server (device / AgentDeviceShim.ts & DeviceService.ts)

Steps to reproduce

  1. Start a thread in a workspace root /path/to/coordinator (or monorepo root /path/to/repo) and call device_open for a local iOS Simulator.
  2. device_open returns a session-bound launcher <stateDir>/device/targets/t3-<hash>/agent-device whose quickStart states:

    "It is bound to this device and session, so it needs no --platform, --udid, --serial, --config or --session flags."

  3. From /path/to/mobile-app/ios, run:
    "<stateDir>/device/targets/t3-<hash>/agent-device" open com.example.app
    (agent-device records the device claim under { session: "t3-<hash>", workspace: "/path/to/mobile-app/ios" }.)
  4. In a subsequent shell tool call whose working_directory is /path/to/coordinator (or /path/to/mobile-app), invoke the exact same bound launcher:
    "<stateDir>/device/targets/t3-<hash>/agent-device" install com.example.app /path/to/Build/App.app

Expected behavior

Because <stateDir>/device/targets/t3-<hash>/agent-device is already bound to that T3 thread's device_open session (--session t3-<hash>), invoking it from any working directory in that thread's shell commands should resolve to the same agent-device workspace/claim and succeed without requiring manual --project-root flags or cd workarounds.

Actual behavior

agent-device (0.21.36) derives workspace from the caller's process.cwd() whenever --project-root is not passed, sees a different directory than step 3's claim, and rejects its own t3-<hash> session with DEVICE_IN_USE:

Error (DEVICE_IN_USE): ios device <UDID> is owned by session "t3-<hash>" in workspace "/path/to/mobile-app/ios".
Hint: Inspect the owner with: agent-device device status --platform ios --udid <UDID>

(And following the hint via the bound launcher exits 1 because AgentDeviceShim.ts:110 blocks the device subcommand on bound launchers.)

Root cause on main (ce884e3a9d11):

  • apps/server/src/device/DeviceService.ts:1194,1224 binds ["--platform", ..., "--udid" | "--serial", ..., "--config", configPath, "--session", session] into targetArgs, without binding --project-root (e.g. the owning thread's workspace root or a fixed session directory).
  • apps/server/src/device/AgentDeviceShim.ts:132 (spawn(node, [entry, ...command], { stdio: "inherit", env })) inherits the caller shell's process.cwd() even though --project-root is already recognized in VALUE_FLAGS (line 94).

Impact

Slows down multi-directory / cross-repo mobile workflows (xcodebuild / Gradle in a subproject vs. coordinator workspace) and contradicts <t3_code_orchestration_instructions> ("never reuse or close another session; if it still fails, tell the user and stop"), causing obedient agents to abort when the "other" owner is actually their own session.

Version or commit

Verified in code on main (ce884e3a9d11, apps/server/src/device/DeviceService.ts:1194,1224 and apps/server/src/device/AgentDeviceShim.ts:94,132,175) with bundled agent-device 0.21.36.

Workaround

Always cd into the exact directory where the first <target>/agent-device open ran (or pass the same --project-root <dir> on every invocation).

Activity

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