October 15, 2026
5 pull requests merged across 1 repo
Offline-Protocol/offline-protocol-sdk
Closes out the non-blocking items left from the reviews of #570, #571 and #572.
What changes
1. A refused C registration now always calls the host's drop(ctx). The guide promised exactly one drop call, including on refusal. A null handle in any of the three setters, and an incomplete storage provider, were refused before the library wrapped ctx, so drop never ran. The setters and the storage adapter now wrap ctx first. offline_protocol_initialize_mls builds both providers before checking either, so refusing one still drops the other.
2. The quick start no longer leaks an error. Its ignored local_address failure did not clear err. The library writes over err without freeing it, so the next failure leaked the previous strings.
3. MlsStorageError is documented as append-only C ABI. OfflineProtocolStorageStatus is each variant's position plus one, so a compiled C provider answers by number. K6, C2, the header comment and the guard's failure message now say to append and never renumber.
4. The generator refuses a namespace function named like an engine method. offline_protocol_call tries the namespace first, so a shared name would silently run the wrong function.
5. A guard pins the Android opt-out. --no-default-features turns off every default, not only capi. The new guard reads the crate's default features and the three commands that build without the C binding. It fails if a command does not add back every default except capi, or if a command stops opting out.
Verification
cargo test -p offline-protocol-uniffi --lib: 260 passed, 4 new tests.- The three new drop tests fail against the old code. The feature guard fails with a second default feature, and again with the opt-out removed from the React Native Android script.
cargo clippy --workspace -- -D warnings, and the crate again with--no-default-features.scripts/generate-c-header.sh --checkafter regenerating the header, and the dispatcher generator's--check. The generated dispatcher is unchanged.make -C bindings/c/consumer-check: both link modes pass on macOS.- The quick start compiles under
-std=c99 -Wall -Wextra -Wpedantic -Werror.
Not in this PR
- The release
workflow_dispatchdry run. The Windows.dll.liband macOS install-name steps still have not run in CI. - A Windows leg in the
C BindingCI job.
Third of three stacked PRs; based on #571, which is based on #570. This PR adds the guide for the C API, its rows across the docs, and the release packaging.
bindings/c/README.mdsays where the header and library come from, then gives a quick start, method naming and encoding, events, and the route for other languages. The quick start was compiled with-std=c99 -Wpedantic -Werror, linked and run end to end against the file stores before this commit: it derives an address and queues a message.- Rows wherever the other bindings have one: the docs index, the bridge contract's document table and its "what each binding owes" table, and the README's install table and features line. They also go in the local API chapter, whose method table the C API shares, and in CLAUDE.md (the knowledge table, the regeneration commands, the rules list and the
unsaferule). The CHANGELOG gets an Unreleased entry.
Release packaging
- The desktop archives now carry
offline_protocol.hbeside UniFFI's internaloffline_protocolFFI.h. Their README no longer calls that internal header one "for consumers linking directly", which it never was. It gains a C section with the link line for each platform. - The Windows archive carries
offline_protocol_uniffi.dll.lib. Without it an MSVC linker cannot link the DLL. The Windows build job collects it, and the release verifies it before anything is published. scripts/tests/test-package-release-assets.shasserts both. It gains two missing-input negative controls,missing-c-headerandmissing-windows-import-library, each of which fails with no assets written.
The static archive is deliberately not shipped. Built for release it is 131.6 MiB, against an 11 MiB shared library on macOS arm64. The plan had it in the archives; that size is why it is not. CI still builds and links it, and the guide says how to build it.
Type of change
-
docs: documentation -
chore: release packaging
Checklist
-
cargo fmt --all -- --checkpasses -
cargo clippy --workspace -- -D warningspasses -
cargo test --workspacepasses (32 suites) -
cargo-denyis satisfied - Commits follow Conventional Commits
- Docs /
CHANGELOG.mdupdated - No em dashes in new prose; every relative link resolves
-
test-package-release-assets.sh,check-license-consistency.sh,check-crate-readmes.shand shellcheck pass; actionlint clean
Breaking changes
None. The desktop archives gain files and lose none.
Notes for reviewers
- Not exercised: the release workflow change runs only on a tag or a dispatch. A
workflow_dispatchdry run from this branch would exercise the Windows collection step before the next release.
Second of three stacked PRs; based on #570. This adds the C API itself: twelve extern "C" functions, a committed header, the guards that keep both honest, and a C program that CI compiles and runs.
| Function | Covers |
|---|---|
offline_protocol_create / _free | The engine, from a ProtocolConfig as JSON |
offline_protocol_call | Every declaration the dispatcher reaches, by its local API name |
offline_protocol_call_static | derive_address, parse_invite, verify_identity_assertion, before any engine exists |
offline_protocol_set_event_callback / _poll_event | Events as JSON, pushed or pulled |
offline_protocol_set_transport_callback | The four outbound notifications |
offline_protocol_initialize_mls | Two storage providers written in C |
offline_protocol_run_storage_conformance | The conformance suite against a C provider (C11) |
offline_protocol_string_free / _error_clear / _version | Ownership and version |
The header bindings/c/include/offline_protocol.h is generated by cbindgen 0.29.4, pinned in scripts/generate-c-header.sh. The contract is docs/bridges/c.md.
Decisions that are easy to undo by accident
- Every entry point catches a panic and answers
Internal. A panic that reaches anextern "C"boundary aborts the host process. - Every callback carries a
drop. The library calls it once when it lets go of the callback. That covers a refused registration, and a replaced event callback that is still running on another thread. - A storage answer outside the six named values is read as the operation's own failure, never as
CorruptedData. The engine answers corruption by minting a new record key, which strands every sealed record. - The transport kind is an
int32_t, not the enum type. A value outside an enum's range is undefined behaviour in Rust. - The storage struct's delete member is
remove.deleteis a C++ keyword, and the header compiles as C++. - The header check never uses
cbindgen --verify. That flag reports a stale header and also rewrites it, which I found when it rewrote the committed file during a negative control. The check generates a scratch copy and compares.
Guards
Each was turned red on purpose before pushing:
every_c_entry_point_is_declared_in_the_committed_header: the#[no_mangle]set equals the header's declarations.unsafe_is_confined_to_the_c_boundary:ffi.rs,adapters.rsand their tests are the only files in the crate that writeunsafe. The red run namedhost_log.rs.the_hand_written_declarations_are_the_ones_the_bridge_doc_lists: the generator's skip list equals the table indocs/bridges/c.md.the_storage_status_values_are_the_definitions_positions_plus_one.every_bridge_reads_the_telemetry_config_sectionnow also pins that the C binding fillsos.
The C side
bindings/c/consumer-check is a C99 program built with -Wall -Wextra -Wpedantic -Werror, with its own mutex-guarded storage provider. It is linked against the shared library and then against the static one, run both times, and the header is compiled as C++11. It checks:
- the version, and an instance-less call
- events on the calling thread, matching the polled copy
- every status, including
EncryptFailedat position 6 for a send before storage, which agrees with the local API's -32006 - the conformance suite green against the C provider
initialize_mlsover two C providers yielding anoff1address- the built-in file stores through
offline_protocol_call
It caught one real ordering rule while being written: initialize_mls belongs before start.
The new c-binding CI job runs the header check, the dispatcher generator's --check, the library build and the consumer check, on Ubuntu and macOS.
Type of change
-
feat: new feature
Checklist
-
cargo fmt --all -- --checkpasses -
cargo clippy --workspace -- -D warningspasses. Under--all-targetsthe crate's count is unchanged, 454 pre-existing inlib.rstests and none in the new files. -
cargo test --workspacepasses (32 suites on the tip of the stack; 246 in this crate) -
cargo-denyis satisfied - Commits follow Conventional Commits
- Docs:
docs/bridges/c.mdhere; the guide and index rows in the next PR - New
unsafeonly at the FFI boundary, each block with a SAFETY comment, confined by a guard - The UDL did not change
- actionlint clean on both workflows
Breaking changes
None. These are additive symbols in the existing cdylib and staticlib; nothing existing changes signature.
Notes for reviewers
- Not verified locally: Linux. The consumer check ran on macOS arm64 only. The CI job covers Linux once this stack reaches
main. Windows is linked by no CI job; the next PR ships its import library. - Not a security boundary: the header documents threading and re-entrancy (K2 in the contract). A callback must not call back into the engine, and
offline_protocol_poll_eventis the supported alternative.
First of three stacked PRs that add a C API to the SDK. This one is the safe Rust layer the C functions will sit on. It has no extern "C" yet.
The design is the local API called in process. A method is named as the local API's method table names it: bare for the engine and the namespace, services. and data. for the other two objects. Its parameters are a JSON object keyed by the definition's parameter names, and its result is JSON. The encoding is the local API's:
- Integers are held to their declared width.
- Bytes are padded standard base64.
- Enums use the definition's spelling.
- Omitted dictionary fields take the definition's defaults.
- Unknown keys are refused.
Engine refusals keep the definition's variant name and its zero-based position, the same n as the local API's -32000 - n.
Why JSON rather than one C function per declaration. Events already cross every boundary as JSON (C3), so a C host parses JSON whatever the call surface is. A typed C API would be about 220 functions and 46 structures with nested ownership and nothing to catch drift. And a fixed set of C functions survives every change to the definition, which is what a Go, C# or C++ wrapper needs.
What is in it
capi/generated.rs. One dispatch arm per declaration (211) and the JSON codec of every enum and dictionary. It is generated fromoffline_protocol.udl, checked in, and verified bythe_generated_c_dispatch_is_current. Every arm compiles against the real wrapper signatures, so the compiler checks that the definition and the wrapper agree.tools/capi-dispatch-gen. Writes that file. It is its own workspace, because a declaration renamed in the definition leaves the checked-in file calling the old name, and the FFI crate then does not compile until it is regenerated. That case was exercised: rename, crate red, tool regenerates, crate green.capi/codec.rs. ACodectrait chosen by the wrapper's Rust type. It is not serde on the wrapper types, which have noDeserialize, and whoseSerializespellsTransportTypeaswifiDirectwhere the definition saysWiFiDirect.- The generator refuses a UDL type form or default it has no rule for, rather than guessing.
enable_telemetryfillsconfig.osfrom the build target and refuses one from the caller (C12). The host suppliesos_major.- Eleven declarations take a callback or an object, or construct one. They are listed in
HAND_WRITTENand answered with a pointer to their own entry point, which arrives in the next PR.
Related issues
None filed. The design plan is summarised above.
Type of change
-
feat: new feature
Checklist
-
cargo fmt --all -- --checkpasses -
cargo clippy --workspace -- -D warningspasses -
cargo test --workspacepasses (run on the tip of the stack: 32 suites) -
cargo-denyis satisfied (one new edge to thebase640.22.1 already in the graph) - Commits follow Conventional Commits
- Docs /
CHANGELOG.md: in the third PR of the stack - No new
unsafe(none in this PR) - The UDL did not change
Breaking changes
None. The interface definition, the generated bindings and the wire are unchanged. The only change outside the new module is one line in lib.rs and one dependency edge.
Notes for reviewers
- The stack: this PR, then the
extern "C"layer with header, guards and C consumer check, then docs and release packaging. CI runs only on PRs targetingmain, so the two children get CI once this merges and they are retargeted. - Negative controls run before pushing: renaming one UDL parameter turns the staleness test red.
- Worth scrutiny:
codec.rs'sFields::take_or. Defaults come from the generator's reading of the UDL literal (null,true,false,256are the only forms in use), never from the binding.
Refs #514. Does not close it: the two-phone soak from the issue has to pass first.
Why
PR #516 numbered native events so a loss could be attributed, but found no cause and recovers nothing. Both gap shapes in #514 share one defect: the engine acts irreversibly before it emits the only event that reports the action.
- Receiver: the id is dedup-marked and the ACK sent, then
message_receivedis emitted. A lost emit means the sender has a receipt and the app has nothing. A retry is re-ACKed as a duplicate. - Sender: the pending ACK, retry and outbox entry are removed, then
message_deliveredis emitted. "No retry" in the issue proves the core consumed the ACK.
The hop that lost those three events is unproven. So this PR makes a loss after numbering recoverable, and closes the core-side paths that dropped one before numbering without a trace.
What changes
- Replay instead of report. Kotlin and Swift each keep the last 256 events handed to JavaScript (
EventReplayRing, no React imports), recorded in the same locked block that spends theseq. A newreplayEvents(fromSeq, toSeq)bridge method serves them. On a skipped number,index.tspauses dispatch, pulls the range, and dispatches it in place. Recovery is reported asnative_event_replayed(info).native_event_gapnow reports only what the ring no longer held. The pause is bounded at 2 s and 1024 deferred events. A module withoutreplayEventskeeps the old behaviour.destroy()drops a paused replay, as it drops every held event of a torn-down account. - Held settlements.
message_deliveredandmessage_failedjoinmessage_received,file_receivedandmessage_decryption_failedin the per-message hold, on all three layers. - Poisoned lock.
lock_shared_staterecovers and clears a poisoned mutex. A refusal used to skip the emit for an already ACKed or settled message, and every later one. - Callback failures are visible. A Kotlin exception in
onEventis caught and logged by event type. It used to become a Rust panic recorded only under a target the host logger filters out. The FFI closure isolates a throwing callback so the poll queue still gets the event. Handler panics are counted and logged bytelemetry_name(), no longer by?event, which printed identifiers.
No UDL or wire change, so no binding regeneration.
Verification
| Gate | Result |
|---|---|
js-ci-harness/event-seq-replay.test.js (new, in test:js) | 13/13; ignoring served events fails 5 |
npm run test:js, tsc --noEmit | green |
| Android JVM suite, clean copy | 695/695, EventReplayRingTest 7/7 |
| iOS SwiftPM harness | 466/466, EventReplayRingTests 4/4 |
OfflineProtocolModule.swift typecheck with React headers | clean; planted error reported |
react_native_events_are_numbered_for_gap_detection, react_native_buffered_inbound_event_set_matches_native | pass; removing the Kotlin record call fails the first |
| New core tests | pass; restoring the refusing lock fails the poison test |
cargo fmt --check, clippy -D warnings, cargo test --workspace --lib, cargo doc -D warnings | clean |
Behaviour apps see
A held message_delivered or message_failed can arrive after the app returns to the foreground. UPGRADING ยง28 says to read latency_ms and dedupe on message_id.
Not done
- No device run. Rerun the issue's soak on the Infinix and Seeker with every event logged by
seq(the demo app now logs both gap diagnostics). Acceptance: sent = received = delivered, and no unrecovered gap. - Swift Package and Android Library assembly jobs were not run locally.