Skip to content

requestLease aborted before the daemon queues the request leaves it queued and the call pending #1479

Closed

Description

@V3RON

An abort that reaches SimlockClient.requestLease after the frame is sent but before the daemon admits the request is lost. The client sends lease.cancel, the daemon answers not-found because the request is not queued yet, and #cancelOnAbort (src/simlock-client/client.ts:916) treats that as ADR 0003 §10's "after the grant resolved" case and waits on the request. The request is then queued, so the call never settles and the request outlives its caller.

lease.request awaits #requireCapabilities and the spec resolve (outside the lock) before it admits (src/daemon/dispatcher.ts:533), and lease.cancel has no such step, so the cancel wins.

Seen with a probe against startTestDaemon in src/cli/index.test.ts (iOS limit 1, one lease held by a): requestLease({ requesterId: "b" }, { signal }), controller.abort() one microtask later, 50 macrotasks of settle:

PROBE state pending waiting [{"id":"req_id1","requesterId":"b",...,"stage":"queued","queuePosition":1,"reason":"device-limit"}]

Every frontend that aborts (simlock lease on a signal, MCP) has this window. Found while triaging #1473.

Written by an agent.

Activity

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

    @V3RON
    ContributorAuthor

    Reproduction

    src/daemon/server-roles.test.ts, "a requestLease aborted right after its frame is sent, with the device limit held, rejects CANCELLED and its request ends cancelled, not by its queue timeout", on bug/1479-repro. The cancel answers not-found on every run, as reported.

    pnpm exec vitest run --project unit src/daemon/server-roles.test.ts -t "aborted right after its frame"
    
    AssertionError: expected SimlockError: Timed out waiting for a dev… to match object { code: 'CANCELLED' }
    -   "code": "CANCELLED",
    +   "code": "QUEUE_TIMEOUT",
    

    Root cause

    Defect, two windows. #leaseCancel (src/daemon/dispatcher.ts:596) runs cancelPending at once, before the same requester's lease.request is admitted: await this.#requireCapabilities (:533) yields even with no requires, then the request waits for the lock. So: not-found. Correction: the spec resolve runs after admission, and is the second window: cancelPending (src/leasing/lease-acquisition-coordinator.ts:799) answers not-cancellable for a waiter still new (resolving its spec, no device work). Either way the client (src/simlock-client/client.ts:916, :944) waits on a request that then queues.

    Simplest fix

    One PR, two changes:

    1. Dispatcher: per requester, a promise for each lease.request not yet admitted, resolved on onAdmitted or when the call settles. #leaseCancel awaits them before cancelPending.
    2. cancelPending: not-cancellable only for processing; a new waiter is rejected like a queued one (#nextPlan skips a rejected waiter). Update its doc comment.
    change 1 only:      AssertionError: expected [ 'timeout' ] to deeply equal [ 'cancelled' ]
    changes 1 + 2:      reproduction passes 3 of 3 runs
    pnpm test:changed:  93 files, 3029 tests passed
    

    Alternatives rejected

    • Client re-sends lease.cancel on the first queued push: a client retry its manual forbids.
    • An admission push on the wire: a contract change and protocol bump for an order the daemon can keep.
    • Skip the await when requires is empty: leaves the lock order to frame timing.

    Risk

    • The gateway's cancelPending (src/gateway/fleet-coordinator.ts:393) has the same queued-only check; not reproduced.
    • A request stuck before admission now stalls its requester's cancel.
    • With allowDownload, a cancelled new waiter leaves its runtime install running.

    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 9, 2026
  5. added
    bug:ready
    fast-track
    and removed
    bug:new
    on Nov 9, 2026
  6. self-assigned this
    on Nov 9, 2026
  7. V3RON commented on Nov 9, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done: PR #1485 fixes both windows from the triage. The dispatcher holds a lease.cancel until the same requester's unadmitted lease.request is admitted or settles, and cancelPending rejects a new waiter. Review: round 1 raised one blocking finding (the finally release had no test). It is fixed and verified, and a later fix-check passed. CI's size-limit failure is fixed by moving the tracking into src/daemon/unadmitted-requests.ts. The PR is ready for review.

    Not done: merge.

    Findings: the gateway's cancelPending (src/gateway/fleet-coordinator.ts:393) has the same check, but it was not reproduced and is out of scope.

    Blocked on: fast-track: #1479 held: PR #1485 changes 272 lines, over 250. The maintainer merges the PR, or removes fast-track.

    Written by an agent.

  8. added
    bug:blocked
    and removed
    bug:ready
    on Nov 9, 2026
  9. removed their assignment
    on Nov 9, 2026
  10. V3RON commented on Nov 9, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: none
    Parked: #1479 — PR #1485 held by the fast track (272 lines, over 250)
    Asleep: 15 min

    Written by an agent.

  11. removed
    fast-track
    on Nov 10, 2026
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

    bug:blocked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions