Repository navigation
Description
Request: #1541
Problem
In the reporter's words: "I keep Android emulators on a machine that can reach a bank's closed network, and real phones on a machine that cannot. A test of that network has to land on the first kind of host. Nothing in a lease says which network the worker is on."
A lease can already require names (requires), but only the names of the modules Simlock ships: agent-device, input, stream, tunnel, fseventsd. An operator has no way to give a worker a name of their own. simlock config set capabilities.bank-network … is refused as an unknown key. A test can then be granted on the worker outside the network and fail for a reason that looks like an app bug. On top of that, simlock lease has no flag for requires, and the MCP lease tool leaves it out.
Who it is for
An operator of a device farm with workers in different places, for example one inside a closed corporate network and one outside it. Coding agents and CI jobs lease through the same gateway. Today someone has to point each job at the right daemon by hand.
Outcome
An operator writes tags on a worker, for example "tags": ["bank-network"], the way a CI runner has tags. A lease from simlock lease --requires bank-network, the MCP lease tool, the HTTP API or the client is placed only on a worker that has every name it asks for. If no connected worker has them, it fails at once with CAPABILITY_MISSING instead of being granted on the wrong network. A lease that asks for no tag can still go to any worker.
How it works for the user
flowchart TD
OP[Operator: tags bank-network in the worker's config.json] --> RS[Restart the worker]
RS --> ST[simlock status: bank-network available]
J[CI job: simlock lease --platform android --requires bank-network] --> G{Gateway: a connected worker with every name?}
ST --> G
G -->|yes| P[Leased on the tagged worker]
G -->|yes, but it is busy| Q[Waits for that worker]
G -->|no| E[CAPABILITY_MISSING, exit 12]
BAD[A tag that breaks the name rules] --> REF[config set refuses it; the daemon will not start with it]
Before:
$ simlock config set tags '["bank-network"]'
{"error":{"code":"USAGE","message":"Invalid config after setting tags: Unknown config key: \"tags\""}}
$ simlock lease --platform android --requires bank-network
{"error":{"code":"USAGE","message":"Unknown option '--requires'. …"}}
After, on the worker inside the network:
$ simlock config set tags '["bank-network"]'
$ simlock daemon stop && simlock daemon start
$ simlock status
… -- stream off -- tunnel off … -- bank-network available
And from a CI job, through the gateway:
$ simlock lease --url https://gw.example.com --platform android --requires bank-network
{"leaseId":"…","device":{…}}
$ simlock lease --url https://gw.example.com --platform android --requires vpn-eu
{"error":{"code":"CAPABILITY_MISSING","message":"No worker connected to this gateway can serve vpn-eu for this request"}}
Examples
The tags an operator writes:
tags in config.json |
Today | After |
|---|---|---|
| absent | unknown key, refused | accepted; no tags |
[] |
unknown key, refused | accepted; no tags |
["bank-network"] |
unknown key, refused | accepted |
["bank-network", "eu-west"] |
unknown key, refused | accepted; both listed in that order |
["Bank"] |
unknown key, refused | refused: not lowercase |
["1st-floor"] |
unknown key, refused | refused: does not start with a letter |
| a 33-character name | unknown key, refused | refused: longer than 32 |
| nine names | unknown key, refused | refused: more than 8 |
["a", "a"] |
unknown key, refused | refused: listed twice |
["stream"] |
unknown key, refused | refused: the name of a module |
"bank-network" (a string, not a list) |
unknown key, refused | refused: not a list |
| set on a gateway | unknown key, refused | ignored with a warning, like other worker-only keys |
What a lease asks for (worker A has tags: ["bank-network"]; worker B has none; both have stream off):
| Request | Today | After |
|---|---|---|
no requires |
A or B | A or B |
--requires bank-network |
no such flag (exit 2) | A only |
client requires: ["bank-network"] |
CAPABILITY_MISSING |
A only |
requires: ["bank-network", "stream"] |
CAPABILITY_MISSING |
CAPABILITY_MISSING (no worker has stream available) |
requires: ["vpn-eu"] |
CAPABILITY_MISSING |
CAPABILITY_MISSING |
requires: ["Bank"] |
BAD_REQUEST |
BAD_REQUEST |
--requires "" |
no such flag (exit 2) | BAD_REQUEST (an empty name) |
requires with idempotencyKey (every simlock lease --url and MCP farm request) |
BAD_REQUEST |
accepted |
| the same key sent again with the same names in another order | BAD_REQUEST |
the first request's answer |
| the same key sent again with another name added | BAD_REQUEST |
IDEMPOTENCY_CONFLICT |
What could go wrong
- An operator tags the wrong worker. Leases then go there, and nothing checks the tag. Likely now and then; the worker list shows the tags, so it can be spotted.
- A typo in a tag: the lease fails at once with
CAPABILITY_MISSING, naming the tag. Easy to see. - A worker is updated but not restarted: its old tags stay until the restart, like every setting.
- A newer
simlock lease --urlagainst an older gateway is refused withPROTOCOL_VERSION_UNSUPPORTED, as after every protocol change. Updating the gateway fixes it. - A Simlock update that adds a module named like an existing tag stops that worker at start until the operator renames the tag. Rare: the module names are few and chosen by Simlock.
Words used
- tag: a name an operator writes in a worker's
tagsconfig list, e.g.bank-network. A lease can require it. - capability: a name in a worker's status that
requirescan ask for. Either a module Simlock ships (stream) or a tag. A tag is alwaysavailable. requires: the list of capability names a lease request asks for, e.g.["bank-network"].- idempotency key: a client's own id for one request, so the same request sent again returns the first answer instead of starting a second request.
simlock lease --urland the MCP server in farm mode always send one. - replay: a request sent again under the same idempotency key.
Non-goals
- Tags on single devices of one worker (Devices on one worker cannot be tagged by the network they can reach #1542).
- Keeping a tagged worker for leases that require its tags. Any lease may still land there.
- Checking that a tag is true, for example by probing the network.
- Changing tags without a restart.
- Routing on the worker's display label (
gateway.label).
Completion conditions
- A worker started with
"tags": ["bank-network"]listsbank-networkasavailableinsimlock status,simlock worker liston its gateway, and the console's worker page. - A config whose tags break a rule in Examples is refused by
simlock config setwith exit code 2, and a daemon will not start with it. - Through a gateway with one tagged and one untagged worker,
simlock lease --url <gateway> --requires bank-networkis granted on the tagged worker every time, and--requires vpn-euexits 12 withCAPABILITY_MISSING. simlock lease --requires bank-networkagainst the tagged worker itself is granted; against the untagged one it exits 12 withCAPABILITY_MISSING.- The MCP
lease_simulatortool withrequires: ["bank-network"]behaves the same, locally and in farm mode. POST /v1/lease-requestswith"requires": ["bank-network"]behaves the same, with or without anIdempotency-Keyheader.- The configuration, CLI, MCP tools, HTTP API, errors and Node client pages describe
tags,--requiresand the replay comparison.
Open questions
Decisions
- ADR 0091 — An operator names a worker's tags, and a lease may require them (PR docs(adr): 0091 an operator names a worker's tags, and a lease may require them #1841): tags are capabilities that are always available, matched by
requires, andrequiresgoes with an idempotency key. - ADR 0026 — agent-device through a gateway: the
has-capabilitiesstage andCAPABILITY_MISSINGrow that tags reuse unchanged. - ADR 0030 — Optional modules: the capability name pattern tags follow, and the one word "capability" users meet.
- Maintainer decision (2026-11-24, comment on A lease cannot require an operator-defined capability, so a closed network cannot be selected like a runner tag #1541): operator-declared names on a worker;
requiresmatches them; CLI and MCP pass them; a gateway places only on a worker with every name, elseCAPABILITY_MISSING; Devices on one worker cannot be tagged by the network they can reach #1542 out of scope. - Decided in the session (maintainer): the key is a top-level
tagslist, not names undercapabilities.<name>. - Decided in the session (maintainer): a lease that asks for no tag may still land on a tagged worker.
- Decided in the session (maintainer): a tag that names a module is a config error, also after an update that adds that module: the worker does not start until the tag is renamed.
- Decided in the session: a worker answers a replay before it checks capabilities, as a gateway already does, so a replay checks nothing again on either side.
- Decided in the session: the protocol bump moves
minwithmax, as the earlier bumps did; no compatibility path is kept. - Decided in the session:
requiresandidempotencyKeymay be sent together, becausesimlock lease --urland MCP farm mode always send a key. Without this, every remote lease with--requireswould be refused. - Decided in the session: a replay compares
requiresas a set, so order does not matter, and an empty list counts as none. This follows how the book already compares the other fields of a request. - Decided in the session (maintainer): the HTTP lease route
POST /v1/lease-requeststakesrequirestoo, in the first task. - Decided in the session: tags follow the module name pattern, 0 to 8 names, each listed once. A tag that names a module is a config error, so a tag can never hide a module's real state.
- Decided in the session: tags come after the modules in the status list, in config order, so the line
simlock statusprints keeps today's order. - Decided in the session:
--requirestakes a comma-separated list, like--except. - Decided in the session: the lease-request record a reader sees (
GET /v1/lease-requests/{id}) does not showrequires; nothing asked for it.
Behaviours
| Id | Behaviour (invoker, action, what it sees) | Seam | Cases | Task |
|---|---|---|---|---|
| B1 | An operator sets tags on a worker; status.get lists each tag as available, after the module entries, in config order |
status.get on a worker dispatcher built by the worker composition from a loaded config, modules faked |
no key; []; ["bank-network"]; ["bank-network","eu-west"] with one module on and one off |
#1844 |
| B2 | An operator writes bad tags; the config loader refuses them with the I1 message, so simlock config set exits 2 and a start fails |
loadConfigWithDefaults (the config loader) on a written layer |
each refused row of the first Examples table: ["Bank"], ["1st-floor"], 33 characters, nine names, ["a","a"], ["stream"], a string |
#1844 |
| B3 | An operator sets tags on a gateway; the gateway starts and logs the worker-only warning (I1) |
the config loader in gateway mode | tags set; tags absent: no warning |
#1844 |
| B4 | A caller asks a worker directly for a lease with requires; it is granted when every name is a tag or an available module, else CAPABILITY_MISSING naming only the missing names (I3) |
lease.request on a worker dispatcher with tags configured |
["bank-network"] granted; ["vpn-eu"] missing vpn-eu; ["bank-network","stream"] with stream off: missing stream only |
#1844 |
| B5 | A caller asks a gateway for a lease that requires a tag; it is dispatched only to a worker whose view lists the tag, and gets CAPABILITY_MISSING (I3) when no connected worker that could serve it does |
gateway lease.request with two faked worker links whose status carries the B1 list |
tagged + untagged worker: the tagged one, every time; no worker tagged: CAPABILITY_MISSING; the tagged worker busy: the request waits, and is not sent to the untagged one |
#1844 |
| B6 | A caller sends requires with an idempotencyKey; it is accepted, and a replay answers the first request's result, or IDEMPOTENCY_CONFLICT (I2) when the set of names differs; on a worker the replay is answered before the capability check (I6) |
lease.request on a worker dispatcher, and on a gateway dispatcher |
first send accepted (worker and gateway); same names in another order: same answer; a name added: conflict; requires sent first then left out: conflict; [] then none: same answer; on the worker, a replay after a daemon restart: same answer (S1); on the worker, a replay that adds a name no source has: IDEMPOTENCY_CONFLICT, not CAPABILITY_MISSING; on the worker, a replay of a granted request after a required module turned unavailable: the first answer |
#1844 |
| B7 | A user runs simlock lease --requires <name,...>; the request carries the names, also with --url and its idempotency key, and the help lists the flag (I4) |
the lease command with a fake client |
--requires bank-network; --requires bank-network,eu-west; with --url: the request has both requires and idempotencyKey; --requires "": the daemon's BAD_REQUEST printed, exit 2; --help shows the flag |
#1845 |
| B9 | An HTTP caller sends POST /v1/lease-requests with requires; the request carries the names to lease.request, also with an Idempotency-Key (I7) |
the HTTP app (src/http/app.ts) with a fake dispatch |
["bank-network"] forwarded; with Idempotency-Key: forwarded with the key, accepted; none: none forwarded; ["Bank"]: 400 BAD_REQUEST with the contract's message |
#1844 |
| B8 | An agent calls MCP lease_simulator with requires; the lease request carries the names, locally and in farm mode (I5) |
lease_simulator through the MCP server with a fake client |
local ["bank-network"]; farm mode ["bank-network"] sends both requires and idempotencyKey; no requires: none sent; the tool's listed input schema has requires |
#1845 |
Stored state
| Id | What and where | Created, changed, deleted by | Listed or swept by | A restart mid-step leaves | Schema step | Task | Used by |
|---|---|---|---|---|---|---|---|
| S1 | lease_requests.requires: a new nullable TEXT column in a worker's state.db, the JSON array of the names a stored request required; NULL when it had none or an empty list |
written with the request row by LeaseRequestBook.admit; never changed; deleted with the row by the existing request retention |
read back by the book's replay check (#stored); listed nowhere else |
the row and its column are one write, so either both or neither exist | registry +1 | #1844 | — |
| S2 | tags in config.json, a top-level list of names (I1) |
written by the operator or simlock config set; read once at daemon start |
simlock config get; the console's settings page through the generic config view |
— | none | #1844 | — |
The gateway keeps its lease requests in memory, so its copy of requires on a stored request is a field of the in-memory record, not stored state.
Interfaces
| Id | What | Shape and bounds | Errors and limits | Where | Task | Used by |
|---|---|---|---|---|---|---|
| I1 | Config key tags |
Optional top-level list of 0 to 8 strings. Each matches ^[a-z][a-z0-9-]{0,31}$ (capabilityNameSchema), is listed once, and is not the name of an optional module in this build. Default []. Worker only. |
Through invalidValue: Invalid config value for "tags": expected a list of tag names (not a list); Invalid config value for "tags[<i>]": expected a name of 1 to 32 lowercase letters, digits and hyphens that starts with a letter; Invalid config value for "tags": expected at most 8 names; Invalid config value for "tags": expected each name once, "<name>" is listed twice; Invalid config value for "tags": expected no module name, "<name>" names an optional module. On a gateway the existing warning: Ignoring "tags": it configures a worker, and this daemon runs in gateway mode. |
src/core/config-validators.ts, config-types.ts, config-defaults.ts; src/contract/config-schemas.ts (configSchema gains an optional tags, so config.get keeps it and a gateway still parses an older worker's answer); website reference/configuration.mdx |
#1844 | — |
| I2 | lease.request accepts requires with idempotencyKey. The refusal requires cannot be combined with idempotencyKey is removed. Bumps the protocol by one. |
requires unchanged: 0 to 8 capability names, none twice |
A replay whose set of names differs is IDEMPOTENCY_CONFLICT, with the message Idempotency key <key> was already used by requester <requesterId> for a different device request, lease ID, run ID, label or required capabilities |
src/contract/operations-lease-request.ts, src/contract/protocol.ts, src/leasing/lease-request-book.ts, src/core/domain.ts (LeaseRequestRecord.requires) |
#1844 | #1845 |
| I3 | A tag as a capability source: one { name, read } per tag that always answers { state: "available" }, added after the module sources the worker composition hands the daemon |
name from I1 | No new error. A worker's CAPABILITY_MISSING: This worker cannot serve <names>; a gateway's: No worker connected to this gateway can serve <names> for this request. Both unchanged. |
src/daemon/worker-composition.ts |
#1844 | — |
| I4 | simlock lease --requires <name,...> |
a string, split on , into requires; sent as given, and the contract checks it. Help line: [--requires <capability,...>] |
the daemon's BAD_REQUEST or CAPABILITY_MISSING as one JSON error line (exit 2 or 12) |
src/cli/commands/lease.ts; website reference/cli.mdx |
#1845 | — |
| I6 | A worker's replay comes first: the lease handler asks the request book whether a request is stored under the caller's (requesterId, idempotencyKey) before it runs requireCapabilities, and skips that check when one is. requires goes into the lease options, so the book stores and compares it (I2). |
a read of the book outside the decision lock; the replay itself is still decided under the lock by LeaseRequestBook.replay |
no new error. Two sends of one key that both miss the read both run the check; the lock then makes the second a replay | src/daemon/dispatcher-leases.ts, src/leasing/lease-request-book.ts, a new read on LeaseCommands (src/leasing/lease-ports.ts:21) built in src/leasing/create-leasing.ts and handed over at src/daemon/worker-composition.ts:552 |
#1844 | — |
| I7 | POST /v1/lease-requests body field requires |
optional list of strings, coarse bound in the body schema (at most 8 strings of at most 32 characters); the names are checked by lease.request, as except is; forwarded as requires by leaseRequestDispatchInput |
the contract's BAD_REQUEST (400) or CAPABILITY_MISSING (422) |
src/http/lease-declarations.ts, src/http/tracker.ts; website using-devices/http-api.mdx (body table); the OpenAPI document follows the declaration |
#1844 | — |
| I5 | MCP lease_simulator input requires |
inherited from lease.request (requires no longer omitted): an optional list of 0 to 8 capability names |
the contract's BAD_REQUEST or the daemon's CAPABILITY_MISSING as a tool error |
src/mcp/contracts.ts; website reference/mcp-tools.mdx |
#1845 | — |
Existing code
Commit 200afe5.
Searches: requires in src/**/*.ts excluding tests (38 files); capabilitySources (10 hits); capabilities in src/core/config*.ts (8 files); idempotencyKey in src/cli, src/mcp (3 hits), src/leasing, src/gateway (8 hits); tags in src/core/config*.ts (0 hits); capabilit in website/src/content/docs (11 pages) and ui/src (5 files).
| Id | Code (path:line) | Today | With this feature | Handled by |
|---|---|---|---|---|
| X1 | src/core/config-validators.ts:307 capabilitiesValidator |
an unknown key under capabilities warns Unknown config key and is dropped; simlock config set refuses it (run on main, exit 2) |
unchanged: tags live under their own key | I1 |
| X2 | src/core/config-validators.ts:160 configValidators |
no tags key; simlock config set tags … refuses it (run on main, exit 2) |
gains tags |
I1, B2 |
| X3 | src/core/config-role-checks.ts:91 GATEWAY_CONFIG_KEYS, :120 |
a top-level key not in the list warns Ignoring "<key>": it configures a worker… on a gateway |
tags stays out of the list, so a gateway warns about it |
B3 |
| X4 | src/modules/host.ts:339 |
one capability source per module, off when not enabled |
unchanged | — |
| X5 | src/daemon/worker-composition.ts:510 |
capabilitySources: [...moduleHost.capabilitySources] |
the tag sources (I3) are appended | I3, B1 |
| X6 | src/daemon/dispatcher-capabilities.ts:13 readCapabilities, :55 requireCapabilities |
read every source for status.get; a direct request checks each required name against the sources |
a tag source reads available, so both serve tags with no change |
B1, B4 |
| X7 | src/contract/status-schemas.ts:405 MAX_CAPABILITIES = 16, :407 capabilityListSchema |
modules alone (5) count against 16 (src/modules/host.ts:150) |
5 modules + at most 8 tags = 13 fit; the output schema refuses a longer list | I1 (8-name cap) |
| X8 | src/gateway/routing/stages/has-capabilities.ts:14, src/gateway/routing/serviceability.ts:126 |
match each required name to an available entry of the worker view; CAPABILITY_MISSING when none fits |
unchanged; tags arrive in the view's list | B5 |
| X9 | src/gateway/fleet-dispatch.ts:391 |
the dispatch to a worker carries fleetRequestId and requires, never idempotencyKey |
unchanged; the worker's own replay check never sees a gateway dispatch | B5 |
| X10 | src/contract/operations-lease-request.ts:74 (requires), :151 refuseRequiresWithIdempotencyKey |
requires with idempotencyKey is BAD_REQUEST |
the refusal is removed; protocol +1 | I2, B6 |
| X11 | src/leasing/lease-request-book.ts:209 #stored, :101 conflict message, :247 admit |
a replay compares the device request, lease ID, run ID and label; admit stores those, not requires |
stores requires and compares it as a set; message gains "or required capabilities" |
I2, S1, B6 |
| X12 | src/core/registry-rows.ts:192 REQUEST_COLUMNS, src/core/registry-schema.ts:155 (last lease_requests migration) |
no requires column |
requires TEXT in the next registry migration |
S1 |
| X13 | src/gateway/dispatcher.ts:735 |
passes idempotencyKey and requires to the fleet coordinator's book |
unchanged; the book's record keeps requires in memory |
B6 |
| X14 | src/cli/commands/lease.ts:65 flags, :94 help, :322 request, :333 farm idempotency key |
no --requires; --requires is Unknown option (run on main, exit 2); a --url request always carries a key |
adds --requires |
I4, B7 |
| X15 | src/mcp/contracts.ts:31, :46 leaseSimulatorInputSchema omits requires; src/mcp/session.ts:190 adds a key in farm mode |
the tool cannot pass requires |
requires is no longer omitted |
I5, B8 |
| X16 | src/cli/format.ts:41, ui/src/model/worker-page.ts:695 |
print or draw each capability entry by name and state | tags show as <name> available with no change |
B1 |
| X17 | website/src/content/docs/docs/reference/errors.mdx:57 |
CAPABILITY_MISSING: "Only the programmatic client asks for modules" |
describes tags and --requires |
#1844, #1845 |
| X21 | src/http/lease-declarations.ts:215 leaseRequestBodySchema (.strict(), no requires), src/http/tracker.ts:97 leaseRequestDispatchInput |
a body with requires is 400; nothing forwards it |
the body takes it and the input forwards it | I7, B9 |
| X18 | src/daemon/dispatcher-leases.ts:52 requireCapabilities, :54 lease options; src/leasing/lease-acquisition-coordinator.ts:94 replay under the lock; src/gateway/fleet-admission.ts:180 the gateway's replay first |
a worker checks capabilities before its replay check and never passes requires to leasing; a gateway replays first |
the worker replays first and passes requires (I6) |
I6, B6 |
| X19 | src/contract/config-schemas.ts:61 configSchema, src/contract/operations-admin.ts:170, src/core/config.test.ts:422 |
config.get strips a key the schema lacks; the test asserts nothing is stripped |
tags is in the schema, optional |
I1, S2 |
| X20 | website/src/content/docs/docs/reference/errors.mdx:51 (IDEMPOTENCY_CONFLICT lists the compared fields), website/src/content/docs/docs/reference/node-client.mdx:94 (requires takes optional modules) |
false once tags and the new comparison land | both name tags and required capabilities | #1844 |
Tasks
- Tags on a worker, matched by requires, and requires with an idempotency key #1844 — tags on a worker, matched by
requires, andrequireswith an idempotency key - simlock lease --requires and MCP lease_simulator requires #1845 —
simlock lease --requiresand MCPlease_simulatorrequires(after Tags on a worker, matched by requires, and requires with an idempotency key #1844)
Written by an agent.
Activity
V3RON commentedon Nov 25, 2026
Design posted: business sections, Decisions (ADR 0091, PR #1841), Behaviours B1–B8, Stored state S1–S2, Interfaces I1–I5, Existing code X1–X17.
Written by an agent.
docs(adr): 0091 replay order, protocol and module-name clash (#1832)
docs(adr): accept 0091 (#1832)
V3RON commentedon Nov 25, 2026
Spec updated: Tasks (#1844, #1845) and the Task cells of Behaviours, Stored state and Interfaces.
Written by an agent.
docs(adr): 0091 HTTP lease route takes requires (#1832)
V3RON commentedon Nov 25, 2026
Spec updated: Outcome, Completion conditions, Decisions, Behaviours (B9), Interfaces (I7) and Existing code (X21) now cover the HTTP lease route. #1844 and #1845 are ready, and ADR 0091 (PR #1841) is Accepted — not yet implemented.
Written by an agent.
docs(adr): 0091 an operator names a worker's tags, and a lease may re…
feat(cli): simlock lease --requires and MCP lease_simulator requires (#…
github-actions commentedon Nov 25, 2026
Closing: all 2 sub-issues are closed. The PR that closed the last one walks the completion conditions (delivery rule 9); reopen this if one does not hold on
main. Flip its ADRs to Accepted if delivery has not.V3RON commentedon Nov 25, 2026
Delivery run
Merged: #1841 (ADR 0091), #1858 (#1844), #1862 (#1845)
Parked: none
Waiting: none
Decided: none
Side notes: #1844's Depends on note named #1842 as prose, which
claim.mjsread as a dependency; reworded to plain numbers. Flaky test #1863 filed (src/agent-device/edge-release.test.ts, fails locally on main too).Written by an agent.