October 14, 2026
2 pull requests merged across 1 repo
Offline-Protocol/offline-protocol-sdk
Problem
min_ble_samples_before_success_rate_escalation (default 5) is documented as the number of delivery samples needed before the low-success-rate rule applies. update_history pushed one success-ratio sample on every select_transport call from the cumulative counts, whether or not anything new had been observed. One failure on a fresh link became five identical 0.0 samples after five sends, which met the floor with no new evidence. is_emergency_switch_needed and should_escalate_to_wifi both read that window. #557 was the BLE case of this.
Change
TransportHistoryremembers the(success_count, failure_count)of its last sample and takes a new one only when those change (observe_outcome_counts). The sample value is still the cumulative ratio.- When a source halves its counts to stay bounded (the engine's
ObservedStats::compactdoes), the counts have moved, so that is one sample. Reading the halved counts again is not. test_low_success_rate_escalation_gated_by_sample_floorpinned the old reading. It now asserts that five selections over unchanged counts do not trip the rule, and that five count changes do.- New
test_success_ratio_sample_taken_once_per_count_changecovers the zero, repeat and halving cases. docs/dors.mdconfig table and a CHANGELOGFixedentry.
Verification
- Negative control: with the change check removed, the rewritten test fails at the "unchanged counts must not advance the floor" assertion.
cargo test -p offline-protocol-router --lib: 69 passed.cargo test -p offline-protocol --lib: 2058 passed.cargo clippy --workspace -- -D warnings,cargo fmt --all -- --check: clean.
Independent of #558: this branch is cut from main, and the two touch different files apart from CHANGELOG.
One lost inbound Bluetooth fragment marked BLE as a failing link for the life of the process.
- The cause. When a partial message idled out of the reassembly cache or was evicted at capacity,
BleTransportcounted it as a failed send. Nothing ever counted a successful one:record_send_successnever had a production caller,ble_return_fragmentis a no-op, and no bridge reports a write outcome. So BLE's own counters could only read0 / N. - Why it spread. The transport manager merged the engine's acknowledgement-based observations only into a transport reporting no counts of its own. After the first drop, every later acknowledgement for BLE was discarded. The comment above that check predicted this failure.
- The effect. DORS samples the ratio once per selection, so within five sends the window average was 0.0. That trips the low-success-rate escalation and, where Wi-Fi Direct is available, the emergency switch that bypasses hysteresis, cooldown and the stability window.
get_transport_metricsreported a 0% delivery ratio and a 100% error rate to the app.
What changes
- A reassembly drop is no longer a delivery sample.
BleTransportnever writes its own success or failure counts, and the two orphan methods are removed. - The manager's merge is explicit by transport type. Internet, Reticulum and Nostr have a send confirmation loop and keep their own counts. BLE and Wi-Fi Direct always take the engine's. The match is exhaustive, so a new transport has to choose.
- The
ble_return_fragmentcomment no longer claims the transport layer confirms sends. - The transport state machine doc gains the invariant, and the CHANGELOG has Fixed and Removed entries.
Tests
Five new tests. Four fail on main and pass here, checked in a separate worktree. The fifth guards the other side of the merge rule and passes on both.
| Test | On main |
|---|---|
a_capacity_eviction_is_not_a_send_failure | fails |
an_idle_expired_assembly_is_not_a_send_failure (no expiry test existed) | fails |
engine_observations_win_over_a_mesh_transports_own_counts | fails |
a_dropped_inbound_fragment_does_not_escalate_ble: a real BLE transport, a capacity eviction through on_fragment_received_from, then eight sends | fails at the escalation assertion |
a_confirmation_loop_transport_keeps_its_own_counts | passes |
Not run on hardware. The end-to-end test is the reproduction.
Not in this PR
DORS's sample floor counts selections, not observations (dors.rs:1259), so it cannot gate a stale ratio on any transport. It needs its own change and a rewrite of the test that pins the current reading. Filed as #559.
Related issues
Closes #557
Type of change
-
fix— bug fix -
docs— documentation only
Checklist
-
cargo fmt --all -- --checkpasses -
cargo clippy --workspace -- -D warningspasses -
cargo test --workspace --libpasses (13 binaries, 0 failures);RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-depspasses - Commits follow Conventional Commits; the transport commit is marked
!for the two removed public methods - Docs /
CHANGELOG.mdupdated - No new
unsafe - UDL unchanged, so no binding regeneration