fix: decode mgmt rssi byte 0x80 as signed int8 -128#540
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #540 +/- ##
=======================================
Coverage 99.59% 99.59%
=======================================
Files 15 15
Lines 2689 2689
Branches 386 386
=======================================
Hits 2678 2678
Misses 1 1
Partials 10 10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 8.93%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | test_resolve_fallback_8_scanners_25_devices_dense_mesh |
629.4 µs | 691.1 µs | -8.93% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing bluetoothbot:koan/fix-rssi-int8-boundary (204e716) with main (ac56ebe)
Footnotes
-
5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
|
Does this actually happen in practice? |
Rarely. Byte |
PR Review — fix: decode mgmt rssi byte 0x80 as signed int8 -128Correct one-character signed-int8 fix. Minimal, well-tested, low-risk. Practical impact is near-zero though.
Checklist
Automated review by Kōan (Claude) |
Simple rebaseBranch StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
What
Decode the BlueZ mgmt
DEVICE_FOUND/ADV_MONITOR_DEVICE_FOUNDrssi byte as a true signed int8: the byte0x80now becomes-128instead of+128.Why
The rssi field in mgmt device-found events is
__s8. The conversion guarded onrssi > 128, which converts0x81..0xFFbut leaves0x80(the int8 floor,-128) as+128. A scanner reporting that byte produced a nonsensical positive RSSI, corrupting the manager's best-scanner scoring (a worst scanner would look closest) and surfacing garbage to consumers. Correct signed-int8 decoding isbyte - 256forbyte > 127.The threshold change also preserves
0x7F(127) unchanged — the mgmt "RSSI not available" sentinel — so only the previously-mishandled0x80value moves.How
One-character fix in
channels/bluez.py:> 128→> 127. No.pxdchange (the comparison constant doesn't affect therssicdef type).Testing
Added a parametrized regression over the int8 range (
0x00, 0x64, 0x7F, 0x80, 0x81, 0xC8, 0xFF) asserting the rssi forwarded to the scanner. The0x80 -> -128case fails onmainand passes here. Fulltests/channels/test_bluez.pysuite green (60 passed); ruff + format clean.