Repository navigation
Description
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.mdxandconcepts/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
sessionsfolder 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 typecheckpasses. - Slow lane: a new case in
e2e/slow-agent-device.test.ts, and one ine2e/slow-agent-device-gateway.test.ts: lease withsimlock lease, hand it over,agent-device openwith the handover secret lands on that device, a screenshot works,closeends the simlock lease, and the secret is then refused. Run withscripts/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 withscripts/slow-e2e.sh e2e/slow-agent-device.test.ts. using-devices/agent-device.mdxdescribes opening a handed-over lease, the flags it refuses, and whatclose,disconnectandconnect --forceend.
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
test: a second open on a handed-over lease is refused and an off agen…
feat(agent-device): a second open on a handed-over lease is refused (#…
test: calls under a handover identity are held to the handed-over lea…
feat(agent-device): calls under a handover identity are held to the h…
test: a handed-over lease's end releases agent-device's lease by its …
feat(agent-device): a handed-over lease's end releases agent-device's…
test: a second open on a handed-over lease releases agent-device's ea…
feat(agent-device): a second open on a handed-over lease releases age…
feat(agent-device): a handover identity adopts nothing after a restart (
test: through a gateway, open on a handed-over lease attaches on its …
133 remaining items
test: the open's unreachable-or-ended answer, the owner-holds check a…
fix(agent-device): an open or re-allocate waiting its turn reads the …
fix(agent-device): a relayed call on a handed-over phone lease checks…
fix(agent-device): a handed-over call reaches the host with no tenant…
fix(e2e): the handover test counts the folders its lease made, and th…
fix(agent-device): an upload ticket carries the caller's credentials …
test: a sessions folder that cannot be read fails the end of a handed…
fix(http): the handover scope gate reads a path decoded once, so an e…
fix(agent-device): an owner entry rebuilt after a worker restart is n…
docs(agent-device): the renewals key comment names the simlock id it …
refactor(agent-device): ownerHolds reads its cases one after another (#…
fix(agent-device): a relayed call's daemon is read from the registry …
refactor(agent-device): the link's status reads its phone decision in…
V3RON commentedon Dec 1, 2026
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.
fix(agent-device): the fake answers reused true for a new id with a l…