Skip to content

fix(serial): bound pre-open family inference, log every WS open outcome (#2083 follow-up) - #2089

Merged
zackees merged 5 commits into
mainfrom
fix/ws-serial-attach-open-timeout-2083
Nov 18, 2026
Merged

zackees merged 5 commits into
mainfrom
fix/ws-serial-attach-open-timeout-2083

Conversation

@zackees

@zackees zackees commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Fixes #2083

Follow-up to #2084. That PR fixed both halves of #2083: board-family inference now runs before the 3 s WebSocket open cap, and the client turns the daemon's Error frame into ConnectionFailed. Three things were still missing.

  1. Inference had no bound. fix(serial): resolve board family before the WS open cap; surface the daemon's error text #2084 moved family_for_port() (available_ports() plus sysfs) outside the cap but did not bound it. A hung enumeration would now leave a serial attach pending forever, which is the daemon: timeout WebSocket serial open_port pending attaches #977 failure the cap exists to prevent. SharedSerialManager::resolve_open_family is now bounded by OPEN_FAMILY_RESOLVE_TIMEOUT (3 s).
    • When the bound expires, or inference panics, the attach uses the family that port last resolved to. That family is recorded even when the inference finishes after the bound. With no recorded family it falls back to CdcAcmBridge.
    • An inference that answers "unidentified" is authoritative. It gets CdcAcmBridge and clears the recorded family, so a board swapped onto a reused port name cannot inherit the previous board's DTR/RTS idle.
    • The last-known family matters because CdcAcmBridge's idle DTR/RTS is wrong for a native-USB ESP32.
    • Inference still runs on every attach, so a different board on a reused port name is detected whenever the host answers in time.
  2. Timed-out opens were not logged. The WebSocket serial attach: pre-open work counts against the 3 s open_port cap, and the client reports the daemon's error as "session closed" #2083 evidence has an opening port line with no outcome after it. Both WS open sites (initial attach and post-deploy recovery) now go through ws_serial_open_port_with_family. It logs the start and the outcome of every open with pre_open_ms and open_ms, and it appends (pre-open N ms) to the failure message the client now shows.
  3. No test of the slow-inference case. The new tests feed in slow inference and check that the attach still succeeds.

Cancellation safety is unchanged and was checked. When the cap fires, the spawn_blocking result is dropped, and the serialport handle closes on drop. The session is published with no .await between the OS open and the map insert, so an open that times out cannot leave a session half-open.

Why 3 s and not 5 s (bench data)

LPC845-BRK on /dev/ttyACM1, dev daemon from this branch, PyPI 2.5.51 AsyncSerialMonitor client, 40 attach/detach cycles per run:

run host load client ok daemon pre-open ms (max) daemon open ms (median / max) daemon open failures
5 s bound, idle-ish ~40 on 16 cores 40/40 (median 0.23 s, max 3.30 s) 3288 0 / 232 0
5 s bound, +32 CPU hogs ~90 12 of 40 attaches had pre-open >= 5 s, past the client's 5 s handshake 6308 0
3 s bound, idle-ish ~59 40/40 (median 0.41 s, max 3.10 s) 0
3 s bound, +32 CPU hogs ~98 34/40 (median 3.09 s); 6 client handshake timeouts 4081 (starved timer) 0

Tests

  • fbuild-serial:
    • resolve_family_bounded_falls_back_when_inference_stalls
    • resolve_family_bounded_keeps_family_inferred_in_time
    • resolve_open_family_remembers_late_inference_for_next_timeout
    • resolve_open_family_forgets_family_when_port_is_unidentified
    • the existing resolve_open_family_is_total_and_bounded
  • fbuild-daemon:
    • ws_slow_family_resolution_does_not_consume_open_cap: 200 ms of inference against a 20 ms cap still attaches, and the open receives the resolved family.
    • ws_open_timeout_reports_pre_open_time
    • the 17 other ws_ tests, including the pty production-path test and the preemption-recovery tests that drive the second call site.
  • soldr cargo clippy -p fbuild-serial -p fbuild-daemon --all-targets --no-deps -- -D warnings is clean, and soldr cargo fmt reports no changes.

…tcome

Follow-up to #2084 for #2083.

#2084 moved board-family inference out of the 3 s WebSocket open cap, but
left it unbounded: a hung available_ports()/sysfs walk would now hold a
serial attach pending forever, the #977 failure the cap exists to prevent.
Bound it with OPEN_FAMILY_RESOLVE_TIMEOUT (5 s, CdcAcmBridge fallback) and
log its time and outcome.

Both WS open sites (initial attach and post-deploy recovery) now go through
ws_serial_open_port_with_family, which resolves the family before the cap,
logs the start and the outcome of the open with pre-open and open times,
and appends the pre-open time to the failure message. The #2083 evidence
had an "opening port" line with no outcome; a timed-out open was silent.

Cancellation safety is unchanged: a timed-out open drops the spawn_blocking
result (the serialport handle closes on drop) and the session is published
with no await between the OS open and the insert, so nothing is half-open.

Tests: resolve_family_bounded_falls_back_when_inference_stalls,
resolve_family_bounded_keeps_family_inferred_in_time,
ws_slow_family_resolution_does_not_consume_open_cap,
ws_open_timeout_reports_pre_open_time.
Bench run on an LPC845-BRK under heavy load (load avg 90 on 16 cores):
family inference alone took up to 6.3 s, past the Python client's 5 s
attach handshake, so a 5 s bound helped nobody. Bound it at 3 s, and on
expiry use the family the port last resolved to (recorded even when the
inference finishes after the bound) instead of CdcAcmBridge, whose idle
DTR/RTS is wrong for native-USB ESP32. Inference still runs on every
attach, so a different board on a reused port name is detected whenever
the host answers in time.

Test: resolve_open_family_remembers_late_inference_for_next_timeout.
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Only a timeout or panic falls back to the last resolved family. An
inference that answers "unidentified" is authoritative: it gets
CdcAcmBridge and clears the remembered family, so a board swapped onto a
reused port name cannot inherit the previous board's DTR/RTS idle.

Test: resolve_open_family_forgets_family_when_port_is_unidentified.
manager/tests.rs hit 1022 LOC and tripped the 1000-LOC gate.
@zackees
zackees added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 843e752 Nov 18, 2026
33 checks passed
@zackees
zackees deleted the fix/ws-serial-attach-open-timeout-2083 branch November 18, 2026 19:13
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 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.

WebSocket serial attach: pre-open work counts against the 3 s open_port cap, and the client reports the daemon's error as "session closed"

1 participant