Skip to content

A joined worker can refuse local leases, so the fleet has one line #1966

Done
1 of 1 issue completed
Done

Description

@V3RON

Request: #1247

Problem

On a fleet with few devices, whoever runs on a worker machine skips the line. A joined worker serves local requests from its own queue, and a freed device goes there first. The gateway sends a simulator or emulator request only to a worker whose own queue is empty. The reporter saw three requests wait at the gateway, two for over 45 minutes and one until QUEUE_TIMEOUT, while a local simlock lease made minutes later got the freed device.

An agent on the worker machine can already wait in the gateway's line, by setting SIMLOCK_URL and SIMLOCK_TOKEN. Nothing makes it do so.

Who it is for

The operator of a fleet whose worker machines also run agents.

Outcome

The operator sets a worker to take leases only through its gateway. Every agent then waits in the gateway's one line. An agent that asks the worker directly is told at once where to ask instead.

How it works for the user

flowchart TD
  O[Operator sets gateway.localLeases to deny, restarts the worker] --> A[Agent on the worker machine runs simlock lease]
  A -->|no URL set| R[Refused at once, exit 16, names the gateway]
  R -->|sets SIMLOCK_URL and SIMLOCK_TOKEN| Q[Waits in the gateway's line]
  A -->|URL and token set| Q
  Q --> D[Gets a device on any worker]
Loading

Before, on the worker machine:

$ simlock lease --platform ios --detach
{"lease":{...},"device":{...}}

After, with gateway.localLeases set to deny:

$ simlock config set gateway.localLeases deny
Updated gateway.localLeases in /Users/alex/.simlock/config.json; takes effect on daemon restart.
$ simlock lease --platform ios --detach
{"error":{"code":"LOCAL_LEASES_DENIED","message":"This worker takes leases only through its gateway. Set SIMLOCK_URL=https://gateway.example.com and SIMLOCK_TOKEN to an agent token, or on the gateway's own machine pass --gateway"}}
$ echo $?
16

Examples

On a worker joined to wss://gateway.example.com:

Request Today allow deny
simlock lease, or --local, no URL set granted or queued as today LOCAL_LEASES_DENIED
MCP lease_simulator, no URL set granted or queued as today LOCAL_LEASES_DENIED
simlock lease --physical granted or queued as today LOCAL_LEASES_DENIED
the same with an admin credential granted or queued as today LOCAL_LEASES_DENIED
simlock lease with SIMLOCK_URL set the gateway's line as today the gateway's line
the gateway's request granted or refused as today as today
renew, release, simctl, adb on a lease held before works as today works
a local lease while the gateway is down granted or queued as today LOCAL_LEASES_DENIED

Config values:

gateway.localLeases gateway.url After
not set any allow
"allow" any starts
"deny" set starts
"deny" not set the worker does not start
"via-gateway" any the worker does not start
"deny" in a gateway's file not set ignored with a warning

What could go wrong

  • An operator turns it on before giving local agents a token, and their leases fail (likely; the message says what to do).
  • An agent's build path does not exist on the worker its lease landed on (likely; the docs say so).
  • Behind a gateway under a proxy path (wss://example.com/simlock), agents on the machine have only the HTTP API (possible; the message and the docs say so).
  • An operator who sets the whole gateway section again, for example to change the token, drops the key and allows local leases (possible; for a worker still joined, the docs set gateway.token alone).
  • With the gateway down, agents on the machine get no device (by design).

Words used

  • joined worker: a worker whose config holds gateway.url, e.g. a Mac mini in a fleet.
  • local lease: a lease asked for over the worker's own socket, e.g. simlock lease on that machine with no SIMLOCK_URL.
  • one line: the gateway's queue, where every request waits in one order.

Non-goals

  • Forwarding a local lease to the gateway.
  • Giving the fleet first claim on a freed device while local leases are allowed.
  • Reserving part of a worker for the gateway.
  • Guarding against someone who edits the worker's config file.
  • Setting it from the gateway.
  • Reaching a gateway under a proxy path with SIMLOCK_URL: it takes no path today.

Completion conditions

  • On a joined worker with gateway.localLeases set to deny, simlock lease exits 16 with LOCAL_LEASES_DENIED, and the same machine leases through the gateway.
  • With the key not set, a joined worker's local lease works as before.
  • A worker with deny and no gateway.url does not start, and the error names the key.
  • The website describes the key, the error and how a local agent moves to the gateway's line, and that a gateway under a path takes only the HTTP API there. For a worker whose config still has gateway.url, it changes the token with gateway.token alone, so the other gateway keys stay.

Open questions

Decisions

  • ADR 0097 — A joined worker may refuse local leases: a worker can take leases from its gateway only (PR docs(adr): 0097 a joined worker may refuse local leases #1967).
  • Decided by the maintainer: refuse local leases; no forwarding, no fleet-first priority.
  • Decided by the maintainer (design check): the refusal prints an address SIMLOCK_URL takes; for ws:// to another host it adds the plain-http opt-in; for a gateway under a path it points at the HTTP API.
  • Decided in the session: the opt-in is named as SIMLOCK_ALLOW_INSECURE_HTTP=1, not the flag, because MCP servers take variables.
  • Decided in the session: the key is gateway.localLeases with allow and deny, default allow, because the request named it and existing fleets must not change.
  • Decided in the session: deny covers every role and phones too, because all local callers are one OS user and phones have the same two lines.
  • Decided in the session: deny stays on while the gateway is down, because falling back would reopen the second line.
  • Decided in the session: only a new lease is refused, because a restart to turn it on must not strand a lease in use.
  • Decided in the session: a repeat of a request the worker already stored is still answered from the store, because a replay starts nothing; the requires check does the same.
  • Decided in the session: exit 16, as the other refusals by operator policy, and no event and no stored request, as for CAPABILITY_MISSING.

Behaviours

Id Behaviour (invoker, action, what it sees) Seam Cases Task
B1 A caller whose lease.request is not on the gateway's uplink, on a worker with deny, gets I2; nothing is stored, queued or granted, and no event is emitted lease.request through the worker's Dispatcher agent; admin; physical: true; noWait: true; a requires the worker lacks (I2, not CAPABILITY_MISSING); an idempotency key not stored #1969
B2 The gateway's uplink on a worker with deny leases as before the same a probe with fleetRequestId and noWait: true is granted #1969
B3 A local caller on a worker with deny still uses what it has the same renew, release and get of a lease granted before; a repeat of a stored request under its idempotency key gets the stored answer #1969
B4 A local caller on a worker with allow leases as before the same key not set; allow #1969
B5 An operator loads a config with I1 loadConfig each row of Examples' config table, the refusal and the warning worded as I1 says; deny in the file and gateway.url in an override starts #1969
B6 An admin reads the config, and sees the key as set config.get output schema allow; deny; absent (an older worker's answer parses) #1969
B7 A caller refused under deny reads an address it can use in I2's message, and details to match lease.request through the worker's Dispatcher; every address of A and B is also given to checkedFarmUrl, which accepts it (B's with plain http allowed) wss://gw.example.com and wss://gw.example.com/: A with https://gw.example.com; ws://127.0.0.1:4700: A with http://127.0.0.1:4700; ws://10.0.0.5:4700: B with http://10.0.0.5:4700; ws://localhost:4700, ws://[::1]:4700 and wss://u:[email protected]/?k=v#f: A with http://localhost:4700, http://[::1]:4700 and https://gw.example.com; wss://gw.example.com/simlock/: C with https://gw.example.com/simlock #1969
B8 An agent on a joined worker's machine with deny leases with the CLI: without a URL it exits 16 with I2 on stderr, and with the printed SIMLOCK_URL and an agent token of the gateway it is granted a device of that same worker the built CLI, a gateway and a worker with fake drivers no URL; --local; the address the refusal printed as SIMLOCK_URL, with a token #1969

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 the key gateway.localLeases in the worker's config.json the operator, by config set or by hand read once at daemon start; config.get the old or the new value: one file write none #1969 —

Interfaces

Id What Shape and bounds Errors and limits Where Task Used by
I1 config key gateway.localLeases "allow" or "deny"; default "allow"; optional in config.get's schema, since a gateway parses an older worker's answer; worker-only. Bumps the protocol by one, once with I2 another value: the worker does not start, worded by stringUnion. deny without gateway.url: Invalid config value for "gateway.localLeases": expected gateway.url to be set too, since gateway.localLeases is "deny". In a gateway's file: Ignoring "gateway.localLeases": it points a worker at its gateway, and this daemon runs in gateway mode. src/core config, src/contract/config-schemas.ts #1969 —
I2 error LOCAL_LEASES_DENIED of lease.request kind domain, CLI exit 16, HTTP 403; details gatewayUrl (string): gateway.url with wss: as https: and ws: as http:, its host, port and path, without user, password, query, fragment or trailing slashes A, no path and https or a loopback host: This worker takes leases only through its gateway. Set SIMLOCK_URL=<gatewayUrl> and SIMLOCK_TOKEN to an agent token, or on the gateway's own machine pass --gateway. B, no path and http to any other host: This worker takes leases only through its gateway. Set SIMLOCK_URL=<gatewayUrl>, SIMLOCK_ALLOW_INSECURE_HTTP=1 (the token is sent unencrypted) and SIMLOCK_TOKEN to an agent token, or on the gateway's own machine pass --gateway. C, a path: This worker takes leases only through its gateway (<gatewayUrl>). Use the gateway's HTTP API with an agent token, or on the gateway's own machine pass --gateway src/contract/errors.ts; thrown in the worker's lease.request handler before requireCapabilities and after the owner and fleetRequestId refusals. Loopback is I3 #1969 —
I3 isLoopbackHost(hostname: string): boolean true for 127.0.0.1, [::1] and localhost, as checkedFarmUrl decides today; checkedFarmUrl calls it — src/shared #1969 —

Existing code

Commit f2393e3.

Searches: rg 'lease\.request"|leases\.request\(' src, tests left out: 14 lines; rg -l leaseRequestTimeoutMs src (every place that holds the whole gateway config section): 17 files; rg isGatewayUplink src, tests left out; rg ADMISSION_DENIED over the repo, for what an error code touches.

Id Code (path:line) Today With this feature Handled by
X1 src/daemon/dispatcher-leases.ts:53 a request not stored yet has its requires checked, then goes to leasing the same guard first refuses a non-uplink session under deny B1, B3
X2 src/daemon/server.ts:527 only a connection accepted as the uplink sets isGatewayUplink the one test for a local caller B1, B2
X3 src/core/config-role-checks.ts:254 a joined worker refuses HTTP, so only the socket and the uplink reach its dispatcher unchanged; no HTTP, session or local agent-device caller to handle B1
X4 src/agent-device/front/allocate.ts:257 agent-device through a gateway asks the gateway's dispatcher, which probes the worker over the uplink unchanged, allowed B2
X5 src/core/config-role-checks.ts:221 checks gateway.url against its partner keys on a worker, after layers merge also checks I1 B5
X6 src/core/config-role-checks.ts:103 the worker-only gateway.* keys a gateway warns about also lists I1 B5
X7 src/core/config-validators.ts:165 the gateway section's validators; a test requires each key in the website's configuration page gains I1 B5
X8 src/contract/config-schemas.ts:167 config.get's gateway section; a key not declared is stripped gains I1, optional B6
X9 src/contract/errors.ts:735 the codes, their details and their table gains I2 B1
X10 src/gateway/routing/stages/idle-queue.ts:6 a worker with a waiting local request gets no virtual fleet request unchanged; under deny no local request waits, since a restart fails the ones still open B2
X12 src/simlock-client/farm-url.ts:39 SIMLOCK_URL is an http(s) origin, http only to loopback unless opted in; the loopback hosts are a private set there the set moves behind I3, shared with I2's message; the rule itself is unchanged B7
X11 src/mcp/session.ts:123 a typed error reaches the MCP client with its code and message unchanged, shows I2 B1

Tasks

Every Completion condition: #1969. The first three by its unit and end-to-end tests, the last by its Done when lines on the website pages.

Open work in the same area:

Written by an agent.

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    feature:spec
    on Nov 30, 2026
  2. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Design posted: every section below Problem.

    Written by an agent.

  3. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Approve?

    #1966 A joined worker can refuse local leases, so the fleet has one line: #1966

    ADR 0097 (PR #1967): a joined worker's operator may set it to take leases only from its gateway. The default allows local leases, as today.

    Decided in the session:

    • The key is gateway.localLeases: allow (default) or deny. deny needs gateway.url.
    • deny covers every role, and phones too.
    • deny stays on while the gateway is down.
    • Only a new lease is refused. Leases already held keep working, and a repeat of a stored request is still answered.
    • The refusal is LOCAL_LEASES_DENIED, exit 16. It stores nothing and emits no event.
    • The refusal names SIMLOCK_ALLOW_INSECURE_HTTP=1 for a plain-http gateway on another host.
    • The docs' steps to change a join token set gateway.token alone, so the key is not dropped.
    Task What it delivers Rows Depends on
    T1 A joined worker can refuse local leases B1 to B8, S1, I1 to I3 —

    Check: ready

    Written by an agent.

  4. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Spec updated: the task is #1969; Tasks filled.

    Written by an agent.

  5. added
    feature:planned
    and removed
    feature:spec
    on Nov 30, 2026
  6. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Tasks ready.

    Task What it delivers Depends on
    #1969 A joined worker can refuse local leases, so the fleet has one line #1134, #1904, #1905, #1907 (protocol range)

    chain 1 of 1 tasks

    Decided since the design was settled:

    Written by an agent.

  7. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1967 (ADR 0097), #1977 (#1969)
    Parked: none
    Waiting: none
    Decided: #1969 — should B7 cover a [::1] gateway? → yes, a test case only; I3 already decides the behaviour
    Asleep: 24 min

    Written by an agent.

  8. github-actions commented on Nov 30, 2026

    @github-actions
    Contributor

    Closing: all 1 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.

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

    feature:planned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions