Repository navigation
Description
Follow-up to #1431 / #1484. Downstream: FastLED/FastLED#4656.
Decision: AsyncSerialMonitor becomes a supported API. The sync SerialMonitor and AsyncSerialMonitor share one session core, and each exposes its own Python API.
1. Current state
SerialMonitor (sync) |
AsyncSerialMonitor |
|
|---|---|---|
| Code | serial_monitor.rs + ws_session.rs (after #1484) |
async_serial_monitor.rs + async helpers in json_rpc.rs |
| Users | FastLED, via a thread-pool adapter | none |
| Tests | fake-daemon Rust tests in ws_session.rs |
none |
| Write during a long read | fixed in #1484 (ReadYield hand-off) |
stalls: write_async waits for write_ack while holding the shared read half (json_rpc.rs:117-150), which a concurrent read_lines holds for its whole timeout |
| RPC reply stolen by a concurrent reader | fixed in #1484 (RpcRoute) |
broken: write_json_rpc polls read_lines_async (json_rpc.rs:161-186) |
| Overlapping requests swap replies | fixed in #1484 (request lock) | broken |
| Cancellation loses lines | n/a | possible: lines pulled into a batch that is never delivered |
| API gaps | — | write -> bool (sync returns bytes); reset_device has no wait_for_output/timeout; no in_waiting, run_until or reset_input_buffer; uses timeout_secs= (sync uses timeout=) |
#1484's hand-off design works, but it is a polling hand-off: 1 ms yield polls and a 50 ms RPC slice. It can't be reused from async code without re-deriving it on tokio mutexes.
2. Protocol facts the design relies on (verified in the daemon)
crates/fbuild-daemon/src/handlers/websockets.rs:
- Request order. The inbound task handles one client message at a time and awaits each
Writebefore reading the next (≈ lines 578-660). Sowrite_ackandin_waitingreplies arrive in the order their requests were sent. There are no request ids, so replies must be matched by FIFO order. - An error can replace an ack. A base64 decode failure sends
{"type":"error"}instead of awrite_ack. The FIFO must treaterroras the reply to the head pending request, or every later reply shifts by one. clear_bufferhas no reply. It must not enter the pending-reply FIFO.- Data and replies interleave arbitrarily.
dataframes come from the daemon's broadcast-reader task through the sameout_tx. A serial line can arrive before or after any ack. - No
REMOTE:protocol at the daemon. JSON-RPC replies are ordinary serial lines starting withREMOTE:(seejson_rpc.rs::extract_remote_json_rpc_response). - Port events are unsolicited:
preempted,reconnected,port_disconnected,port_renumbered,port_reattached,port_rebind_failed.
If any of these facts changes on the daemon side, the design must change with it. Add a daemon-side test that pins "replies are emitted in request order".
3. Target architecture
┌────────────────────────── serial_session.rs ───────────────────────────┐
WebSocket read half ──► reader task (one per session, owns WsSource) │
│ data lines ─(REMOTE:, RPC waiting)──► rpc slot (oneshot per RPC) │
│ data lines ─(everything else)───────► line queue (bounded, Notify) │
│ write_ack / in_waiting / error ─────► reply FIFO (oneshot per request)│
│ port events ────────────────────────► status (watch) │
│ write path: sink mutex + "register pending reply, then send", atomically │
└───────────────▲──────────────────────────────────────▲───────────────────┘
│ │
serial_monitor.rs (sync facade) async_serial_monitor.rs (async facade)
waits on channels with py.detach future_into_py over the same calls
- New module:
crates/fbuild-python/src/serial_session.rs, or aserial_session/directory with a README. It is a module, never a new crate (monocrate policy). ws_session.rsand the async loops injson_rpc.rsare deleted.extract_remote_json_rpc_responsecan stay.SerialSessionis a plain Rust type with no PyO3 in it, so every concurrency property can be tested without a Python interpreter.
Core API (Rust)
pub(crate) struct SerialSession { /* Arc<Inner>, reader JoinHandle, runtime handle */ }
impl SerialSession {
pub async fn connect(cfg: SessionConfig) -> Result<Self, SessionError>; // attach handshake (5 s cap)
pub async fn read_lines(&self, timeout: Duration) -> Vec<String>; // cancel-safe
pub async fn write(&self, data: &[u8], timeout: Duration) -> Result<usize, SessionError>;
pub async fn json_rpc(&self, line: &str, timeout: Duration) -> Result<String, SessionError>; // returns JSON after "REMOTE:"
pub async fn in_waiting(&self, timeout: Duration) -> Result<usize, SessionError>;
pub async fn clear_input(&self); // local queue + clear_buffer
pub fn status(&self) -> watch::Receiver<SessionStatus>;
pub async fn close(self); // detach, close, join reader
}Each facade's blocking or awaitable call is a thin wrapper over these methods.
4. Implementation guidelines
4.1 Reader task
- Sole owner of
WsSource. Nothing else ever reads the socket. This deletesReadYield,RpcTurn/RpcRoute,pendingand the request lock from fix(python): let SerialMonitor.write run while read_lines is in flight (#1431) #1484. - Frame dispatch:
data: for each line, if an RPC waiter is registered and the line starts withREMOTE:, complete the oldest RPC waiter's oneshot. Otherwise push it to the line queue.write_ack/in_waiting/error: pop the head of the reply FIFO and complete it. If the kind doesn't match the head's kind (for examplein_waitingarriving while the head is aWrite), fail the head withProtocolDesyncand log loudly. Never silently re-order.- Port events: update the
watchstatus.preemptedblocks readers only whenauto_reconnect == false.port_disconnected/port_rebind_failedwake all readers with an empty result and fail every pending reply withPortGone.
close/ stream end: mark the session closed, wake everyone, fail all pending replies withClosed, and exit.
- Keep the task non-blocking. No
std::sync::Mutexheld across.await. Useparking_lotor a short std lock around queue operations only, or a tokio mutex if an await is unavoidable.
4.2 Write path, where ordering matters
- Register, then send, atomically. Take the sink mutex, push a oneshot to the reply FIFO, then
send, then release the sink. Registration and send must happen under the same lock. Otherwise two writers can register in one order and send in the other. - Send failure. Remove your FIFO entry before releasing the lock, or mark it abandoned (see timeouts).
- Timeouts and cancellation. A waiter that gives up must not break the FIFO. Leave the entry in place but mark it abandoned: its receiver is dropped, so
oneshot::Sender::sendreturnsErrand the reader simply discards the reply. Never remove a sent request's entry: the daemon will still answer it. clear_input(clear_buffer) takes the sink lock but does not register a reply.- Bounded send.
sendon the sink is wrapped in the caller's timeout, default 5 s. If the daemon stops reading and the TCP buffer fills, the call fails withTimeout. The sink lock is released on every path, so one wedged send can't stall every other writer forever.- A send that times out mid-frame leaves the WebSocket in an unknown state, so the session is marked
Closed(fail everything, wake everyone). That is better than silently desyncing.
- A send that times out mid-frame leaves the WebSocket in an unknown state, so the session is marked
4.3 Read path
- Line queue:
VecDeque<String>plustokio::sync::Notify, bounded atmax_buffered_lines, default 10 000. - Overflow policy (maintainer to confirm): drop the oldest lines, count them, and surface the count (a
lines_droppedgetter plus atracing::warn!once per burst). Do not stop reading the socket when the queue is full: that would stallwrite_acks, which travel on the same socket. Blocking is therefore not an option here. read_lines(timeout)returns immediately with everything queued, if anything is. Otherwise it waits forNotify, a status change, or the deadline. It returns at most one batch, the whole queue at wake time.- Cancel safety. Lines are only removed from the queue inside a synchronous critical section that also returns them. Dropping the
read_linesfuture before that point removes nothing, so no data is lost. This is a hard requirement for the async facade (AT-6). - Multiple concurrent readers are allowed. Each line is delivered to exactly one reader, whichever drains first, as today. Document it.
- Abandoned-reader rule (FastLED #3219, "every 2nd RPC times out"). A read whose caller has gone away must never consume lines.
- Async: a cancelled
read_linesfuture removes nothing (cancel safety above). - Sync: a blocked
read_linesthread cannot be cancelled from Python today. AddSerialMonitor.interrupt_reads(). It is an additive, backward-compatible method: it wakes every blocked sync reader, which returns[]without draining, so queued lines stay for the next reader. - With that, FastLED's adapter calls
interrupt_reads()from its generator'sfinallyinstead of relying on a 50 ms polling cap.
- Async: a cancelled
4.4 JSON-RPC
- Registration order.
json_rpcregisters an RPC waiter (a FIFO of oneshots) before writing the request line, then awaits the write's ack and then itsREMOTE:reply. There is no request id matching today, so replies are FIFO too. Keep that and document it. Id matching is a possible follow-up. - Where
REMOTE:lines go. While any RPC waiter is registered,REMOTE:lines never reachread_lines. When none is registered, they are ordinary lines. That is the current behaviour, keep it. - Stale replies. An RPC that times out leaves its slot abandoned. A late
REMOTE:for it must be discarded, not delivered to the next RPC. Track a per-slot abandoned flag, or a generation counter.
4.5 Reconnect and deploy preemption
auto_reconnectkeeps today's semantics:- After
preempted, readers keep waiting untilreconnected. - Pending writes fail with a typed
Preemptederror. They must not hang until timeout.
- After
reset_device(sync and async) closes the session (close()joins the reader), posts/api/resetas today, reconnects by creating a new reader task, and optionally waits for output.- Hold an exclusive facade-level guard:
&mut selfon sync, and an asyncRwLockwrite guard on async. - Calls that overlap a reset get a clear error, never a hang.
- Hold an exclusive facade-level guard:
4.6 Sync facade (SerialMonitor)
- Python API unchanged, byte for byte (
crates/CLAUDE.mdconsumer contract): names, defaults, return types,hooks,last_line,in_waiting,run_until,reset_input_buffer,reset_device(board, wait_for_output, timeout),write -> int. - Blocking calls. Every blocking call runs
py.detach(|| rt.block_on(session.op(...))). Guard against calling from inside the runtime:block_onpanics if already on a runtime thread, so detect it and return a PythonRuntimeError. - Hooks are called with the GIL held, after the lines are returned, as today.
- Exclusive access.
__enter__,__exit__andreset_devicestay&mut self, so PyO3 raisesRuntimeError: Already borrowedfor overlapping lifecycle calls instead of racing.
4.7 Async facade (AsyncSerialMonitor)
- API table (this becomes the public contract, documented in
docs/architecture/pyo3-bindings.mdand in class docstrings):
| method | signature | returns |
|---|---|---|
| ctor | AsyncSerialMonitor(port, baud_rate=115200, auto_reconnect=True, verbose=False) |
— |
__aenter__ / __aexit__ |
— | self / False |
read_lines |
read_lines(timeout=30.0) (keep timeout_secs= as a deprecated alias for one release) |
list[str] |
write |
write(data: str) |
int bytes written (breaking change from bool, call it out in release notes) |
write_json_rpc |
write_json_rpc(request: dict, timeout=5.0) |
dict |
in_waiting |
awaitable method in_waiting() (a property can't be awaited) |
int |
reset_input_buffer |
reset_input_buffer() |
None |
reset_device |
reset_device(board=None, wait_for_output=False, timeout=5.0) |
bool |
- Awaitables. All of them come from
pyo3_async_runtimes::tokio::future_into_pyover the sharedSerialSession. Futures capture anArcto the session, never&self. - Cancellation. Cancelling the asyncio task cancels the Rust future (pyo3-async-runtimes propagates it). Combined with §4.3, no data is lost and no reply slot desyncs (§4.2).
- Remove the experimental wording from the docstrings and from
python/fbuild/api/__init__.py.
4.8 Errors
Map SessionError in one place to Python exceptions: Timeout → TimeoutError, Closed/PortGone/Preempted → ConnectionError (with the reason), ProtocolDesync → RuntimeError.
For compatibility, the sync write keeps returning 0 on failure. The async write raises. Document the difference.
4.9 Deadlock-freedom rules (enforced, not just documented)
- No lock held across
.await. Enforce with#![deny(clippy::await_holding_lock, clippy::await_holding_refcell_ref)]on the session module. - No lock held while calling into Python. Hooks,
run_untilconditions and exception construction run only after every core lock is released. So a hook may callmon.write()/mon.write_json_rpc()/mon.read_lines()re-entrantly. - Fixed lock order, documented at the top of the module:
sink→reply FIFO→line queue→status. The reader task only ever takesreply FIFO,line queueandstatus, and neversink. - The GIL is released for every call that can block, including
__enter__(handshake),__exit__(detach + join),write,write_json_rpc,in_waiting,reset_input_bufferandreset_device, not justread_lines. - No
block_onon a runtime thread. Before blocking, the sync facade checkstokio::runtime::Handle::try_current(). If the caller is already on a runtime thread, it raisesRuntimeError("SerialMonitor called from inside the async runtime; use AsyncSerialMonitor")instead of panicking or deadlocking. - Reader-task death is observable. The reader task runs under a guard (
scopeguard/Drop) that, on panic or exit, marks the sessionClosed, completes every pending oneshot with an error and wakes every reader. Nobody waits on a dead task. - Drop without
__exit__(GC, exception in thewithbody, a leaked object) runs the same teardown asclose(): detach best-effort, abort the reader, wake everyone.
4.10 Observability
Add tracing spans per request: kind, queue depth and latency. Use a debug! for every FIFO completion and a warn! for desync, drop and abandoned replies. No new env vars.
5. Acceptance tests
Every AT runs against both facades' shared core, and the AT-P tests run again through each Python facade. Each AT must be shown red first: run against today's AsyncSerialMonitor path (or a deliberately broken core), with the output of the red run pasted in the PR. Timing bounds are generous (≥10× the expected value) so CI can't flake.
5.1 Core tests: Rust, fake daemon, no Python
Extend the fake-daemon harness from ws_session.rs (tokio_tungstenite::accept_async, set_nodelay(true)). Give it knobs for echo delay, ack delay, injected error frames, injected port events, and dropping the connection.
| ID | Scenario | Pass criteria |
|---|---|---|
| AT-1 | Write during a 10 s read_lines from another task/thread |
write returns Ok(n) in < 1 s; the reader gets the echoed line; the reader returns in < 5 s, not at 10 s |
| AT-2 | json_rpc while another task sits in read_lines(10 s); the reply arrives 150 ms later (several empty slices) |
RPC returns the reply JSON; the concurrent reader never sees a REMOTE: line |
| AT-3 | 32 concurrent writers × 5 rounds, distinct payload lengths | every writer gets its own bytes_written |
| AT-4 | write and in_waiting interleaved from 16 tasks |
each gets the right reply type and value; no timeouts |
| AT-5 | fake daemon answers one write with error (the bad-base64 path) |
that write fails; the next write still gets its own ack (no FIFO shift) |
| AT-6 | cancel read_lines futures (tokio::time::timeout 1 ms, select! drop) 1 000× while lines stream in |
total delivered lines == total sent, in order, no duplicates |
| AT-7 | a writer times out waiting (daemon ack delayed past the timeout), then another write | the late ack is discarded; the second write gets its own ack |
| AT-8 | RPC times out; its late REMOTE: arrives during a second RPC |
the second RPC gets its own reply, not the stale one |
| AT-9 | preempted → reconnected with auto_reconnect=true |
readers keep waiting and then get post-reconnect lines; a write during preemption fails fast with Preempted (< 1 s), not at its timeout |
| AT-10 | port_disconnected / connection drop |
all blocked readers return promptly; pending writes/RPCs fail with PortGone/Closed; close() joins the reader task (no leaked task: assert the JoinHandle finished) |
| AT-11 | overflow: 50 000 lines with nobody reading, max_buffered_lines = 10 000 |
the oldest are dropped; lines_dropped == 40 000; writes still get acks throughout (the socket keeps draining) |
| AT-12 | clear_input with lines queued |
the queue is empty; clear_buffer is sent; the next ack still matches (clear registers no reply) |
| AT-13 | throughput sanity: 10 000 request/reply round trips on loopback | median < 5 ms; no desync warnings (assert on a captured tracing subscriber) |
| AT-14 | abandoned reader (FastLED #3219): reader A is blocked in read_lines(10 s) and is then abandoned (async: future dropped; sync: interrupt_reads()); a request goes out and reader B reads |
B receives the reply line; A returns [] promptly and consumed nothing; repeat 100× with no "every 2nd RPC" failures |
| AT-15 | peer stops reading (the fake daemon stops polling its socket; TCP buffer fills) | write fails with Timeout within its timeout plus 1 s; the sink lock is released; the session reports Closed; concurrent readers return promptly |
| AT-16 | handshake stall: TCP accept but no WebSocket handshake / no attached |
connect fails with Timeout in ≤ 5 s + slack; no leaked task |
| AT-17 | reader-task death: a test-only fault hook panics the reader task mid-stream | all blocked read_lines/write/json_rpc return errors in < 1 s; later calls fail fast with Closed |
| AT-18 | malformed frames: garbage text, unknown type, binary frames, JSON missing fields |
ignored with a debug!; the session keeps working; no FIFO shift |
| AT-19 | chaos soak (deadlock and stall detector). 64 tasks run a random mix of read_lines, write, json_rpc, in_waiting, clear_input and cancellations for 30 s, against a daemon with random delays (0-50 ms), injected error frames, preempted/reconnected pairs and one mid-run disconnect plus reconnect |
no call exceeds its own timeout + 1 s (per-call watchdog); every write gets exactly its own ack or a typed error; every line is delivered exactly once or counted as dropped; the reader task is joined at the end. Seeded RNG, and the seed is printed on failure |
| AT-20 | teardown races: close() while 16 calls are in flight, 100 iterations |
every in-flight call returns within 1 s with Closed; no panic; no leaked task (JoinHandle::is_finished) |
5.2 Python facade tests: Rust integration tests that embed CPython
The repo requires tests in Rust, and GIL, PyO3-borrow and asyncio behaviour can only be observed from Python. So these are Rust integration tests (crates/fbuild-python/tests/python_facades.rs) that embed an interpreter via PyO3, register the _native module, and drive Python code with py.run/py.eval. The fake daemon runs in a separate OS process (a small test binary, or the harness in a std::process::Command child), because __enter__ blocks on the handshake.
| ID | Facade | Scenario | Pass criteria |
|---|---|---|---|
| AT-P1 | sync | Python thread A in read_lines(timeout=10), thread B calls write ×10 |
no exception; each write returns its byte count in < 50 ms; A receives all echoes (#1431 regression) |
| AT-P2 | sync | thread A reading, thread B write_json_rpc ×10 |
each returns the matching dict; A never sees REMOTE: |
| AT-P3 | sync | GIL release: while thread A blocks in read_lines(2), thread B runs a pure-Python counter loop |
B makes progress, measured as a counter increase above a floor, during A's wait |
| AT-P4 | sync | __exit__ while another thread reads |
RuntimeError (borrow) or a clean return, never a hang or crash; the reader thread returns |
| AT-P5 | async | asyncio.gather(mon.read_lines(10), writes×10) |
all writes return ints; all echoes delivered; wall time < 2 s |
| AT-P6 | async | write_json_rpc concurrent with a long read_lines |
correct replies; the reader never sees REMOTE: |
| AT-P7 | async | cancel read_lines tasks repeatedly (asyncio.wait_for(..., 0.001) ×500) while lines stream |
no lines lost or duplicated; no InvalidStateError/panic |
| AT-P8 | async | reset_device(board=None, wait_for_output=True, timeout=5) against the fake daemon's /api/reset stub |
returns True; the session is usable afterwards (write + read round trip) |
| AT-P9 | both | API contract: introspect signatures and defaults against the §4.6/§4.7 tables | exact match (this pins the consumer contract) |
| AT-P10 | sync | FastLED #3219 replay: the adapter pattern (reader thread per request, consumer abandons it after the reply) with interrupt_reads() in finally, 100 RPCs |
100/100 RPCs succeed; none waits for its timeout |
| AT-P11 | sync | GIL matrix: for each blocking method (__enter__, read_lines, write, write_json_rpc, in_waiting, reset_input_buffer, reset_device, __exit__), a second Python thread counts while the call blocks against a slowed fake daemon |
the counter advances during every call |
| AT-P12 | sync | in-process peer deadlock (the one we hit while validating #1484): the fake daemon runs as an asyncio server in a Python thread of the same process | __enter__, write and read_lines all succeed (possible only once the GIL is released everywhere) |
| AT-P13 | sync | re-entrancy: a hooks=[...] callback calls mon.write() and mon.write_json_rpc(); a run_until condition calls mon.write() |
completes; no deadlock; replies delivered |
| AT-P14 | sync | a sync method called from inside a coroutine on the pyo3 runtime thread (via AsyncSerialMonitor callbacks) |
raises RuntimeError with the guidance message; no panic, no hang |
| AT-P15 | async | __aexit__ while read_lines/write/write_json_rpc are awaited in other tasks |
the pending awaitables raise ConnectionError in < 1 s; __aexit__ completes |
| AT-P16 | both | drop without exit: create, enter, start a read, drop every reference and gc.collect() |
the reader task terminates (test-only live-session counter returns to 0); the daemon sees a detach or close |
Gating. AT-P tests need libpython at link time and at runtime. Mark them #[ignore = "embeds CPython; run by the python-facade CI job"] and add a CI job (Linux; Windows too if feasible) that runs them with --ignored under the pinned Python.
5.3 Hang-to-failure harness (required for every AT)
A deadlock must fail fast with evidence, never burn CI's job timeout:
- Rust async tests: wrap each body in
tokio::time::timeout(TEST_BUDGET, …). On expiry, dump the core's state (FIFO depth and kinds, queue length, status,JoinHandlefinished?) and panic. - Rust sync or threaded tests: run the body on a spawned thread and join with a deadline (
std::sync::mpsc::recv_timeout). On expiry, print the core state andstd::process::abort(), so the test binary can't hang. - Embedded-Python tests: each snippet starts with
faulthandler.dump_traceback_later(TEST_BUDGET, exit=True), so a hang prints every Python thread's stack and exits. - CI: the python-facade job and the unit job have
timeout-minutesset well above the sum of the budgets, as a last resort only.
5.4 Failure-case coverage audit
Every failure observed so far maps to at least one test:
| Observed failure | Where seen | Covered by |
|---|---|---|
write waits out a concurrent read_lines (stall) |
#1431, FastLED#4343 (~220 ms per RPC) | AT-1, AT-P1, AT-P5 |
RuntimeError: Already mutably borrowed / dead liveness probe with 2 workers |
#1431, #1484 A/B | AT-P1, AT-P2, AT-P4 |
| RPC reply stolen by a concurrent reader | CodeRabbit on #1484 | AT-2, AT-P2, AT-P6 |
overlapping requests swap or drop replies (in_waiting → 0, write → 0) |
CodeRabbit on #1484 | AT-3, AT-4 |
error frame replaces an ack → FIFO shift |
daemon code (bad base64) | AT-5, AT-18 |
| every 2nd RPC times out: an abandoned reader eats the reply | FastLED #3219 | AT-14, AT-P10 |
| GIL held while blocking → other Python threads starve; in-process peer deadlock | #1484 validation (handshake timeout) | AT-P3, AT-P11, AT-P12 |
| cancellation loses lines | AsyncSerialMonitor code review |
AT-6, AT-P7 |
| late ack or late RPC reply misattributed | design review | AT-7, AT-8 |
| writers wedged behind a send to a peer that stopped reading | design review | AT-15 |
| hang on a peer that never finishes the handshake | 5 s cap exists and is untested | AT-16 |
| waiting forever on a dead reader task | design review | AT-17, AT-20 |
re-entrant hook or run_until deadlock |
design review | AT-P13 |
block_on panic inside the runtime |
design review | AT-P14 |
| teardown while calls are in flight | design review | AT-P4, AT-P15, AT-20 |
| leaked session or task on GC | design review | AT-P16 |
| unknown deadlocks and stalls under realistic contention | — | AT-19 chaos soak + §5.3 watchdogs |
5.5 End-to-end smoke (manual, recorded in the PR)
Real daemon and a real board (RP2350W or ESP32-S3):
- FastLED's
ci/rpc_client.pyping median, before and after, through the thread-pool adapter (sync) and through a quick asyncio-native adapter (async). - The expected result for both is ≈ wire time + ~50 ms, versus ~110 ms today.
6. Delivery plan and definition of done
PR 1: core + sync facade
serial_session.rswith AT-1…AT-20, each shown red first against the old async path where applicable, all under the §5.3 watchdogs.SerialMonitoron the core. Deletews_session.rs.- AT-P1…AT-P4, AT-P9 (sync part), AT-P10…AT-P14 and AT-P16 (sync part), plus the python-facade CI job.
interrupt_reads()added (additive, so the sync API stays compatible).- No change to the sync Python API.
PR 2: async facade
AsyncSerialMonitoron the core with the §4.7 API. Delete the async loops injson_rpc.rs.- AT-P5…AT-P9, AT-P15 and AT-P16 (async part).
- Docs:
docs/architecture/pyo3-bindings.md(concurrency model, both API tables, error mapping, overflow policy) andpython/fbuild/api. - Remove the experimental wording. Release-note the
write -> intchange and thetimeout_secsdeprecation.
Every PR must pass:
- clippy
-D warnings, rustdoc-D warningsandbash test; - the new CI job;
- CodeRabbit resolved;
- before/after latency numbers.
Then:
- fbuild release: serial: drop the single-worker executor + 50 ms read cap in FbuildSerialAdapter once fbuild's read_lines takes &self FastLED#4656 switches its adapter to
AsyncSerialMonitor, keeping the thread-pool path whenAsyncSerialMonitorlacks the new API (version skew).
7. Open questions for the maintainer
- Overflow policy: drop-oldest with a counter (proposed) vs. an error. Blocking is ruled out by §4.3.
in_waitingon async: an awaitable method (proposed) vs. keeping it sync-only.- The
write -> intbreaking change on async: acceptable, given there are no known users? - JSON-RPC id matching instead of FIFO: in scope here, or a follow-up?
interrupt_reads(): acceptable as the additive sync API for abandoning blocked reads (FastLED #3219)? The alternative is aread_lines(timeout, cancel=threading.Event)kwarg.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
zackees commentedon Sep 26, 2026
Downstream: FastLED/FastLED#4656 tracks FastLED's adapter change.
[-]Should serial monitor be fully async? Shared session core; promote AsyncSerialMonitor out of experimental[/-][+]Serial monitor: shared async session core; promote AsyncSerialMonitor out of experimental[/+][-]Serial monitor: shared async session core; promote AsyncSerialMonitor out of experimental[/-][+]Should serial monitor be fully async? Shared session core; promote AsyncSerialMonitor out of experimental[/+]feat(python): shared serial session and supported async monitor (#1490)
zackees commentedon Sep 27, 2026
Delivered as one combined shared-core/sync/async PR per the agreed delivery choice: #1490 merged, released in v2.5.29 (https://github.com/FastLED/fbuild/releases/tag/v2.5.29), with the FastLED native-async adapter and 2.5.29 pin merged in FastLED/FastLED#4657. The Pico 2 smoke recorded 30/30 pings and a 44.36 ms median versus the 110.27 ms thread-pool baseline. The separate local embedded-Python loader-path follow-up remains open as #1487.