Skip to content

feat(daemon): opt-in bounded FIFO queue for a foreign device lease (#1864) - #1873

Merged
zackees merged 1 commit into
mainfrom
agent/1864-lease-wait-queue
Nov 3, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/1864-lease-wait-queue

Conversation

@zackees

@zackees zackees commented Nov 3, 2026

Copy link
Copy Markdown
Member

Continues #1864 (criterion 3: "Add an opt-in bounded wait/queue
for competing workflows, with holder/progress diagnostics, cancellation, and
deterministic ordering. Retain fail-fast behavior for callers that do not opt
in. Waiting must occur before preemption/reset/open."
).

The first two slices merged as #1869 (deploy/reset admission) and #1871 (serial
write path). Both refuse a foreign exclusive lease immediately; a second
checkout still had to retry in a shell loop. This slice adds the queue.

What changed

  • DeviceManager admission queue (device_manager/wait_queue.rs, a
    sibling module so the parent stays under the LOC gate):
    • enqueue_waiter / leave_queue / queued_client_ids / queued_workflows
      over a per-port FIFO keyed by a monotonic sequence number.
    • poll_admission(port, lease_id, ticket) — the single admission rule:
      the lease holder is always admitted, an unknown port is admitted (emulator
      and probe routes stay outside the lease path, as in fix(daemon): enforce explicit device leases on deploy and reset admission #1869), and a waiter is
      admitted only at the head of its port's queue with no foreign lease.
      A fail-fast caller (no ticket) is refused while anyone is queued, so two
      clients that observe a release in the same instant cannot reorder.
    • await_admission(port, lease_id, wait_ms, client_id) — the opt-in bounded
      wait. wait_ms == 0 keeps today's fail-fast behaviour; otherwise the
      call joins the queue and polls on a 20 ms → 200 ms backoff until admitted
      or the deadline expires. QueueGuard owns the ticket, so a cancelled
      request (dropped future) leaves the queue and promotes the next workflow
      instead of becoming a phantom head-of-line blocker.
  • DeployRequest.lease_wait_ms (#[serde(default)], so older clients that
    never send it keep fail-fast admission) and fbuild deploy --lease-wait <seconds>. The wait runs at the same admission site as fix(daemon): enforce explicit device leases on deploy and reset admission #1869 — on the
    resolved port, before preempt_for_deploy — so a queued deploy never
    resets, closes or flashes the holder's board. The holder deploying under its
    own --lease-id is never queued.
  • New error DeviceLeaseError::LeaseWaitTimedOut names the queue position,
    the holder (lease id, client, description) and the elapsed wait, and states
    that the board was not reset, closed or flashed. With waited_ms == 0 it
    recommends --lease-wait / fbuild device take.
  • Reset stays fail-fast: it has no CLI lease flag and remains gated by fix(daemon): enforce explicit device leases on deploy and reset admission #1869.
  • docs/reference/cli.md "Workflow leases" documents the queue semantics.

Tests (real output)

  • New device_manager/tests.rs::lease_wait_queue_tests (8): FIFO head-only
    admission, foreign-lease head blocking + holder naming, an unqueued caller
    cannot jump a waiter, unknown ports admitted, bounded wait admits after a
    release (≥100 ms, real tokio::time), timeout leaves the queue empty,
    wait_ms == 0 stays fail-fast, holder never queued.
  • New models.rs tests (2): lease_wait_ms defaults to 0, and carries the
    opt-in value.
  • RED proven behaviourally: stubbing the admission rule to
    AdmissionPoll::Admitted → test result: FAILED. 2 passed; 6 failed
    (a foreign lease admitted the waiter, …); restored →
    ok. 39 passed; 0 failed (cargo test -p fbuild-daemon --lib device_manager).
  • cargo test -p fbuild-daemon --lib → 317 passed / 0 failed / 3 ignored
    (baseline was 307/0/3).
  • soldr cargo clippy -p fbuild-daemon -p fbuild-cli --all-targets -- -D warnings
    → rc 0. cargo fmt --all --check → rc 0.
  • ci/check_test_layout.py → ok (8 categories). ci/enforce_platform_boundary.py --print-totals → rows=44; dylint_rows=43, rc 0 (no host occurrences added;
    the ledger ratchet is untouched).

Still open on #1864

Lease identity across re-enumeration/recovery reattach, Python facade
lease_id/lease_wait_ms plumbing, and the two-real-checkout hardware
turn-taking validation (needs an idle board).

A competing workflow can now queue for a board instead of failing fast:
`fbuild deploy --lease-wait <seconds>` joins a per-port FIFO and proceeds
in ticket order once the holder releases.

- DeviceManager gains enqueue_waiter/leave_queue/poll_admission and the
  bounded await_admission; admission is head-of-queue only, so waiters
  cannot reorder, and the lease holder is never queued. QueueGuard owns
  the ticket, so a cancelled request leaves the queue.
- DeployRequest.lease_wait_ms (serde default 0 = fail fast) and the
  --lease-wait flag; the wait runs before preemption, reset or open.
- New DeviceLeaseError::LeaseWaitTimedOut reports queue position, holder
  and elapsed wait, and states the board was not reset/closed/flashed.

#1864 criterion 3.
@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@zackees
zackees added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit acc3ac5 Nov 3, 2026
31 checks passed
@zackees
zackees deleted the agent/1864-lease-wait-queue branch November 3, 2026 11:15
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant