Skip to content

feat(agent-device): an agent opens and closes a device through simlock - #497

Draft
V3RON wants to merge 7 commits into
mainfrom
task/472
Draft

V3RON wants to merge 7 commits into
mainfrom
task/472

Conversation

@V3RON

@V3RON V3RON commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #472

Status

Green: 48 of 49 spec tests pass. One is red on a spec gap: stopping the daemon while an allocate waits ends with no simlock lease and no lease request stored (edge.test.ts). A stored request keeps a record with its lease ID for retentionMs even once cancelled, and dispatch refuses lease.cancel once a stop has begun (DAEMON_STOPPING), so the front cannot remove the waiting request and the not.toContain(hex(2)) check on state.json cannot hold. Nothing is leased after the stop; the open request is failed at the next start like any other.

Done when

  • Every line under Tests is a test in src/agent-device/edge.test.ts (the adapter and authenticate lines in src/agent-device/host/upstream.test.ts, the front map lines in src/agent-device/front/front-map.test.ts, the shared line in src/agent-device/shared/rpc.test.ts), and each fails when the behaviour it names is removed.
  • With agentDevice.enabled true and HTTP on, /v1/agent-device/health with a simlock token answers the proxy's health; with it false, 404.
  • An allocate followed by a release leaves the device free in simlock list --devices, shown by the release test.
  • docs/HTTP-API.md documents /v1/agent-device/*, the one-token-per-agent rule and the messages above.
  • No line needs real hardware: End-to-end tests: agent-device through a simlock worker on real iOS and Android devices #477 runs these flows with the real CLI on iOS and Android.

Assumptions

  • Assumption: names the spec leaves open (AgentDeviceHost.tag / .authenticate, SupervisorAgentDeviceUpstream, FrontMap.add / get / markEnded / refresh, commandLeaseId) — the red commit holds inert stubs with these names so the tests typecheck; green may rename them and update the tests that call them, since no spec line fixes them.
  • Assumption: the "no idempotency key" half of the allocate test is not observable at the daemon seam (the stored request record is not exposed) — the test proves the request names no osVersion, mode, imageTag or physical device and offers no download; green's code must still send no idempotency key.
  • Assumption: FakeAgentDevice reads the tenant from the x-agent-device-tenant header, else params.tenantId, else params.meta.tenantId, as the proxy on agent-device's simlock-integration branch stamps it.
  • Assumption: HostLink.forward(request, identity) takes the identity, and the host tags the request it hands the proxy with a random header value (a map the host owns), not a WeakMap keyed on the Request: the proxy gives authenticate a copy of the request, so a WeakMap would never match. The header is overwritten on every forward and never reaches agent-device.
  • Assumption: --target values other than mobile, tv and desktop ask for no class (the smallest change; the spec names no message for them).
  • Assumption: the host and front map are built right after the supervisor, not before createLeasing: they need nothing from leasing, and TokenStore stays where it is because the host does not use it (requireAuth is the one token check).
  • Assumption: before lease.request, the front waits on a lease.list dispatch (raced against the CLI's hang-up). A request parked while the daemon starts cannot be called back, and this keeps a CLI that left before startup finished from ever being admitted (the "hangs up before simlock admitted" test).
  • Assumption: a refusal answers HTTP 400, not available 503, a failure 502/504, an operator token 403; the CLI reads the body.
  • Fixture fixes in edge.test.ts (no assertion changed): the slow and no-address drivers get phone models; the held lease in the 330 s test gets the maximum TTL so it does not expire during the wait; the --target test allows 8 running devices for its 5 leases; the two hang-up tests wait 50 ms after the hang-up so the server sees the closed socket before the daemon moves on.

Written by an agent.

V3RON added 7 commits October 13, 2026 01:33
7 failing -> 1 failing

The /v1/agent-device mount, the proxy host, the front map and the lease flow.
Fixture fixes in edge.test.ts: phone models for the slow drivers, a long TTL
for the held lease, room for 5 devices, timing gaps after a hang-up.
1 failing -> 1 failing

Splits the refusal check and the settle steps so Fallow's complexity check passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An agent opens and closes a device through simlock

1 participant