Skip to content

A lease.cancel through a gateway refuses a fleet request that is not queued yet, so an early abort leaves it standing #1492

Closed

Description

@V3RON

What happens. Suspected, not reproduced: a lease.cancel through a gateway for a fleet request that is not queued yet answers not-cancellable, and the request then goes on to queue or be dispatched. That is the same race #1479 fixed on a worker (PR #1485). The client's abort then leaves the request standing, so a killed simlock --gateway lease can still end up holding a device until its TTL.

Where. FleetLeaseCoordinator.cancelPending (src/gateway/fleet-coordinator.ts:386-398) answers not-cancellable for any waiter whose state !== "queued". #1479's fix on the worker made a waiter that is still resolving its spec cancellable, and made lease.cancel wait for the same requester's not-yet-admitted lease.request. The gateway has neither change. #1479's triage report flagged it as a risk.

Seen. Code reading only, on main after #1485 merged. Nothing was run through a gateway.

Found while delivering #1479.

Written by an agent.

Activity

  1. added
    bug:new
    on Nov 10, 2026
  2. self-assigned this
    on Nov 10, 2026
  3. V3RON commented on Nov 10, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Confirmed. src/gateway/fleet-requests.test.ts, "FleetLeaseCoordinator: a lease.cancel sent right after its lease.request (#1492)", two cases: a fleet with no room (the request would queue) and a free worker (it would be dispatched). Each expects cancelled, a RequestCancelledError, nothing waiting and no lease.request to the worker. Without the cancel, the same fixtures do queue and dispatch. Branch bug/1492-repro.

    pnpm exec vitest run --project unit src/gateway/fleet-requests.test.ts -t 1492
    
    × with no room, so the request would queue, answers cancelled, ...
    × with a free worker, so the request would be …, answers cancelled, ...
    AssertionError: expected 'not-cancellable' to be 'cancelled'
     ❯ src/gateway/fleet-requests.test.ts:1658:27
    

    Root cause

    src/gateway/fleet-coordinator.ts:395 refuses every waiter not queued. request() creates the waiter (state new) inside its decision and calls #admit only after #decisions.run returns, so a cancel queued behind that decision runs first and sees new. ADR 0005 §10 asks for the codes a worker uses, and since #1485 a worker cancels a new waiter. A correction to the issue: the second half of #1485 (waiting for a not-yet-admitted request) is not needed here. GatewayDispatcher#leaseRequest reaches the coordinator's FIFO decision with no await in between, so the cancel always finds the waiter.

    Simplest fix

    if (waiter.state === "processing") return "not-cancellable";

    #admit then finds the waiter terminal: markProcessing and enqueue refuse it, and no RPC goes out.

    pnpm exec vitest run --project unit src/gateway/   →  25 files, 814 passed
    

    Alternatives rejected

    • Port UnadmittedRequests to the gateway dispatcher: it has no window to cover.
    • Also return early from #admit for a terminal waiter: same result, a second guard.

    Risk

    • A cancelled new waiter still walks once in #admit and claims a worker for that pass, but it sends nothing.
    • processing (forwarded, before the worker's answer) stays not-cancellable, as on a worker. A killed CLI there keeps the lease until its TTL.
    • Over the wire, new is seen only when both frames are dispatched in one tick, for example from a single socket read.

    Fast track

    • Defect: yes
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: yes

    Written by an agent.

  4. removed their assignment
    on Nov 10, 2026
  5. added
    bug:ready
    fast-track
    and removed
    bug:new
    on Nov 10, 2026
  6. self-assigned this
    on Nov 10, 2026
  7. V3RON commented on Nov 10, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1493 (#1492)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

  8. added a commit that references this issue on Nov 10, 2026
    c0a70cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:readyfast-track

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions