Repository navigation
perf(autoresearch): replace sleep-based reset waits with spin-poll - #2274
Conversation
…put=True) FbuildSerialAdapter.reset_device() now passes wait_for_output=True and timeout=5.0 to fbuild 2.1.16's SerialMonitor, which polls for serial output instead of returning immediately. This eliminates the fixed 3-second sleep after DTR reset. - gpio.py: boot_wait reduced from 3.0 to 1.0 (device already producing output) - serial_interface.py: passes wait_for_output=True, timeout=5.0 to fbuild Typical ESP32-S3 USB-CDC: reset+ready in ~1.3s instead of 6s. Closes #2271 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughDTR-reset recovery now captures reset result and uses output-driven semantics; reconnect boot_wait is set dynamically (1.0s on successful reset, 3.0s on failure) instead of always sleeping 3s. Fbuild adapter reset_device forwards wait_for_output=True with a 5.0s output wait. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant TestRunner
participant SerialInterface
participant Device
participant RpcClient
TestRunner->>SerialInterface: request reset_device(board=None, wait_for_output=True)
SerialInterface->>Device: toggle DTR / send reset
Device-->>SerialInterface: emits serial output (boot signatures)
SerialInterface-->>TestRunner: return reset_ok (True/False)
alt reset_ok True
TestRunner->>RpcClient: connect(boot_wait=1.0, drain_boot=True)
else reset_ok False
TestRunner->>RpcClient: connect(boot_wait=3.0, drain_boot=True)
end
RpcClient->>Device: read lines / drain boot output
RpcClient-->>TestRunner: connected
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
ci/autoresearch/gpio.py (1)
5-13:⚠️ Potential issue | 🔴 CriticalImport
asynciofor the new fallback sleeps.Lines 77 and 270 now call
asyncio.sleep(...), but this module is not imported, so the pyserial fallback reset path raisesNameError.Proposed fix
from __future__ import annotations +import asyncio from dataclasses import dataclass from typing import TYPE_CHECKINGAlso applies to: 77-77, 270-270
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ci/autoresearch/gpio.py` around lines 5 - 13, The module uses asyncio.sleep at lines referenced (fallback reset paths) but asyncio isn't imported; add "import asyncio" to the top-level imports alongside the other imports in ci.autoresearch.gpio so that the calls to asyncio.sleep(...) (used in the fallback reset logic) don't raise NameError; ensure the import is placed with the existing standard-library imports so it is available to the functions that perform the pyserial fallback sleeps.
🤖 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/autoresearch/gpio.py`:
- Around line 70-77: The reset paths currently ignore the boolean result of
serial_interface.reset_device(...) and _pyserial_dtr_reset(port) and proceed
with a shortened reconnect boot_wait; change both locations (the block shown and
the similar code in run_pin_discovery / lines ~263-270) to check the return
value and fail fast if reset failed: call await
serial_interface.reset_device(...) and if it returns False raise or return a
descriptive error (do not continue with boot_wait=1.0), and similarly capture
the boolean from _pyserial_dtr_reset(port) and abort with a clear error instead
of proceeding to asyncio.sleep/short reconnect; ensure the reconnect logic only
uses the shortened boot_wait when the reset boolean is True.
In `@ci/util/serial_interface.py`:
- Around line 225-230: The reset_device call swallows KeyboardInterrupt and
silently returns False on failure; update the try/except around the await
self._run_in_thread(self._monitor.reset_device, ...) to first add an explicit
except KeyboardInterrupt: raise, change the positional args to keywords
(board=board, wait_for_output=True, timeout=5.0) when calling
self._monitor.reset_device via self._run_in_thread, and replace the generic
except Exception: return False behavior with either re-raising the exception or
logging a clear error and then raising (i.e., do not return False on failure) so
callers see the real failure.
---
Outside diff comments:
In `@ci/autoresearch/gpio.py`:
- Around line 5-13: The module uses asyncio.sleep at lines referenced (fallback
reset paths) but asyncio isn't imported; add "import asyncio" to the top-level
imports alongside the other imports in ci.autoresearch.gpio so that the calls to
asyncio.sleep(...) (used in the fallback reset logic) don't raise NameError;
ensure the import is placed with the existing standard-library imports so it is
available to the functions that perform the pyserial fallback sleeps.
🪄 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: 2314f89b-9f7c-4522-9b9f-0b3c3f41e483
📒 Files selected for processing (2)
ci/autoresearch/gpio.pyci/util/serial_interface.py
…er wait on failure Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Summary
Eliminates fixed
sleep(3.0)delays after device reset by using fbuild 2.1.16'sreset_device(wait_for_output=True), which polls for serial output and returns as soon as the device reboots.Before: reset + 3s sleep + 3s boot_wait = ~6s wasted per reset
After: reset + wait_for_output (~0.5s) + 1s boot_wait = ~1.5s
Changes
FbuildSerialAdapter.reset_device(): passeswait_for_output=True, timeout=5.0gpio.py: removessleep(3.0)after reset, reducesboot_waitfrom 3.0 to 1.0Test plan
test_serial_interface_reset.py)Closes #2271
Depends on fbuild 2.1.16 (fbuild#68, fbuild#69)
🤖 Generated with Claude Code
Summary by CodeRabbit