Skip to content

fix(serial): resolve board family before the WS open cap; surface the daemon's error text - #2084

Merged
zackees merged 2 commits into
mainfrom
agent/ws-serial-attach-2083
Nov 18, 2026
Merged

zackees merged 2 commits into
mainfrom
agent/ws-serial-attach-2083

Conversation

@zackees

@zackees zackees commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Why

Issue #2083, from FastLED AutoResearch on an LPC845-BRK: 5 of 12 post-deploy
AsyncSerialMonitor attaches failed with only ConnectionError: session closed,
while the daemon log showed the open starting 3.3–3.6 s after the attach was
pending — i.e. WS_SERIAL_OPEN_PORT_TIMEOUT (3 s) had already fired during
board-family inference, before the tty was ever opened (the OS open itself is
~2 ms).

Two defects, both fixed here:

  1. Pre-open work was charged to the open cap. family_for_port() walks
    available_ports() plus sysfs health and runs inside the open_port future,
    so the WS handler's 3 s deadline covered enumeration, not just the open.
  2. The client discarded the daemon's reason. SerialSession::connect only
    understood attached; the daemon's error frame fell into the wildcard and
    became a bare session closed.

What

  • fbuild-serial: new SharedSerialManager::resolve_open_family(&self, port)
    — runs family_for_port_or_default on spawn_blocking and is total (a port
    that cannot be identified yields BoardFamily::CdcAcmBridge, the same
    (true, true) idle DTR/RTS state open_port already applies for None).
  • fbuild-daemon: both WS open sites (initial attach and the post-deploy
    recovery reopen) resolve the family before starting
    await_ws_serial_open_port and pass it as the explicit family argument, so
    the timed region now covers only the OS open and its retries.
  • fbuild-python: ServerMessage::Error { message } on the attach reply now
    returns SessionError::ConnectionFailed("daemon rejected serial attach: …"),
    so callers see open_port(/dev/ttyACM1) exceeded 3s; … instead of
    session closed.

Ask 3 of the issue (make the cap configurable / longer) is deliberately not
implemented: after moving inference out of the timed region the cap only covers
an open that takes ~2 ms in the reported runs, so widening it would mask real
driver wedges rather than help.

Tests

  • soldr cargo test -p fbuild-serial --lib → 207 passed, 0 failed, 1 ignored
    (includes new resolve_open_family_is_total_and_bounded).
  • soldr cargo test -p fbuild-python --lib → 69 passed, 0 failed
    (includes new attach_error_frame_surfaces_daemon_reason, which drives the
    real SerialSession::connect against a fake daemon that answers the attach
    with {"type":"error","message":"open_port(/dev/ttyACM1) exceeded 3s; …"}
    and asserts the text reaches the caller).
  • soldr cargo test -p fbuild-daemon --lib → 330 passed, 0 failed, 3 ignored
    (existing real-pty WS attach test now exercises the pre-resolved-family path).
  • soldr cargo fmt -p fbuild-serial -p fbuild-daemon -p fbuild-python -- --check → clean.

Fixes #2083

Note: the first push pushed serial_session.rs to 1008 LOC and tripped the
1000-LOC gate; the final commit folds the error-frame case into the shared
attach-rejection arm (both frames carry a reason string) and uses let-else
for non-text frames, landing the file at 999 LOC.

WebSocket serial attach wrapped open_port in a 3 s deadline, but
open_port inferred the board family first: available_ports() plus sysfs
health can take seconds on a loaded host, so healthy attaches failed as
"exceeded 3s" before the tty was opened (the OS open is ~2 ms). The
client then discarded the daemon's error frame and reported only
"session closed".

- SharedSerialManager::resolve_open_family runs family_for_port_or_default
  on spawn_blocking and is total (CdcAcmBridge fallback, the same
  (true, true) idle DTR/RTS state open_port applies for None).
- Both WS open sites resolve the family before starting the timed open
  and pass it as the explicit family argument.
- fbuild-python maps ServerMessage::Error on the attach reply to
  ConnectionFailed so the daemon's diagnosis reaches the caller.

Fixes #2083
@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

The first cut pushed serial_session.rs to 1008 LOC, which the LOC gate
rejects. Fold the error-frame case into the shared attach-rejection arm
(an or-pattern; both frames carry a reason string), and use let-else for
the non-text frame. Net file size is 999 LOC.
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