Repository navigation
Description
Part of #1419.
Scope
A test runner's boot on its leased device succeeds, answered by simlock, so a runner that always boots first (the e2e runner) needs no relay. A boot that names no lease, a lease the token does not hold, an ended lease or another device is refused by the front. A runner on agent-device's own client, which drops the address from the allocate reply (F16), reads its device's udid or serial as the boot answer's id.
In short
Today the front forwards boot (F4), and agent-device refuses it because simlock's policy file denies boot (F1, F2). After this PR the front answers a boot on a lease the token holds with a success reply built from what it knows of the lease (F5), in the shape agent-device's own boot reply has (F6). agent-device never sees it, and the policy keeps denying boot and shutdown, so nothing boots a device behind simlock's back.
flowchart LR
R[runner: boot --udid U, leaseId L] --> F[front]
F -->|changed: answered from the lease| R
F -.->|no longer forwarded| A[agent-device]
Before:
boot --udid 6F2C… (leaseId L)
→ error UNAUTHORIZED "This daemon's policy denies the boot command."
After:
boot --udid 6F2C… (leaseId L)
→ { "ok": true, "data": { "platform": "ios", "target": "mobile", "device": "iPhone 17 Pro", "id": "6F2C…", "kind": "simulator", "booted": true } }
boot call |
Today | After |
|---|---|---|
| names the token's lease, no device selector | refused by agent-device's policy | answered, id = the lease's address |
names the token's lease and --udid = its address |
refused by agent-device's policy | answered |
names the token's lease and --device <its name or model> |
refused by agent-device's policy | answered |
names the token's lease and another --udid, or a --platform other than the lease's |
refused: simlock picks the device (--udid), refused by agent-device's policy (--platform) |
refused: simlock picks the device |
names the token's lease and a --target |
refused by agent-device's policy | answered; the --target is not checked |
| names a lease simlock ended (still in the front's map) | refused by agent-device's policy | lease ended by simlock; run disconnect, then open |
| names a lease the agent ended (close or release) | refused by agent-device's policy | refused: this lease has ended; open a device |
| names a lease of another token | refused by agent-device's policy | refused: simlock picks the device |
| names no lease and no device | refused by agent-device's policy | refused: boot names no lease; open a device first |
names no lease and --udid X |
refused: simlock picks the device |
the same |
The reply's kind is simulator for an iOS simulator, emulator for an Android emulator and device for a physical phone. device is the device's name if the front has already read it from agent-device's device list for this lease (F11), else the lease's model; boot makes no call to read it. target is the --target the allocate asked for, mobile when it named none; it is kept in its own field of the map entry, so the target that test sharding reads (F15) stays as today.
If this goes wrong, a runner's boot fails as today, or a boot on another device is answered.
Technical spec
Facts
Commit e4599cf.
| # | Fact | Source |
|---|---|---|
| F1 | simlock's policy file denies boot and shutdown. |
src/agent-device/shared/daemon-environment.ts:9 |
| F2 | agent-device refuses a denied command with UNAUTHORIZED "This daemon's policy denies the boot command." before it resolves a device. |
agent-device v0.21.35:packages/daemon/src/core/daemon-policy.ts:163-188, v0.21.35:packages/daemon/src/core/daemon-policy.ts:29 |
| F3 | The front reads a command's name and its lease from meta.leaseId or flags.leaseId. |
src/agent-device/shared/selectors.ts:50-52, src/agent-device/shared/rpc.ts:124-129 |
| F4 | checkRequest runs on every RPC before routing; then a command naming no lease is forwarded with no lease handling, and one naming a lease is forwarded with renewals. Today boot passes the rules and reaches agent-device. |
src/agent-device/front/front.ts:111-128, :131-151, src/agent-device/edge-request-rules.test.ts:995-1001 |
| F5 | The front map entry of a lease holds its address, platform, model and physical from the grant; name and target only from a device in agent-device's allocate reply, which real agent-device never sends. The rules see the entry only when the lease is the token's, ended or not. |
src/agent-device/front/front-map.ts:6-24, src/agent-device/front/allocate.ts:368-377, :430-437, src/agent-device/front/request-rules.ts:360-372, agent-device v0.21.35:packages/daemon/src/sessions/handlers/lease.ts:141-144 |
| F6 | agent-device's boot reply carries platform, target, device (the device name), id, kind, booted and selection; kind is one of simulator, emulator, device. |
agent-device v0.21.35:packages/daemon/src/sessions/handlers/session-device-status-response.ts:21-39, v0.21.35:packages/kernel/src/device.ts:44 |
| F7 | The e2e runner reads id and device from the boot reply. |
@e2e-dev/mobile v0.12.5:dist/surface.js:368-369 |
| F8 | A udid or serial other than the lease's address is refused with refused: simlock picks the device, as is a device selector with no leased lease. |
src/agent-device/front/request-rules.ts:27, :215, :241-250 |
| F9 | The front already answers one command itself: orientation on an iOS simulator lease, with successReply. |
src/agent-device/front/orientation.ts:77-89, src/agent-device/shared/replies.ts:59-61 |
| F10 | The slow lane asserts boot is refused after an upload install. |
e2e/slow-agent-device.test.ts:326-327 |
| F11 | A rule that checks a --device name reads agent-device's device list once per lease and keeps the name in the map; agent-device's allocate reply names no device. |
src/agent-device/front/request-rules.ts:205-210, agent-device v0.21.35:packages/daemon/src/sessions/handlers/lease.ts:141-144 |
| F12 | The map keeps an ended entry one TTL with endedBy simlock or agent; heartbeat answers a simlock-ended lease with leaseEndedByHost and relays agent-device's reply for an agent-ended one. |
src/agent-device/front/front-map.ts:79-82, :118-124, :174, src/agent-device/front/heartbeat.ts:130-131, :150 |
| F13 | A --device naming the leased device's name or model is accepted by the rules. |
src/agent-device/front/request-rules.ts:212-223 |
| F14 | The slow-lane suite runs each case for iOS and, with the SDK, Android, and the case knows its lease's address. | e2e/slow-agent-device.test.ts:150, :326-336, :819 |
| F15 | test sharding counts a lease by the map entry's target, mobile when unset, and real agent-device never sets it. |
src/agent-device/front/request-rules.ts:270-276, src/agent-device/edge-request-rules.test.ts:641-646 |
| F16 | agent-device's client keeps only model, osVersion, imageTag and physical of the allocate reply's lease.device. |
agent-device v0.21.35:src/client/lease-client.ts:97, v0.21.35:packages/contracts/src/lease-scope.ts:362-375 |
Modules touched
Searches: "boot" in src/agent-device (policy, tests), successReply (2 callers), commandName and checkRequest callers in front/.
flowchart LR
FR[front/front.ts *] --> B[front/boot.ts * new]
B --> M[front/front-map.ts]
B --> RP[shared/replies.ts]
FR --> RR[front/request-rules.ts]
Changed: src/agent-device/front/front.ts, a new src/agent-device/front/boot.ts, src/agent-device/front/allocate.ts (map.add keeps the requested --target, default mobile, in a new field), src/agent-device/front/front-map.ts (that field, beside the reply's target), src/agent-device/front/front.ts adoptLeases (fills that field from the device class adoptable() maps after a gateway restart, src/agent-device/front/front.ts:371-384, src/agent-device/front/relay-host-link.ts:175), src/agent-device/edge-request-rules.test.ts, e2e/slow-agent-device.test.ts, website/src/content/docs/docs/using-devices/agent-device.mdx, src/agent-device/AGENTS.md.
Contract and event changes
None in simlock's contract. The boot reply copies agent-device's shape (F6) without selection, which the e2e runner does not read (F7). No event.
Other code on the same state
Searches: front map reads (map.get, 14 hits). boot reads the map entry only. orientation (F9) answers another command and shares nothing. A batch with a boot step is forwarded as today: agent-device's policy refuses it.
Failure modes
| Call | Outcome | What happens | Limit, counted from |
|---|---|---|---|
boot on the token's lease |
answered | success reply, nothing forwarded | none: answered at once |
boot naming no lease and no device |
refused | refused: boot names no lease; open a device first |
none |
boot on a lease simlock ended |
refused | lease ended by simlock; run disconnect, then open (leaseEndedByHost) |
none |
boot on a lease the agent ended |
refused | refused: this lease has ended; open a device |
none |
boot on a lease not the token's, another device, or another --platform |
refused | refused: simlock picks the device |
none |
boot on a lease whose device has crashed |
answered | booted: true; the next forwarded command fails as it does today |
none; no test: the front does not read device state (ADR 0070 §1) |
Rules in play
- ADR 0070 §1, "answered by the front from what it knows of the lease. It is never sent to agent-device".
- ADR 0023 §3, "a policy file that refuses
bootandshutdown": kept.
Tests
Seam: the agent-device front with agent-device faked, src/agent-device/edge-request-rules.test.ts (model: the case at :995-1001, which this replaces).
- A runner sends
booton its lease and simlock answers it; agent-device gets noboot. Cases: iOS simulator; Android emulator; physical phone (kind: device); a lease taken with--target tv; name read from the device list; model only;--udidof the lease;--deviceof its name; a boot--targetdifferent from allocate's target (ignored); a gateway-adopted lease whose reply uses its adopted device class; unsupportedruntime.udidnaming another device (ignored, reply still names only the held lease; decided in delivery, pending the maintainer). - A
bootthat names no lease, another token's lease, an ended lease or another device is refused. Cases: no lease and no device; another token's lease; another device's udid; a--platformother than the lease's (a rig with both drivers, since a platform simlock lacks is refused earlier withrefused: android is not available on this simlock); a lease simlock ended; a lease the agent ended.
Done when
pnpm exec vitest run --project unit src/agent-device/edge-request-rules.test.tspasses with both Tests lines.- Slow lane (agent-device through simlock, iOS):
scripts/slow-e2e.sh e2e/slow-agent-device.test.ts -t "after an accepted upload install"passes withbootmoved from the refused list to an answeredbootwhoseidis the case's lease address (a udid on iOS, a serial on Android). agent-device.mdxsaysbooton a leased device is answered by simlock, that itsidis the device's udid or serial (the way to get it for a caller on agent-device's client), and listsrefused: boot names no lease; open a device firstandrefused: this lease has ended; open a deviceunder Messages you may see.
Out of scope
- Letting agent-device boot a device (ADR 0070 §1).
shutdown: still denied.
Depends on
Written by an agent.
Activity
test: refuse boot outside a live lease (#1422)
feat(agent-device): refuse boot outside a live lease (#1422)
test(agent-device): cover boot target and adopted leases (#1422)
test(agent-device): cover boot target and platform cases (#1422)
fix(agent-device): check lease before answering boot (#1422)
fix(agent-device): retain physical kind on adoption (#1422)
docs(agent-device): qualify local boot behavior (#1422)
test(agent-device): cover gateway boot expiry (#1422)
test(agent-device): assert default boot target literally (#1422)
test(agent-device): probe literal boot default first (#1422)
docs(agent-device): remove duplicated worker flow step (#1422)
V3RON commentedon Nov 7, 2026
Handoff
Done
Boot behavior, acceptance tests and documentation are implemented. R1–R8 are fixed and verified. Unit tests and website checks passed. Reviewed head:
82c6be51c8a9b7d85df75d4fbaf4f534fef62236; PR #1439.Not done
Done when line 2: real agent-device boot after an accepted upload install. The slow lane ran no test. CI is pending; delivery continues its CI follow-up.
Findings
scripts/slow-e2e.sh checkexited 69: worker pid 89138 holds/Users/aitwar/.simlock. No worker, device or configuration was changed. All review findings are resolved; the unchecked hardware checklist line is intentional.Blocked on
The maintainer must free the slow-lane machine and rerun hardware verification. #1424 and the feature stack wait. PR remains open with
needs-hardware.Written by an agent.
refactor(agent-device): lower boot check and test complexity under th…
test(agent-device): boot scenario helper is split under the CRAP thre…
docs(adr): accept 0070, test runners drive a lease through the agent-…
feat(agent-device): label front errors with retry guidance (#1437)
feat(agent-device): retain leases through close (#1436)
feat(agent-device): answer boot on the leased device (#1439)