Skip to content

Errors the agent-device front makes carry a reason and a retriable flag #1423

Closed

Description

@V3RON

Part of #1419.

Scope

Every error the agent-device front makes itself carries a reason and a retriable flag, so a test runner tells "simlock or the worker is unreachable, try again" from "refused" and "failed" by a field, not by message text. Errors agent-device makes pass through unchanged.

In short

Today simlock's errors carry a reason only when a worker is unreachable or simlock ended the lease (F1), and never a retriable flag. After this PR every reply the front builds names one of six reasons and says whether trying again may help. The code stays as today (F1), since agent-device's client knows a fixed code set (F6).

reason: the string naming why simlock failed a call, e.g. SIMLOCK_UNAVAILABLE. retriable: true when trying again later may succeed.

The reason names the kind of reply; retriable follows the condition, so a full farm says "try again" and a bad model name does not.

Reason Made for retriable
REFUSED_BY_SIMLOCK every refusal the front makes (INVALID_ARGS; status 400, 403, 404 or 413), and an allocate whose lease request failed with any code not named below false
SIMLOCK_UNAVAILABLE agent-device not available on this simlock (COMMAND_FAILED, 503) true when the condition can clear by itself: the daemon is starting, or failed to start (start-failed, retried by the supervisor); no worker is connected to the gateway; the worker holding the lease cannot serve agent-device right now; a forward to the daemon threw. false when it needs an operator: the module is off; agent-device is not-found, not-agent-device or the wrong-version; its state-dir is unusable; @agent-device/proxy could not load; it reported no lease ceiling. A phone daemon's reason (phone daemon: <reason>) takes the value of the reason it wraps. This is every condition that reaches notAvailable (F17).
SIMLOCK_UNAVAILABLE an allocate whose lease request failed with NO_CAPACITY, DAEMON_STOPPING or DAEMON_CONNECTION_LOST (reply as today, INVALID_ARGS 400) true
WORKER_UNREACHABLE the lease's worker is not connected to the gateway (503), or an allocate whose lease request failed with WORKER_UNREACHABLE true
NO_DEVICE_IN_TIME an allocate that timed out in simlock's queue (QUEUE_TIMEOUT, reply 504) true
SIMLOCK_FAILED every other failure the front makes (COMMAND_FAILED, 502) false; true for could not check your leases; try again
LEASE_ENDED_BY_HOST a call on a lease simlock ended (UNAUTHORIZED, 200) false

Messages, codes and statuses stay as today.

Where they sit:

  • A JSON-RPC error: error.data.details.reason, and error.data.retriable beside code, where agent-device's client reads it (F6).
  • A flat error ({ code, error, ok: false }, on the upload, artifact and health routes): reason and retriable beside code.

Before (JSON-RPC):

{ "error": { "code": -32000, "message": "agent-device is not available on this simlock: no worker connected to this gateway can serve agent-device", "data": { "code": "COMMAND_FAILED", "message": "agent-device is not available on this simlock: no worker connected to this gateway can serve agent-device" } } }

After:

{ "error": { "code": -32000, "message": "agent-device is not available on this simlock: no worker connected to this gateway can serve agent-device", "data": { "code": "COMMAND_FAILED", "message": "agent-device is not available on this simlock: no worker connected to this gateway can serve agent-device", "details": { "reason": "SIMLOCK_UNAVAILABLE" }, "retriable": true } } }

Before (flat): { "code": "COMMAND_FAILED", "error": "agent-device is not available on this simlock: …", "ok": false }. After: { "code": "COMMAND_FAILED", "error": "agent-device is not available on this simlock: …", "ok": false, "reason": "SIMLOCK_UNAVAILABLE", "retriable": true }.

flowchart LR
  C[front call sites] --> R[shared/replies.ts constructors *]
  R -->|changed: reason + retriable| W[JSON-RPC and flat replies]
Loading

If this goes wrong, a runner retries a refusal forever, or gives up on a farm that would have come back.

Technical spec

Facts

Commit e4599cf.

# Fact Source
F1 The front's replies come from five constructors: refusal (INVALID_ARGS, 400 by default), failure (COMMAND_FAILED, 502 by default), notAvailable (COMMAND_FAILED, 503), workerUnreachable (notAvailable plus reason WORKER_UNREACHABLE) and leaseEndedByHost (UNAUTHORIZED, 200, reason LEASE_ENDED_BY_HOST). src/agent-device/shared/replies.ts:3-57
F2 frontReply writes a JSON-RPC error with error.data.details when a reply has details, and a flat { code, error, ok: false } with no details when there is no RPC. src/agent-device/shared/replies.ts:65-90
F3 The allocate timeout is failure("timed out waiting for a device; nothing was leased", 504). src/agent-device/front/allocate.ts:263
F4 unreachableReply gives notAvailable when the link names a reason, else failure(fallback). src/agent-device/front/context.ts:66-75
F5 A test asserts a flat reply has no details. src/agent-device/gateway-front.test.ts:1927-1931
F6 agent-device's client reads retriable only from error.data.retriable and overwrites a details.retriable; it keeps details.reason. Its known codes include INVALID_ARGS, COMMAND_FAILED, UNAUTHORIZED. agent-device v0.21.35:src/daemon-client/daemon-client-rpc.ts:119-127, v0.21.35:src/daemon-client/daemon-client-rpc.ts:141-147, v0.21.35:packages/kernel/src/errors.ts:11-28
F7 agent-device's client treats a lease as gone only for UNAUTHORIZED with LEASE_NOT_FOUND, LEASE_EXPIRED or LEASE_REVOKED; none of the six reasons is one of them, and neither agent-device nor the e2e runner branches on any of the six. agent-device v0.21.35:packages/contracts/src/lease-scope.ts:489-504; @e2e-dev/mobile v0.12.5:dist/errors.js:73-84
F8 Errors agent-device makes are relayed unchanged. src/agent-device/front/heartbeat.ts:149-154, src/agent-device/front/context.ts:77-90
F9 The worker's relay target answers notAvailable when agent-device is unavailable. src/agent-device/worker.ts:74
F10 The docs list the front's messages without a reason. website/src/content/docs/docs/using-devices/agent-device.mdx:204-221
F11 The allocate turns every leasing error but QUEUE_TIMEOUT into refusal("refused by simlock: <message>"); leasing's codes include NO_CAPACITY, DAEMON_STOPPING and DAEMON_CONNECTION_LOST (503) and WORKER_UNREACHABLE. src/agent-device/front/allocate.ts:258-264, src/contract/errors.ts:33-44, :305-318
F12 agent-device's unavailable reasons are not-found, not-agent-device, wrong-version, state-dir and start-failed; only start-failed is retried. The gateway is unavailable with no worker connected to this gateway can serve agent-device, and the allocate with agent-device reported no lease ceiling for this lease. src/agent-device/host/agent-device-supervisor.ts:30-36, :246-249, src/agent-device/front/relay-host-link.ts:71, src/agent-device/front/allocate.ts:36, :118
F13 A failed lease check says could not check your leases; try again and is sent with failure. src/agent-device/front/token-devices.ts:9-12, src/agent-device/front/request-rules.ts:390-391, src/agent-device/front/devices-filter.ts:35-36
F14 A download over the cap is refused with status 413. src/agent-device/host/host.ts:34-41
F15 Three more tests compare whole front error bodies. src/agent-device/edge-request-rules.test.ts:103-107, src/agent-device/front/relay-host-link.test.ts:124-128, src/agent-device/front/orientation.test.ts:168-171
F16 simlock's HTTP layer answers a bad token or a wrong role on /v1/agent-device before the front, with its contract codes. src/http/module-routes.ts:14-17
F17 The conditions that reach notAvailable: the supervisor's states and reasons (passed on as a message only, its kind dropped), the proxy load error, the gateway's NO_WORKER and HOLDER_CANNOT, the phone daemon's wrapped reason, a forward that threw, and NO_CEILING. The fake's unavailable state takes a string only. src/agent-device/host/upstream.ts:11, :32-35, src/agent-device/host/host.ts:108, :166, src/agent-device/front/relay-host-link.ts:71-72, :195, src/agent-device/front/host-link.ts:97, src/agent-device/front/front.ts:282, src/agent-device/front/allocate.ts:36, src/agent-device/testing.ts:182, :215-217

Modules touched

Searches: callers of refusal(, failure(, notAvailable(, workerUnreachable(, leaseEndedByHost( outside tests: 44 call sites in 11 files of src/agent-device. The reason comes from the constructor, except at the allocate's leasing error (F11) and the unavailable and lease-check sites, where the condition sets the reason or retriable (F12, F13).

flowchart LR
  A[front/allocate.ts *] --> R[shared/replies.ts *]
  O[other front files] --> R
  W[worker.ts] --> R
Loading

Changed: src/agent-device/shared/replies.ts, src/agent-device/front/allocate.ts (the leasing error at :258-264 and :118), src/agent-device/front/token-devices.ts or its callers (the lease-check failure), the modules that hand the front its unavailable condition, which today pass a message only (F17): src/agent-device/host/upstream.ts, src/agent-device/host/host.ts, src/agent-device/front/host-link.ts, src/agent-device/front/relay-host-link.ts, src/agent-device/worker.ts, and the fake in src/agent-device/testing.ts, src/agent-device/edge.test.ts, src/agent-device/gateway-front.test.ts, the tests of F15, website/src/content/docs/docs/using-devices/agent-device.mdx, src/agent-device/AGENTS.md.

Contract and event changes

None in simlock's contract: these are the agent-device front's own replies. New wire fields: error.data.details.reason (string, one of the six), error.data.retriable (boolean), and flat reason and retriable with the same values. No event.

Other code on the same state

Searches: details reads in src/agent-device (isUnreachableAnswer, markUnreachableAnswer, LEASE_GONE). isUnreachableAnswer marks responses, not details, and is unchanged. The allocate's LEASE_GONE check reads agent-device's reasons, which pass unchanged (F8).

Failure modes

None: the change writes no state and adds no call; it adds fields to replies the front already sends.

Rules in play

  • ADR 0070 §4, "Every error the front makes itself carries a reason from a fixed, documented list and a retriable flag".
  • The code values stay, ADR 0070 §4.

Tests

Seam: the agent-device front on a worker and through a gateway, agent-device faked, src/agent-device/edge.test.ts and src/agent-device/gateway-front.test.ts (model: expectUnreachable at gateway-front.test.ts:1919-1925).

  • Every error the front makes carries its reason and retriable flag; agent-device's errors pass unchanged. Cases: each of the six reasons, as a JSON-RPC error; an allocate refused for a model simlock lacks (REFUSED_BY_SIMLOCK, false) and one failed with NO_CAPACITY (SIMLOCK_UNAVAILABLE, true); agent-device start-failed (true) and wrong-version (false); a lease check failure (SIMLOCK_FAILED, true); a flat error (an upload through an unavailable worker); an agent-device error. The flat assertion at gateway-front.test.ts:1927-1931 changes to expect reason and retriable.

Done when

  • pnpm exec vitest run --project unit src/agent-device/edge.test.ts src/agent-device/gateway-front.test.ts src/agent-device/edge-request-rules.test.ts src/agent-device/front/relay-host-link.test.ts src/agent-device/front/orientation.test.ts passes with the Tests line.
  • agent-device.mdx has an Error reasons section, apart from the Messages you may see table: the six reasons, when each is retriable, where they sit in a JSON-RPC and a flat error, and that simlock's own sign-in errors (UNAUTHENTICATED, FORBIDDEN, F16) and errors from outside simlock (a proxy in front of it, a refused connection) carry none.

Out of scope

  • Labelling errors agent-device makes.
  • exec (/v1/leases/<id>/exec): simlock's contract errors already carry stable codes.

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 #1437 is ready and review-complete at a39d47691ce99cf77920d38fbc3e3f46babf1b6f. R1/R2 and the final test-relocation fix-check remain verified; code CI passed.

    Not done

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

    Findings

    #1421's CI correction is verified and green. #1422 PR #1439 at d5a1d3b1 has Fallow and PR-body failures; its hardware line remains unverified. #1424 has not been delivered. A status edit falsely triggered the branch-name check; its wording was corrected. Issue-state run 42404322508 is checking the correction.

    Blocked on

    Nothing in this task. Confirm the new issue-state checks; the stack waits for #1422's hardware and CI, and #1424's delivery.

    Written by an agent.

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

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: none.
    Parked: none in #1423.
    Waiting: #1423 — issue-state run 42404322508 after a corrected status edit; #1422 hardware and CI, #1424 delivery, then the complete #1419 stack.
    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