Skip to content

Track leased devices by USB serial - #639

Merged
zackees merged 1 commit into
mainfrom
fix/device-track-serial
Jun 18, 2026
Merged

zackees merged 1 commit into
mainfrom
fix/device-track-serial

Conversation

@zackees

@zackees zackees commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add track_serial to device lease requests and lease attribution
  • preserve tracked leases when a USB device reappears on a different port with the same serial number
  • expose serial/previous-port metadata through daemon responses and CLI device output

Closes #638

Verification

  • soldr cargo fmt --all --check
  • soldr cargo check -p fbuild-daemon -p fbuild-cli
  • soldr cargo test -p fbuild-daemon device_manager -- --nocapture
  • soldr cargo test -p fbuild-daemon handlers::devices -- --nocapture
  • soldr cargo test -p fbuild-daemon handlers::operations::deploy_port -- --nocapture
  • soldr cargo clippy -p fbuild-daemon -p fbuild-cli --all-targets -- -D warnings

Summary by CodeRabbit

  • New Features
    • Added --track-serial flag to fbuild device lease to follow USB devices by serial number across port renumbering.
    • Device output now displays USB serial numbers when available.
    • Device output now shows previous port information when a device has been renumbered.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 98bb4d97-c4a3-4f20-910f-8b58e3219cb5

📥 Commits

Reviewing files that changed from the base of the PR and between 54e6351 and 7e39b40.

📒 Files selected for processing (8)
  • crates/fbuild-cli/src/cli/args.rs
  • crates/fbuild-cli/src/cli/device.rs
  • crates/fbuild-cli/src/daemon_client.rs
  • crates/fbuild-cli/src/daemon_client/types.rs
  • crates/fbuild-daemon/src/device_manager.rs
  • crates/fbuild-daemon/src/handlers/devices.rs
  • crates/fbuild-daemon/src/handlers/operations/deploy_port.rs
  • crates/fbuild-daemon/src/models.rs

📝 Walkthrough

Walkthrough

Adds USB serial-number-based lease tracking to the device manager. When a device reconnects on a different port and its serial number matches a disconnected state with a track_serial lease, the daemon migrates the lease to the new port and records the old port. New fields propagate through daemon models, HTTP handlers, and the CLI.

Changes

USB Serial Lease Tracking

Layer / File(s) Summary
API model and serde contracts
crates/fbuild-daemon/src/models.rs, crates/fbuild-cli/src/daemon_client/types.rs
DeviceInfo, DeviceLeaseRequest, DeviceLeaseInfo, and DeviceStatusResponse gain serial_number, previous_port, and track_serial fields. CLI response types add #[serde(default)] to the matching optional fields for backward-compatible deserialization.
DeviceManager: state, discovery, and port-migration logic
crates/fbuild-daemon/src/device_manager.rs
DeviceLease gains track_serial; DeviceState gains serial_number, previous_port, and has_tracked_serial_lease(). A new DiscoveredDevice struct carries serial numbers into refresh_devices(). refresh_from_discovered() migrates a disconnected state to a new port key when serial numbers match and a tracked lease exists, stamping previous_port. acquire_exclusive and acquire_monitor accept and store track_serial; preempt_device forces it to false.
Daemon HTTP handlers
crates/fbuild-daemon/src/handlers/devices.rs
device_status not-found payload defaults serial_number/previous_port to None. device_info and device_status_response populate those fields from DeviceState. device_lease forwards req.track_serial into acquisition calls. lease_info maps track_serial from DeviceLease into DeviceLeaseInfo.
CLI flag, daemon client, and display
crates/fbuild-cli/src/cli/args.rs, crates/fbuild-cli/src/daemon_client.rs, crates/fbuild-cli/src/cli/device.rs
DeviceAction::Lease gains a --track-serial Clap flag. DaemonClient::device_lease accepts and sends track_serial in the JSON body. A new device_description() helper annotates list output with "(renum from …)" when previous_port is set. Status output conditionally prints Serial and Previous port; print_lease prints track_serial.
Unit and regression tests
crates/fbuild-daemon/src/device_manager.rs, crates/fbuild-daemon/src/handlers/devices.rs, crates/fbuild-daemon/src/handlers/operations/deploy_port.rs
New regression tests verify that a tracked-serial lease migrates to a renumbered port while an untracked lease does not. All existing tests are updated to supply the new track_serial parameter and initialize serial_number/previous_port on DeviceState fixtures.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 A USB plug goes pop, then reappears anew,
But my serial number stays the same — I'm still me, it's true!
The daemon checks the list, finds a match by name,
Moves the lease right over, port-migration's the game.
"(renum from COM21)" the little CLI gleams,
No lost authoritative holder — nothing broken, nothing seams. 🔌

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/device-track-serial

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees
zackees merged commit 8cb1b89 into main Jun 18, 2026
89 of 90 checks passed
@zackees
zackees deleted the fix/device-track-serial branch June 18, 2026 22:59
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 19, 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.

device leases: add track_serial and preserve leases across USB port renumbering

1 participant