Skip to content

feat(agent-device): agent-device opens on a handed-over lease #1906

In progress

Description

@V3RON

Part of #1895.

Scope

An agent with a handover credential runs agent-device connect proxy … --daemon-auth-token <handover secret> and agent-device open, and agent-device opens on the handed-over lease's device: no new lease, no lease id to pass. Every call is held to that lease. The agent's close or disconnect ends the lease, a release its CLI sends by itself does not, an open that asks for a device is refused, and the lease's end, from either side, releases agent-device's lease and removes its session folders. It works on a standalone worker and through a gateway.

If this goes wrong, a user would notice open leasing a new device, an attached lease ended while the simlock lease lives, another lease's session folder deleted, or agent-device sessions left behind.

Technical spec

Commit 4b39322.

Rows

Behaviours: B10, B11, B12, B13 (and B6's /v1/agent-device/* case: the path gate passes it from this task on)
Stored state: S3, S4 (and reads S2 through I5)
Interfaces: I8, I9, I10 (and uses I4, I5, I6)
Existing code: X18, X19, X20, X21, X22, X23, X24, X25, X27, X28, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41

Facts

# Fact Source
F1 agent-device 0.21.41 through the proxy sends a random 32-hex leaseId on agent_device.lease.allocate and ignores connect proxy --lease-id and open --lease-id run on 2026-11-27 against a stub server: connect proxy --lease-id lse_abc123 --session s1, then open --platform ios --session s1, logged "leaseId":"669b4a9e18d9144c093269b9b94a0bb9"
F2 The bundled proxy builds each upstream request from its own header list node_modules/@agent-device/proxy/dist/index.mjs:395-409 buildUpstreamHeaders
F3 The host hands a front call to the proxy in forward src/agent-device/host/host.ts:134-158
F4 Every lease call I10 names ran on a real agent-device 0.21.41 daemon with no device: a first allocate, the same id again (reused: true), a new id with the same scope (answered with the first lease), another client (DEVICE_IN_USE, DEVICE_LEASE_BUSY), a release without the device key (LEASE_SCOPE_REQUIRED), of an unknown id (released: false), in full (released: true), a heartbeat of an unknown id (LEASE_NOT_FOUND), a used id (INVALID_ARGS, LEASE_ID_IN_USE), and the same allocate with another tenantId in its params (LEASE_ID_IN_USE) run on 2026-11-30: daemon.js with AGENT_DEVICE_DAEMON_SERVER_MODE=http, POST /rpc with deviceKey ios:mobile:no-such-device, backend ios-instance

Modules touched

src/agent-device/host (attached-lease, host, lease-end), src/agent-device/front (the S3 map, attach, allocate, front, heartbeat, renewals, release, ended, boot, context, token-devices, devices-filter, host-link, relay-host-link, request-rules, orientation, edge-parts), src/agent-device/shared (replies, paths, rpc for LEASE_GONE), src/agent-device/lease-cases.ts (I10), src/agent-device/testing.ts, worker.ts, gateway.ts, the path gate in src/http (pass /v1/agent-device/*), src/agent-device/test-gateway.ts, e2e/slow-agent-device.test.ts, e2e/slow-agent-device-gateway.test.ts, e2e/helpers, website docs. Searches: leaseId and principal in src/agent-device/front, adoptable, ReleaseScopeRecord, recordingFetch, onLeaseRemoved, forget, #roles, ATTACH_HEADER, workerTenant, sessionFolderNames, sendRpc, ruleAddresses, releaseSimlock.

The branch holds an earlier build (56e72a6). Keep its front, map and link work and its tests of B10 to B13 where the rows still say so; a test that asserts the opposite of a row goes. Replace its host part: #ids, #sessions, confirm, serve, pass, #generation in attached-lease.ts and the folder names they give. src/agent-device/shared/tenant.ts, sessionFolderNames, the tenant sentence of ADR 0070 and every line about them in src/agent-device/AGENTS.md end as task/1905 has them.

Rules in play

  • src/agent-device/AGENTS.md: the simlock lease is the only clock; the host sets the tenant; front map and release scopes live in memory only; the edge imports nothing from the gateway.
  • ADR 0098 §4; ADR 0070 §3 (lease tenant); ADR 0071 (re-allocate after agent-device forgot a lease).
  • ADR 0098 §4 as changed on 2026-11-30: the host's id, the tenant, the CLI's release.
  • testing: one step of S4 at a time is proven by the overlaps B10 and B12 name, each with a fake clock and a held reply, never by sleeping.
  • documentation rule 9: using-devices/agent-device.mdx (a handed-over lease: connect, open, close, and what a call with no open gets), using-devices/http-api.mdx and concepts/tokens-and-roles.mdx (each still says a handover secret is refused on /v1/agent-device/*).

Tests

Seam: the agent-device front with a faked host link and daemon (worker) and the relay link (gateway), modelled on src/agent-device/front/allocate.test.ts, front-map.test.ts and src/agent-device/host/lease-end.test.ts. Where no call through the front can show a case (an attach that ended before its open ran, S3 and the phone role after the end, a release answered LEASE_GONE), the test drives the attach, the S3 map or the link directly. The fake agent-device answers as X31 and X40 say and runs I10's table; a test never gives it a reply to a lease call that I10 does not pin, but for the directly driven LEASE_GONE release.

  • B10: every case of the row, on a worker and, for the open, the refused flags and the dropped uplink, through a gateway; the calls agent-device got hold the host's id and never the CLI's; a lost reply then an open from another client id; a repeated allocate answered with an earlier lease's id: that id is used and released.
  • B11: every case of the row; the owner's entries untouched; the tenant and session agent-device got on each kind of call.
  • B12: every case of the row, with the content of the fake's sessions folder before and after each end: agent-device running, stopped and restarted; another lease with the same session name; a session named as another lease's folder; L1's id granted again with an attach of the first grant still open; L1's end while an open waits, while a settle is silent and while a release hangs.
  • B13: every case of the row, the worker restarted behind a running gateway included.

Done when

  • The new and changed test files pass with pnpm exec vitest run --project unit <files>; pnpm typecheck passes.
  • Slow lane: a new case in e2e/slow-agent-device.test.ts, and one in e2e/slow-agent-device-gateway.test.ts: lease with simlock lease, hand it over, agent-device open with the handover secret lands on that device, a screenshot works, close ends the simlock lease, and the secret is then refused. Run with scripts/slow-e2e.sh <file>.
  • Unit: the routed link refuses a credential whose principal does not own the lease, driven directly; I10's two added releases (no tenant and run, another tenant) run on the fake. (decided in delivery, pending the maintainer)
  • Slow lane: in e2e/slow-agent-device.test.ts, I10's table passes on the real agent-device daemon, and the handover case also opens with no --platform, uploads an app, and shows that no folder of the lease's tenant is left after its end. Run with scripts/slow-e2e.sh e2e/slow-agent-device.test.ts.
  • using-devices/agent-device.mdx describes opening a handed-over lease, the flags it refuses, and what close, disconnect and connect --force end.

Out of scope

Any change to agent-device. The owner's ids, tenants and folders (#2003). More than one agent-device lease on one handed-over lease.

Depends on

Written by an agent.

Activity

  1. added
    task:draft
    on Nov 27, 2026
  2. added
    task:ready
    and removed
    task:draft
    on Nov 27, 2026
  3. self-assigned this
    on Nov 30, 2026
  4. 133 remaining items

  5. V3RON commented on Dec 1, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done: the rebuild, audit and reviews are on PR #1988 at 6648896. Review passed with nothing open. CI was green on that commit. Stack synced, #1976 fixed and checked.

    Not done: the slow lane. Attempt 1 failed under machine load and proved nothing. Attempt 2 was not triaged: 17 passed, 4 failed, 10 skipped at the last read; the gateway file had not run. Its log: simlock-slow-e2e-20261201-102118.log in this Mac's temp folder. The lane may still be running.

    Findings: I10's case "a new id with the same scope" failed on iOS and Android (the reply has a field the table does not list); two Android tests missed expected screen text. None is sorted. Attempt 2's report has not been given to deliver-step.mjs, so #1988's State line is still at attempt 2.

    Blocked on: the session's 10 h budget. A new session resumes with deliver #1906.

    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

Labels

task:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions