Skip to content

GET /v1/leases/{id} answers 404 on a gateway for a lease it issued #186

Closed

Description

@V3RON

What happens

On a gateway, GET /v1/leases/{id} answers 404 UNKNOWN_LEASE for a live lease that gateway issued. The request resource for the same lease answers 200 and shows it granted.

Reproduction

In e2e/gateway-smoke.test.ts, test "leases and execs through a gateway over HTTP…", right after the lease request is granted:

GET /v1/leases/<leaseId>          -> 404 {"error":{"code":"UNKNOWN_LEASE","message":"Unknown lease: c9e9eefd-….lse_48e0709f-…"}}
GET /v1/lease-requests/<reqId>    -> 200 {"request":{"state":"granted","lease":{"id":"c9e9eefd-….lse_48e0709f-…", …}}}

Run on feature/158 (7ce701f); src/http and src/gateway are the same as main there.

Likely cause

The route finds the lease through lease.list, then looks the device up in the local registry (findDevice, src/http/app.ts). A gateway is given an empty one (registry: { snapshot: { devices: [] } } in startGatewayDaemon, src/daemon/main.ts), so the lookup misses and the route throws unknownLease. The comment beside that stub says lease routes answer UNSUPPORTED_IN_GATEWAY_MODE, which is no longer true.

Expected

The lease object, as a worker returns it and as docs/HTTP-API.md describes.

Written by an agent.

Activity

  1. added
    bug:new
    and removed
    bug:new
    on Oct 1, 2026
  2. self-assigned this
    on Oct 1, 2026
  3. added a commit that references this issue on Oct 2, 2026
  4. V3RON commented on Oct 2, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Defect. On a gateway, GET /v1/leases/{id} answers 404 UNKNOWN_LEASE for a live lease it granted. Reproduced with a fake-driver gateway and one worker.

    e2e/gateway-smoke.test.ts, "serves GET /v1/leases/{id} for a lease the gateway granted over HTTP: the granted lease, naming its worker (#186)", on bug/186-repro. It expects the request resource's lease plus workerId and worker, as docs/HTTP-API.md describes a gateway lease.

    pnpm run build && pnpm run build:e2e
    pnpm exec vitest run --project e2e e2e/gateway-smoke.test.ts -t "#186"
    
    -   "status": 200,
    +   "status": 404,
    +     "error": { "code": "UNKNOWN_LEASE", "message": "Unknown lease: d72ce1b8-….lse_d4ba7189-…" }
    

    Root cause

    src/http/app.ts:347-348. The route finds the lease through lease.list, which works on a gateway, then needs a device record from deps.registry and throws unknownLease without one. A gateway gets an empty registry (src/daemon/main.ts:765); the comment above it is false. The issue's diagnosis is right, with one correction: the worker views cannot stand in for the registry. Their devices are narrowed to statusDeviceSchema (src/gateway/worker-link.ts:110), which has no driverDeviceId, so udid would be lost. Also, buildLeasePayload (src/http/tracker.ts:60) drops worker and workerId.

    Simplest fix

    1. The gateway keeps each worker's devices in the grant shape (grantedDeviceSchema), parsed from the list.get its view refresh already makes. Not on the contract's WorkerView.
    2. startGatewayDaemon wires that as the device reader; fix the comment.
    3. buildLeasePayload copies worker and workerId from the lease record.

    A throwaway prototype of this passed the test and the other four smoke tests.

    Alternatives rejected

    • Views as the registry: no udid; adding it to statusDeviceSchema shows every udid to every agent.
    • The gateway's request book: gone after lease.requestRetentionMs and on restart.
    • A forwarded lease.get operation: closest to ADR 0005 §15, but a contract change; a spec session's call.

    Risk

    • HttpRegistryReader is typed as full DeviceRecords, and DELETE /v1/leases/{id} reads state from it. Narrow the type rather than fake a state.
    • Lease and device come from one refresh; check a lease is never visible before its device.
    • Keep driverDeviceId off status.get and worker.list.

    Side findings

    Written by an agent.

  5. added
    bug:ready
    on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions