Repository navigation
fix(daemon): honor exclusive device leases on the serial write path (#1864) - #1871
Merged
Merged
Conversation
A foreign exclusive lease now refuses /ws/serial-monitor attach before the port is opened, and every write frame is re-admitted so a lease taken by another workflow mid-session stops the bytes. `fbuild monitor` gains --lease-id for the holder. The protocol field is optional and omitted by older clients, which present no lease (the safe default). See #1864.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
…dger
The host-platform ledger is a shrink-only ratchet (44 rows; adding rows fails
`test_committed_exact_occurrence_ledger_matches_whole_tree`), so the coverage
is restructured instead of baselined:
- new portable test `ws_serial_attach_is_refused_under_a_foreign_exclusive_lease`
asserts the refusal (no lease) and that the holder clears admission, using a
registered test device and `open_if_needed: false` so no tty is needed and no
platform gate is introduced;
- the existing linux/pty WebSocket test gains the mid-session lease-steal
assertion (a write after another workflow leases the port must come back
`write_ack{success:false}`), reusing the session it already holds.
Net: 0 new ledger rows, 0 new libc:: occurrences; the ledger and dylint
baseline are byte-identical to main.
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.
Why
#1864's first slice (#1869) made
deployandresethonor a foreign exclusivedevice lease. The remaining mutating path — serial attach + write — still
reached the board: any client could attach
/ws/serial-monitor, take thewriter lock, and talk to a board another workflow had reserved with
fbuild device lease <port> --exclusive. A validation holder could bepreempted by an unrelated
fbuild monitor(or a PythonSerialSession) thatheld no lease at all.
This is #1864 criterion 1/2 ("require every mutating device path — deploy,
reset, serial write/RPC writer — to honor a foreign exclusive device lease";
"let the lease holder pass its lease identity through … subsequent serial/RPC
calls").
What changed
SerialClientMessage::Attachgainslease_id: Option<String>(
skip_serializing_if = "Option::is_none"): the wire format is unchanged forclients that predate it, and an omitted lease means "present no lease" — the
safe reading, which is refused on a reserved board.
handle_serial_wsadmits the attach throughDeviceManager::admit_operation(&port, lease_id)beforeserial_manager.open_port(), so a refused client never opens, resets, orreads the board. The refusal is a typed
errorframe carryingForeignLeaseHeld's message (lease id, holder,--lease-id).writeframe is re-admitted before the bytes reach the port, so alease acquired by another workflow after a session attached stops the next
write with
write_ack{success:false}instead of silently flashing over theholder.
fbuild monitor --lease-id <id>passes an existing lease through (the leaseid is the bearer token, same model as
fbuild deploy --lease-id).docs/reference/cli.md: the workflow-lease section and thefbuild monitorexample now cover the serial write path.
Tests
ws_serial_attach_is_refused_under_a_foreign_exclusive_lease(portable, notty, no platform gate — the refusal happens ahead of
open_port): with aregistered test device and an exclusive lease held by client A,
errorframe containing"reserved by exclusive lease" + the lease id +
--lease-id, and the port isnever opened (
has_clients == false);is "port … not open", not a lease refusal).
serial_ws_replies_follow_request_order(existing real-WS + real-pty test)gains the mid-session case: after another workflow leases the pty port, the
attached session's next write returns
write_ack{success:false, bytes_written:0}naming that lease.RED first — stubbing
admit_operationtoreturn Ok(()):assertion left == right failed: {"bytes_written":3,"success":true,"type":"write_ack"}for the pty test and a failed message assertion for the portable test; both
pass once restored.
No new host-platform debt: the ledger/dylint baseline are byte-identical to
main (
rows=44), and the research inventory only shifts line numbers.Real output
Not in this PR (still open on #1864)
holder/progress diagnostics (criterion 3).
fbuild-pythonhas its ownClientMessage) cannot presenta lease yet — it is correctly refused rather than admitted, which is the
safe default; a
lease_idkwarg is a separate additive change.board; two board-bearing builds were running during this work.