feat: detect scanners stuck reporting zero free connection slots#407
feat: detect scanners stuck reporting zero free connection slots#407bluetoothbot wants to merge 2 commits into
Conversation
Bluetooth proxies can enter a state where they report all connection slots as occupied even though no devices are actually connected. The only known recovery is a proxy reboot (see #340). Until now this symptom was invisible unless the operator enabled debug logging on habluetooth.wrappers and grep'd for "slots=0/N free". The manager now tracks how long each source has reported zero free slots and surfaces stuck sources via: - a one-shot WARNING log fired from the existing periodic check - async_stuck_allocations() public query - a "stuck_allocations" entry in async_diagnostics() A source is only flagged when habluetooth has no in-flight connection attempts through it, so legitimately busy proxies are not warned about. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #407 +/- ##
==========================================
- Coverage 94.50% 94.25% -0.26%
==========================================
Files 14 14
Lines 1911 1949 +38
Branches 230 240 +10
==========================================
+ Hits 1806 1837 +31
- Misses 62 65 +3
- Partials 43 47 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 7.73%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | test_inject_100_simple_advertisements |
188.8 µs | 204.6 µs | -7.73% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing koan/detect-stuck-allocations (b99ca8d) with main (931296d)
|
@bluetoothbot plan This proposed solution is the wrong fix. We should figure out why they are getting stuck in the first place |
I have what I need. Writing the updated plan now.Pivot: investigate root cause of stuck slot allocations, not detect-and-warn Changes in this iteration
SummaryIssue #340 reports that ESPHome proxies sometimes report Alternatives Considered
Implementation PhasesPhase 1: Diagnostics-only instrumentation in habluetooth (small, additive)
Phase 2: Audit habluetooth's contribution to the lifecycle
Phase 3: Upstream coordination (bleak-esphome / aioesphomeapi / ESPHome firmware)
Phase 4: Apply the real fix in the responsible layer (conditional)
Corner Cases
Testing Strategy
Risks & Alternatives
Open Questions
Generated by Kōan /plan — iteration on existing issue |
What
Detect when a Bluetooth scanner (typically an ESPHome proxy) is stuck reporting zero free connection slots, and surface it as a warning + diagnostic instead of letting it silently break BLE connections.
Why
Closes #340. Proxies can enter a state where they report all slots as occupied even though no devices are actually connected. Recovery requires a proxy reboot, but the symptom is hidden — the user has to enable debug logging on
habluetooth.wrappersand grep INFO output forslots=0/N freeto even know which proxy to power-cycle.How
BluetoothManagernow tracks_allocations_zero_sinceper source: the timestamp when a source first reportedfree == 0(cleared on any non-zero update or scanner unregister)._async_check_unavailablecalls a new_async_check_stuck_allocationswhich logs a one-shot WARNING once a source has stayed at zero free slots forSTUCK_ALLOCATION_THRESHOLD_SECONDS(30 min) — but only if habluetooth has no in-flight connections through that scanner, to avoid false positives for legitimately busy proxies.async_stuck_allocations()public query and astuck_allocationsfield inasync_diagnostics()for HA's diagnostics download.STUCK_ALLOCATION_THRESHOLD_SECONDSis exposed in__init__for tuning/tests..pxdupdated to keep the cython build in sync.Testing
🤖 Generated with Claude Code