Skip to content

serial: drop the single-worker executor + 50 ms read cap in FbuildSerialAdapter once fbuild's read_lines takes &self #4656

Closed

Description

@zackees

Blocked on FastLED/fbuild#1431. Do this once that fix ships in an fbuild release and FastLED's fbuild== pin in pyproject.toml moves to that release.

Background

fbuild.api.SerialMonitor.read_lines takes &mut self, while write takes &self. A write therefore cannot overlap an in-flight read, so FbuildSerialAdapter (ci/util/serial_interface.py) works around it in two ways:

  • One worker. Every sync call goes through a single-worker ThreadPoolExecutor (self._executor = ThreadPoolExecutor(max_workers=1), around line 159). Raising the worker count to 2 breaks the transport: the session stops answering its liveness probe.
  • A polling cap. read_lines' producer caps each inner self._monitor.read_lines(timeout=inner) at inner = min(remaining, 0.05), around line 281. This lets it re-check stop_event and free the lone worker for the next call.

Each RPC's write still queues behind the tail of the previous reply's read, so every request pays the cap on top of the real round trip. #4343 cut the cap from 0.25 s to 0.05 s, which took a ping from ~330 ms to ~110 ms. That is a mitigation, not a fix: the adapter is still trading latency against cancellation responsiveness.

When FastLED/fbuild#1431 lands (read_lines(&self))

  1. Bump the fbuild pin in pyproject.toml to the release that contains the fix, then relock (uv lock && uv sync).
  2. Let writes stop queueing behind reads. Either give writes their own worker (or call write directly), or use max_workers=2. Only do this once a write can run concurrently with an in-flight read_lines without breaking the liveness probe.
  3. Drop or relax the 50 ms inner read cap. It exists only to free the single worker. Keep a cap only if cancellation latency still needs it, and update the comment block that documents the cap/latency curve.
  4. Re-measure the ping round trip on real hardware (the perf(serial): stop paying 220 ms of dead wait on every device RPC #4343 method: an RP2350W, 10–20 calls per point, medians). The expectation is that the write-side queueing (write ≈ 1.1 × cap + ~45 ms) disappears. The target is round-trip ≈ wire time plus fbuild's own submit → first-item (~51 ms), instead of ~110 ms.
  5. Update the adapter docstring, which currently explains the executor only as the run_until_complete() workaround.

Acceptance

  • A write issued while a read_lines is in flight completes without waiting for the read's cap/timeout.
  • The liveness probe still passes with the new concurrency.
  • The ping median is recorded before and after in the PR.

Refs: FastLED/fbuild#1431, #4343.

Activity

  1. zackees commented on Sep 26, 2026

    @zackees
    MemberAuthor

    Update: FastLED/fbuild#1431 is fixed in FastLED/fbuild#1484 (merged). A concurrent write no longer waits on read_lines, and overlapping requests and RPC replies are handled. It ships in the next fbuild release.

    Longer term, FastLED/fbuild#1485 moves the sync and async monitors onto one shared session core and promotes AsyncSerialMonitor out of experimental. Once that ships, this adapter should switch to AsyncSerialMonitor: native asyncio, no thread pool, no polling producer. It keeps the thread-pool path as a fallback for older fbuild.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions