Skip to content

fix(ble): slow connects time out, and a failed connect hides the pad until restart - #29

Merged
SeanathanVT merged 2 commits into
developmentfrom
fix/ble-connect-timeout
Oct 22, 2026
Merged

SeanathanVT merged 2 commits into
developmentfrom
fix/ble-connect-timeout

Conversation

@SeanathanVT

Copy link
Copy Markdown
Owner

Summary

Fixes intermittent failures to connect and reconnect to the WalkingPad. They come from two older bugs in the connect path, both present since #11 (2026-08-25), that compound:

  1. The connect timed out on a slow connect. controller.run() covers the OS-level connect plus discovering every service and descriptor on the pad. It shared _BLE_WRITE_TIMEOUT_SECONDS = 5, which is sized for single commands. A macOS connect that took 4.2 s ran out of time partway through service discovery and logged a blank BLE connection attempt failed:. A TimeoutError prints as an empty string.
  2. A failed connect left the connection half open. Nothing disconnected the client afterwards, so the pad stayed connected to the Mac and stopped advertising. Every retry then reported Device not found until WalkingDad was restarted.

Changes

  • _BLE_CONNECT_TIMEOUT_SECONDS = 10 applies only to controller.run(). Commands keep 5 s, so the lock and shutdown timeouts sized around one write are unchanged.
  • If the connect or the switch to manual mode fails, including a timeout or a cancellation, _connect_to_pad() disconnects the half-open client before re-raising.
  • The first-connect and auto-reconnect failure messages log the exception type (TimeoutError()) instead of a blank.
  • CHANGELOG.md [Unreleased] › Fixed has an entry for each fix.

Tests

Six new tests in tests/test_ble_async.py, each watched failing first:

  • a connect slower than the command timeout succeeds
  • a connect past the connect timeout still times out, and disconnects the half-open client
  • a failed mode switch disconnects the client
  • the first-connect and auto-reconnect failure messages include the exception type

The full suite passes on Python 3.10, 3.12 and 3.13 (505 tests each).

Manual check (macOS)

  • Start WalkingDad several times and confirm it connects, including when the connect is slow.
  • If a connect fails, the log shows the exception type, and a later retry finds the pad without restarting the app.

🤖 Generated with Claude Code

SeanathanVT and others added 2 commits October 22, 2026 13:00
- The connect plus service discovery shared the 5 s per-command timeout, so a slow macOS connect timed out mid-discovery
- Add _BLE_CONNECT_TIMEOUT_SECONDS = 10 for controller.run(); commands keep 5 s
- Tests for a slow connect succeeding and an over-limit connect still timing out

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A connect that failed partway left the half-open connection open, so the pad stopped advertising and every retry missed it until restart; disconnect before re-raising
- Log connect and auto-reconnect failures with the exception type (e.g. TimeoutError()) instead of a blank message
- Tests for both, plus a CHANGELOG entry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SeanathanVT
SeanathanVT merged commit d58db79 into development Oct 22, 2026
2 checks passed
@SeanathanVT
SeanathanVT deleted the fix/ble-connect-timeout branch October 30, 2026 17:56
@SeanathanVT SeanathanVT mentioned this pull request Oct 30, 2026
SeanathanVT added a commit that referenced this pull request Oct 30, 2026
…until restart (#29)

* fix(ble): give the connect its own 10 s timeout

- The connect plus service discovery shared the 5 s per-command timeout, so a slow macOS connect timed out mid-discovery
- Add _BLE_CONNECT_TIMEOUT_SECONDS = 10 for controller.run(); commands keep 5 s
- Tests for a slow connect succeeding and an over-limit connect still timing out

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(ble): disconnect after a failed connect and name the error

- A connect that failed partway left the half-open connection open, so the pad stopped advertising and every retry missed it until restart; disconnect before re-raising
- Log connect and auto-reconnect failures with the exception type (e.g. TimeoutError()) instead of a blank message
- Tests for both, plus a CHANGELOG entry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant