Skip to content

fix: decode mgmt rssi byte 0x80 as signed int8 -128#540

Draft
bluetoothbot wants to merge 1 commit into
Bluetooth-Devices:mainfrom
bluetoothbot:koan/fix-rssi-int8-boundary
Draft

fix: decode mgmt rssi byte 0x80 as signed int8 -128#540
bluetoothbot wants to merge 1 commit into
Bluetooth-Devices:mainfrom
bluetoothbot:koan/fix-rssi-int8-boundary

Conversation

@bluetoothbot

Copy link
Copy Markdown
Contributor

What

Decode the BlueZ mgmt DEVICE_FOUND / ADV_MONITOR_DEVICE_FOUND rssi byte as a true signed int8: the byte 0x80 now becomes -128 instead of +128.

Why

The rssi field in mgmt device-found events is __s8. The conversion guarded on rssi > 128, which converts 0x81..0xFF but leaves 0x80 (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 is byte - 256 for byte > 127.

The threshold change also preserves 0x7F (127) unchanged — the mgmt "RSSI not available" sentinel — so only the previously-mishandled 0x80 value moves.

How

One-character fix in channels/bluez.py: > 128> 127. No .pxd change (the comparison constant doesn't affect the rssi cdef type).

Testing

Added a parametrized regression over the int8 range (0x00, 0x64, 0x7F, 0x80, 0x81, 0xC8, 0xFF) asserting the rssi forwarded to the scanner. The 0x80 -> -128 case fails on main and passes here. Full tests/channels/test_bluez.py suite green (60 passed); ruff + format clean.

@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.59%. Comparing base (ac56ebe) to head (204e716).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq

codspeed-hq Bot commented Jun 7, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 8.93%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 25 untouched benchmarks
⏩ 5 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

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)

Open in CodSpeed

Footnotes

  1. 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.

@bdraco

bdraco commented Jun 7, 2026

Copy link
Copy Markdown
Member

Does this actually happen in practice?

@bdraco

bdraco commented Jun 7, 2026

Copy link
Copy Markdown
Member

@bluetoothbot rr

@bluetoothbot

Copy link
Copy Markdown
Contributor Author

@bdraco: Does this actually happen in practice?

Rarely. Byte 0x80 decodes to -128 dBm. Below any radio noise floor. Real RSSI seldom under -110. Not a confirmed live bug. Pure int8 correctness — mgmt rssi field declared __s8. Bad path produces nonsensical +128, corrupting best-scanner scoring if ever emitted.

@bluetoothbot

Copy link
Copy Markdown
Contributor Author

PR Review — fix: decode mgmt rssi byte 0x80 as signed int8 -128

Correct one-character signed-int8 fix. Minimal, well-tested, low-risk. Practical impact is near-zero though.

  • Logic correct: > 127 decodes 0x80 as -128 (mgmt rssi is __s8); 0x7F sentinel preserved, only 0x80 changes.
  • Parametrized test covers the full int8 boundary range and asserts forwarded rssi — good coverage.
  • Real-world impact tiny: -128 dBm sits below any receiver noise floor, so the bad +128 value is essentially never emitted by hardware (answers bdraco's question).
  • CodSpeed -8.93% regression is on an auto_scheduler bench unrelated to this bluez change, flagged across different runtime environments — noise, not caused by this PR.


Checklist

  • Signed int8 decode correct across boundary
  • Edge/boundary coverage (0x7F, 0x80, 0x81, 0xFF)
  • No .pxd change needed (constant only)
  • Tests verify observable behavior, not source
  • No security/error-handling concerns in diff

Automated review by Kōan (Claude) HEAD=204e716 36s

@bluetoothbot

Copy link
Copy Markdown
Contributor Author

Simple rebase

Branch koan/fix-rssi-int8-boundary was rebased onto main — no additional changes were needed.

Stats

2 files changed, 51 insertions(+), 1 deletion(-)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=No commit on main touches the BlueZ mgmt rssi int8 decoding; commit 632e840 only adds scanner name t)
  • Rebased koan/fix-rssi-int8-boundary onto upstream/main
  • Pre-push CI check: previous run #27088426023 failed
  • Pre-push CI fix: no changes needed or Claude found nothing to fix
  • Force-pushed koan/fix-rssi-int8-boundary to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

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.

2 participants