Repository navigation
fix(daemon): enforce explicit device leases on deploy and reset admission - #1869
Merged
Merged
Conversation
… 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.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This was referenced Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
fbuild device lease <port> --exclusive --track-serialreserved the board onlyagainst another lease: every mutating device path went straight to
serial_manager.preempt_for_deploy, which happily closed the holder's port andflashed over its firmware. Observed in FastLED/FastLED#5001 validation: a
fastled3deploy preempted thefastledlease and replaced the image betweenthe 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: anexclusive 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, theholder, and both escape hatches (
--lease-id <id>, orfbuild 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/deploycalls it on the resolved port beforepreempt_for_deploy, so a competing client can no longer close the holder'ssession or flash at all.
DeployRequestgains an optionallease_id; the CLIgains
fbuild deploy --lease-id <id>./api/resetgets the same gate and the same optionallease_idfield —a reset would otherwise drop the holder mid-validation.
fbuild device take --reasonis 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 theproduction
DaemonContext— client B's deploy is refused while client A'slease 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.