Skip to content

perf(autoresearch): replace sleep-based reset waits with spin-poll validation #2265

Closed

Description

@zackees

Summary

The autoresearch tool currently uses fixed sleep(3.0) calls after device reset and between phases. These should be replaced with fast spin-polls that check for specific validation signals and break early.

Current behavior

# After DTR reset
await asyncio.sleep(3.0)  # Wait for device to reboot

# After pin discovery  
await asyncio.sleep(2.0)  # Wait for RPC to become available

# Boot drain
await asyncio.sleep(boot_wait)  # Fixed 3s wait

Proposed behavior

Replace sleeps with poll loops that check for expected output:

# Instead of sleep(3.0), poll for boot signature
deadline = time.time() + 5.0  # max timeout
while time.time() < deadline:
    lines = await read_lines(timeout=0.1)
    if any("entry 0x" in line or "RESULT:" in line for line in lines):
        break  # Device is booted, proceed immediately
    await asyncio.sleep(0.05)  # 50ms spin

Benefits

  • Fast devices (ESP32-S3 with USB-CDC) could be ready in <500ms instead of waiting 3s
  • Slow devices still work via the max timeout
  • Each phase exits as soon as validation passes, not after a fixed delay
  • Total autoresearch cycle time could drop significantly

Validation signals to watch for

Phase Signal Meaning
Post-reset "entry 0x" or ESP-ROM: ROM bootloader started
Post-boot "Before Setup Start" Arduino setup() beginning
RPC ready "RESULT:" or ping response JSON-RPC server is up
Pin discovery "found":true Pin pair detected

Related

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