Repository navigation
perf(autoresearch): replace sleep-based reset waits with spin-poll (#2265) - #2318
Conversation
… sleeps (#2265) Replaces the fixed ``asyncio.sleep(boot_wait)`` loop inside ``RpcClient.connect()`` with a spin-poll (``ci/util/boot_wait.wait_for_signal``) that watches serial output for ROM-loader / Arduino ``setup()`` banners (``entry 0x``, ``ESP-ROM:``, ``Before Setup Start``, ``REMOTE: ``) and exits immediately when one appears. If none of the expected signals arrive within ``boot_wait`` the call still returns cleanly — the timeout IS the fallback, matching the legacy fixed-sleep behavior so slow devices continue to work. Callers can pass ``boot_signals=[]`` to opt out of spin-polling entirely. Fast devices (ESP32-S3 w/ USB-CDC) should see connect() return in a few hundred milliseconds instead of the full 3s / 8s ``boot_wait`` used by ``phases.py`` and ``gpio.py``. Scope deliberately limited: - Only ``ci/rpc_client.py`` and the new ``ci/util/boot_wait.py`` helper are touched. Autoresearch callers (``phases.py``, ``gpio.py``, ``net.py``, ``ota.py``, ``ble.py``, ``driver_sweep.py``, ``decode.py``) inherit the speedup for free via the shared ``connect()`` entry point. - ``gpio.py``'s DTR reset pyserial code is untouched — that's #2264 / fbuild upstream. - Public CLI / RPC surface unchanged. Tests: - ``ci/tests/test_boot_wait.py`` — 9 unit tests covering early-exit, timeout-fallback, on_line mirroring, empty-patterns drain, and substring containment semantics. - ``ci/tests/test_rpc_client_connect_spin_poll.py`` — 3 integration tests exercising ``RpcClient.connect()`` end-to-end with a fake SerialInterface: early-exit on banner, fallback on silence, opt-out via ``boot_signals=[]``. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughIntroduced async boot signal polling to Changes
Sequence DiagramsequenceDiagram
participant Client as RpcClient
participant BootWait as ci.util.boot_wait
participant Serial as SerialInterface
participant Thread as Event/Signal
Client->>Client: connect(boot_signals=...)
Client->>BootWait: wait_for_signal(patterns, timeout)
loop Spin-Poll Loop (until timeout or match)
BootWait->>Serial: read_line()
Serial-->>BootWait: line (or timeout)
BootWait->>BootWait: check if pattern in line
alt Pattern Matched
BootWait-->>Client: (matched_pattern, drained_lines)
Client->>Client: return early
else KeyboardInterrupt
BootWait->>Thread: handle_keyboard_interrupt()
Thread-->>BootWait: re-raise
BootWait-->>Client: KeyboardInterrupt
else No Match & Timeout Expired
BootWait-->>Client: (None, drained_lines)
Client->>Client: proceed with drain_boot_output()
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
ci/tests/test_rpc_client_connect_spin_poll.py (1)
22-26: Avoid default parameters in the fake serial constructor.
bannerandemit_bannershould be required and supplied explicitly by each test to satisfy the Python standards. As per coding guidelines,All function parameters MUST have explicit type annotations and MUST NOT have default values.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ci/tests/test_rpc_client_connect_spin_poll.py` around lines 22 - 26, The fake serial constructor (__init__) currently uses default values for parameters banner and emit_banner; change the signature to require both parameters (remove the defaults so banner: str and emit_banner: bool are mandatory) and update all tests/instantiations that create this fake serial to pass explicit banner and emit_banner arguments; ensure the __init__ body and any type annotations remain unchanged except for removing the default values.ci/tests/test_boot_wait.py (1)
37-37: Remove the default from_FakeSerial.__init__.
per_batch_delay: float = 0.0violates the project’s no-default-parameter rule for Python functions; passper_batch_delay=0.0explicitly at call sites instead. As per coding guidelines,All function parameters MUST have explicit type annotations and MUST NOT have default values.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ci/tests/test_boot_wait.py` at line 37, The __init__ signature of the test helper class _FakeSerial currently uses a default value for per_batch_delay; remove the default so the signature becomes def __init__(self, batches: list[list[str]], per_batch_delay: float) -> None and update every call site that instantiates _FakeSerial (in tests within this file or test helpers) to pass per_batch_delay explicitly (e.g., per_batch_delay=0.0 where the previous behavior is desired); ensure the type annotation remains and no callers rely on the previous implicit default.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ci/rpc_client.py`:
- Around line 211-243: connect() currently defaults to BOOT_SIGNALS_ANY so
wait_for_signal can return on ROM banners like "ESP-ROM:" and treat the device
as RPC-ready; change the logic in connect() around effective_signals and
wait_for_signal so ROM/banner signals are not considered sufficient for RPC
readiness — either (A) replace BOOT_SIGNALS_ANY with a safer default set that
only includes setup/RPC-ready markers, or (B) implement a two-phase wait: first
detect device-alive ROM banners (using BOOT_SIGNALS_ANY) without returning, then
continue waiting (up to the original boot_wait deadline) for explicit
RPC/setup-ready signals before proceeding. Update references to
effective_signals, BOOT_SIGNALS_ANY, wait_for_signal and the boot_wait timeout
handling to reflect the chosen approach so connect() only returns when the RPC
dispatcher is actually ready.
- Line 266: The print statement currently uses an unnecessary f-string for a
static message; locate the print call that prints "📥 [RPC] Draining boot
output..." (the print(...) containing that exact text) and remove the leading f
so it becomes a normal string literal (print("📥 [RPC] Draining boot
output...")). Ensure no other changes are made.
In `@ci/util/boot_wait.py`:
- Around line 91-128: The loops that call iface.read_lines(...) currently
swallow all exceptions; replace the broad "except Exception:" handlers with
catching only timeout-related exceptions (e.g., asyncio.TimeoutError) so real
errors propagate (do not catch RuntimeError), and ensure asyncio is imported if
needed; specifically update both try/except blocks around the async for over
iface.read_lines (the block that appends to drained, calls on_line, checks
patterns_list and deadline) to catch asyncio.TimeoutError (treat as normal
timeout) and let RuntimeError and other real failures bubble up.
---
Nitpick comments:
In `@ci/tests/test_boot_wait.py`:
- Line 37: The __init__ signature of the test helper class _FakeSerial currently
uses a default value for per_batch_delay; remove the default so the signature
becomes def __init__(self, batches: list[list[str]], per_batch_delay: float) ->
None and update every call site that instantiates _FakeSerial (in tests within
this file or test helpers) to pass per_batch_delay explicitly (e.g.,
per_batch_delay=0.0 where the previous behavior is desired); ensure the type
annotation remains and no callers rely on the previous implicit default.
In `@ci/tests/test_rpc_client_connect_spin_poll.py`:
- Around line 22-26: The fake serial constructor (__init__) currently uses
default values for parameters banner and emit_banner; change the signature to
require both parameters (remove the defaults so banner: str and emit_banner:
bool are mandatory) and update all tests/instantiations that create this fake
serial to pass explicit banner and emit_banner arguments; ensure the __init__
body and any type annotations remain unchanged except for removing the default
values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 31097440-ee68-422a-a158-93be9b11041e
📒 Files selected for processing (4)
ci/rpc_client.pyci/tests/test_boot_wait.pyci/tests/test_rpc_client_connect_spin_poll.pyci/util/boot_wait.py
| # Resolve default boot signals lazily so tests that don't touch | ||
| # serial I/O don't import the util module. | ||
| effective_signals: tuple[str, ...] | list[str] | ||
| if boot_signals is None: | ||
| from ci.util.boot_wait import BOOT_SIGNALS_ANY | ||
|
|
||
| effective_signals = BOOT_SIGNALS_ANY | ||
| else: | ||
| effective_signals = boot_signals | ||
|
|
||
| poll_drained_lines: list[str] = [] | ||
|
|
||
| if boot_wait > 0: | ||
| if self.verbose: | ||
| print(f"⏳ [RPC] Waiting {boot_wait}s for device boot...") | ||
| # Use async sleep to allow other tasks to run | ||
| # Poll in small increments for interrupt checking | ||
| start = time.time() | ||
| while time.time() - start < boot_wait: | ||
| self._check_interrupt() | ||
| await asyncio.sleep(0.05) # Async sleep, check interrupt every 50ms | ||
| print(f"⏳ [RPC] Waiting up to {boot_wait}s for device boot...") | ||
| from ci.util.boot_wait import wait_for_signal | ||
|
|
||
| def _mirror(line: str) -> None: | ||
| if self.verbose: | ||
| print(f" [boot-poll] {line[:120]}") | ||
|
|
||
| # Spin-poll for a boot signal. If none of the expected signals | ||
| # arrive within ``boot_wait`` the call still returns (timeout IS | ||
| # the fallback — see issue #2265), preserving the original | ||
| # "waited N seconds then moved on" behavior. | ||
| assert self._serial is not None | ||
| try: | ||
| matched, poll_drained_lines = await wait_for_signal( | ||
| self._serial, | ||
| effective_signals, | ||
| timeout=boot_wait, | ||
| on_line=_mirror if self.verbose else None, | ||
| ) |
There was a problem hiding this comment.
Don’t treat ROM banners as RPC readiness in connect().
Defaulting to BOOT_SIGNALS_ANY means connect() returns on "ESP-ROM:", "rst:", or "entry 0x" immediately, even though Arduino setup() and the RPC dispatcher may still be unavailable. A slow-but-chatty device will no longer get the boot_wait fallback and the first RPC can race boot completion.
Prefer setup/RPC-ready signals by default, or make ROM detection a separate “device alive” phase that continues waiting for setup readiness until the deadline.
Proposed safer default
effective_signals: tuple[str, ...] | list[str]
if boot_signals is None:
- from ci.util.boot_wait import BOOT_SIGNALS_ANY
+ from ci.util.boot_wait import BOOT_SIGNALS_SETUP
- effective_signals = BOOT_SIGNALS_ANY
+ effective_signals = BOOT_SIGNALS_SETUP
else:
effective_signals = boot_signals🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@ci/rpc_client.py` around lines 211 - 243, connect() currently defaults to
BOOT_SIGNALS_ANY so wait_for_signal can return on ROM banners like "ESP-ROM:"
and treat the device as RPC-ready; change the logic in connect() around
effective_signals and wait_for_signal so ROM/banner signals are not considered
sufficient for RPC readiness — either (A) replace BOOT_SIGNALS_ANY with a safer
default set that only includes setup/RPC-ready markers, or (B) implement a
two-phase wait: first detect device-alive ROM banners (using BOOT_SIGNALS_ANY)
without returning, then continue waiting (up to the original boot_wait deadline)
for explicit RPC/setup-ready signals before proceeding. Update references to
effective_signals, BOOT_SIGNALS_ANY, wait_for_signal and the boot_wait timeout
handling to reflect the chosen approach so connect() only returns when the RPC
dispatcher is actually ready.
|
|
||
| if drain_boot: | ||
| if self.verbose: | ||
| print(f"📥 [RPC] Draining boot output...") |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
uv run ruff check ci/rpc_client.py --select F541Repository: FastLED/FastLED
Length of output: 101
🏁 Script executed:
# First, check if the file exists and read the relevant section
cat -n ci/rpc_client.py | sed -n '260,275p'Repository: FastLED/FastLED
Length of output: 838
🏁 Script executed:
# Try running ruff without uv to check for F541
ruff check ci/rpc_client.py --select F541 2>&1 || trueRepository: FastLED/FastLED
Length of output: 1283
Remove the f-string prefix; this f-string has no placeholders.
Ruff F541 correctly identifies that the f-string at line 266 has no interpolations and should be a regular string.
Proposed fix
- print(f"📥 [RPC] Draining boot output...")
+ print("📥 [RPC] Draining boot output...")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| print(f"📥 [RPC] Draining boot output...") | |
| print("📥 [RPC] Draining boot output...") |
🧰 Tools
🪛 Ruff (0.15.10)
[error] 266-266: f-string without any placeholders
Remove extraneous f prefix
(F541)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@ci/rpc_client.py` at line 266, The print statement currently uses an
unnecessary f-string for a static message; locate the print call that prints "📥
[RPC] Draining boot output..." (the print(...) containing that exact text) and
remove the leading f so it becomes a normal string literal (print("📥 [RPC]
Draining boot output...")). Ensure no other changes are made.
| async def wait_for_signal( | ||
| iface: "SerialInterface", | ||
| patterns: Iterable[str], | ||
| timeout: float, | ||
| spin_interval: float = 0.05, | ||
| on_line: "callable[[str], None] | None" = None, # type: ignore[valid-type] | ||
| ) -> tuple[str | None, list[str]]: |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
cat > /tmp/verify_callable_annotation.py <<'PY'
from typing import get_type_hints
def bad_callback_type(cb: "callable[[str], None] | None") -> None:
pass
try:
get_type_hints(bad_callback_type)
except Exception as exc:
print(type(exc).__name__)
print(exc)
PY
uv run python /tmp/verify_callable_annotation.pyRepository: FastLED/FastLED
Length of output: 102
🏁 Script executed:
python3 /tmp/verify_callable_annotation.py <<'PY'
from typing import get_type_hints
def bad_callback_type(cb: "callable[[str], None] | None") -> None:
pass
try:
hints = get_type_hints(bad_callback_type)
print("get_type_hints succeeded")
print(f"Hints: {hints}")
except Exception as exc:
print(f"Error: {type(exc).__name__}")
print(f"Message: {exc}")
PYRepository: FastLED/FastLED
Length of output: 125
🏁 Script executed:
# Read the actual file to verify the issues
head -130 ci/util/boot_wait.py | tail -80Repository: FastLED/FastLED
Length of output: 3550
🏁 Script executed:
# Check if dataclass is already imported in the file
grep -n "^import\|^from" ci/util/boot_wait.py | head -20Repository: FastLED/FastLED
Length of output: 175
🏁 Script executed:
# Look for exception handling blocks around lines 91-128 mentioned in scratchpad
sed -n '85,130p' ci/util/boot_wait.pyRepository: FastLED/FastLED
Length of output: 1903
Fix function signature and return type.
The type annotation "callable[[str], None]" is invalid; callable is a built-in function that cannot be subscripted. Use Callable from collections.abc instead. Additionally, this function violates Python standards by using default parameters and returning a tuple instead of a dataclass struct. Per coding guidelines: "All function parameters MUST have explicit type annotations and MUST NOT have default values" and "Return dataclass structs instead of tuples or dicts for functions with multiple return values."
| try: | ||
| async for line in iface.read_lines(timeout=spin_interval): | ||
| drained.append(line) | ||
| if on_line is not None: | ||
| on_line(line) | ||
| if time.monotonic() >= deadline: | ||
| break | ||
| except KeyboardInterrupt as ki: | ||
| from ci.util.global_interrupt_handler import handle_keyboard_interrupt | ||
|
|
||
| handle_keyboard_interrupt(ki) | ||
| raise | ||
| except Exception: | ||
| # Read timeouts are normal. | ||
| pass | ||
| await asyncio.sleep(0) | ||
| return (None, drained) | ||
|
|
||
| deadline = time.monotonic() + timeout | ||
| while time.monotonic() < deadline: | ||
| try: | ||
| async for line in iface.read_lines(timeout=spin_interval): | ||
| drained.append(line) | ||
| if on_line is not None: | ||
| on_line(line) | ||
| for pat in patterns_list: | ||
| if pat in line: | ||
| return (pat, drained) | ||
| if time.monotonic() >= deadline: | ||
| break | ||
| except KeyboardInterrupt as ki: | ||
| from ci.util.global_interrupt_handler import handle_keyboard_interrupt | ||
|
|
||
| handle_keyboard_interrupt(ki) | ||
| raise | ||
| except Exception: | ||
| # Read timeouts are normal — keep polling until deadline. | ||
| pass |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect read_lines implementations and nearby exception behavior.
rg -nP -C8 'async\s+def\s+read_lines\s*\('
# Look for explicit timeout raises/catches in serial-related code.
rg -nP -C4 '(raise\s+(asyncio\.)?TimeoutError|except\s+(asyncio\.)?TimeoutError|TimeoutError)' ciRepository: FastLED/FastLED
Length of output: 40304
🏁 Script executed:
# Find serial_monitor implementation and its read_lines behavior
cat -n ci/util/serial_monitor.py | head -100
# Look for the actual read_lines implementation in serial_monitor
rg -nA20 'def read_lines' ci/util/serial_monitor.py
# Check what exceptions are raised in the producer/read loop
rg -nB5 -A10 'def _producer|raise.*Timeout|except.*Error' ci/util/serial_interface.py | head -80Repository: FastLED/FastLED
Length of output: 4943
🏁 Script executed:
# Get the complete _producer function and its exception handling
sed -n '186,250p' ci/util/serial_interface.py
# Also check what serial_monitor.read_lines does
rg -nA30 'def read_lines' ci/util/serial_monitor.pyRepository: FastLED/FastLED
Length of output: 2448
🏁 Script executed:
# Find serial_monitor read_lines implementation
fd serial_monitor ci/util --type f
# If found, get the read_lines method
rg -nA25 'def read_lines' ci/util/serial_monitor.py --max-count=1Repository: FastLED/FastLED
Length of output: 112
🏁 Script executed:
# Check pyserial_monitor.py for read_lines
rg -nA30 'def read_lines' ci/util/pyserial_monitor.py
# Also check serial_monitor.py
rg -nA30 'def read_lines' ci/util/serial_monitor.pyRepository: FastLED/FastLED
Length of output: 1382
🏁 Script executed:
# Get more of the read_lines implementation to see exception handling
sed -n '123,200p' ci/util/pyserial_monitor.pyRepository: FastLED/FastLED
Length of output: 2980
🏁 Script executed:
# Check PySerialAsyncAdapter's read_lines implementation
sed -n '105,175p' ci/util/serial_interface.pyRepository: FastLED/FastLED
Length of output: 2357
🏁 Script executed:
# Check what fbuild's SerialMonitor.read_lines raises (if available in this repo)
# and search for any TimeoutError usage in serial-related code
rg -n 'TimeoutError' ci/util/serial_interface.py ci/util/pyserial_monitor.py ci/util/boot_wait.py
# Check if asyncio.TimeoutError is used anywhere in boot_wait context
rg -nB3 -A3 'asyncio.TimeoutError|asyncio.wait_for' ci/util/boot_wait.pyRepository: FastLED/FastLED
Length of output: 41
🏁 Script executed:
# Search for RuntimeError in serial backends - these are the real errors
rg -n 'raise RuntimeError' ci/util/pyserial_monitor.py
# Check what exceptions BLE read_lines can raise
rg -nB5 -A15 'async def read_lines' ci/util/ble_interface.py | head -50
# Look at the actual boot_wait code more carefully
sed -n '80,130p' ci/util/boot_wait.pyRepository: FastLED/FastLED
Length of output: 3499
🏁 Script executed:
# Verify what exceptions are actually possible from iface.read_lines()
# by checking each backend's docstring and exception handling
# PySerialMonitor complete read_lines signature
rg -B5 'Raises:' ci/util/pyserial_monitor.py | grep -A10 'read_lines' | head -20
# BLE read_lines complete signature
rg -B5 'Raises:' ci/util/ble_interface.py | grep -A10 'read_lines' | head -20
# Check if RuntimeError propagates from the async adapters
rg -n 'RuntimeError' ci/util/serial_interface.pyRepository: FastLED/FastLED
Length of output: 41
🏁 Script executed:
# Get the full docstring for PySerialMonitor.read_lines
sed -n '123,140p' ci/util/pyserial_monitor.py
# Get BLE read_lines docstring
sed -n '98,110p' ci/util/ble_interface.py
# Check the PySerialAsyncAdapter - does it wrap exceptions?
sed -n '105,125p' ci/util/serial_interface.py
# Look for any timeout behavior in these - what really happens on timeout?
rg -n 'timeout' ci/util/pyserial_monitor.py | head -10Repository: FastLED/FastLED
Length of output: 2518
🏁 Script executed:
# Double-check: what does PySerialAsyncAdapter do with exceptions from read_lines?
sed -n '120,130p' ci/util/serial_interface.py
# Also verify: does read_lines in pyserial_monitor ever actually raise on timeout?
# (We saw it just returns at line 149)
sed -n '145,165p' ci/util/pyserial_monitor.py
# Check if there are any other serial backend implementations
fd 'serial' ci/util --type f -name '*.py' | head -20Repository: FastLED/FastLED
Length of output: 1508
🏁 Script executed:
# Check the full context of PySerialAsyncAdapter - what exceptions can propagate?
sed -n '100,130p' ci/util/serial_interface.py
# Verify: does PySerialMonitor.read_lines actually propagate RuntimeError?
sed -n '175,185p' ci/util/pyserial_monitor.pyRepository: FastLED/FastLED
Length of output: 1438
🏁 Script executed:
# Final verification: check if boot_wait actually receives RuntimeError
# by looking at what the adapters actually do
# Confirm PySerialAsyncAdapter just passes through exceptions
sed -n '120,128p' ci/util/serial_interface.py
# Does read_lines ever actually raise TimeoutError in any backend?
rg -n 'raise.*TimeoutError|raise asyncio.TimeoutError' ci/util/pyserial_monitor.py ci/util/ble_interface.py ci/util/serial_interface.py
# What DOES PySerialAsyncAdapter.read_lines propagate?
rg -B2 -A8 'async def read_lines' ci/util/serial_interface.py | grep -A8 'PySerialAsyncAdapter' | head -20Repository: FastLED/FastLED
Length of output: 396
Catch only specific timeout exceptions instead of all exceptions.
Both poll loops treat every Exception from iface.read_lines() as a normal timeout. That silently hides real failures like disconnected devices, serial errors, and permission issues.
However, the timeout behavior varies by backend:
- BLE: raises
asyncio.TimeoutErroron timeout (caught at line 115 inble_interface.py) - PySerial: returns silently on timeout (no exception raised)
- Real errors: Both backends raise
RuntimeErrorfor actual failures (device not connected, serial read error)
The current broad except Exception masks both normal timeouts AND critical errors. The exceptions should be handled as:
Safer approach
- except Exception:
- # Read timeouts are normal.
- pass
+ except asyncio.TimeoutError:
+ # Read timeouts are normal (from BLE backend).
+ pass
@@
- except Exception:
- # Read timeouts are normal — keep polling until deadline.
- pass
+ except asyncio.TimeoutError:
+ # Read timeouts are normal (from BLE backend).
+ passFor PySerial, timeouts don't raise exceptions—the iterator just returns. For BLE, asyncio.wait_for() raises asyncio.TimeoutError. Real errors (RuntimeError from disconnected devices or serial failures) must propagate to fail fast.
🧰 Tools
🪛 Ruff (0.15.10)
[error] 103-105: try-except-pass detected, consider logging the exception
(S110)
[warning] 103-103: Do not catch blind exception: Exception
(BLE001)
[error] 126-128: try-except-pass detected, consider logging the exception
(S110)
[warning] 126-126: Do not catch blind exception: Exception
(BLE001)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@ci/util/boot_wait.py` around lines 91 - 128, The loops that call
iface.read_lines(...) currently swallow all exceptions; replace the broad
"except Exception:" handlers with catching only timeout-related exceptions
(e.g., asyncio.TimeoutError) so real errors propagate (do not catch
RuntimeError), and ensure asyncio is imported if needed; specifically update
both try/except blocks around the async for over iface.read_lines (the block
that appends to drained, calls on_line, checks patterns_list and deadline) to
catch asyncio.TimeoutError (treat as normal timeout) and let RuntimeError and
other real failures bubble up.
CI status
Root cause + fix in #2322. Once #2322 merges, this PR will rebase cleanly on top and CI should go green. WASM check failures ( All autoresearch-specific validation in this PR's own test suite passes:
|
Summary
Replaces the fixed
asyncio.sleep(boot_wait)loop insideRpcClient.connect()with a spin-poll (ci/util/boot_wait.wait_for_signal) that watches serial output for ROM-loader / Arduinosetup()banners and exits immediately when one appears. Fixes #2265.BOOT_SIGNALS_ROM:entry 0x,ESP-ROM:,rst:,boot:BOOT_SIGNALS_SETUP:Before Setup Start,setup() start,RESULT:,REMOTE:boot_waitthe call still returns cleanly. The timeout IS the fallback — no raising, no regressions for devices that boot slowly or don't emit a banner.boot_signals=[]to disable spin-polling and get the legacy "sleep the full duration" behavior.Only
ci/rpc_client.pychanges. All autoresearch callers (phases.py,gpio.py,net.py,ota.py,ble.py,driver_sweep.py,decode.py) inherit the speedup for free via the sharedconnect()entry point.Out of scope (intentionally):
ci/autoresearch/gpio.py's DTR reset pyserial sequence — that's refactor(autoresearch): replace raw pyserial DTR reset with SerialInterface.reset_device() #2264, blocked on fbuild upstream.Expected speedup
boot_waitboot_wait(gpio.py)Before Setup StartfiresRough claim: ~2s saved per autoresearch cycle on fast devices, with no regression on slow ones.
Test plan
uv run pytest ci/tests/test_boot_wait.py -v— 9 unit tests for the helper (early-exit, timeout-fallback, on_line mirroring, empty-patterns drain, substring-containment semantics)uv run pytest ci/tests/test_rpc_client_connect_spin_poll.py -v— 3 integration tests exercisingRpcClient.connect()end-to-end with a fakeSerialInterface(early-exit on banner, fallback on silence, opt-out viaboot_signals=[])uv run pytest ci/tests/test_serial_interface_reset.py -v— unchanged, still passesuv run ruff check ci/rpc_client.py ci/util/boot_wait.py ci/tests/test_boot_wait.py ci/tests/test_rpc_client_connect_spin_poll.py— cleanbash autoresearch --parlioon ESP32-S3 to confirm sub-second banner detection (requires hardware)Pre-existing unrelated test failures in
test_autoresearch_phases.py(lcd_spiarg) andtest_running_process.py::test_output_formatterare not affected by this change — verified on master.🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Tests