fix(sdk): send() returns SendState (Sent|Queued), and build the SDK in CI #51

Merged
sirius merged 7 commits from wt/t_9a29fd3c into main 2026-09-12 23:58:30 +00:00
Owner

crates/onionwire-sdk has not compiled since the outbox work (Node::send() -> Result<OutboxStatus, String>, PR #45): E0308 at crates/onionwire-sdk/src/lib.rs:195. Root CI never compiled the crate (separate cargo workspace) and android-release.yml only builds it on a v*.*.* tag, so a release would have shipped a broken AAR. This PR is the fix plus the CI job that makes the rot impossible.

Send shape (SDK is the consumer boundary)

Wire::send() now returns WResult<SendState>, and SendState is a UniFFI enum -> Kotlin enum class SendState { SENT, QUEUED }:

when (wire.send(friend.pubkeyHex, "hello wire")) {
    SendState.SENT   -> { /* the peer's onion took the frame */ }
    SendState.QUEUED -> { /* local-only: in the outbox, retried with backoff */ }
}

ChatMessage gains delivery: String? = "sent" | "queued" | "sending" | "failed: <reason>" for outgoing rows (read from the message's outbox row), null for incoming. An outgoing row with no outbox row was accepted on the first attempt, so it reads "sent". Both are documented and verified against real generated UniFFI output, not hand-written from memory.

Drift found (item 2)

  • crates/onionwire-sdk/Cargo.lock was stale: the root crate gained sha2 (zeroize work) and the SDK lock did not list it, so cargo build --locked failed with "cannot update the lock file ... because --locked was passed". Updated here; the new CI job runs --locked, which is what caught it.
  • crates/onionwire-sdk/README.md still documented "Fail closed: peer onion down -> the send fails. No outbox, no spool in v1", "a send retries the peer for up to 3 minutes before failing", and "identity keys in sqlite are plaintext". All three are untrue now (outbox, SQLCipher). Rewritten against the actual API.
  • The crate-level doc comment said identity keys in sqlite are not encrypted at rest; same fix.
  • No rusqlite feature change, so no NDK rebuild was required: the SDK host build compiles vendored OpenSSL since SQLCipher landed, and the new job exercises that on every PR.

CI

New sdk job in .forgejo/workflows/ci.yml, same docker runner label and same onionwire-ci-pi concurrency group so it cannot overlap the root job: cargo test --locked && cargo clippy --locked --all-targets -- -D warnings in crates/onionwire-sdk, same rust:1.91-bookworm container, with its own target volume (the SDK resolves the root crate with rustls, so sharing the root job's target dir would thrash both jobs' feature-unified artifacts). The job body was smoke-run locally in the same image before pushing.

Verification

  • RED first: cargo build in the SDK reproduced the card's E0308; the two new unit tests failed to compile against the missing mapping (cannot find function send_state).
  • crates/onionwire-sdk: cargo test 4 passed / 0 failed (2 new), cargo clippy --all-targets -- -D warnings exit 0.
  • Root: cargo test --locked exit 0, 0 failed.

Stack / merge order

Based on feat/tui-msgid-join (PR #50) because it consumes store::Message::id and the outbox API from #45. Merge order: #45 -> #48 -> #50 -> this. Forgejo reports mergeable: false against main until those land - that is the stack, not a conflict.

Left out of scope on purpose (follow-up card filed): android/app's Compose UI still says "Sends fail closed ... There is no outbox in v1." and WireViewModel.send() drops the returned SendState. Kotlin-facing, so it belongs with the app, not this crate.

`crates/onionwire-sdk` has not compiled since the outbox work (`Node::send()` -> `Result<OutboxStatus, String>`, PR #45): E0308 at `crates/onionwire-sdk/src/lib.rs:195`. Root CI never compiled the crate (separate cargo workspace) and `android-release.yml` only builds it on a `v*.*.*` tag, so a release would have shipped a broken AAR. This PR is the fix plus the CI job that makes the rot impossible. ### Send shape (SDK is the consumer boundary) `Wire::send()` now returns `WResult<SendState>`, and `SendState` is a UniFFI enum -> Kotlin `enum class SendState { SENT, QUEUED }`: ```kotlin when (wire.send(friend.pubkeyHex, "hello wire")) { SendState.SENT -> { /* the peer's onion took the frame */ } SendState.QUEUED -> { /* local-only: in the outbox, retried with backoff */ } } ``` `ChatMessage` gains `delivery: String?` = `"sent" | "queued" | "sending" | "failed: <reason>"` for outgoing rows (read from the message's outbox row), `null` for incoming. An outgoing row with no outbox row was accepted on the first attempt, so it reads `"sent"`. Both are documented and verified against real generated UniFFI output, not hand-written from memory. ### Drift found (item 2) * `crates/onionwire-sdk/Cargo.lock` was stale: the root crate gained `sha2` (zeroize work) and the SDK lock did not list it, so `cargo build --locked` failed with *"cannot update the lock file ... because --locked was passed"*. Updated here; the new CI job runs `--locked`, which is what caught it. * `crates/onionwire-sdk/README.md` still documented "Fail closed: peer onion down -> the send fails. No outbox, no spool in v1", "a send retries the peer for up to 3 minutes before failing", and "identity keys in sqlite are plaintext". All three are untrue now (outbox, SQLCipher). Rewritten against the actual API. * The crate-level doc comment said identity keys in sqlite are not encrypted at rest; same fix. * No `rusqlite` feature change, so no NDK rebuild was required: the SDK host build compiles vendored OpenSSL since SQLCipher landed, and the new job exercises that on every PR. ### CI New `sdk` job in `.forgejo/workflows/ci.yml`, same `docker` runner label and same `onionwire-ci-pi` concurrency group so it cannot overlap the root job: `cargo test --locked && cargo clippy --locked --all-targets -- -D warnings` in `crates/onionwire-sdk`, same `rust:1.91-bookworm` container, with its own target volume (the SDK resolves the root crate with `rustls`, so sharing the root job's target dir would thrash both jobs' feature-unified artifacts). The job body was smoke-run locally in the same image before pushing. ### Verification * RED first: `cargo build` in the SDK reproduced the card's E0308; the two new unit tests failed to compile against the missing mapping (`cannot find function send_state`). * `crates/onionwire-sdk`: `cargo test` 4 passed / 0 failed (2 new), `cargo clippy --all-targets -- -D warnings` exit 0. * Root: `cargo test --locked` exit 0, 0 failed. ### Stack / merge order Based on `feat/tui-msgid-join` (PR #50) because it consumes `store::Message::id` and the outbox API from #45. Merge order: **#45 -> #48 -> #50 -> this**. Forgejo reports `mergeable: false` against `main` until those land - that is the stack, not a conflict. Left out of scope on purpose (follow-up card filed): `android/app`'s Compose UI still says "Sends fail closed ... There is no outbox in v1." and `WireViewModel.send()` drops the returned `SendState`. Kotlin-facing, so it belongs with the app, not this crate.
feat(outbox): local retry queue for chat sends
All checks were successful
ci / test (pull_request) Successful in 3m22s
068b655c19
Queue a chat send locally when the peer's v3 onion is unreachable and retry
it with exponential backoff (30s doubling, capped at 30 min, 8 attempts then
terminal Failed). Still peer-to-peer: no server, no store-and-forward relay,
no new frame prefix — every attempt is a fresh Noise IK handshake.

- src/outbox.rs: Outbox + Deliverer + ArtiDeliverer, pure backoff_secs(),
  is_permanent_send_error(), background worker (15s scan).
- store: `outbox` table (no body column — the body is read from the joined
  messages row, under that row's existing AEAD + AAD), append_message_id(),
  queue/due/pending/mark_* helpers, reset_sending_outbox(), wipe.
- Node::send() returns Result<OutboxStatus, String> (Sent/Queued) instead of
  Err on transport failure; protocol errors still fail immediately and are
  never queued.
- Retry triggers: timer, unlock/foreground (spawn_flush_all), and "that peer
  was just seen" (handshake or connect_onion -> spawn_flush_friend).
- File transfer and payment/rcp frames stay fail-closed.
- docs/PROTOCOL.md + docs/THREAT_MODEL.md: replace the no-queue statements;
  add the seizure/cadence delta to the threat model.

src/tui.rs gets one forced arm change (Ok(()) -> Ok(_)); UI surfacing is
child card t_d9a5b065.
Merge remote-tracking branch 'origin/feat/local-outbox' into feat/tui-outbox-state
All checks were successful
ci / test (pull_request) Successful in 3m16s
7c6de696a1
feat(tui): per-message outbox delivery state + N queued footer
All checks were successful
ci / test (pull_request) Successful in 3m20s
ebd3a306e8
Chat rows now carry the state the local outbox actually holds: `✓` delivered,
`◷ queued (try n/8, retry 45s)` while the retry worker still has it, `» sending`
mid-attempt and `✗ failed: <short reason>` once attempts are exhausted. The
footer replaces the flat `sent` / `send failed` copy with the live count
(`2 queued`), and keeps a fail-closed `send failed: …` statement as long as any
row is terminally failed.

States come from the outbox API (`Node::outbox_pending` → `Queued` / `Sending` /
`Failed`; a delivered row is deleted, so absence is `Sent`). No parallel state
model, no new wire prefix. Every new glyph has an ASCII fallback (`ok` plus the
state word) exercised by a test.

- `chat_with_delivery()` / `delivery_tag()` / `retry_in_text()` /
  `short_send_reason()` / `OutboxSummary::note()` are pure and unit-tested.
- `draw_chat()` is now the real chat-pane renderer (extracted from
  `App::draw_main`) so width/wrap is testable without a `Node`.
- docs/TUI.md: delivery markers, copy, and the 80x24 floor / 120x40 target.

Verified: cargo test 26/26 suites ok (tui_spec 20/20, incl. a real Store +
Outbox::send -> pending() -> render path); clippy --all-targets -D warnings clean.
feat(tui): join outbox rows to chat rows by message id
All checks were successful
ci / test (pull_request) Successful in 3m27s
afff5f8dff
`chat_with_delivery` matched pending outbox rows to chat rows by body
because `store::Message` carried no id, so an older send that was still
queued showed a delivered mark whenever a newer send of the same text had
already crossed the circuit.

`store::Message` now carries its `messages.id`, and the TUI joins
`OutboxEntry::message_id` == `Message::id`. The body match and its
newest-first fallback are gone.

`list_messages()` keeps its signature; callers that do not need the id
are untouched.
fix(sdk): surface Sent/Queued on send(), and build the SDK in CI
All checks were successful
ci / test (pull_request) Successful in 3m37s
ci / sdk (pull_request) Successful in 10m7s
08a4accf37
`Node::send()` became `Result<OutboxStatus, String>` in the local-outbox work,
which broke `crates/onionwire-sdk` (E0308 at src/lib.rs:195) — and nothing
noticed, because the SDK is a separate cargo workspace that root CI never
compiles and android-release.yml only builds on a v*.*.* tag.

- `Wire::send()` now returns `WResult<SendState>` (`Sent` | `Queued`) instead
  of swallowing the outcome as `()`. A queued send is local-only until the
  retry worker gets a circuit through, so the Kotlin boundary must be able to
  tell it apart from a delivered one.
- `ChatMessage` gains `delivery: Option<String>` ("sent" | "queued" |
  "sending" | "failed: <reason>"), populated from the message's outbox row;
  `None` for incoming messages. An outgoing row with no outbox row was accepted
  on the first attempt, so it reads "sent".
- New `sdk` job in `.forgejo/workflows/ci.yml`: `cargo test --locked` +
  `cargo clippy --locked --all-targets -- -D warnings` in `crates/onionwire-sdk`
  in the same rust:1.91-bookworm container, with its own target volume (the SDK
  resolves the root crate with rustls, so sharing the root job's target dir
  would thrash feature-unified artifacts).
- Drift found while un-rotting it: the SDK `Cargo.lock` was stale (missing
  `sha2`, added to the root crate by the zeroize work), so `--locked` failed;
  and the SDK README still said "no outbox, no spool in v1" and "identity keys
  in sqlite are plaintext", both untrue since the outbox and SQLCipher landed.

Tests: crates/onionwire-sdk 4 passed (2 new unit tests over the status
mapping), clippy clean; root `cargo test --locked` clean. The CI job body was
smoke-run locally in the same container image before being committed.
sirius changed target branch from main to feat/tui-msgid-join 2026-09-12 21:10:58 +00:00
sirius force-pushed wt/t_9a29fd3c from 08a4accf37
All checks were successful
ci / test (pull_request) Successful in 3m37s
ci / sdk (pull_request) Successful in 10m7s
to 0de5f7b220
All checks were successful
ci / test (pull_request) Successful in 3m2s
ci / sdk (pull_request) Successful in 55s
2026-09-12 21:10:58 +00:00
Compare
sirius force-pushed wt/t_9a29fd3c from 0de5f7b220
All checks were successful
ci / test (pull_request) Successful in 3m2s
ci / sdk (pull_request) Successful in 55s
to 168727ac39
All checks were successful
ci / test (pull_request) Successful in 4m5s
ci / sdk (pull_request) Successful in 6m47s
2026-09-12 21:15:30 +00:00
Compare
sirius changed target branch from feat/tui-msgid-join to main 2026-09-12 22:14:38 +00:00
sirius force-pushed wt/t_9a29fd3c from 168727ac39
All checks were successful
ci / test (pull_request) Successful in 4m5s
ci / sdk (pull_request) Successful in 6m47s
to 381f424733
All checks were successful
ci / test (pull_request) Successful in 3m56s
ci / sdk (pull_request) Successful in 1m6s
2026-09-12 22:14:40 +00:00
Compare
The SDK has returned `SendState` and a per-row `ChatMessage.delivery` since
the local outbox landed, but the app still said "there is no outbox in v1"
and threw the state away.

- `WireViewModel.send()` returns `SendState`; `ChatScreen` no longer discards
  it. A `QUEUED` send raises a "local-only until the retry worker gets a
  circuit through" hint instead of pretending success.
- Outgoing rows render the TUI's delivery markers from `ChatMessage.delivery`
  (`✓` / `◷ queued` / `» sending` / `✗ failed: <reason>`), plus the TUI's
  `{n} queued` footer while the outbox still owns rows. Incoming rows stay
  unmarked; an unreadable state renders no marker rather than a tick.
- The empty-chat copy describes the outbox (8 attempts, backoff capped at
  30 min, local-only until it lands) instead of denying it exists.
- New pure `Delivery.kt` so the vocabulary is unit-testable without a device.

Verified: `./gradlew :app:assembleDebug :app:testDebugUnitTest` → BUILD
SUCCESSFUL, 15 tests / 0 failures (10 new), APK contains the new copy and no
longer the "There is no outbox" string. Stacked on the SDK fix (PR #51).
Merge pull request 'fix(android): surface the outbox send state instead of denying it' (#52) from wt/t_7233051b into wt/t_9a29fd3c
All checks were successful
ci / test (pull_request) Successful in 3m54s
ci / sdk (pull_request) Successful in 58s
6867a6c430
Reviewed-on: #52
sirius force-pushed wt/t_9a29fd3c from 6867a6c430
All checks were successful
ci / test (pull_request) Successful in 3m54s
ci / sdk (pull_request) Successful in 58s
to 6796f861e0
All checks were successful
ci / test (pull_request) Successful in 3m55s
ci / sdk (pull_request) Successful in 58s
2026-09-12 23:13:44 +00:00
Compare
sirius force-pushed wt/t_9a29fd3c from 6796f861e0
All checks were successful
ci / test (pull_request) Successful in 3m55s
ci / sdk (pull_request) Successful in 58s
to f2dcd79d5c
All checks were successful
ci / test (pull_request) Successful in 3m56s
ci / sdk (pull_request) Successful in 53s
2026-09-12 23:14:53 +00:00
Compare
Renders the core's own Queued/Sending/Sent/Failed per outgoing row instead of
implying a message either sent or did not: a clock for queued, a progress
spinner for sending, a double-check for delivered and an error marker with the
short reason for a terminal failure, plus a chat-level `N queued` footer that
keeps a fail-closed `send failed: <reason>` statement on screen.

States are read verbatim from ChatMessage.delivery (Node::outbox_status_of_message
over UniFFI) — no parallel enum, nothing guessed from a timeout. A missing or
unrecognised status renders as queued, never delivered.

WireViewModel.send() now returns the SDK SendState instead of dropping it, so the
composer can say a send is queued rather than pretend it landed, and the empty-chat
copy no longer claims 'there is no outbox in v1'.

Accessibility: every marker carries an explicit contentDescription sentence and a
test tag; the glyph is never what a screen reader announces.
The TUI can say why a queued row is still queued ('queued (try n/8,
retry 45s)') because it reads OutboxEntry::attempts and next_attempt_at
directly. The SDK exposed neither: ChatMessage.delivery is a flat
'queued'/'sending'/'failed: <reason>' string and Wire had no outbox
accessor, so an Android chat row could only invent a countdown.

Adds OutboxRow { message_id, status, attempts, next_attempt_at,
last_error } and Wire::outbox(pubkey_hex) over Node::outbox_pending, plus
outbox_max_attempts() so the client renders 'try n/8' against the core's
own budget instead of a hardcoded 8. Additive: Wire::send() and
ChatMessage.delivery are untouched.

# Conflicts:
#	crates/onionwire-sdk/src/lib.rs
`OutboxRow::message_id` documents itself as *the* join key (the
`messages.id` a `ChatMessage` belongs to), but the record carried no id,
so the Android client could only pair the two lists positionally.

Add `ChatMessage.id: i64` as the first field, copied straight from the
`messages.id` the store already selects. Additive over UniFFI: Kotlin
consumers only gain a constructor field and the bindings regenerate.

The id mapping moves into a `chat_message` helper so the join property is
testable without a Node: the new test builds a real store, queues an
outbox row for a message, and asserts the id on the message equals the
`message_id` the outbox row reports for that same row.

# Conflicts:
#	crates/onionwire-sdk/src/lib.rs
feat(android): chat row renders queued (try 3/8, retry 45s) from the SDK's outbox rows
All checks were successful
ci / test (pull_request) Successful in 3m55s
ci / sdk (pull_request) Successful in 1m2s
fc2b2197c7
Consumes the SDK surface from PR #58 (`Wire.outbox(pubkeyHex)` →
`OutboxRow { messageId, status, attempts, nextAttemptAt, lastError }` and
`outboxMaxAttempts()`): a queued chat row now says *why* it is still queued
instead of a flat `queued`.

* `OutboxDetail.kt` — `retryInText` mirrors `src/tui.rs::retry_in_text`
  (`<= 0` → `retry now`; `< 60` → `retry {n}s`; else `retry {ceil-minutes}m`),
  and `outboxDetails` joins the SDK's rows onto the chat rows. The denominator
  is the core's `outboxMaxAttempts()`/`Rust` budget, fetched once — never 8.
* A terminal `"failed"` row keeps the marker's own `failed: <reason>` and gets
  **no** countdown: `nextAttemptAt` on a failed row is the last time it was
  scheduled for, so a countdown there would promise an attempt that never comes.
  `"sending"` stays bare, matching the TUI.
* `ChatScreen` polls the outbox rows on the same 2s cadence as the bodies and
  renders the countdown against an injectable `nowSeconds` (the store holds an
  absolute instant, the app computes the age).
* The join is positional — `ChatMessage` carries no `messages.id` — and
  fail-closed: mismatched row counts, an unknown status, or a status that
  contradicts the one the SDK resolved for that message drops every detail and
  leaves the flat markers. `ChatMessage.id` would remove the positional part;
  filed as follow-up.
* `OutboxDetailTest` (17 tests) asserts the three `retry_in_text` buckets, the
  `queued (try 3/8, retry 45s)` wording, that a failed row shows no countdown,
  that the denominator comes from the caller, and the three fail-closed cases.
  32 unit tests, 0 failures.

Android base: PR #56 (`feat/android-outbox-state`, t_f46a9863) — the Android
half of the #52/#56 duplicate pair, which is not merged here. SDK base: PR #58
on PR #51.
Reviewed-on: #58
Reviewed-on: #56
sirius merged commit a8aa3098c7 into main 2026-09-12 23:58:30 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!51
No description provided.