Skip to content

Through a gateway, simlock adb and simctl send stdin only with --stdin #1176

Closed

Description

@V3RON

Part of #1174.

Scope

Through a gateway, simlock adb and simlock simctl send stdin to the command only when the caller passes --stdin. Without it they never read stdin and send empty input, so a caller whose piped stdin never closes no longer hangs. On a worker the flag is accepted and ignored. One task: the change is one decision in one CLI command (ADR 0058).

In short

Through a gateway, simlock adb shell getprop now runs at once even when stdin is a pipe nobody closes. To send input, write simlock adb --stdin shell cat < file: the CLI reads stdin to its end (Ctrl-D at a terminal) and sends it once. Without --stdin the command gets empty input, as with < /dev/null today.

flowchart LR
  A[simlock adb ... via gateway] --> B{"--stdin? (new)"}
  B -->|no| C["device.exec, stdin = '' (new)"]
  B -->|yes| D[read stdin to its end] --> E[device.exec with stdin]
Loading

Before and after, through a gateway:

$ echo hello | simlock adb shell cat        # before: hello      after: (nothing)
$ echo hello | simlock adb --stdin shell cat  # before: adb gets --stdin and fails   after: hello
$ simlock adb shell getprop                 # open pipe: before hangs forever   after: prints, exits
Arguments Today (gateway) After (gateway) After (worker)
shell getprop stdin read to its end if not a terminal stdin not read; stdin: "" sent as today
--stdin shell cat --stdin passed to adb stdin read to its end and sent --stdin dropped, adb runs shell cat here
--lease L --stdin shell cat --stdin passed to adb lease L, stdin sent --stdin and --lease L dropped
--stdin --lease L shell cat --stdin passed to adb lease L, stdin sent both dropped
shell --stdin --stdin passed to adb --stdin passed to adb --stdin passed to adb

If this goes wrong, a user sees a remote command that still hangs on an open pipe, or input they piped with --stdin that never arrives.

Technical spec

Facts

Commit: d0c2664 (origin/main; these files are unchanged on main since).

# Fact Source
F1 Through a gateway, runRemotePassthrough awaits environment.readStdin() before client.exec, and sends stdin only when it is defined src/cli/commands/passthrough.ts:58, :66
F2 readPipedStdin returns undefined for a terminal without reading, else reads stdin to its end; an existing test pins the terminal case src/cli/stdio.ts:2; src/cli/index.test.ts:7730 ("returns undefined without reading anything when stdin is a terminal")
F3 extractLeaseFlag takes --lease <id> and --lease=<id> from the front of the arguments and stops at the first other argument; it runs before the mode check, so on a worker too src/cli/commands/passthrough.ts:81-104, :17
F4 On a worker the CLI resolves the command and spawns it with inherited stdio; it never calls readStdin there src/cli/commands/passthrough.ts:33-40; src/cli/passthrough.ts (spawnPassthrough)
F5 The worker passes device.exec's stdin to the child as input only when it is defined; the streaming spawn writes input and closes the pipe, and an omitted input leaves the child's stdin open src/daemon/dispatcher.ts:741; src/ports/process-runner.ts:92, :313
F6 device.exec's input accepts stdin as any string, the empty string included src/contract/operations.ts:441
F7 The gateway e2e exec step runs adb ... devices with input: "" to avoid the hang, with a comment saying why; the fake driver can echo the stdin it got with --fake-exec-echo-stdin e2e/gateway-smoke.test.ts:180-197; e2e/fake-driver/fake-driver.ts:188
F8 The CLI reference says "a piped stdin is sent along" in the simlock simctl section only, and lists --lease as "accepted and ignored" on a worker in both sections website/src/content/docs/docs/reference/cli.mdx:169, :172, :184, :187
F9 The CLI manual's step 5 says a piped stdin "is read to EOF first", and Known gaps lists the hang with the /dev/null workaround src/cli/AGENTS.md:91, :131-133
F10 Existing tests to extend: "takes --lease <id> out of the arguments and runs against that lease" and "sends whatever readStdin resolves with as the command's one-shot stdin" src/cli/index.test.ts:978, :1010
F11 A commit subject with ! is refused by the commit hook, so only the PR title can mark the change breaking; the release notes read PR titles .agents/scripts/commit-msg-check.mjs:39; scripts/release.mjs:24

Modules touched

Searches: readStdin (4 hits in src/cli/), readPipedStdin (11 hits: stdio.ts, environment.ts, index.test.ts, AGENTS.md), piped stdin in website/ and src/cli/AGENTS.md (2 hits), input: "" in e2e/ (3 hits: gateway-smoke.test.ts:196, gateway-lease-limit.test.ts:85, gateway-physical-routing.test.ts:412; only the first changes, the other two keep passing).

