Skip to content

A slim lease keeps named categories running (--except) #1330

Closed

Description

@V3RON

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):

  1. Plan (lock): take a boot claim on the ready device. No capacity reservation: the device keeps its running slot and RAM, because its record stays ready through the reboot.
  2. Reboot (no lock, rebootForLease in core's lifecycle, under the held claim): driver shutdown, then makeReady({ purpose: "prepare", mode: "slim", except }). Nothing is committed in between: the record stays ready, so no other part acts on it (it is claimed) and the warm pool counts it as handed to a lease (a ready device under a boot claim, F27).
  3. Commit, as one new registry write with no transition and no event (ready → ready is no edge, src/core/domain.ts:515), the fields readyTransitionUpdate builds from makeReady's result: driverData, address and mode (readyDevice.mode ?? "full", src/core/driver.ts:98-104), so a reboot granted full records full. Then grant through #grantHandoff; lease.granted.source is booted (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]
Loading

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]
Loading
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
Loading
  • src/contract/operations.ts (field, refinements, requestedDevice), schemas.ts (device except), protocol.ts (+1)
  • src/cli/commands/lease.ts, src/http/lease-declarations.ts (body), src/http/tracker.ts (copies except to lease.request; the flat reply gets top-level except beside mode, F28), src/mcp/ (inherits; tool description)
  • src/leasing/lease-acquisition-coordinator.ts (effective-mode refusal at resolve; reboot-ready perform; one failure count across provision, boot-shutdown and reboot-ready when the request has except; GRANT_SOURCE["reboot-ready"] = "booted"), acquisition-planner.ts (reboot-ready), lease-lifecycle.ts (the grant commit writes device.except), lease-request-book.ts (replay compares except)
  • src/core/managed-device-lifecycle.ts (rebootForLease), driver.ts (passes except), domain.ts (DeviceRecord.except), registry.ts, registry-rows.ts, registry-schema.ts (V4: devices.except_categories TEXT and lease_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's BadDeviceRequestError, 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.granted source booted for a rebooted warm device); manuals of leasing, core, contract

Contract and event changes

This PR bumps the protocol by one.

  • lease.request.except: a plain z.array(z.string()) field, checked by one object-level refinement with no path (F29), so every transport, MCP included, answers BAD_REQUEST with 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); with physical: true or a platform other than ios (except is for iOS simulators); with mode: "full" (except needs a slim lease (mode is full)). This is a refinement of its own, not refusePhysicalWithImageFields.
  • The leasing refusals (effective mode full) throw BadDeviceRequestError (F31) with the messages in the table above.
  • Device shapes (grantedDeviceSchema, deviceRecordSchema, statusDeviceSchema): optional except, the same item bounds; absent when none.
  • lease.requested: requestSpec.except as 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):

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, except on 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 except and 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, no except); the device's except in the reply, list.get and status.get, and requestSpec.except on lease.requested.
  • A client's except request 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 as BAD_REQUEST with its message; on socket, HTTP and MCP.
  • A failed except boot is never granted: cases warm reboot's prepare fails then a second device is granted; warm reboot's driver shutdown fails (record shutdown, destroyed, counted); the record stays ready under the boot claim during the reboot (capacity and the warm pool see no change); a shut-down device booted with except succeeds and fails (counted, not boot-timeout); a provision failure then an except boot failure → PROVISION_FAILED (one shared count); a replay with the same key and another except → IdempotencyConflictError; lease.granted.source booted for 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.ts gains a case that leases --mode slim --except store,other and finds every store and other label enabled in launchctl print-disabled system on the leased device, one lease per runtime (slow lane).
  • On the newest 26.x runtime: a case in e2e/slow-ios-slim.test.ts that 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.ts has 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's lease.requested row names it.

Out of scope

  • Gateway routing (T4); the agent-device front (T5).
  • Driver.estimate for an except lease (ADR 0066 Consequences).

Depends on

Written by an agent.

Activity

  1. added
    task:draftScope written; technical spec or its spec check missing.
    on Nov 5, 2026
  2. added
    task:readySpec checked. An agent may implement it once its Depends on allow.
    and removed
    task:draftScope written; technical spec or its spec check missing.
    on Nov 5, 2026
  3. self-assigned this
    on Nov 6, 2026
  4. added 20 commits that reference this issue on Nov 6, 2026
  5. added a commit that references this issue on Nov 6, 2026
    3352ef1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

task:readySpec checked. An agent may implement it once its Depends on allow.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions