Skip to content

fix(daemon): enforce explicit device leases on deploy and reset admission - #1869

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

zackees merged 1 commit into
mainfrom
agent/1864-workflow-lease

Conversation

@zackees

@zackees zackees commented Nov 3, 2026

Copy link
Copy Markdown
Member

Problem

fbuild device lease <port> --exclusive --track-serial reserved the board only
against another lease: every mutating device path went straight to
serial_manager.preempt_for_deploy, which happily closed the holder's port and
flashed over its firmware. Observed in FastLED/FastLED#5001 validation: a
fastled3 deploy preempted the fastled lease and replaced the image between
the holder's flash and its validation, with no lease-release or daemon restart
in between (#1864).

What this changes

  • DeviceManager::admit_operation(port, lease_id) — one admission check: an
    exclusive lease admits only its own lease_id; a caller that presents none
    (or a different one) is refused with a new
    DeviceLeaseError::ForeignLeaseHeld. The message names the lease id, the
    holder, and both escape hatches (--lease-id <id>, or
    fbuild device release <port> --lease-id <id>). Monitor leases never block,
    unknown ports are not an admission failure (emulator/probe routes stay out of
    the path).
  • /api/deploy calls it on the resolved port before
    preempt_for_deploy, so a competing client can no longer close the holder's
    session or flash at all. DeployRequest gains an optional lease_id; the CLI
    gains fbuild deploy --lease-id <id>.
  • /api/reset gets the same gate and the same optional lease_id field —
    a reset would otherwise drop the holder mid-validation.
  • fbuild device take --reason is unchanged: an explicit takeover still works,
    it is a human decision, not a silent override.

This is the admission slice of #1864. Sequestration/queueing for competing
workflows (bounded wait, deterministic ordering, cancellation), lease identity
on the serial-write/RPC writer path, and lost-lease reporting on daemon restart
are the remaining acceptance criteria and are not in this PR; #1864 stays
open.

Tests

  • crates/fbuild-daemon/src/device_manager/tests.rs: unleased port admits,
    foreign client with no lease is refused and reports holder + lease id,
    wrong lease id refused, the holder itself admits, monitor leases don't block,
    unknown port admits, message names both escape hatches.
  • crates/fbuild-daemon/src/handlers/operations/tests.rs
    (device_lease_admission_tests): drives the same admission call through the
    production DaemonContext — client B's deploy is refused while client A's
    lease is held, and the holder admits repeatedly (deploy → reset/RPC) with no
    release/reacquire gap, all hardware-free.

Behaviour change

Scripts that acquire an exclusive lease and then deploy must now pass
--lease-id. Deploys against unleased boards are unchanged.

Closes nothing; refs #1864.

… lease

A `fbuild device lease <port> --exclusive --track-serial` reserved the
board only against another lease: deploy and reset went straight to
serial_manager.preempt_for_deploy, which closed the holder's port and
flashed over its firmware (#1864).

New DeviceManager::admit_operation(port, lease_id) is the single
admission check: an exclusive lease admits only its own lease id, a
caller presenting none/different gets DeviceLeaseError::ForeignLeaseHeld
naming the lease, holder and both escape hatches. Deploy calls it on the
resolved port before preemption; reset calls it before touching the
port. DeployRequest/ResetRequest gain an optional lease_id and the CLI
gains `fbuild deploy --lease-id`.

Remaining #1864 scope (bounded queue, serial-write identity, lost-lease
reporting) is untouched.

Tests: device_manager admit_* (7) + operations device_lease_admission_tests (2) through the production DaemonContext; full daemon lib 306p/0f/3i, fbuild-cli bin 472p/0f, clippy -D warnings rc0, fmt rc0, boundary 44/43.
@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 13e4820 Nov 3, 2026
31 checks passed
@zackees
zackees deleted the agent/1864-workflow-lease branch November 3, 2026 06:46
@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