Skip to content

The agent-device front ends a lease for good when one lease.list answer leaves it out #750

Closed

Description

@V3RON

The agent-device front marks a lease ended by simlock whenever one `lease.list` answer does not contain it:

  • `src/agent-device/front/token-devices.ts:26` (a `devices` call or a device-list rule)
  • `src/agent-device/front/front-map.ts:148` (`refresh`, on allocate)

Nothing undoes it: renewals stop (`front/renewals.ts:54`, `:100`, `:127`) and heartbeats answer "ended by host" (`front/heartbeat.ts:128`). The simlock lease then runs out its TTL.

On a gateway, `lease.list` leaves out leases that are still live: entries whose view is missing for a moment ("a race with a reconnect rebuild", `src/gateway/dispatcher.ts:427-439`), and every lease on a starting worker (#405). The gateway's own rule is that only a worker's relayed fact or answer ends a lease (`src/gateway/AGENTS.md`, Rules). Fixing #405 removes one cause, not this one.

Found while triaging #405.

Written by an agent.

Activity

  1. added
    bug:new
    and removed
    bug:new
    on Oct 20, 2026
  2. self-assigned this
    on Oct 20, 2026
  3. V3RON commented on Oct 20, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Defect, confirmed through a gateway. The issue names two sites; there are four. renewLease also reads lease.list, so a renewal tick or a heartbeat that misses the lease ends it too.

    src/agent-device/gateway-front.test.ts: "a lease the gateway's lease.list leaves out of one answer, read by a devices call, an allocate, a renewal while a command runs, or a heartbeat, is not ended: the next heartbeat succeeds and renews the simlock lease".

    pnpm exec vitest run --project unit src/agent-device/gateway-front.test.ts -t "is not ended"
    
    expect(outcomes).toEqual({ allocate: live, devices: live, heartbeat: live, renewal: live })
      every case:  cut: 1
    -   "ok": true,                         +   "reason": "LEASE_ENDED_BY_HOST",
    -   "leftMs": 60000,                    +   "leftMs": 14000   (renewal: 4000)
    

    Root cause

    src/agent-device/front/token-devices.ts:26, front-map.ts:148 and renewals.ts:24 (returns gone, then renewals.ts:130 and heartbeat.ts:87 call markEnded). All four treat "not in this lease.list answer" as "ended by simlock". On a worker that is true: the list is the source. On a gateway it is not: dispatcher.ts:436 skips an indexed lease whose view is missing. The gateway's lease index (FleetPort.leaseOf) only drops a lease on the worker's fact, but the front never asks it. The symptom shows later: heartbeat.ts:128, the renewal guards.

    Simplest fix

    Add an optional HostLink method, e.g. stillHeld?(leaseId). RelayHostLink answers fleet.leaseOf(leaseId) !== undefined. The worker link leaves it out, so a missing lease stays final. At the four sites, a lease missing from the list is ended only when stillHeld is false. Otherwise: devices leaves it out of this answer, refresh skips it, and renewLease returns failed (try again).

    Alternatives rejected

    Risk

    • devices must still hide an unlisted lease's device in that answer.
    • Use fleet.leaseOf, not the link's routing memory. That memory keeps dropped leases for lease.maxTtlMs.
    • Worker-direct behaviour stays (edge.test.ts).

    Written by an agent.

  4. removed their assignment
    on Oct 20, 2026
  5. added
    bug:ready
    and removed on Oct 20, 2026
  6. self-assigned this
    on Oct 20, 2026
  7. V3RON commented on Oct 20, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #753 (#750)
    Parked: none
    Waiting: none
    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

Labels

bug:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions