Skip to content

Android: emulators start without gRPC, so tools that need the emulator gRPC endpoint (Argent) cannot drive leased devices #639

Closed

Description

@robrechtme

This issue was written by Claude (an AI coding agent) while it investigated a tooling problem for me. I reviewed it and approved posting it.

simlock 0.2.0 starts emulators with the args below. main (0.3.0) uses the same args.

emulator -avd <avd> -port <n> -no-snapshot-save [-snapshot simlock_clean_baseline]

When -port is set and -grpc is not, the emulator:

  • starts no gRPC server, and
  • writes no discovery file (~/Library/Caches/TemporaryItems/avd/running/pid_<pid>.ini on macOS).

Without -port, the emulator turns on gRPC by default (console port + 3000, with a token) and writes the file.

Tools that drive the emulator over gRPC read that file. Argent is one. On a leased emulator its screenshot and gesture-tap fail with:

emulator "emulator-5558" not found among running emulators (a token-less `-grpc` launch omits grpc.token; check avd/running/*.ini)

adb-only tools still work, so the device looks healthy. Argent documents the same failure for any emulator launched without -grpc: software-mansion/argent#1192.

Repro (macOS, emulator 36.6.11, simlock 0.2.0)

  1. simlock lease --platform android --device "Pixel 9" --agent-id test --detach
  2. ls ~/Library/Caches/TemporaryItems/avd/running/ → no pid_*.ini for the leased emulator.
  3. lsof -nP -iTCP -sTCP:LISTEN -p <emulator pid> → console and adb ports only, no gRPC port.

Matrix (throwaway AVD, launched by hand)

Flags gRPC endpoint + .ini
-port 5570 -no-snapshot-save no
no -port yes, grpc.port=8556
-port 5570 -grpc 8570 -grpc-use-token yes, and Argent works

Proposed fix

Add -grpc <port + 3000> -grpc-use-token to the emulator launch args.

  • Base the gRPC port on the console port, like the emulator's own default, so parallel leases never collide. With console ports above 5585 on main, it may be worth checking that port + 3000 stays clear of other simlock-managed ports.
  • The token keeps the endpoint authenticated. Argent also requires grpc.token in the .ini.
  • Users cannot work around this: config cannot add raw emulator flags (by design, per the comment near emulatorLaunchFlags).

Optional: expose the gRPC port in the grant, so tools do not have to find it through the discovery file.

Activity

  1. robrechtme commented on Oct 20, 2026

    @robrechtme
    Author

    @V3RON tagging you to make sure you see this 😄

  2. self-assigned this
    on Oct 24, 2026
  3. V3RON commented on Oct 24, 2026

    @V3RON
    Contributor

    Reproduction

    Confirmed. This is a gap: no ADR or doc promises a gRPC endpoint, so the test's expectation (-grpc <console port + 3000> -grpc-use-token on every launch) is a proposal.

    src/drivers/android/index.test.ts on bug/639-repro, "boots every launch of an emulator on %s with a token gRPC endpoint at the console port plus 3000". Two cases: the first console port, and one after a taken port.

    pnpm exec vitest run --project unit src/drivers/android/index.test.ts -t "token gRPC endpoint"
    
    - { "grpc": "8586", "token": true } x2
    + { "grpc": undefined, "token": false } x2
    (same for 8588)   Tests  2 failed
    

    Root cause

    src/drivers/android/index.ts:2071-2081: #startEmulator passes -port <n> but never -grpc. The reporter's matrix shows that the emulator then starts no gRPC server and writes no avd/running/pid_*.ini. Argent reads that file, so it cannot find the device, while adb-only tools still work. Config cannot add the flag, because emulatorLaunchFlags (index.ts:2635) maps only four fixed settings. Local emulator -help (36.5.11) lists both -grpc <port> and -grpc-use-token.

    Simplest fix

    Add "-grpc", String(data.port + 3000), "-grpc-use-token" after -no-snapshot-save in #startEmulator. With that change the repro passes. The 32 existing tests that assert the exact emulator argv need the three new args. Update the Boot section of the Android driver manual.

    Alternatives rejected

    • A config switch for gRPC: it turns a default every tool expects into an opt-in.
    • Exposing the gRPC port in the grant: it is new surface (protocol bump). Tools already find the port through the .ini. A separate change if wanted.
    • A gRPC port from its own range: needs a new allocator. +3000 matches the emulator's own default.

    Risk

    • consolePortsInUse (index.ts:2349) probes only port and port+1. A busy 8586–8682 port is not checked; confirm the emulator still boots when it is.
    • On hardware, check that the endpoint binds to loopback only.
    • On hardware, check that a baseline captured without -grpc still loads with it, so the upgrade does not wipe devices.

    Written by an agent.

  4. removed their assignment
    on Oct 24, 2026
  5. V3RON commented on Oct 25, 2026

    @V3RON
    Contributor

    Decision

    Maintainer: deliver the proposed fix. Start emulators with -grpc <console port + 3000> -grpc-use-token, and make the free-port check (consolePortsInUse) cover the +3000 port. The slow lane must confirm two things on a real emulator: gRPC listens on localhost only, and an existing snapshot still loads with -grpc.

    Written by an agent.

  6. added
    bug:ready
    and removed on Oct 25, 2026
  7. github-actions commented on Oct 28, 2026

    @github-actions
    Contributor

    Claim released: no activity for 3 days. The label is unchanged; the next agent starts from the branch and the last handoff.

  8. added a commit that references this issue on Oct 30, 2026
    7fc5186
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

    bug:ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions