Skip to content

A lease may keep its device through a close, and the allocate reply names the device #1421

Closed

Description

@V3RON

Part of #1419.

Scope

A test runner can allocate a lease with agent-device's retainOnClose: true through the agent-device front, close and reopen sessions on it, and keep the device until it releases the lease or the TTL runs out. The allocate reply names the device's address for a caller that reads the reply's JSON. A caller on agent-device's own client, which drops that field (F13), gets the address as the id of simlock's boot answer (#1422). Either way the runner no longer parses deviceKey. The docs say the agent-device leaseId is the simlock lease id.

In short

Today the front refuses retainOnClose: true with refused: simlock leases only plain devices (F1), and any close ends the lease (F4). After this PR the front forwards the flag. agent-device then keeps its lease on a close and names it in no endedLeases (F2, F3), so the simlock lease stays too. An allocate without the flag behaves as today. The allocate reply's lease.device gains udid (iOS) or serial (Android), the address the front already sends agent-device (F5). agent-device's own client drops it when it rebuilds the lease (F13), so #1422's docs point client users to boot's id.

retainOnClose: an agent-device allocate flag; a lease allocated with it survives a session close.

flowchart LR
  A[allocate retainOnClose true] -->|changed: forwarded, not refused| F[front]
  F --> D[agent-device keeps lease on close]
  F -->|changed: lease.device.udid or serial| R[runner]
Loading

Before:

allocate {platform: ios, retainOnClose: true}
→ error INVALID_ARGS "refused: simlock leases only plain devices"

After:

allocate {platform: ios, retainOnClose: true}
→ { lease: { leaseId: "…", retainOnClose: true, device: { model: "iPhone 17 Pro", osVersion: "26.0", physical: false, udid: "6F2C…" } } }
close        → ok; the lease is still listed
snapshot     → ok
release      → ok; the device is deleted
Allocate Today After
retainOnClose: true refused: simlock leases only plain devices granted, retainOnClose: true in the reply
retainOnClose: false or absent granted granted
leaseProvider: "x", provider*, aws*, a foreign backend refused: simlock leases only plain devices the same

If this goes wrong, a runner that set retainOnClose loses its device at its first close, as today.

Technical spec

Facts

Commit e4599cf.

# Fact Source
F1 The front refuses retainOnClose: true as not plain, with refused: simlock leases only plain devices. src/agent-device/front/allocate.ts:75-84, :105 (e4599cf)
F2 agent-device stores retainOnClose on the lease and echoes it in the allocate reply; its client keeps it. agent-device v0.21.35:packages/daemon/src/resources/lease-registry-scope.ts:353, v0.21.35:packages/daemon/src/sessions/handlers/lease.ts:141-144, v0.21.35:src/client/lease-client.ts:98
F3 On a close of a session whose lease has retainOnClose, agent-device keeps the lease and returns no ended lease, so the reply's endedLeases does not name it; heartbeat and release still act on it. This holds for a bare close and close <app>. agent-device v0.21.35:packages/daemon/src/sessions/lease-lifecycle.ts:189, :221-232; v0.21.35:packages/daemon/src/sessions/session-lifecycle/internal/session-close.ts:131-132, :379; v0.21.35:packages/daemon/src/sessions/handlers/lease.ts:148-176
F4 The front ends the simlock lease for every id a reply names in endedLeases. src/agent-device/front/ended.ts:43-58, src/agent-device/front/front.ts:175
F5 The front sends agent-device the granted address as udid (iOS) or serial (Android), and for a physical phone the address is its driver device id. src/agent-device/front/allocate.ts:296-297, :333, src/agent-device/shared/selectors.ts:55
F6 The front adds lease.device (model, osVersion, physical, and imageTag, baseline, deviceMode when set) to the allocate reply. src/agent-device/front/allocate.ts:411-427
F7 The fake agent-device ends a lease on any close that names it, with no retainOnClose handling. src/agent-device/testing.ts:709
F8 The existing refusal table has a retainOnClose: true case. src/agent-device/edge.test.ts:842-843
F9 A close on a plain lease ends both leases, tested for a bare close, a failing close and a batch close. src/agent-device/edge.test.ts:1306-1330
F10 The docs say close gives the device back. website/src/content/docs/docs/using-devices/agent-device.mdx:136
F11 The e2e runner's own provider path allocates with retainOnClose: true and refuses a grant that does not echo it. @e2e-dev/mobile v0.12.5:dist/lease/index.js:57, :65-66
F12 The front's agent-device lease id is the simlock lease id and its requester id. src/agent-device/front/allocate.ts:144, :196; ADR 0020
F13 agent-device's client rebuilds the allocate reply's lease and keeps only model, osVersion, imageTag and physical of lease.device; the e2e runner and budgie allocate through it. agent-device v0.21.35:src/client/lease-client.ts:77-102, v0.21.35:packages/contracts/src/lease-scope.ts:362-375; @e2e-dev/mobile v0.12.5:dist/lease/driver.js:6
F14 The fake's allocate reply carries no retainOnClose. src/agent-device/testing.ts:514-535
F15 A baseline test checks the exact lease.device shape. src/agent-device/baseline.test.ts:84-90

Modules touched

Searches: notPlain, retainOnClose, withGrantedDevice, endedLeases in src/agent-device and website/.

flowchart LR
  T[test-support / testing.ts fake *] --> F
  F[front/allocate.ts *] --> S[shared/selectors.ts]
  D[website agent-device.mdx *]
Loading

Changed: src/agent-device/front/allocate.ts, src/agent-device/testing.ts (the fake echoes retainOnClose in its allocate reply and keeps such a lease on close, copying F2 and F3), src/agent-device/edge.test.ts, src/agent-device/baseline.test.ts (F15), website/src/content/docs/docs/using-devices/agent-device.mdx.

Contract and event changes

None in simlock's contract: the agent-device allocate reply is agent-device's shape, which the front decorates (F6). lease.device.udid and lease.device.serial are strings, the granted address (F5). No event.

Other code on the same state

Searches: endedLeases (4 hits in front/), releaseEndedLeases (2), map.add (1). releaseEndedLeases reads endedLeases: a retained lease is not named there (F3), so it ends nothing. The lease end (host/lease-end.ts) still releases the agent-device lease when simlock ends a lease on its own, retained or not. #1419's tenant task changes the tenant of these calls, not which calls end a lease.

Failure modes

Call Outcome What happens Limit, counted from
allocate with retainOnClose agent-device grants, echoes the flag lease granted as today
allocate with retainOnClose agent-device refuses the front releases the simlock lease, as today as today
close on a retained lease ok, no endedLeases both leases stay TTL, from the last heartbeat

A retained lease the runner never releases ends at its TTL, as any lease does. Covered by the existing TTL tests; no new line.

Rules in play

  • ADR 0070 §2, "accepts retainOnClose: true on an allocate and forwards it": the flag leaves notPlain.
  • ADR 0023 §2, "one lifetime": release and the TTL still end both leases together.
  • ADR 0020, "the granted lease has exactly that id": the docs say so.

Tests

Seam: the agent-device front with agent-device faked, src/agent-device/edge.test.ts (model: the close cases at :1306-1330).

  • A runner allocates with retainOnClose: true, closes, and its lease stays: the reply echoes retainOnClose: true, the next heartbeat and command work and release frees the device. Cases: bare close; close <app>; a batch with a close step. The retainOnClose: true case leaves the refusal table (F8). The plain-lease close cases at :1306-1330 stay as they are.
  • A runner reads the device address from the allocate reply. Cases: iOS simulator udid; Android emulator serial.

Done when

  • pnpm exec vitest run --project unit src/agent-device/edge.test.ts passes with both Tests lines.
  • agent-device.mdx says a test runner allocates with retainOnClose: true to keep its device through a close, that lease.device.udid or lease.device.serial names the device in the reply's JSON, which agent-device's client drops (F13), and that the agent-device leaseId is the simlock lease id used by /v1/leases/<id>/….

Out of scope

Depends on

Written by an agent.

Activity

  1. added
    task:draft
    on Nov 7, 2026
  2. added
    task:ready
    and removed
    task:draft
    on Nov 7, 2026
  3. self-assigned this
    on Nov 7, 2026
  4. V3RON commented on Nov 7, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done

    PR #1436 is ready, review-complete and CI-green (35 checks). Retained-close and device-address coverage passed. The CI correction removes only three blank lines, independently verified at 826939616700daac19d25fcf2323be6b380ddbf6.

    Not done

    Merge with the complete #1419 feature stack; never merge this PR alone.

    Findings

    Review R1 is fixed. The CI correction is already merged forward into #1439. No new implementation or review is required on this task.

    Blocked on

    Nothing in this task. The ready PR remains in the feature stack; resume its merge after #1422 hardware verification and #1424 delivery.

    Written by an agent.

  5. assigned and unassigned on Nov 7, 2026
  6. V3RON commented on Nov 7, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done

    PR #1436 is ready and review-complete at 826939616700daac19d25fcf2323be6b380ddbf6. CI passed, including the three-blank-line correction and its final mechanical check.

    Not done

    Merge with the complete #1419 feature stack, not independently.

    Findings

    No #1421 CI follow-up remains. #1437's Status refers to the earlier pending state. #1439 has separate Fallow and PR-body failures and its hardware line remains unverified.

    Blocked on

    Nothing in this task. The feature stack waits for #1422 hardware verification and #1424 delivery.

    Written by an agent.

  7. removed their assignment
    on Nov 7, 2026
  8. V3RON commented on Nov 7, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: none
    Parked: none
    Waiting: #1421 — feature stack needs #1422 hardware verification and #1424 delivery
    Decided: none

    Written by an agent.

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

    task:ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions