Repository navigation
Description
Source PR: #3863
Related implementation issue: #3861
Source comments:
- feat(rp2350w): add BTstack BLE transport #3863 (comment)
- feat(rp2350w): add BTstack BLE transport #3863 (comment)
- feat(rp2350w): add BTstack BLE transport #3863 (comment)
Why this matters: the RP2350W transport can corrupt or strand JSON-RPC notifications when responses overlap or a connection drops, and the HIL reader can miss a later valid notification.
CodeRabbit suggestions (verbatim):
Handle each BLE notification independently.
read_lines()yields one notification value per line, but this loop accumulates them. If one complete JSON-RPC line arrives and a laterjson.loads()cannot parse because the next value appends to the previous line, keep parsing completed lines instead of treatingnotification_payloadas a shared fragment buffer.
Queue complete responses before notification scheduling.
response_sinkclears and replaces the singlenotification_payloadwhile an earlier response can still have unsent chunks. If two RPC responses are produced before the first transfer completes, the client receives a truncated first response and loses its remaining bytes.Add an outbound FIFO. Advance to the next response only after all chunks of the current response are sent. Add a regression test that produces two responses before the send-ready callback completes.
Reset notification registration state on disconnect.
onDisconnectedstill leavesstate->notification_scheduledandruntime.notification_callback_pendingset. If a request registers last and the connection drops beforeATT_EVENT_CAN_SEND_NOW, new writes can be blocked and a disconnected callback can hit clearednotification_payload. Set both flags false when disconnecting while a pending registration exists.
Acceptance criteria:
- RED: add a focused transport test that queues two complete responses before the first BTstack send-ready callback finishes and demonstrates that current code truncates/replaces the first response.
- GREEN: introduce a bounded outbound FIFO, preserve response order, and advance only after the final ATT-MTU-sized chunk is accepted.
- RED: add a focused disconnect/reconnect test with a pending notification registration that demonstrates stale pending state blocks the next connection or accesses cleared payload state.
- GREEN: make disconnect/destroy lifecycle generation-safe, clear application pending state without reusing a still-owned BTstack registration unsafely, and prove a subsequent write/notification succeeds.
- RED: add a focused Python test with multiple independent notification values where a valid pong follows another complete or malformed value.
- GREEN: parse each complete notification independently while retaining correct ATT-fragment reassembly at the BleInterface boundary.
- Preserve singleton-owned RP runtime state, bounded queue-full behavior, ESP32 NimBLE behavior, and unsupported-platform stubs.
- Run focused BLE tests, strict lint, RP2350W and ESP32-C6 target builds, then record live GATT discovery/ping plus disconnect/reconnect evidence on the Pico 2 W.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
fix(ble): queue RP2350W notifications instead of clobbering them (#3955)
fix(ble): queue RP2350W notifications instead of clobbering them (#3955…
zackees commentedon Aug 21, 2026
Landed via #3958 (
9655e7abd9). All three CodeRabbit findings are fixed, plus several defects surfaced by review of the first pass.Done
BleNotifyQueue(src/fl/net/ble_notify_queue.h) keeps completed responses in order and advances only after the final ATT-MTU chunk is accepted, replacing the single shared buffer that truncated an in-flight response. Bounded at 4; a full queue refuses the newest response rather than evicting one already partly on the wire.onDisconnectednow clearsnotification_scheduledandnotification_callback_pending;destroyTransportclears the pending flag too. A failedatt_server_notifyre-arms instead of stranding the response, with bounded retries so a permanent error (CCC not enabled, bad handle) can't spin forever; undeliverable payloads are dropped so the queue keeps moving.BleNotificationAssembler(ci/util/ble_notify_assembler.py) consumes exactly the bytes of each complete JSON value. It resynchronizes only at a fragment start, never by searching the buffer, so a payload that legitimately embeds the literalREMOTE:can't be chopped in two.BleInterfaceno longer.strip()s each notification (which dropped whitespace landing on a chunk boundary) and uses an incremental UTF-8 decoder so a multi-byte sequence split across two notifications no longer decodes to U+FFFD on both sides.push()(RPC pump) andadvance()(BTstack callback) never write the same variable — matching the RX ring already in that transport.Verification: 282/282 host unit tests (9 queue cases), 13 assembler cases,
bash lintclean,rp2350w+esp32c6builds green. The[BLE RP] TX queue fullanddropping undeliverable responsestrings are present in the linked rp2350w firmware, confirming the modified transport is compiled in rather than gated out.Still open — why this issue is not closed
The final acceptance bullet asks for live GATT discovery/ping plus disconnect/reconnect evidence on the Pico 2 W. No RP2350W was attached to the bench, so that evidence was not collected and every fix above is verified by host tests and target builds only. Leaving this open for that HIL pass.
zackees commentedon Sep 7, 2026
The hardware clause on this issue is now unblocked.
The bench fixture is confirmed a Raspberry Pi Pico 2 W — live evidence, not the historical record:
Until now the variant was unestablished, so the W-only acceptance criteria here could not be attempted at all. They can be run now:
bash autoresearch rp2350w --rpc-smoke— PASS (71 RPC methods, dual-core concurrency 200/200)bash autoresearch rp2350w --net-peer— deploys both boards; six full cycles ofwifiConnect→ join the C6 SoftAP →startNetServer→ bidirectional HTTP →stopNet→ pingDeploying the W build onto a board running non-W firmware needs
--upload-port— fbuild refuses to guess which board to BOOTSEL and fails clean without flashing.One known blocker for long soaks: #4173 — the RP2350W hangs in
wifiConnecton the 7th consecutive peer cycle and watchdog-resets. It self-recovers, so it limits repetition rather than stranding the fixture.Generated with Claude Code
https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51
zackees commentedon Sep 11, 2026
Partial: the GATT server and TX characteristic exist; the notification lifecycle still cannot be exercised here
This issue is about hardening the notification lifecycle, which needs a subscribed central. Recording what I could and could not establish on the attached RP2350W (
2DCB876B587EA334), so the boundary is precise rather than "BLE blocked".Driving the device directly over serial RPC — no host BLE stack involved — the server side is real and repeatable (detail on #3861):
So the pieces this issue's lifecycle depends on — a live GATT server with the TX characteristic registered — are confirmed present, and
bleStatusalready reports the state a lifecycle test would assert against:connected,connected_count,tx_value_len,ring_head,ring_tail.But every one of those is at its zero value, because nothing ever subscribes:
connected: false,connected_count: 0,tx_value_len: 0,ring_head: 0,ring_tail: 0. The notification path is therefore entirely unexercised — the ring buffer indices in particular are exactly what a hardening test would need to watch move.Blocked on bench provisioning rather than firmware:
hci0is present butbluetooth.servicedoes not exist on this host, so BlueZ userspace is absent andbleakcannot act as a central. Needs root to install and enable; not something to do unattended. Recorded on #3714.Worth noting for whoever picks this up:
bleStatusreturningring_head/ring_tail/tx_value_lenmeans a notification-lifecycle test does not need a bespoke device build — the observability is already in the firmware. It only needs a host that can subscribe.zackees commentedon Sep 12, 2026
Status check before anyone reopens this: all three CodeRabbit suggestions are implemented, with the focused tests the acceptance criteria ask for. What is left is the final HIL bullet, and I re-confirmed today that it is still blocked on bench provisioning rather than on firmware.
What is already in
src/fl/net/ble_notify_queue.h— bounded outbound FIFO, single-producer/single-consumer, advances only after the final chunk is accepted; used asTransportState::notificationsinble_rp.cpp.hpptests/fl/net/ble_notify_queue.cppble_rp.cpp.hpponDisconnected()clearsnotifications,notify_failures,notification_scheduledandruntime.notification_callback_pending;destroyTransport()nulls the registration context and clears the pending flagci/tests/test_rp2350w_board_config.pyci/util/ble_notify_assembler.py—BleNotificationAssembleryields each complete JSON value and reassembles ATT fragments per message;ci/autoresearch/ble.pyuses it instead of a shared fragment bufferci/tests/test_ble_notification_assembler.py, 13 casesThe Python cases cover the specific ones named in the acceptance criteria —
test_two_responses_in_one_stream_are_independent,test_valid_pong_after_malformed_value,test_valid_pong_after_unrelated_complete_value,test_partial_value_is_held_not_dropped,test_runaway_garbage_is_bounded.The remaining bullet, and why it is still blocked
Re-checked on this host today, unchanged from the earlier note:
bleakis installed, but with no BlueZ userspace it has no adapter to drive, so the host cannot act as a central. Installing and enabling BlueZ needs root — not something to do unattended.And the workaround that does not exist
Worth writing down so nobody spends time on it: the attached ESP32-C6 cannot stand in for the missing central. FastLED's BLE surface is peripheral-only —
There is no scan, connect, discover or subscribe. Using the C6 as the central would mean building a BLE central role first, which is #3861-scale work and not what this issue is about. The two-MCU pattern that unblocked the network side (
--net-peer) has no BLE equivalent to reach for.So the boundary is exact: firmware and host-side parsing are done and tested; the evidence bullet needs a host with BlueZ, or a central role that does not exist yet. Everything else on the acceptance list is satisfied by the artifacts above.
As noted before,
bleStatusalready reportsconnected,connected_count,tx_value_len,ring_headandring_tail, so whoever gets a central attached needs no bespoke device build — only a subscriber.