Repository navigation
Description
Part of #1326.
Scope
A client asks for a slim iOS lease with except (CLI --except store,other, HTTP and MCP except) and gets a slim simulator booted with those categories on. It is told so on the device (except beside mode). A warm slim device serves it after one reboot. A request the worker cannot serve is refused BAD_REQUEST, and a device whose boot fails is never granted. This task covers a worker, not a gateway (T4).
Kept whole: the contract field, its refusals, the grant path and the device field are one behaviour seen through one seam (lease.request); a split would leave a field accepted and ignored.
In short
lease.request takes except. Leasing hands it to the driver at resolve (which checks the names, T2) and at the boot before the grant. The request's effective mode (the baseline's when it names one, else mode, else the worker's default) must be slim. A ready warm device is claimed, shut down, and prepared again with the except list before the grant. A failure destroys the device and the request plans again once; the second failure rejects PROVISION_FAILED.
The reboot of a warm device, step by step (a new plan, reboot-ready, chosen only when the resolved spec is slim and the request has except; below iOS 18.5 the spec is full and a ready full device is granted as today):
- Plan (lock): take a
bootclaim on the ready device. No capacity reservation: the device keeps its running slot and RAM, because its record staysreadythrough the reboot. - Reboot (no lock,
rebootForLeasein core's lifecycle, under the held claim): drivershutdown, thenmakeReady({ purpose: "prepare", mode: "slim", except }). Nothing is committed in between: the record staysready, so no other part acts on it (it is claimed) and the warm pool counts it as handed to a lease (areadydevice under abootclaim, F27). - Commit, as one new registry write with no transition and no event (
ready → readyis no edge,src/core/domain.ts:515), the fieldsreadyTransitionUpdatebuilds frommakeReady's result:driverData,addressandmode(readyDevice.mode ?? "full",src/core/driver.ts:98-104), so a reboot grantedfullrecordsfull. Then grant through#grantHandoff;lease.granted.sourceisbooted(the client waited for a boot).
On a failure in step 2 the lifecycle commits ready → shutdown (an existing edge, device.shutdown initiator lease), then destroys the device as a boot failure does; a destroy that fails goes to quarantine, which takes a shutdown device (F26).
flowchart LR
A[lease.request except] --> B{contract refusals} -->|ok| C[resolve: driver checks names]
C --> D{plan}
D -- ready warm device --> E["claim, shut down, prepare with except *new*"]
D -- shut-down device --> F["boot with except *changed*"]
D -- provision --> G["provision, prepare with except *changed*"]
E & F & G --> H[grant: device.except]
E & F & G -- fails --> I["destroy, plan again once *new*"] --> J[PROVISION_FAILED]
Session, after:
$ simlock lease --platform ios --mode slim --except store,other
{ "lease": { ... }, "device": { "mode": "slim", "except": ["store", "other"], ... } }
$ simlock lease --platform ios --mode full --except store
error BAD_REQUEST: except needs a slim lease (mode is full)
$ simlock lease --platform ios --except store # worker ios.defaultMode: full
error BAD_REQUEST: except needs a slim lease (this worker's default mode is full)
$ simlock lease --platform ios --mode slim --except store,store
error BAD_REQUEST: except names "store" twice
| Input | Today | After |
|---|---|---|
--mode slim --except store,other |
unknown option --except |
granted slim, except: [store, other] |
--except store, default slim |
unknown option | granted slim, except: [store] |
--except store, default full |
unknown option | BAD_REQUEST except needs a slim lease (this worker's default mode is full) |
--baseline b --except store, baseline slim, default full |
unknown option | granted slim, except: [store] (the baseline's mode wins) |
--mode full --except store |
unknown option | BAD_REQUEST except needs a slim lease (mode is full) |
--physical --except store |
unknown option | BAD_REQUEST except is for iOS simulators |
--platform android --except store |
unknown option | BAD_REQUEST except is for iOS simulators |
--except store,store |
unknown option | BAD_REQUEST except names "store" twice |
--except Store |
unknown option | BAD_REQUEST (schema: a-z0-9-, starting with a letter) |
--baseline b --except store, baseline full |
unknown option | BAD_REQUEST except needs a slim lease (baseline "b" is full) |
--mode slim --except store on iOS 18.4 |
unknown option | granted full, no except |
HTTP {"except": ["store"]} |
BAD_REQUEST (strict body) |
as the CLI |
If this goes wrong, a lease is granted a slim device that was never booted with the smaller list, so Wallet's services are off.
Technical spec
Facts
Commit cc39ec8.
| # | Fact | Source |
|---|---|---|
| F1 | lease.request input has mode and is .strict() |
src/contract/operations.ts:160, :180 |
| F2 | The physical refinement refuses mode on a physical request; one list to extend |
src/contract/operations.ts:232-236 |
| F3 | requestedDevice rebuilds the request field by field for the handler and lease.requested |
src/contract/operations.ts:314-325 |
| F4 | The contract imports nothing, so a refusal that needs config cannot sit in it | src/contract/operations.ts:168; contract manual |
| F5 | The device in the lease reply, list.get and status.get carry mode |
src/contract/schemas.ts:319, :260, :281 |
| F6 | lease.get and the lease record carry no device mode |
src/contract/operations.ts:546; src/contract/schemas.ts:338-349 |
| F7 | Protocol range { min: 77, max: 77 } |
src/contract/protocol.ts:13 |
| F8 | Schema failures become BAD_REQUEST |
src/daemon/dispatch.ts:395 |
| F9 | UnsupportedRequestOptionError maps to BAD_REQUEST |
src/daemon/error-code.ts:154-158 |
| F10 | CLI mode option and its cast; the grant is printed as JSON |
src/cli/commands/lease.ts:55, :204, :225-227 |
| F11 | The HTTP body is hand-written and .strict(), mode at 207 |
src/http/lease-declarations.ts:199-217 |
| F12 | The MCP lease input inherits the contract's fields | src/mcp/contracts.ts:37-38, :45-49 |
| F13 | lease.requested is emitted at admission with requestSpec: request |
src/leasing/lease-acquisition-coordinator.ts:313-322 |
| F14 | A resolve failure rejects unresolvable-spec with the error's code |
src/leasing/lease-acquisition-coordinator.ts:511, :528 |
| F15 | A baseline request resolves from the baseline, which carries its mode; the default mode is applied in one place | src/leasing/lease-acquisition-coordinator.ts:546-548 |
| F16 | A first provision failure counts and plans again; the second rejects ProvisionFailedError |
src/leasing/lease-acquisition-coordinator.ts:989-1001 |
| F17 | A boot failure of a shut-down device destroys it and rejects boot-timeout, no retry |
src/leasing/lease-acquisition-coordinator.ts:1270-1276 |
| F18 | A ready warm device is granted inside the lock with no claim (grant-ready) |
src/leasing/acquisition-planner.ts:75-76, :125-129; src/leasing/lease-acquisition-coordinator.ts:1040-1063 |
| F19 | Provisioned and booted handoffs go through #grantHandoff with the boot claim held |
src/leasing/lease-acquisition-coordinator.ts:1012, :1279, :1320 |
| F20 | Lifecycle verbs bootForLease, bootWarm, readyProvisionedForLease, shutdown |
src/core/managed-device-lifecycle.ts:71-102 |
| F21 | Registry schema version 3, migrations add columns with ALTER TABLE devices ADD COLUMN |
src/core/registry-schema.ts:118-130 |
| F22 | A virtual device serves one lease (mayBeGranted) |
src/core/domain.ts:387-396 |
| F23 | Docs naming --mode: CLI reference, choosing a device, errors (BAD_REQUEST, PROVISION_FAILED) |
website/src/content/docs/docs/reference/cli.mdx:98,111,117; website/src/content/docs/docs/using-devices/choosing-a-device.mdx:107-121; website/src/content/docs/docs/reference/errors.mdx:46,52 |
| F24 | Model test: dispatcher leases with driverOptions: { mode: "slim" } |
src/daemon/dispatcher.test.ts:228-240, :2871-2891; coordinator harness src/leasing/lease-acquisition-coordinator.test.ts:99, :1500-1512 |
| F25 | GRANT_SOURCE maps each granting plan to lease.granted.source (warm, booted, provisioned), which usage stats count |
src/leasing/lease-acquisition-coordinator.ts:204-211; src/history/projections/usage/wire.ts:31; docs/internal/EVENTS.md:51 |
| F26 | shutdown takes a ready device under any claim but boot; destroy takes only provisioning/shutdown; a lease boot claims boot on provisioning/shutdown |
src/core/managed-device-lifecycle.ts:102-124, :228-236 |
| F27 | Capacity counts a device by its state; boot-shutdown takes tryReserveBoot; the warm pool counts a ready device under a boot claim as handed to a lease |
src/core/capacity/devices.ts:12-19; src/leasing/acquisition-planner.ts:174-192; src/core/warm-pool/converger.ts:638-641 |
| F28 | HTTP copies body fields to lease.request one by one, and builds the flat lease reply (top-level mode) field by field |
src/http/tracker.ts:64-102, :257 |
| F29 | osVersion is a plain string checked by an object-level refinement, because the MCP SDK checks a refined field before the handler and its error stands in for BAD_REQUEST; a refinement with a path gets it prefixed (<path>: <message>) |
src/contract/operations.ts:156-157; src/mcp/contracts.ts:49-56; src/contract/errors.ts:605-613 |
| F30 | The replay check compares stored request fields; lease_requests gained baseline in V3 |
src/leasing/lease-request-book.ts:412-423; src/core/registry-rows.ts:330-347; src/core/registry-schema.ts:123-124 |
| F31 | UnsupportedRequestOptionError builds a fixed message; #1329 adds BadDeviceRequestError(message) mapped to BAD_REQUEST |
src/core/driver.ts:591-598; #1329 Modules touched |
Modules touched
Searches: mode in operations.ts, schemas.ts, lease-declarations.ts, lease.ts (CLI); requestedDevice; grant-ready; bootForLease; registry-schema versions; --mode in website/.
flowchart LR
cli[cli lease *changed*] --> contract
http[http lease body *changed*] --> contract
mcp[mcp, inherits] --> contract
contract["contract *changed*<br/>except, refinements, device.except, protocol +1"] --> disp[daemon dispatcher]
disp --> leasing["leasing *changed*<br/>resolve, plan rebooting a warm device, failure count"]
leasing --> core["core *changed*<br/>lifecycle verb, registry column"]
core --> driver[driver makeReady except, T2]
sequenceDiagram
participant C as Client
participant L as Leasing
participant K as Core lifecycle
participant D as iOS driver
C->>L: lease.request except [store]
L->>D: resolveSpec (checks names)
L->>K: claim ready device, rebootForLease(except)
K->>D: shutdown, makeReady(prepare, slim, except)
alt ok
D-->>K: slim device
K-->>L: handoff
L-->>C: granted, device.except [store]
else KeptCategoriesError or boot failure
K->>D: destroy
L->>L: failures 1 → plan again; 2 → PROVISION_FAILED
L-->>C: PROVISION_FAILED (second)
end
src/contract/operations.ts(field, refinements,requestedDevice),schemas.ts(deviceexcept),protocol.ts(+1)src/cli/commands/lease.ts,src/http/lease-declarations.ts(body),src/http/tracker.ts(copiesexcepttolease.request; the flat reply gets top-levelexceptbesidemode, F28),src/mcp/(inherits; tool description)src/leasing/lease-acquisition-coordinator.ts(effective-mode refusal at resolve;reboot-readyperform; one failure count across provision,boot-shutdownandreboot-readywhen the request hasexcept;GRANT_SOURCE["reboot-ready"] = "booted"),acquisition-planner.ts(reboot-ready),lease-lifecycle.ts(the grant commit writesdevice.except),lease-request-book.ts(replay comparesexcept)src/core/managed-device-lifecycle.ts(rebootForLease),driver.ts(passesexcept),domain.ts(DeviceRecord.except),registry.ts,registry-rows.ts,registry-schema.ts(V4:devices.except_categories TEXTandlease_requests.except_categories TEXT, names joined by,)src/daemon/error-code.ts(the leasing refusal uses The iOS driver boots a slim simulator with a lease's except list #1329'sBadDeviceRequestError, already mapped)- docs:
website/.../reference/cli.mdx,choosing-a-device.mdx,errors.mdx,connect-your-agent.mdx,remote-agents.mdx;docs/internal/EVENTS.md(lease.requested;lease.grantedsourcebootedfor a rebooted warm device); manuals of leasing, core, contract
Contract and event changes
This PR bumps the protocol by one.
lease.request.except: a plainz.array(z.string())field, checked by one object-level refinement with no path (F29), so every transport, MCP included, answersBAD_REQUESTwith the message as written: 1 to 16 items (except names 1 to 16 categories), each matching^[a-z][a-z0-9-]{0,31}$(except: "<name>" is not a category name), distinct (except names "<name>" twice); withphysical: trueor a platform other thanios(except is for iOS simulators); withmode: "full"(except needs a slim lease (mode is full)). This is a refinement of its own, notrefusePhysicalWithImageFields.- The leasing refusals (effective mode full) throw
BadDeviceRequestError(F31) with the messages in the table above. - Device shapes (
grantedDeviceSchema,deviceRecordSchema,statusDeviceSchema): optionalexcept, the same item bounds; absent when none. lease.requested:requestSpec.exceptas the request named it (EVENTS.md row).
Other code on the same state
Searched devices column writers (registry.ts registerDevice, createLease, transitions), grant-ready and every makeReady caller (managed-device-lifecycle.ts, warm pool bootWarm, health recoverLeased):
- Warm pool: boots warm devices with no except (unchanged). A warm device claimed for an except reboot is no longer free; the pool sees it claimed, as with a grant, and refills by its own rule.
- Health monitor:
recoverLeasedboots withrecover, which writes nothing (ADR 0060), so the smaller list stays. - Cleanup and reaper skip claimed and leased devices (core rules).
device.exceptis written only in the grant commit; a device never serves a second lease (F22), so nothing clears it.- Open PR feat(ios): lease --label names the leased simulator #1243 (
lease --label, request A lease's label is its device's window title: lease --label #1240, no task issue) addslabelto the same request and device shapes and bumps the protocol: whichever merges second takes the other's fields and bumps again. - Warm pool: a baseline kind is learned on its Nth lease in 24 h and warms its newest version #1261 bumps the protocol: this task depends on it.
Failure modes
| Call | Outcome | What happens | Limit, counted from |
|---|---|---|---|
resolveSpec with except |
BadDeviceRequestError (#1329) |
rejected unresolvable-spec, BAD_REQUEST, the driver's message |
none |
| resolve, no mode, no baseline, default full | refused | BAD_REQUEST except needs a slim lease (this worker's default mode is full) |
none |
| resolve, baseline full | refused | BAD_REQUEST except needs a slim lease (baseline "<name>" is full) |
none |
reboot-ready: driver shutdown |
fails | commit ready → shutdown, destroy (a failed destroy goes to quarantine, as after a boot failure); counts one failure |
30 s per simctl call, as today |
reboot-ready: makeReady |
boot failure or KeptCategoriesError |
the same: commit ready → shutdown, destroy; counts one failure |
ios.slim.bootTimeoutMs, from the boot |
boot-shutdown with except |
boot or KeptCategoriesError |
destroy (state shutdown); counts one failure and plans again, instead of today's boot-timeout reject |
ios.slim.bootTimeoutMs |
makeReady with except |
KeptCategoriesError |
destroy; counts one failure | — |
makeReady with except |
BootTimeoutError |
destroy; counts one failure (not boot-timeout) |
ios.slim.bootTimeoutMs, from the boot |
| second failure | — | rejected PROVISION_FAILED with the last message |
— |
makeReady granted full |
runtime below 18.5 or non-kept mismatch | granted, mode: full, no except |
— |
A restart mid-reboot: a normal stop waits for it (settleAcquisitions). A crash mid-reboot leaves the open request failed at startup (daemon-restarted) and, for a warm reboot, a ready record whose simulator may be shut down; startup's reconcile only reports that drift (fix is off, src/daemon/main.ts:701-704). A later grant of it is caught by the health monitor, which reboots it under the lease (device-unhealthy, then device-recovered). Known gap, written in the leasing manual; no test (a crash between two driver calls). Two requests for one warm device: the claim lets one take it; the other plans again.
Rules in play
- ADR 0066 §1-§4: field, refusals, the smaller list at the boot before the grant, one retry,
excepton the device. - ADR 0007 §5, "Full is a guarantee": an except lease is granted only as asked or
full. - leasing manual, "Read-decide-commit runs under it; driver I/O never does": the reboot runs outside the lock under a claim.
- contract manual, "Every change to a contract shape bumps it by one in the same PR".
- documentation rule 9: CLI, HTTP, MCP and errors pages updated.
Tests
Seam: lease.request through the daemon dispatcher with the fake driver, modelled on dispatcher.test.ts (the slim driverOptions cases at 2871-2891) and the coordinator harness (lease-acquisition-coordinator.test.ts:1500-1512).
- A client leases slim with
exceptand is granted a device reporting it: cases warm ready device (shut down and prepared with the except list, then granted); new device (provisioned and prepared with it); runtime below 18.5 (granted full, noexcept); the device'sexceptin the reply,list.getandstatus.get, andrequestSpec.exceptonlease.requested. - A client's
exceptrequest is refused: cases duplicate; bad characters;mode: full; no mode, no baseline, default full; full baseline; a slim baseline with default full is granted, not refused; physical; Android; the driver's refusal reaches the client asBAD_REQUESTwith its message; on socket, HTTP and MCP. - A failed
exceptboot is never granted: cases warm reboot's prepare fails then a second device is granted; warm reboot's driver shutdown fails (recordshutdown, destroyed, counted); the record staysreadyunder thebootclaim during the reboot (capacity and the warm pool see no change); a shut-down device booted withexceptsucceeds and fails (counted, notboot-timeout); a provision failure then anexceptboot failure →PROVISION_FAILED(one shared count); a replay with the same key and anotherexcept→IdempotencyConflictError;lease.granted.sourcebootedfor a rebooted warm device.
Done when
pnpm exec vitest run --project unit src/contract/ src/leasing/ src/core/ src/daemon/ src/cli/ src/http/ src/mcp/passes.- The protocol is one above the base branch's.
- On a Mac with an iOS 18.5 runtime, and again with the newest 26.x (each picked by version, not the newest installed):
e2e/slow-ios-slim.test.tsgains a case that leases--mode slim --except store,otherand finds everystoreandotherlabel enabled inlaunchctl print-disabled systemon the leased device, one lease per runtime (slow lane). - On the newest 26.x runtime: a case in
e2e/slow-ios-slim.test.tsthat excepts each category in turn finds its labels enabled (slow lane). - On a Mac with an iOS 26.x runtime: a case in
e2e/slow-ios-slim.test.tshas a warm slim device rebooted with the smaller list and granted (slow lane). - The website's CLI, choosing-a-device, errors, MCP and HTTP pages describe
except; EVENTS.md'slease.requestedrow names it.
Out of scope
- Gateway routing (T4); the agent-device front (T5).
Driver.estimatefor an except lease (ADR 0066 Consequences).
Depends on
- The iOS driver boots a slim simulator with a lease's except list #1329 (the driver's except boot)
- Warm pool: a baseline kind is learned on its Nth lease in 24 h and warms its newest version #1261 (bumps the protocol)
Written by an agent.
Activity
test: a client leases slim with except and a warm ready device is shu…
feat(leasing): a ready warm device is rebooted with the except list a…
test: a client's except request is refused with BAD_REQUEST and the r…
feat(leasing): an except request is refused unless it is a slim iOS s…
test: an except list reaches the lease request from the CLI and HTTP,…
feat(cli): simlock lease --except, the HTTP body and lease reply carr…
test: a failed except boot is never granted (#1330)
feat(leasing): a failed warm reboot destroys the device and counts to…
test: a replay with another except is a conflict, and a failed boot o…
feat(leasing): a replay naming another except is a conflict, and the …
docs(leasing): except on the CLI, errors, events and manuals, and its…
refactor(leasing): keep the request comparison and the HTTP dispatch …
refactor(leasing): the acquisition's timing and request helpers move …
docs(leasing): list the acquisition parts and the dispatcher test hel…
test(daemon): the warm reboot's new address reaches the granted device (
fix(leasing): a slim baseline's except names reach the driver, and a …
test(leasing): a slim except boot granted full, the retry count of a …
chore(merge): bring main up to ff11319 into the branch (#1330)
chore(merge): bring task/1329 into the branch (#1330)
refactor(daemon): drop the test-dispatcher helpers no test uses after…
fix(contract): the slim except shapes bump the protocol past main's 78 (
chore(stack): merge task/1329 into the slim-except wiring branch, exc…
docs(leasing): restore the crash-mid-reboot known gap dropped in the …
feat(leasing): a slim lease keeps named categories running (--except) (…