October 20, 2026
2 pull requests merged across 1 repo
Offline-Protocol/offline-protocol-sdk
Follow-up to #586. A PEP 561 marker changes what counts as *exported*, not only whether the package is typed. offline_protocol_sdk/__init__.py re-exported the eleven hand-written managers as from .x import Y # noqa: F401, with no __all__ and no as Y alias, and under PEP 561 a type checker treats those as private. So with the marker alone, on the README's own quick start (from offline_protocol_sdk import ProtocolManager):
# pyright 1.1.407, default mode
app.py:2:34 - error: "ProtocolManager" is not exported from module "offline_protocol_sdk"
Import from "offline_protocol_sdk.protocol_manager" instead (reportPrivateImportUsage)
# mypy 2.4.0 --strict
app.py:2: error: Module "offline_protocol_sdk" does not explicitly export attribute "ProtocolManager" [attr-defined]
Before the marker both accepted it, since pyright reads an untyped library's source. Pyright is what Pylance runs, so this is the first thing a VS Code user sees after upgrading. The generated names were never affected: from .offline_protocol import * is a wildcard import and the generated module defines __all__.
This PR:
- lists the root package's public surface in
__all__: the generated module's own__all__plus the eleven managers, using only the+=forms the typing spec requires every checker to read; - adds
bindings/python/tests/test_public_surface.py, which pins__all__to the attributes the package exposes (non-underscore, non-module), so a manager added to the root without a line in__all__fails in CI rather than in a user's editor; - adds the refusal case to
scripts/tests/test-build-wheel.shfor a package without the marker, which #586 had checked by hand; - extends the #586 changelog entry.
Related issues
Refs #586.
Type of change
-
fix: bug fix -
test: adding or correcting tests
Checklist
- Commits follow Conventional Commits
-
CHANGELOG.mdupdated (Unreleased, Fixed; extends the #586 entry) - No Rust, UDL or binding-generation change, so the cargo gates and binding regeneration don't apply.
Breaking changes
None at runtime. from offline_protocol_sdk import * in an application now brings in exactly the names in __all__; before, it also brought in the submodule names (secure_storage, protocol_manager, ...) that the package's own imports bind. Those stay reachable as attributes.
Notes for reviewers
How I verified it:
- Built the wheel from this branch, installed it in a clean venv, and ran pyright 1.1.407 and mypy 2.4.0
--stricton a consumer doing the README's imports from the root: both pass with full types, and the only reported error is the consumer's intentional wrong-argument call. The same consumer against the #586 wheel shows the fourreportPrivateImportUsageandattr-definederrors above. - The whole Python suite against this branch: 1128 passed, 4 skipped. The new guard fails on a copy with one name removed from
__all__and names it (missing from __all__: ['BleManager']). scripts/tests/test-build-wheel.shon Linux (python:3.12-bookworm, aarch64): all checks pass, including the new "a package without the PEP 561 marker is refused".shellcheck --severity=warningis clean on it.
Draft. Seven device runs of the two-phone volume test (iPhone 11 and Galaxy M36, 5,000 DMs each way at 5 msg/s over BLE) drove this branch. Run 7, on the head commit with the three review fixes, delivered and acknowledged 10,000 of 10,000.
Device runs
| Run | Build | Delivered | What it showed |
|---|---|---|---|
| 1 | main | 70.6% | Engine wedged at 1,000 pending ACKs; sendMessage failed sends already on the wire; Android went deaf past the forward window; BLE queues tore large messages |
| 2 | first fixes | 44.8% | Wedge and false failures gone; one-way iOS write stall for 17 min; resends burned ratchet keys |
| 3 | re-seal budget, stall teardown | 58.2% | iOS sent to a stale identifier after Android rotated its address |
| 4 | link resolution, pull mark | 70.5% | Congestion collapse: no per-peer flow control, ACKs queued behind data |
| 5 | window, ACK lane, coalesced ACKs | 50.0% | Flow control held (first 1,800 each way at 100%, ACK RTT about 760 ms); a 10-min outage from two LL links between the same radios |
| 6 | one link per pair, outbox admission | 94.6% | iPhone to Android 5,000/5,000; Android to iPhone 4,460, limited by the indication-only egress at exactly the offered load |
| 7 | review fixes (e8bc81e8) | 100% | 10,000/10,000 delivered and acknowledged; 0 duplicates, 0 decrypt failures, 0 peers lost, 0 write-stall teardowns (run 6 had 4); about 50 retries per side; ACK RTT p50 under 1 s, p90 17 to 34 s from window holding at the offered load |
What changed
Engine
- A frame is never transmitted without an ACK slot. At the ceiling a send is held and reported as
message_deferred(ack_capacity).process()runs every step on every tick. Two leaks that kept the table full are fixed. sendMessageno longer reports failure for a message it sent.- A receiver past the forward window re-keys (
TooDistantInTheFutureisSessionDesync; authenticated, so R2 is unchanged). The OpenMLS window rises to 8,192. - Per-peer window: at most 16 frames awaiting ACK to one peer over a mesh link; the rest are held (
message_deferred,peer_window) and sent in order. Session control is never held. - BLE queues an ACK ahead of data. Delivery ACKs to a peer advertising
ack_versionsentry 2 are coalesced, up to 5 per frame within 500 ms (ack_more). - Re-seal budget: resends re-seal only while fewer than 256 frames are sealed past the last ACK, then go verbatim; a verbatim copy that can no longer decrypt is re-sealed up to 512. Both derive from the smallest receiver window, a leaf's 1,024, which mls-rs fixes and
tools/mls-interoppins. - A frame still in the BLE transport queue gets a bounded ACK extension instead of a retry.
- Outbox admission: a full outbox refuses the newest message to the recipient with the largest backlog. A lighter recipient evicts from the heaviest one (its newest held message first, else its oldest entry). A message awaiting its ACK is never evicted.
- A message sent during a block is never delivered.
Bridges
- Outbound fragment queues: cap 768, pull stops at 32 fragments, checked before the destructive pop and only for recipients with a link.
- iOS: a link refusing every write for 15 s is torn down; a foreground connect is cancelled at 10 s, bound to its own attempt; the stall clock is forgotten on connect and disconnect; sends go to the connected identifier after an address rotation; a departed peer is not redialled forever.
- One BLE link per peer pair (ADR 0030): no peer is reported lost while it has another live link (a subscribed central counts only while heard from in the last minute); Android refuses a client link beside a subscribed server link; Android's forced refresh keeps the advertisement while an identified peer is linked unless it has stopped. iOS eviction drops every identifier of the peer.
- Android's indication path drains on confirmation; a failed indication is logged and paced.
Demo app: shows the lock for restored sessions.
Review fixes (last three commits)
fix(protocol): let a full outbox evict never-sent held messages: one slow live peer could make every send to every other recipient a refusal.fix(protocol): size the re-seal budget for the leaf's receiver window: the budget assumed an 8,192 window that a leaf (mls-rs, fixed at 1,024) does not have.fix(bindings): stop the BLE bridges stalling and flapping peers: the global backed-up stop, the connect-timer binding, the redial loop, the stall clock, the stale-subscription gate,evictPeer, and the Android refresh. A Rust guard now pins this wiring.
Verification
cargo fmt --all -- --check,cargo clippy --workspace -- -D warnings,cargo test --workspace --libandRUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-depspass; each of the three review commits passes the unit tests on its own.offline-protocol-sealedlints clean onthumbv8m.main-none-eabihf.tools/mls-interoppasses, including the two new leaf-window steps; with the constant set to 1,025 it fails.- The new bridge-wiring guard fails when the connect timer is unbound.
- Swift: the three policy suites pass 39 of 39, and the iOS bridge type-check exits 0.
- Android: 701 of 711 pass from a copy outside the checkout; the 10 failures are
PeerStreamFramingTest, which cannot find its vector file there.
Still owed: a three-device leg for the cross-recipient stall the two-phone harness cannot exercise. Open follow-ups: the iOS write-stall trigger (none fired in run 7), Android's indication-only egress ceiling, and the iPhone's futile dials to Android's rotating advertising address: the stack changed it 9 times in run 7 although the forced refresh kept the advertisement, and the iPhone timed out 92 dials to those addresses while already linked (no effect on delivery).
Checklist
-
cargo fmt --all -- --checkpasses -
cargo clippy --workspace -- -D warningspasses -
cargo test --workspacepasses -
cargo-denyis satisfied (no dependency changes; not run locally) - Commits follow Conventional Commits
- Docs /
CHANGELOG.mdupdated where relevant - No new
unsafein core crates - The UniFFI UDL did not change