flowchart LR
  P["cli/commands/passthrough.ts (changed)"] --> S["cli/stdio.ts (changed)"]
  P --> C[admin client: device.exec]
  D["website cli.mdx (changed)"]
  M["cli/AGENTS.md (changed)"]
  E["e2e/gateway-smoke.test.ts (changed)"]
Loading
sequenceDiagram
  participant U as caller
  participant CLI
  participant GW as gateway
  participant W as worker
  U->>CLI: simlock adb shell getprop (pipe left open)
  CLI->>GW: device.exec {stdin: ""}
  GW->>W: device.exec
  W-->>GW: output, exit 0
  GW-->>CLI: output, exit 0
  CLI-->>U: prints, exits 0
  Note over CLI,W: a refusal (e.g. PASSTHROUGH_REFUSED) comes back as today: one error line, exit 2
Loading

readPipedStdin (stdio.ts) loses its terminal shortcut: it is called only with --stdin now, and then reads stdin to its end whatever it is, a terminal included (F2).

Contract and event changes

none: device.exec already takes any stdin string (F6). No protocol bump.

Other code on the same state

Searches: process.stdin in src/cli/ (1 hit, stdio.ts), readStdin (4 hits: environment.ts, types.ts twice, passthrough.ts). Only runRemotePassthrough reads stdin; nothing else competes for it.

Failure modes

Call Outcome What happens Limit, counted from
readStdin with --stdin ends (pipe closed, file, Ctrl-D at a terminal, /dev/null) its contents are sent, "" when empty none (the caller asked)
readStdin with --stdin never ends the CLI waits, as asked none
readStdin without --stdin — never called; stdin: "" is sent —
device.exec ok / refusal / lost connection as today as today

No state is written.

Rules in play

  • ADR 0058 §1–4: "reads stdin only when the caller passes --stdin"; the build follows it line by line.
  • ADR 0005 §19c (narrowed): the one-shot string stays; only when it is read changes.
  • Documentation rule 9: "A change to the public surface … updates the pages that describe it": cli.mdx for both commands.

Tests

Seam: runCli in src/cli/index.test.ts with a fake gateway client, extending "sends whatever readStdin resolves with as the command's one-shot stdin" (F10); readPipedStdin's own tests in the same file (F2); and e2e/gateway-smoke.test.ts.

  • A user runs simlock adb or simlock simctl through a gateway, and device.exec carries stdin only when --stdin was given: adb and simctl; no flag with a stdin that never ends → sent with stdin: "", stdin never read; --stdin → stdin's contents sent; --stdin before --lease and after it; --stdin after the tool's first argument → passed to the tool.
  • A user runs simlock adb --stdin on a worker, and the flag is accepted and ignored: --stdin alone; with --lease.
  • A user passes --stdin at a terminal, and the CLI reads what they type until it ends: readPipedStdin with a terminal stdin returns its chunks joined (the existing terminal test at index.test.ts:7730 changes to this); a piped stdin as today.
  • An agent runs simlock adb through a real gateway with a piped stdin left open, and the command runs, gets empty input and exits with the tool's code: the existing exec step in e2e/gateway-smoke.test.ts without input: "", its workaround comment removed, with --fake-exec-echo-stdin and an assertion that the stdin it got is "".

Done when

  • Through a gateway, simlock adb and simlock simctl without --stdin never read stdin and send stdin: ""; with --stdin they send stdin's contents (src/cli/index.test.ts).
  • --stdin is taken out of the arguments before the tool's, in either order with --lease, and is accepted and ignored on a worker (src/cli/index.test.ts).
  • With --stdin, a terminal stdin is read to its end like a pipe (readPipedStdin's tests in src/cli/index.test.ts).
  • The gateway e2e exec step runs without input: "", its command gets "" as stdin, and it passes (e2e/gateway-smoke.test.ts, fast lane).
  • website/src/content/docs/docs/reference/cli.mdx lists --stdin in the flag tables of simlock adb and simlock simctl and says stdin is sent only with it; src/cli/AGENTS.md step 5 says the same and its Known gaps entry about the hang is gone.
  • The PR title (not a commit subject, F11) marks the change breaking (feat(cli)!:), so the release notes say piped input now needs --stdin.

Out of scope

  • Streaming input while the command runs; -i / --interactive.
  • Any change to device.exec, HTTP, MCP or the gateway.

Depends on

Written by an agent.

Metadata

Metadata

Assignees

Labels

task:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions