feat(sdk): expose outbox rows (attempts + next attempt time) behind a queued chat message #58

Merged
sirius merged 3 commits from feat/sdk-outbox-rows into feat/android-outbox-state 2026-09-12 23:58:01 +00:00
Owner

What

Card t_d6cabc4b — the SDK half of the unmet sub-item in t_f46a9863 ("queued (with age or attempt count)"): the TUI can render queued (try n/8, retry 45s) from OutboxEntry::attempts / next_attempt_at (src/store.rs:149), but crates/onionwire-sdk exposed neither field, so an Android chat row could only invent a countdown. Additive accessor only — no new state model, OutboxStatus stays the only source of truth.

pub struct OutboxRow {
    pub message_id: i64,        // messages.id — the join key the chat already has
    pub status: String,         // the store's own encoding: "queued" | "sending" | "failed"
    pub attempts: u32,          // compare against outbox_max_attempts()
    pub next_attempt_at: i64,   // absolute unix seconds; client counts down from now
    pub last_error: Option<String>,
}

impl Wire {
    pub async fn outbox(&self, pubkey_hex: String) -> WResult<Vec<OutboxRow>>;
}
pub fn outbox_max_attempts() -> u32;  // the "8" in "try n/8"

outbox() maps Node::outbox_pending (src/node.rs:557) row-for-row. outbox_max_attempts() exists because a Kotlin consumer cannot read onionwire::outbox::DEFAULT_MAX_ATTEMPTS; without it the Android row would hardcode 8 and silently drift from the core's retry budget. It is a free function, not a Wire method: it is a core constant, not per-node state.

status never reads "sent" from this accessor — a delivered outbox row is deleted before it can be read (Store::mark_outbox_sent). next_attempt_at is only meaningful while status == "queued": a terminal "failed" row keeps the last time it was scheduled for, so a client must not render it as a countdown (documented on the field).

Base is wt/t_9a29fd3c, not main (on purpose)

main's crates/onionwire-sdk/src/lib.rs does not compile against main's outbox API: its send() still returns WResult<()> while Node::send returns Result<OutboxStatus, String>. PR #51 (wt/t_9a29fd3c) is the fix and is still open, so this branch is cut from its head. Retarget this PR to main once #51 is merged — until then the base keeps the diff to my own commit instead of swallowing #51's. The change is independent of #51's content: it touches only the new OutboxRow / outbox() / outbox_max_attempts() surface and the test module, so a textual conflict, if any, is one hunk in crates/onionwire-sdk/src/lib.rs.

Evidence

  • cargo test --locked in crates/onionwire-sdk — 6 lib tests, 2 integration tests, 0 failures:
    • tests::outbox_row_carries_the_join_key_the_attempt_count_and_the_next_attempt_time
    • tests::outbox_row_keeps_the_stores_own_status_encoding
    • tests::a_failed_outbox_row_carries_the_cores_reason_verbatim
    • tests::outbox_max_attempts_is_the_denominator_a_client_renders_against
    • (plus the pre-existing sent_is_sent_everything_else_is_queued, delivery_is_reported_for_outgoing_rows_only)
  • cargo clippy --locked --all-targets -- -D warnings — exit 0.
  • Generated Kotlin (uniffi-bindgen --library libonionwire_sdk.so --language kotlin):
data class OutboxRow (
    var `messageId`: kotlin.Long,
    var `status`: kotlin.String,
    var `attempts`: kotlin.UInt,
    var `nextAttemptAt`: kotlin.Long,
    var `lastError`: kotlin.String?
)
suspend fun `outbox`(`pubkeyHex`: kotlin.String): List<OutboxRow>
fun `outboxMaxAttempts`(): kotlin.UInt

Wire::send() -> SendState and ChatMessage.delivery are untouched, so #51/#52/#56 keep working.

Not in this PR

  • android/** consumption (the row text queued (try n/8, retry 45s) and the N queued footer wording) — that is a separate card, as the board requires.
## What Card `t_d6cabc4b` — the SDK half of the unmet sub-item in `t_f46a9863` ("queued (with age or attempt count)"): the TUI can render `queued (try n/8, retry 45s)` from `OutboxEntry::attempts` / `next_attempt_at` (`src/store.rs:149`), but `crates/onionwire-sdk` exposed neither field, so an Android chat row could only invent a countdown. Additive accessor only — no new state model, `OutboxStatus` stays the only source of truth. ```rust pub struct OutboxRow { pub message_id: i64, // messages.id — the join key the chat already has pub status: String, // the store's own encoding: "queued" | "sending" | "failed" pub attempts: u32, // compare against outbox_max_attempts() pub next_attempt_at: i64, // absolute unix seconds; client counts down from now pub last_error: Option<String>, } impl Wire { pub async fn outbox(&self, pubkey_hex: String) -> WResult<Vec<OutboxRow>>; } pub fn outbox_max_attempts() -> u32; // the "8" in "try n/8" ``` `outbox()` maps `Node::outbox_pending` (`src/node.rs:557`) row-for-row. `outbox_max_attempts()` exists because a Kotlin consumer cannot read `onionwire::outbox::DEFAULT_MAX_ATTEMPTS`; without it the Android row would hardcode `8` and silently drift from the core's retry budget. It is a free function, not a `Wire` method: it is a core constant, not per-node state. `status` never reads `"sent"` from this accessor — a delivered outbox row is deleted before it can be read (`Store::mark_outbox_sent`). `next_attempt_at` is only meaningful while `status == "queued"`: a terminal `"failed"` row keeps the last time it was scheduled for, so a client must not render it as a countdown (documented on the field). ## Base is `wt/t_9a29fd3c`, not `main` (on purpose) `main`'s `crates/onionwire-sdk/src/lib.rs` does **not compile** against `main`'s outbox API: its `send()` still returns `WResult<()>` while `Node::send` returns `Result<OutboxStatus, String>`. PR #51 (`wt/t_9a29fd3c`) is the fix and is still open, so this branch is cut from its head. **Retarget this PR to `main` once #51 is merged** — until then the base keeps the diff to my own commit instead of swallowing #51's. The change is independent of #51's content: it touches only the new `OutboxRow` / `outbox()` / `outbox_max_attempts()` surface and the test module, so a textual conflict, if any, is one hunk in `crates/onionwire-sdk/src/lib.rs`. ## Evidence * `cargo test --locked` in `crates/onionwire-sdk` — 6 lib tests, 2 integration tests, 0 failures: * `tests::outbox_row_carries_the_join_key_the_attempt_count_and_the_next_attempt_time` * `tests::outbox_row_keeps_the_stores_own_status_encoding` * `tests::a_failed_outbox_row_carries_the_cores_reason_verbatim` * `tests::outbox_max_attempts_is_the_denominator_a_client_renders_against` * (plus the pre-existing `sent_is_sent_everything_else_is_queued`, `delivery_is_reported_for_outgoing_rows_only`) * `cargo clippy --locked --all-targets -- -D warnings` — exit 0. * Generated Kotlin (`uniffi-bindgen --library libonionwire_sdk.so --language kotlin`): ```kotlin data class OutboxRow ( var `messageId`: kotlin.Long, var `status`: kotlin.String, var `attempts`: kotlin.UInt, var `nextAttemptAt`: kotlin.Long, var `lastError`: kotlin.String? ) suspend fun `outbox`(`pubkeyHex`: kotlin.String): List<OutboxRow> fun `outboxMaxAttempts`(): kotlin.UInt ``` `Wire::send() -> SendState` and `ChatMessage.delivery` are untouched, so #51/#52/#56 keep working. ## Not in this PR * `android/**` consumption (the row text `queued (try n/8, retry 45s)` and the `N queued` footer wording) — that is a separate card, as the board requires.
feat(sdk): expose the outbox rows behind a queued chat message
All checks were successful
ci / test (pull_request) Successful in 3m4s
ci / sdk (pull_request) Successful in 57s
c6a586c2da
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.
sirius force-pushed feat/sdk-outbox-rows from c6a586c2da
All checks were successful
ci / test (pull_request) Successful in 3m4s
ci / sdk (pull_request) Successful in 57s
to 6437f9ee90
All checks were successful
ci / test (pull_request) Successful in 3m0s
ci / sdk (pull_request) Successful in 55s
2026-09-12 21:11:04 +00:00
Compare
sirius force-pushed feat/sdk-outbox-rows from 6437f9ee90
All checks were successful
ci / test (pull_request) Successful in 3m0s
ci / sdk (pull_request) Successful in 55s
to f304f78628
All checks were successful
ci / test (pull_request) Successful in 2m59s
ci / sdk (pull_request) Successful in 54s
2026-09-12 21:12:02 +00:00
Compare
sirius force-pushed feat/sdk-outbox-rows from f304f78628
All checks were successful
ci / test (pull_request) Successful in 2m59s
ci / sdk (pull_request) Successful in 54s
to 37742a5e09
Some checks failed
ci / test (pull_request) Successful in 3m55s
ci / sdk (pull_request) Failing after 25s
2026-09-12 21:16:05 +00:00
Compare
sirius force-pushed feat/sdk-outbox-rows from 37742a5e09
Some checks failed
ci / test (pull_request) Successful in 3m55s
ci / sdk (pull_request) Failing after 25s
to 1d52df8529
Some checks failed
ci / test (pull_request) Has been cancelled
ci / sdk (pull_request) Has been cancelled
2026-09-12 21:16:42 +00:00
Compare
ci: re-run after self.inner fix (E0609 on 37742a5)
All checks were successful
ci / test (pull_request) Successful in 4m22s
ci / sdk (pull_request) Successful in 1m1s
5962c6a229
sirius force-pushed feat/sdk-outbox-rows from 5962c6a229
All checks were successful
ci / test (pull_request) Successful in 4m22s
ci / sdk (pull_request) Successful in 1m1s
to cce0721ba9
All checks were successful
ci / test (pull_request) Successful in 3m57s
ci / sdk (pull_request) Successful in 1m1s
2026-09-12 22:15:14 +00:00
Compare
feat(sdk): ChatMessage.id — join a chat row to its outbox row
All checks were successful
ci / test (pull_request) Successful in 3m52s
ci / sdk (pull_request) Successful in 59s
c969e60185
`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
Merge pull request 'feat(sdk): ChatMessage.id — join a chat row to its outbox row' (#61) from wt/t_254f9025 into feat/sdk-outbox-rows
All checks were successful
ci / test (pull_request) Successful in 3m57s
ci / sdk (pull_request) Successful in 1m4s
febc963421
Reviewed-on: #61
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.
Merge pull request 'feat(android): chat row renders queued (try 3/8, retry 45s) from the SDK outbox rows' (#59) from wt/t_f8658427 into feat/sdk-outbox-rows
All checks were successful
ci / test (pull_request) Successful in 3m54s
ci / sdk (pull_request) Successful in 54s
563388d18d
Reviewed-on: #59
sirius changed target branch from wt/t_9a29fd3c to feat/android-outbox-state 2026-09-12 23:15:09 +00:00
sirius force-pushed feat/sdk-outbox-rows from 563388d18d
All checks were successful
ci / test (pull_request) Successful in 3m54s
ci / sdk (pull_request) Successful in 54s
to fc2b2197c7
All checks were successful
ci / test (pull_request) Successful in 3m55s
ci / sdk (pull_request) Successful in 1m2s
2026-09-12 23:15:11 +00:00
Compare
sirius merged commit a948627896 into feat/android-outbox-state 2026-09-12 23:58:01 +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!58
No description provided.