From f8f94083d2e8dcbdc233b4504c55bf8bc464d05c Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sun, 25 Oct 2026 09:08:10 +0100 Subject: [PATCH 1/2] docs(gateway): a starting worker's leases are hidden from their owner (#405) --- src/gateway/AGENTS.md | 5 +++++ .../content/docs/docs/getting-started/connect-your-agent.mdx | 2 +- .../docs/docs/using-devices/working-with-a-device.mdx | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gateway/AGENTS.md b/src/gateway/AGENTS.md index 9035ccec2..6de51c4d1 100644 --- a/src/gateway/AGENTS.md +++ b/src/gateway/AGENTS.md @@ -131,6 +131,11 @@ Persisted: the `drained_workers` and `tokens` tables of `state.db`, `instance.js ## Known gaps +- **A starting worker's leases are hidden from their owner.** `lease.list` and `lease.get` leave out + a `starting` worker's leases (the worker's startup checks plus one gateway refresh, usually seconds, + up to about a minute: a platform's startup read is capped at 60 s). Meanwhile the owner's remote + commands fail with "No lease is held by …" and MCP `status()` reports none, though the lease stands. + Agents must not request a new device on that message right after a worker restart. - **A fleet request is stored only once a worker takes it.** A gateway restart loses every open request; ids answer `404`, a repeated `Idempotency-Key` is new. Leases survive, so a repeat may get `REQUESTER_ALREADY_LEASED` naming the lease. diff --git a/website/src/content/docs/docs/getting-started/connect-your-agent.mdx b/website/src/content/docs/docs/getting-started/connect-your-agent.mdx index 85a46badd..f48c06bb2 100644 --- a/website/src/content/docs/docs/getting-started/connect-your-agent.mdx +++ b/website/src/content/docs/docs/getting-started/connect-your-agent.mdx @@ -70,7 +70,7 @@ While the request waits in the queue or a device boots, `simlock lease` blocks a | `list_devices` | Lists the models, OS versions and Android system images you can lease on this machine. It never downloads anything. | | `lease_simulator` | Leases one simulator or emulator for this session. Takes `platform` and, optionally, `model` or `class`, `osVersion`, `ttlMs`, `noWait`, `timeoutMs` and `allowDownload`, the same options as `simlock lease`. Returns the same lease the CLI prints. | | `release_simulator` | Releases this session's lease. | -| `lease_status` | Reports this session's lease, or `held: false` when it has none. Safe to call any time, for example after the agent's context was compacted. | +| `lease_status` | Reports this session's lease, or `held: false` when it has none. Safe to call any time, for example after the agent's context was compacted. Through a gateway it can report `held: false` for up to about a minute after the worker holding the lease restarts, while the worker is `starting`; do not request a new device on that answer, call it again. | | `run_on_device` | Runs one `simctl`, `adb` or `devicectl` command on this session's lease, on the machine that holds the device. Takes `tool`, `args` and, optionally, `stdin`. Never takes a device or a lease id: Simlock fills in the lease's device and refuses a command that names another. Returns `{exitCode, stdout, stderr, truncated}`; stdout and stderr each keep their last 32768 characters, and `truncated` says when any was cut. A non-zero `exitCode` is the command's own answer, not an error. Without a lease it answers `NO_LEASE`. There is no terminal, and a command that waits for input is stopped after the time limit (10 minutes by default). | The server sends the short version of the rules to the client when it connects, and the full text as the resource `simlock://instructions`. It renews its lease while it runs, and releases it when the agent tool closes the connection. It also starts the daemon if it is not running. diff --git a/website/src/content/docs/docs/using-devices/working-with-a-device.mdx b/website/src/content/docs/docs/using-devices/working-with-a-device.mdx index 274ab0bab..0088461eb 100644 --- a/website/src/content/docs/docs/using-devices/working-with-a-device.mdx +++ b/website/src/content/docs/docs/using-devices/working-with-a-device.mdx @@ -86,6 +86,7 @@ simlock --gateway simctl --lease 3f81a2c4-9b7d-4e21-8a55-1c0e6f2d7b93.lse_9f2c6a - `--lease ` names which lease the command runs under. Put it right after `simctl` or `adb`. You can leave it out when you hold exactly one lease. Against a worker it is accepted and ignored. - File paths in the arguments are paths on the worker, not on your machine. `simctl install` needs the app to exist on the worker already. - Commands that need a terminal, such as a bare `adb shell`, are refused. Input piped to the command is sent once. +- Right after a worker restarts, the gateway hides its leases from `lease.list` and `lease.get` until the worker is no longer `starting`. That is the worker's startup checks plus one gateway refresh: usually seconds, up to about a minute, because a platform's startup read is capped at 60 seconds. In that window the command fails with `No lease is held by ` although the lease stands. Do not request a new device on that message: wait a minute and run the command again. ## Commands Simlock refuses From 8d4c11f4576816194ac0ae7e7e0ee70f1f01a0b9 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sun, 25 Oct 2026 09:20:29 +0100 Subject: [PATCH 2/2] docs(gateway): keep the gateway manual within 150 lines (#405) --- src/gateway/AGENTS.md | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/gateway/AGENTS.md b/src/gateway/AGENTS.md index 6de51c4d1..45b364d69 100644 --- a/src/gateway/AGENTS.md +++ b/src/gateway/AGENTS.md @@ -131,25 +131,20 @@ Persisted: the `drained_workers` and `tokens` tables of `state.db`, `instance.js ## Known gaps -- **A starting worker's leases are hidden from their owner.** `lease.list` and `lease.get` leave out - a `starting` worker's leases (the worker's startup checks plus one gateway refresh, usually seconds, - up to about a minute: a platform's startup read is capped at 60 s). Meanwhile the owner's remote - commands fail with "No lease is held by …" and MCP `status()` reports none, though the lease stands. - Agents must not request a new device on that message right after a worker restart. -- **A fleet request is stored only once a worker takes it.** A gateway restart loses every open - request; ids answer `404`, a repeated `Idempotency-Key` is new. Leases survive, so a repeat may get - `REQUESTER_ALREADY_LEASED` naming the lease. +- **A starting worker's leases are hidden from their owner.** `lease.list` and `lease.get` omit them + for the startup checks plus one refresh (up to about 60 s). Meanwhile remote commands fail with + "No lease is held by …" and MCP `status()` reports none; the lease stands. Don't request a new device. +- **A fleet request is stored only once a worker takes it.** A gateway restart loses every open request; + ids answer `404`, a repeated `Idempotency-Key` is new (maybe `REQUESTER_ALREADY_LEASED`). - **A dispatched request whose uplink drops may have granted a lease anyway.** Client sees - `WORKER_UNREACHABLE`; the lease stands on the worker until TTL. Re-request: at the limit the - answer names the earlier lease once the index is rebuilt; below it you get a second lease. -- **A lease survives a gateway restart, but nothing can renew it until the gateway is back.** - Renew, release and exec fail meanwhile; past the TTL it expires. Knob: the gateway's - `lease.defaultTtlMs`, or `--ttl`. -- **Local agents and the gateway share a worker's capacity.** A busy local machine answers - `NO_CAPACITY`; the request waits for another worker. `simlock worker drain` leaves it to its owner. + `WORKER_UNREACHABLE`; the lease stands until TTL. A re-request may name it or get a second lease. +- **A lease survives a gateway restart, but nothing renews it until the gateway is back.** Renew, + release and exec fail meanwhile; past the TTL it expires. Knob: `lease.defaultTtlMs`/`--ttl`. +- **Local agents and the gateway share a worker's capacity.** A busy machine answers `NO_CAPACITY`; + the request waits elsewhere. `worker drain` leaves it to the owner. - **A worker's claimed id is never verified against its join token.** Any `worker`-token holder can - claim any id and take over that worker's link, view, drain flag and forwarded calls. Ids cut to 128 chars. + claim any id and take over its link, view, drain flag and calls. Ids cut to 128 chars. - **`device.exec` backpressure through a gateway does not slow the worker's own process.** Output is relayed with `void session.onOutput(...)`; a slow fleet client is buffered in the gateway. - **Three gaps in gateway warm hits.** A slim-pool device that failed its slim pass reports `full` - and counts for `full`; a default-slim worker's full device on an unslimmable runtime is no hit for - a mode-less request; a `--mode slim` request on an unslimmable runtime is no hit on a ready full device. + and counts for `full`; a default-slim worker's full device on an unslimmable runtime is no hit for a + mode-less request; a `--mode slim` request there is no hit on a ready full device.