Skip to content

Fix macOS daemon crash: remove non-existent wait_until_ready call#56

Open
GordonHannan wants to merge 1 commit into
HermannBjorgvin:mainfrom
GordonHannan:fix/macos-daemon-wait-until-ready
Open

Fix macOS daemon crash: remove non-existent wait_until_ready call#56
GordonHannan wants to merge 1 commit into
HermannBjorgvin:mainfrom
GordonHannan:fix/macos-daemon-wait-until-ready

Conversation

@GordonHannan

Copy link
Copy Markdown

Problem

On macOS, the launchd-managed daemon crashed immediately on every start with SIGABRT, producing repeated "Python quit unexpectedly" dialogs. The daemon would print its startup banner and exit before attempting any BLE connection.

Root cause

_get_cb_manager() called await mgr.wait_until_ready() on a CentralManagerDelegate instance, but this method does not exist in bleak's API. State readiness and error signalling (Bluetooth off, unauthorized) are handled inside CentralManagerDelegate.__init__ itself — calling a non-existent method raised AttributeError before any BLE work could begin.

Fix

Remove the await mgr.wait_until_ready() line. CentralManagerDelegate() already raises BleakError on failure, so no additional readiness check is needed.

Notes

  • The daemon requires Python 3.10+ (str | None union syntax is used throughout). Venvs built with Python 3.9 (macOS system default) also crash at import time with TypeError: unsupported operand type(s) for |.
  • Tested on macOS with bleak 1.1.1 and Python 3.14.

Test plan

  • Rebuild venv with Python 3.10+: python3 -m venv daemon/.venv && daemon/.venv/bin/pip install bleak httpx
  • Reload launchd agent: launchctl kickstart -k gui/$(id -u)/com.user.claude-usage-daemon
  • Confirm daemon connects and sends data (check ~/Library/Logs/claude-usage-daemon.out.log)
  • Confirm no crash dialogs appear

🤖 Generated with Claude Code

bleak's CentralManagerDelegate does not expose a wait_until_ready()
method. State readiness and error raising (BT off, unauthorized) happen
inside __init__, so the extra await was a NameError that caused the
daemon to SIGABRT on every launch when started via launchd.

Also documents that the daemon requires Python 3.10+ (str | None union
syntax is used throughout the file).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes an invalid wait_until_ready() call from the macOS CoreBluetooth path so the launchd-managed daemon no longer crashes at startup due to an AttributeError, allowing BLE logic to proceed normally.

Changes:

  • Removed await mgr.wait_until_ready() from _get_cb_manager() because the method does not exist on bleak’s CentralManagerDelegate.
  • Updated the inline comment to reflect that CentralManagerDelegate() is expected to raise on Bluetooth off/unauthorized conditions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@HermannBjorgvin

Copy link
Copy Markdown
Owner

You have a test plan but nothing on it is checked. Have you tested this?

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.

3 participants